-- USE mydb;
CREATE TABLE `HOLDEM_BET_HIST` (
  `HOLDEM_BET_IDX` bigint(21) unsigned NOT NULL AUTO_INCREMENT COMMENT 'uniqe idx',
  `REG_DTM` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'reg_dt',
  `MBR_IDX` int(11) NOT NULL DEFAULT 0 COMMENT 'member id',
  `GAME_NUM` int(11) NOT NULL DEFAULT 0 COMMENT 'round num',
  `START_MONEY` int(11) unsigned NOT NULL DEFAULT 0 COMMENT 'start money',
  `BET_MONEY` int(11) unsigned NOT NULL DEFAULT 0 COMMENT 'betting money',
  `FINAL_MONEY` int(11) NOT NULL DEFAULT 0 COMMENT 'final money',
  `WIN_MONEY` int(11) NOT NULL DEFAULT 0 COMMENT 'win money',
  `STACK` int(11) NOT NULL DEFAULT 0,
  `UPDATE_DT` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `EVENT` varchar(45) NOT NULL DEFAULT '',
  `FEE` decimal(7,2) NOT NULL DEFAULT 0.00,
  `CALL_BACK_DATA` text DEFAULT '',
  PRIMARY KEY (`HOLDEM_BET_IDX`),
  KEY `REG_DTM_INDEX` (`REG_DTM`),
  KEY `MBR_ID_INDEX` (`MBR_IDX`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='holdem bet table';

CREATE TABLE `HOLDEM_CALL_BACK_DATA` (
  `IDX` bigint(21) unsigned NOT NULL AUTO_INCREMENT COMMENT 'uniqe idx',
  `MBR_IDX` int(11) NOT NULL COMMENT 'member idx',
  `MONEY` int(11) DEFAULT 0,
  `EVENT` varchar(45) NOT NULL DEFAULT '',
  `DATA` text DEFAULT NULL,
  `CREATE_DT` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`IDX`),
  KEY `MBR_IDX` (`MBR_IDX`),
  KEY `CREATE_DT` (`CREATE_DT`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='holdem call back data';


CREATE 
    OR REPLACE ALGORITHM = UNDEFINED 
    SQL SECURITY DEFINER
VIEW day_holdem_view AS
    SELECT 
        IFNULL(SUM(CBH.BET_MONEY), 0) AS total_bet_money,
        IFNULL(SUM(CBH.WIN_MONEY), 0) AS total_win_money
    FROM
        (member MB
        LEFT JOIN HOLDEM_BET_HIST CBH ON (MB.idx = CBH.MBR_IDX))
    WHERE
        CBH.UPDATE_DT >= DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%m-%d 00:00:00')
            AND CBH.UPDATE_DT <= DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%m-%d 23:59:59')
            AND MB.level <> 9
            AND MB.u_business = 1;

ALTER TABLE `member` 
ADD COLUMN `is_holdem_register` ENUM('Y', 'N') NULL DEFAULT 'N' COMMENT '홀덤 가입 여부' AFTER `info_change_dt`;

ALTER TABLE `member` 
ADD COLUMN `is_holdem_start` ENUM('Y', 'N') NULL DEFAULT 'N' COMMENT '홀덤 세션시작 여부' AFTER `is_holdem_register`;

ALTER TABLE `member` 
ADD COLUMN `is_holdem_start_dt` DATETIME NULL DEFAULT CURRENT_TIMESTAMP() COMMENT '홀덤 최근 플레이 시간' AFTER `is_holdem_start`;


ALTER TABLE `shop_config` 
ADD COLUMN `bet_holdem_fee` DECIMAL(7,2) NULL DEFAULT 0.00 AFTER `bet_hash_fee`;

ALTER TABLE `shop_calculate_result` 
ADD COLUMN `total_holdem_bet_money` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `total_espt_bet_money`,
ADD COLUMN `bet_holdem_fee` DECIMAL(7,2) NULL DEFAULT 0.00 AFTER `bet_hash_fee`;

ALTER TABLE `shop_calculate_result` 
ADD COLUMN `holdem_bet_take` DECIMAL(11,2) NULL DEFAULT '0.00' AFTER `espt_bet_take`;

/*ALTER TABLE `shop_calculate_result` 
ADD COLUMN `pre_bet_take_s` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `bet_holdem_fee`,
ADD COLUMN `pre_bet_take_d` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `pre_bet_take_s`,
ADD COLUMN `real_bet_take_s` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `pre_bet_take_d`,
ADD COLUMN `real_bet_take_d` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `real_bet_take_s`,
ADD COLUMN `mini_bet_take` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `real_bet_take_d`,
ADD COLUMN `slot_bet_take` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `mini_bet_take`,
ADD COLUMN `hash_bet_take` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `slot_bet_take`,
ADD COLUMN `espt_bet_take` DECIMAL(11,2) NULL DEFAULT 0.00 AFTER `hash_bet_take`;*/


ALTER TABLE `total_member_cash` 
ADD COLUMN `holdem_total_money` BIGINT(20) NULL DEFAULT 0 AFTER `take_hash_total_money`,
ADD COLUMN `take_holdem_total_money` BIGINT(20) NULL DEFAULT 0 AFTER `holdem_total_money`;

-- USE `mydb`;
DROP procedure IF EXISTS `insert_total_member_cash`;

DELIMITER $$
CREATE PROCEDURE `insert_total_member_cash`(IN dt_start DATETIME, IN dt_end DATETIME)
BEGIN
-- 커서에서사용할Select 테이블선언
		 DECLARE v_member_idx,v_charge_total_count,v_charge_total_money,v_exchange_total_count,v_exchange_total_money, 
         v_loock_up_total_count,v_bet_total_count,v_bet_total_money,v_pre_s_total_money,v_pre_m_total_money,
         v_real_s_total_money,v_real_m_total_money,v_mini_total_money,v_take_total_money,v_take_mini_total_money,
         v_take_real_m_total_money,v_take_real_s_total_money,v_take_pre_m_total_money,v_take_pre_s_total_money,
         v_casino_total_bet_money,v_casino_total_win_money,v_slot_total_bet_money,v_slot_total_win_money,
		 v_espt_total_bet_money, v_espt_total_win_money, v_hash_total_bet_money, v_hash_total_win_money,
         v_holdem_total_bet_money, v_holdem_total_win_money int;
                          
         DECLARE done INTEGER DEFAULT 0;
         
         DEClARE openCursor CURSOR FOR 
         SELECT 
         mb.idx AS member_idx,
         IFNULL(mb_ch_his.ch_cnt,0) AS charge_total_count,
         IFNULL(mb_ch_his.ch_sum,0) AS charge_total_money,
         IFNULL(mb_ex_his.ex_cnt,0) AS exchange_total_count,
         IFNULL(mb_ex_his.ex_sum, 0) AS exchange_total_money, 
         IFNULL(loock.loock_cnt,0) AS loock_up_total_count,
	     IFNULL(mini_bet.mini_count,0) + IFNULL(mb_cnt_bet.mb_cnt_count,0) + IFNULL(mb_casino.cs_cnt_count,0) + IFNULL(mb_slot.sl_cnt_count,0) + IFNULL(mb_espt.esp_cnt_count,0) + IFNULL(mb_hash.hs_cnt_count,0) + IFNULL(mb_holdem.holdem_cnt_count,0) AS bet_total_count,
         IFNULL(bet.pre_bet_sum_s, 0) + IFNULL(bet.pre_bet_sum_d, 0) +  IFNULL(bet.real_bet_sum_s, 0) + IFNULL(bet.real_bet_sum_d, 0) 
         AS bet_total_money,
         IFNULL(bet.pre_bet_sum_s, 0) AS pre_s_total_money,
         IFNULL(bet.pre_bet_sum_d, 0) AS pre_m_total_money,
         IFNULL(bet.real_bet_sum_s, 0) AS real_s_total_money,
         IFNULL(bet.real_bet_sum_d, 0) AS real_m_total_money,
         IFNULL(mg_bet.mini_bet_sum_d, 0) AS mini_total_money,
		 IFNULL(bet.pre_take_sum_s, 0) +  IFNULL(bet.pre_take_sum_d, 0)  +  IFNULL(bet.real_take_sum_s, 0) + IFNULL(bet.real_take_sum_d, 0)
         AS take_total_money,
		 IFNULL(mg_bet.mini_take_sum_d, 0) AS take_mini_total_money,
         IFNULL(bet.real_take_sum_d, 0) AS take_real_m_total_money,
	     IFNULL(bet.real_take_sum_s, 0) AS take_real_s_total_money,
         IFNULL(bet.pre_take_sum_d, 0) AS take_pre_m_total_money,
         IFNULL(bet.pre_take_sum_s, 0) AS take_pre_s_total_money,
         
         IFNULL(mb_casino.casino_total_bet_money, 0) AS casino_total_bet_money,
         IFNULL(mb_casino.casino_total_win_money, 0) AS casino_total_win_money,
         
         IFNULL(mb_slot.slot_total_bet_money, 0) AS slot_total_bet_money,
         IFNULL(mb_slot.slot_total_win_money, 0) AS slot_total_win_money,

         IFNULL(mb_espt.espt_total_bet_money, 0) AS espt_total_bet_money,
         IFNULL(mb_espt.espt_total_win_money, 0) AS espt_total_win_money,
         IFNULL(mb_hash.hash_total_bet_money, 0) AS hash_total_bet_money,
         IFNULL(mb_hash.hash_total_win_money, 0) AS hash_total_win_money,
         
         IFNULL(mb_holdem.holdem_total_bet_money, 0) AS holdem_total_bet_money,
         IFNULL(mb_holdem.holdem_total_win_money, 0) AS holdem_total_win_money
		FROM (SELECT m.idx, m.id, m.nick_name from member AS m ) AS mb
    LEFT JOIN 
        (SELECT IFNULL(sum(ch_his.money), 0) AS ch_sum,
            count(idx) AS ch_cnt,
            ch_his.member_idx AS member_idx
            FROM member_money_charge_history AS ch_his 
            WHERE ch_his.status = 3
             AND ch_his.update_dt >= dt_start
             AND ch_his.update_dt <= dt_end
            GROUP BY ch_his.member_idx) AS mb_ch_his 
    ON 
    mb.idx =  mb_ch_his.member_idx
    LEFT JOIN 
        (SELECT IFNULL(sum(ex_his.money), 0) AS ex_sum,
            count(idx) AS ex_cnt,
            ex_his.member_idx AS member_idx
            FROM member_money_exchange_history AS ex_his 
            WHERE ex_his.status = 3
            AND ex_his.update_dt >= dt_start
            AND ex_his.update_dt <= dt_end
            GROUP BY ex_his.member_idx) AS mb_ex_his
    ON mb.idx =  mb_ex_his.member_idx
    LEFT JOIN 
	    (SELECT 
        mb_bet.member_idx AS member_idx,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0) AS pre_bet_sum_s,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS pre_take_sum_s,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0)
            - 	IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS pre_sum_s,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0) AS pre_bet_sum_d,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS pre_take_sum_d,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0)
            - 	IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 1 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS pre_sum_d,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0) AS real_bet_sum_s,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS real_take_sum_s,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0)
            - 	IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'S'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS real_sum_s,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0) AS real_bet_sum_d,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS real_take_sum_d,
            IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.total_bet_money ELSE 0 END), 0)
            - 	IFNULL(SUM(CASE 
                        WHEN mb_bet.bet_type = 2 AND mb_bet.folder_type = 'D'
                        THEN mb_bet.take_money ELSE 0 END), 0) AS real_sum_d
	FROM member_bet AS mb_bet
        WHERE mb_bet.bet_status = 3
        AND mb_bet.calculate_dt >= dt_start
        AND mb_bet.calculate_dt <= dt_end
        AND total_bet_money != take_money
	GROUP BY mb_bet.member_idx) AS bet
    ON 
    mb.idx =  bet.member_idx
 LEFT JOIN 
	(SELECT mg.member_idx AS member_idx,
	    IFNULL(sum(mg.total_bet_money), 0) AS mini_bet_sum_d,
        IFNULL(sum(mg.take_money), 0) AS mini_take_sum_d,
        IFNULL(sum(mg.total_bet_money), 0) - IFNULL(sum(mg.take_money), 0) AS mini_sum_d
	FROM mini_game_member_bet AS mg
	WHERE mg.bet_status = 3  
        AND mg.calculate_dt >= dt_start
        AND mg.calculate_dt <= dt_end
        AND mg.total_bet_money != take_money
    GROUP BY mg.member_idx) AS mg_bet
    ON 
    mb.idx =  mg_bet.member_idx  
 LEFT JOIN
  (SELECT count(idx) as loock_cnt
  ,member_idx
  FROM t_log_cash
  WHERE   ac_code IN(103) 
         AND t_log_cash.reg_time >= dt_start
         AND t_log_cash.reg_time <= dt_end
        ) as loock
   ON mb.idx = loock.member_idx      
 LEFT JOIN 
	(SELECT count(idx) as mini_count
    ,member_idx
	FROM mini_game_member_bet AS mg
	WHERE mg.bet_status = 3  
         AND mg.calculate_dt >= dt_start
         AND mg.calculate_dt <= dt_end
    
    GROUP BY mg.member_idx) AS mini_bet
    ON 
    mb.idx =  mini_bet.member_idx    
 LEFT JOIN 
	(SELECT count(idx) as mb_cnt_count
    ,member_idx
	FROM member_bet AS mg
	WHERE mg.bet_status = 3  
         AND mg.calculate_dt >= dt_start
         AND mg.calculate_dt <= dt_end
    
    GROUP BY mg.member_idx) AS mb_cnt_bet
    ON 
    mb.idx =  mb_cnt_bet.member_idx 
 LEFT JOIN  -- 카지노 
    (SELECT count(CSN_BET_IDX) as cs_cnt_count,
		MBR_IDX,
        IFNULL(SUM(`BET_MNY`), 0) AS `casino_total_bet_money`,
        IFNULL(SUM(CASE
                    WHEN `TYPE` = 'W' THEN `BET_MNY` + `RSLT_MNY`
                END),
                0) AS `casino_total_win_money`
    FROM `KP_CSN_BET_HIST` 
    WHERE 
         `CALC_DTM` >= dt_start
         AND `CALC_DTM` <= dt_end
      GROUP BY MBR_IDX) AS mb_casino
    ON 
    mb.idx =  mb_casino.MBR_IDX 
    LEFT JOIN  -- 슬롯 
    (SELECT count(SLOT_BET_IDX) as sl_cnt_count,
		MBR_IDX,
        IFNULL(SUM(`BET_MNY`), 0) AS `slot_total_bet_money`,
        IFNULL(SUM(CASE
                    WHEN `TYPE` = 'W' THEN `BET_MNY` + `RSLT_MNY`
                END),
                0) AS `slot_total_win_money`
    FROM `KP_SLOT_BET_HIST` 
    WHERE 
         `CALC_DTM` >= dt_start
         AND `CALC_DTM` <= dt_end
      GROUP BY MBR_IDX) AS mb_slot
    ON 
    mb.idx =  mb_slot.MBR_IDX
    LEFT JOIN  -- 이스포츠
    (SELECT count(SLOT_BET_IDX) as esp_cnt_count,
		MBR_IDX,
        IFNULL(SUM(`BET_MNY`), 0) AS `espt_total_bet_money`,
        IFNULL(SUM(CASE
                    WHEN `TYPE` = 'W' THEN `BET_MNY` + `RSLT_MNY`
                END),
                0) AS `espt_total_win_money`
    FROM `KP_ESPT_BET_HIST`
    WHERE
         `CALC_DTM` >= dt_start
         AND `CALC_DTM` <= dt_end
      GROUP BY MBR_IDX) AS mb_espt
    ON
    mb.idx =  mb_espt.MBR_IDX
    LEFT JOIN  -- 해시
    (SELECT count(HASH_BET_IDX) as hs_cnt_count,
		MBR_IDX,
        IFNULL(SUM(`BET_MNY`), 0) AS `hash_total_bet_money`,
        IFNULL(SUM(CASE
                    WHEN `TYPE` = 'W' THEN `BET_MNY` + `RSLT_MNY`
                END),
                0) AS `hash_total_win_money`
    FROM `OD_HASH_BET_HIST`
    WHERE
         `CALC_DTM` >= dt_start
         AND `CALC_DTM` <= dt_end
      GROUP BY MBR_IDX) AS mb_hash
    ON
    mb.idx =  mb_hash.MBR_IDX
    LEFT JOIN  -- holdem
    (SELECT count(HOLDEM_BET_IDX) as holdem_cnt_count,
		MBR_IDX,
        IFNULL(SUM(`BET_MONEY`), 0) AS `holdem_total_bet_money`,
        IFNULL(SUM(`WIN_MONEY`), 0) AS `holdem_total_win_money`
    FROM `HOLDEM_BET_HIST` 
    WHERE 
         `REG_DTM` >= dt_start
         AND `REG_DTM` <= dt_end
      GROUP BY MBR_IDX) AS mb_holdem
    ON 
    mb.idx =  mb_holdem.MBR_IDX
     
   GROUP BY mb.idx; 
         
         -- 반복문핸들러선언
         DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;

         -- 커서오픈
         OPEN openCursor;

                  -- 반복문시작
                  read_loop: LOOP
                           -- 커서에서데이터가져옴
                           FETCH openCursor INTO v_member_idx,v_charge_total_count,v_charge_total_money,v_exchange_total_count,v_exchange_total_money, 
												 v_loock_up_total_count,v_bet_total_count,v_bet_total_money,v_pre_s_total_money,v_pre_m_total_money,
												 v_real_s_total_money,v_real_m_total_money,v_mini_total_money,v_take_total_money,v_take_mini_total_money,
												 v_take_real_m_total_money,v_take_real_s_total_money,v_take_pre_m_total_money,v_take_pre_s_total_money,v_casino_total_bet_money,
                                                 v_casino_total_win_money,v_slot_total_bet_money,v_slot_total_win_money,v_espt_total_bet_money,v_espt_total_win_money,
                                                 v_hash_total_bet_money,v_hash_total_win_money,v_holdem_total_bet_money,v_holdem_total_win_money;
                           -- 반복문종료시조건
                           IF done THEN
                                   LEAVE read_loop;
                           END IF;
                       
                           -- 테이블에저장
                           insert into `total_member_cash` ( member_idx,charge_total_count,charge_total_money,exchange_total_count,exchange_total_money, 
												 loock_up_total_count,bet_total_count,bet_total_money,pre_s_total_money,pre_m_total_money,
												 real_s_total_money,real_m_total_money,mini_total_money,take_total_money,take_mini_total_money,
												 take_real_m_total_money,take_real_s_total_money,take_pre_m_total_money,take_pre_s_total_money,casino_total_money,
                                                 take_casino_total_money,slot_total_money,take_slot_total_money,espt_total_money,take_espt_total_money,
                                                 hash_total_money,take_hash_total_money,holdem_total_money,take_holdem_total_money)
						   values(v_member_idx,v_charge_total_count,v_charge_total_money,v_exchange_total_count,v_exchange_total_money, 
												 v_loock_up_total_count,v_bet_total_count,v_bet_total_money,v_pre_s_total_money,v_pre_m_total_money,
												 v_real_s_total_money,v_real_m_total_money,v_mini_total_money,v_take_total_money,v_take_mini_total_money,
												 v_take_real_m_total_money,v_take_real_s_total_money,v_take_pre_m_total_money,v_take_pre_s_total_money,v_casino_total_bet_money,
                                                 v_casino_total_win_money,v_slot_total_bet_money,v_slot_total_win_money,v_espt_total_bet_money,v_espt_total_win_money,
                                                 v_hash_total_bet_money,v_hash_total_win_money,v_holdem_total_bet_money,v_holdem_total_win_money)
                                                 ON DUPLICATE KEY UPDATE
                                                 charge_total_count  = charge_total_count + VALUES(charge_total_count),
                                                 charge_total_money = charge_total_money + VALUES(charge_total_money),
                                                 exchange_total_count = exchange_total_count + VALUES(exchange_total_count),
                                                 exchange_total_money  = exchange_total_money + VALUES(exchange_total_money), 
												 loock_up_total_count  = loock_up_total_count + VALUES(loock_up_total_count),
                                                 bet_total_count  = bet_total_count + VALUES(bet_total_count),
                                                 bet_total_money  = bet_total_money + VALUES(bet_total_money),
                                                 pre_s_total_money  = pre_s_total_money + VALUES(pre_s_total_money),
                                                 pre_m_total_money  = pre_m_total_money + VALUES(pre_m_total_money),
												 real_s_total_money  = real_s_total_money + VALUES(real_s_total_money),
                                                 real_m_total_money  = real_m_total_money + VALUES(real_m_total_money),
                                                 mini_total_money  = mini_total_money + VALUES(mini_total_money),
                                                 take_total_money  = take_total_money + VALUES(take_total_money),
                                                 take_mini_total_money  = take_mini_total_money + VALUES(take_mini_total_money),
												 take_real_m_total_money  = take_real_m_total_money + VALUES(take_real_m_total_money),
                                                 take_real_s_total_money  = take_real_s_total_money + VALUES(take_real_s_total_money),
                                                 take_pre_m_total_money  = take_pre_m_total_money + VALUES(take_pre_m_total_money),
                                                 take_pre_s_total_money   = take_pre_s_total_money + VALUES(take_pre_s_total_money),

                                                 casino_total_money  = casino_total_money + VALUES(casino_total_money),
                                                 take_casino_total_money  = take_casino_total_money + VALUES(take_casino_total_money),
                                                 slot_total_money  = slot_total_money + VALUES(slot_total_money),
                                                 take_slot_total_money   = take_slot_total_money + VALUES(take_slot_total_money),
                                                 espt_total_money  = espt_total_money + VALUES(espt_total_money),
                                                 take_espt_total_money  = take_espt_total_money + VALUES(take_espt_total_money),
                                                 hash_total_money  = hash_total_money + VALUES(hash_total_money),
                                                 take_hash_total_money   = take_hash_total_money + VALUES(take_hash_total_money),
                                                 holdem_total_money  = holdem_total_money + VALUES(holdem_total_money),
                                                 take_holdem_total_money   = take_holdem_total_money + VALUES(take_holdem_total_money)
                                                 ;

             -- 반복문끝

                  END LOOP read_loop;

         -- 커서해제

         CLOSE openCursor;
END$$

DELIMITER ;


INSERT INTO `t_game_config` (`u_level`, `set_type`, `set_type_val`, `title`) VALUES ('0', 'holdem_check_time', '120', '홀덤 플레이 유저 체크시간');
INSERT INTO `t_game_config` (`set_type`, `set_type_val`, `title`) VALUES ('service_holdem', 'N', '홀덤 점검');

INSERT INTO `lsports_game_type` (`id`, `name`, `ko_name`, `status`) VALUES ('21', 'holdem', '홀덤', 'ON');

ALTER TABLE `t_log_cash` 
ADD COLUMN `holdem_user_money` INT(11) NULL DEFAULT 0 COMMENT '홀덤 당시 유저머니' AFTER `charge_total_money`;

INSERT INTO `t_game_config` (`set_type`, `title`) VALUES ('holdem_token_key', '홀덤 토큰키');
