--
-- Host: 210.175.72.81    Database: mydb
-- ------------------------------------------------------

 SET NAMES utf8 ;

--
-- Dumping data for table `lsports_markets`
--

INSERT INTO `lsports_markets` VALUES (1,1,1,6046,'승무패','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,1,0.00,0.00,0,0,0,NULL,1,1,1),(2,2,1,6046,'오버언더','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,1.50,2.40,0,0,0,NULL,3,1,3),(3,3,1,6046,'핸디캡','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,2,1.40,2.60,0,0,0,NULL,2,1,2),(6,6,1,6046,'정확한스코어','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,5.00,50.00,0,0,0,NULL,14,0,0),(7,7,1,6046,'더블찬스','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,1.20,0.00,0,0,0,NULL,10,0,2),(9,11,1,6046,'코너 합계','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,2.00,0.00,0,0,0,NULL,16,0,0),(12,16,1,6046,'첫 득점팀','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,0.00,0,0,0,NULL,11,0,0),(13,17,1,6046,'양팀 모두득점','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,NULL,12,0,0),(19,28,1,48242,'연장포함 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-08 12:04:05',NULL,0,-100,4,3,1.75,0.00,0,0,0,NULL,3,1,3),(21,30,1,6046,'오버언더 - 코너 [홈팀]','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,0.00,1.00,0,0,0,NULL,18,0,0),(22,31,1,6046,'오버언더 - 코너 [원정팀]','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,0.00,1.00,0,0,0,NULL,19,0,0),(25,41,2,6046,'전반전 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:37',NULL,0,8,3,1,1.20,0.00,10,40,0,NULL,5,1,0),(26,42,2,6046,'후반전 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:37',NULL,0,8,3,1,1.20,0.00,20,40,0,NULL,8,1,0),(27,43,2,154914,'3이닝 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,1,1.10,0.00,3,-1,0,NULL,9,1,0),(28,44,2,154914,'4이닝 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,1,1.10,0.00,4,-1,0,NULL,11,1,0),(29,45,2,48242,'2Q 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-20 11:48:19',NULL,0,13,3,3,1.60,0.00,2,7,0,NULL,7,1,0),(30,46,2,48242,'3Q 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-20 11:48:23',NULL,0,13,3,3,1.60,0.00,3,7,0,NULL,9,1,0),(31,47,2,48242,'4Q 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:55',NULL,0,13,3,3,2.00,0.00,4,2,0,NULL,11,1,0),(32,48,2,154914,'5이닝 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,3,1.30,0.00,5,-1,0,NULL,14,1,0),(33,49,2,154914,'5이닝 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,1,1.10,0.00,5,-1,0,NULL,13,1,0),(36,52,1,154830,'승패','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,1,1.01,0.00,0,0,0,NULL,1,1,1),(37,53,2,48242,'전반전 핸디캡','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:55',NULL,1,13,3,2,1.60,0.00,2,5,0,NULL,16,0,0),(44,63,2,48242,'전반전 승패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:55',NULL,1,13,3,1,0.00,0.00,2,5,0,NULL,14,0,0),(46,65,2,48242,'2Q 핸디캡','',NULL,'2020-10-09 16:18:37','2022-11-20 13:32:45',NULL,0,13,3,2,1.50,0.00,2,7,0,NULL,6,1,0),(47,66,2,48242,'3Q 핸디캡','',NULL,'2020-10-09 16:18:37','2022-11-20 13:32:48',NULL,0,13,3,2,1.50,0.00,3,7,0,NULL,8,1,0),(48,67,2,48242,'4Q 핸디캡','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:55',NULL,0,13,3,2,2.00,0.00,4,2,0,NULL,10,1,0),(50,69,1,48242,'연장전 발생','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,0.00,0,0,0,NULL,19,0,0),(51,70,1,48242,'최고득점 쿼터','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,1.00,0,0,0,NULL,16,0,0),(52,71,1,48242,'최고득점 하프','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,2.00,0,0,0,NULL,17,0,0),(58,77,2,48242,'전반전 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:55',NULL,1,13,3,3,1.60,0.00,2,5,0,NULL,15,0,0),(73,95,1,6046,'코너 - 핸디캡  ','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,2,0.00,1.00,0,0,0,NULL,15,0,0),(76,98,1,6046,'홈팀 무득점','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,1.00,0,0,0,NULL,17,0,0),(77,99,1,6046,'원정팀 무득점','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,1.00,0,0,0,NULL,21,0,0),(79,101,1,6046,'홈팀 오버언더','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,1.40,2.45,0,0,0,NULL,4,1,4),(80,102,1,6046,'원정팀 오버언더','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,1.40,2.45,0,0,0,NULL,5,1,5),(116,153,1,48242,'홈팀 1Q 오버언더','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,2.00,0.00,0,0,0,NULL,21,0,0),(118,155,1,48242,'원정팀 1Q 오버언더','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,3,2.00,0.00,0,0,0,NULL,22,0,0),(177,220,1,48242,'원정팀 오버언더 연장포함','',NULL,'2020-10-09 16:18:37','2022-11-08 12:05:02',NULL,0,-100,4,3,1.80,0.00,0,0,0,NULL,18,0,0),(178,221,1,48242,'홈팀 오버언더 연장포함','',NULL,'2020-10-09 16:18:37','2022-11-08 12:05:05',NULL,0,-100,4,3,1.80,0.00,0,0,0,NULL,20,0,0),(183,226,1,48242,'승패 연장포함','',NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,1,0.00,0.00,0,0,0,NULL,1,1,1),(263,342,2,48242,'핸디캡 연장포함','',NULL,'2020-10-09 16:18:37','2022-11-20 11:48:39',NULL,0,13,3,2,1.60,0.00,3,5,0,NULL,2,0,0),(269,348,2,154914,'6이닝 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,1,1.10,0.00,6,-1,0,NULL,15,1,0),(270,349,2,154914,'7이닝 승무패','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,1,1.10,0.00,6,-1,0,NULL,17,1,0),(273,352,2,154914,'6이닝 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,3,1.30,0.00,6,-1,0,NULL,16,1,0),(274,353,2,154914,'7이닝 오버언더','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:25',NULL,0,13,3,3,1.30,0.00,7,-1,0,NULL,18,1,0),(342,427,1,6046,'승무패 및 오버언더',NULL,NULL,'2020-10-09 16:18:37','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,NULL,6,1,6),(376,464,2,48242,'후반전 승패 연장포함 ','',NULL,'2020-10-09 16:18:37','2022-11-16 15:02:55',NULL,1,13,3,1,0.00,0.00,4,1,0,NULL,17,0,0),(619,866,2,154830,'세트 핸디캡','',NULL,'2020-10-09 16:18:37','2022-11-16 15:03:01',NULL,1,8,3,2,1.30,0.00,0,0,0,0,10,1,0),(1237,1537,1,154914,'홈팀승 + 오버언더','Home Team To Win & Under/Over - Including Ove',NULL,'2020-10-09 16:18:38','2022-10-28 02:11:50','2021-05-06 16:57:59',1,-100,4,3,0.00,0.00,0,0,0,NULL,7,1,0),(1238,1538,1,154914,'원정팀승 + 오버언더','Away Team To Win & Under/Over - Including Ove',NULL,'2020-10-09 16:18:38','2022-10-28 02:11:50','2021-05-06 16:58:04',1,-100,4,3,0.00,0.00,0,0,0,NULL,8,1,0),(1257,1558,1,154830,'점수 핸디캡','점수 핸디캡',NULL,'2020-10-09 16:18:38','2022-10-28 02:11:50',NULL,0,-100,4,2,1.65,0.00,0,0,0,NULL,2,1,2),(2796,1,2,6046,'승무패','',NULL,'2021-02-15 18:45:42','2022-11-16 15:02:37',NULL,0,8,3,1,1.05,0.00,20,40,0,NULL,1,1,1),(2805,28,2,48242,'오버언더 연장포함','',NULL,'2021-02-15 19:01:15','2022-11-20 13:31:58',NULL,0,13,3,3,1.60,0.00,3,5,0,NULL,3,1,0),(2806,226,2,48242,'승패 연장포함','',NULL,'2021-02-15 19:01:16','2022-11-17 09:37:18',NULL,0,13,3,1,1.10,0.00,4,5,0,NULL,1,0,1),(2807,220,2,48242,'원정팀 오버언더 연장포함','',NULL,'2021-02-15 19:01:16','2022-11-16 15:02:55',NULL,0,13,3,3,2.00,0.00,3,5,0,NULL,13,1,0),(2808,221,2,48242,'홈팀 오버언더 연장포함','',NULL,'2021-02-15 19:01:16','2022-11-16 15:02:55',NULL,0,13,3,3,2.00,0.00,3,5,0,NULL,12,1,0),(2809,41,1,6046,'전반전 승무패','',NULL,'2021-02-15 19:13:05','2022-10-28 02:11:50',NULL,0,-100,4,1,1.50,0.00,0,0,0,NULL,7,0,0),(2811,4,1,6046,'전반전+풀타임','',NULL,'2021-02-15 19:13:06','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,1.00,0,0,0,NULL,20,0,0),(2814,21,1,48242,'1Q 오버언더','',NULL,'2021-02-15 19:22:00','2022-11-16 16:05:51',NULL,0,-100,4,3,1.75,0.00,0,0,0,NULL,9,0,7),(2815,53,1,48242,'전반전 핸디캡','',NULL,'2021-02-15 19:22:00','2022-11-08 12:04:47',NULL,0,-100,4,2,1.75,0.00,0,0,0,NULL,6,1,6),(2816,63,1,48242,'전반전 승패','',NULL,'2021-02-15 19:22:00','2022-10-28 02:11:50',NULL,0,-100,4,1,1.01,0.00,0,0,0,NULL,5,1,5),(2817,64,1,48242,'1Q 핸디캡','',NULL,'2021-02-15 19:22:00','2022-11-16 14:00:38',NULL,0,-100,4,2,1.80,0.00,0,0,0,NULL,8,0,6),(2818,77,1,48242,'전반전 오버언더','',NULL,'2021-02-15 19:22:00','2022-11-08 12:04:53',NULL,0,-100,4,3,1.80,0.00,0,0,0,NULL,7,1,7),(2820,342,1,48242,'핸디캡 연장포함','',NULL,'2021-02-15 19:22:00','2022-10-28 07:29:57',NULL,0,-100,4,2,1.70,0.00,0,0,0,NULL,2,1,2),(2821,390,1,48242,'전반전+풀타임 연장포함','',NULL,'2021-02-15 19:22:00','2022-10-28 02:11:50',NULL,0,-100,4,4,3.00,0.00,0,0,0,NULL,15,0,0),(2823,866,1,154830,'세트 핸디캡','',NULL,'2021-02-15 19:26:12','2022-10-28 02:11:50',NULL,0,-100,4,2,1.40,0.00,0,0,0,NULL,3,1,3),(2830,282,1,48242,'전반전 승무패','',NULL,'2021-03-18 15:44:40','2022-10-28 02:11:50',NULL,0,-100,4,1,3.00,0.00,0,0,0,NULL,4,1,4),(2833,64,1,154830,'1세트 핸디캡','',NULL,'2021-03-18 15:51:43','2022-10-28 02:11:50',NULL,0,-100,4,2,1.55,0.00,0,0,0,NULL,4,1,5),(2835,2,1,154830,'오버언더','',NULL,'2021-03-18 15:51:43','2022-10-28 02:11:50',NULL,0,-100,4,3,1.60,0.00,0,0,0,NULL,5,1,4),(2839,21,1,154914,'1이닝 오버언더','',NULL,'2021-03-18 15:56:05','2022-10-28 02:11:50',NULL,0,-100,4,3,1.30,0.00,0,0,0,NULL,9,1,5),(2840,28,1,154914,'오버언더 연장포함','',NULL,'2021-03-18 15:56:05','2022-10-28 02:11:50',NULL,0,-100,4,3,1.60,2.35,0,0,0,NULL,3,1,3),(2841,41,1,154914,'1이닝 승무패','',NULL,'2021-03-18 15:56:05','2022-10-28 02:11:50',NULL,0,-100,4,1,0.00,0.00,0,0,0,NULL,4,1,4),(2845,226,1,154914,'승패 연장포함','',NULL,'2021-03-18 15:56:05','2022-10-28 02:11:50',NULL,0,-100,4,1,1.01,0.00,0,0,0,NULL,1,1,1),(2846,342,1,154914,'핸디캡 연장포함','',NULL,'2021-03-18 15:56:05','2022-10-28 02:11:50',NULL,0,-100,4,2,1.50,2.35,0,0,0,NULL,2,1,2),(2848,281,1,154914,'5이닝 핸디캡','',NULL,'2021-03-18 15:56:06','2022-10-28 02:11:50',NULL,0,-100,4,2,1.60,0.00,0,0,0,NULL,5,1,6),(2850,236,1,154914,'5이닝 오버언더','',NULL,'2021-03-18 15:57:27','2022-10-28 02:11:50',NULL,0,-100,4,3,1.60,2.30,0,0,0,NULL,6,1,7),(2851,21,2,48242,'1Q 오버언더','',NULL,'2021-03-18 16:19:28','2022-11-26 21:24:19',NULL,0,13,3,3,2.00,0.00,1,5,0,NULL,5,1,0),(2852,64,2,48242,'1Q 핸디캡','',NULL,'2021-03-18 16:19:28','2022-11-26 21:24:24',NULL,0,13,3,2,2.00,0.00,1,5,0,NULL,4,1,0),(2853,2,2,154830,'언더오버','',NULL,'2021-03-18 16:30:18','2022-11-16 15:03:01',NULL,0,8,3,3,1.65,0.00,0,0,0,NULL,1,1,0),(2854,21,2,154830,'1세트 오버언더','',NULL,'2021-03-18 16:30:18','2022-11-16 15:03:01',NULL,0,8,3,3,1.65,0.00,1,0,12,0,3,1,0),(2855,45,2,154830,'2세트 오버언더','',NULL,'2021-03-18 16:30:18','2022-11-16 15:03:01',NULL,0,8,3,3,1.65,0.00,2,0,12,0,5,1,0),(2856,46,2,154830,'3세트 오버언더','',NULL,'2021-03-18 16:30:18','2022-11-16 15:03:01',NULL,0,8,3,3,1.65,0.00,3,0,12,0,7,1,0),(2857,47,2,154830,'4세트 오버언더','',NULL,'2021-03-18 16:30:19','2022-11-16 15:03:01',NULL,0,8,3,3,1.65,0.00,4,0,12,0,9,1,0),(2858,52,2,154830,'승패','',NULL,'2021-03-18 16:30:19','2022-11-16 15:03:01',NULL,0,8,3,1,1.05,0.00,0,0,0,NULL,11,1,1),(2859,64,2,154830,'1세트 핸디캡','',NULL,'2021-03-18 16:30:19','2022-11-16 15:03:01',NULL,0,8,3,2,1.40,0.00,1,0,12,0,2,1,0),(2860,65,2,154830,'2세트 핸디캡','',NULL,'2021-03-18 16:30:19','2022-11-16 15:03:01',NULL,0,8,3,2,1.40,0.00,2,0,12,0,4,1,0),(2861,66,2,154830,'3세트 핸디캡','',NULL,'2021-03-18 16:30:19','2022-11-16 15:03:01',NULL,0,8,3,2,1.40,0.00,3,0,12,0,6,1,0),(2862,67,2,154830,'4세트 핸디캡','',NULL,'2021-03-18 16:30:19','2022-11-16 15:03:01',NULL,0,8,3,2,1.40,0.00,4,0,12,0,8,1,0),(2867,45,2,154914,'2이닝 오버언더','',NULL,'2021-03-18 16:34:27','2022-11-16 15:03:25',NULL,0,13,3,3,1.30,0.00,2,-1,0,NULL,8,1,0),(2868,46,2,154914,'3이닝 오버언더','',NULL,'2021-03-18 16:34:28','2022-11-16 15:03:25',NULL,0,13,3,3,1.30,0.00,3,-1,0,NULL,10,1,0),(2869,47,2,154914,'4이닝 오버언더','',NULL,'2021-03-18 16:34:28','2022-11-16 15:03:25',NULL,0,13,3,3,1.30,0.00,4,-1,0,NULL,12,1,0),(2873,42,2,154914,'2이닝 승무패','',NULL,'2021-03-18 16:34:28','2022-11-16 15:03:25',NULL,0,13,3,1,1.10,0.00,2,-1,0,NULL,7,1,0),(2876,3,2,6046,'핸디캡','',NULL,'2021-04-07 01:32:05','2022-11-16 15:02:37',NULL,0,8,3,2,1.60,0.00,20,40,0,0,2,1,0),(2877,64,2,6046,'전반전 핸디캡','',NULL,'2021-04-07 01:32:05','2022-11-16 15:02:37',NULL,0,8,3,2,3.00,3.00,10,40,0,0,6,0,0),(2878,2,2,6046,'오버언더','',NULL,'2021-04-07 01:33:08','2022-11-30 01:14:51',NULL,0,8,3,3,1.40,0.00,20,40,0,0,3,1,0),(2879,21,2,6046,'전반전 오버언더','',NULL,'2021-04-07 01:33:08','2022-11-16 15:02:37',NULL,0,8,3,3,1.35,0.00,10,40,0,0,7,0,0),(2880,101,2,6046,'홈팀 오버언더','',NULL,'2021-04-07 01:33:08','2022-11-16 15:02:37',NULL,0,8,3,3,1.60,0.00,20,35,0,0,9,0,0),(2881,102,2,6046,'원정팀 오버언더','',NULL,'2021-04-07 01:33:09','2022-11-16 15:02:37',NULL,0,8,3,3,1.60,0.00,20,35,0,0,10,0,0),(2882,17,2,6046,'양팀득점성공','',NULL,'2021-04-07 01:34:14','2022-11-30 01:14:30',NULL,0,8,3,4,3.00,0.00,20,35,0,0,4,0,0),(2883,113,2,6046,'전반전 양팀득점성공','',NULL,'2021-04-07 01:34:14','2022-11-16 15:02:37',NULL,1,8,3,4,0.00,0.00,10,40,0,0,13,0,0),(2884,211,2,6046,'후반전 양팀득점성공','',NULL,'2021-04-07 01:34:14','2022-11-16 15:02:37',NULL,1,8,3,4,0.00,0.00,20,40,0,0,14,0,0),(2885,34,2,6046,'홈팀 스코어','',NULL,'2021-04-07 01:34:14','2022-11-16 15:02:37',NULL,1,8,3,4,2.00,0.00,20,40,0,0,11,0,0),(2886,35,2,6046,'원정팀 스코어','',NULL,'2021-04-07 01:34:14','2022-11-16 15:02:37',NULL,1,8,3,4,2.00,0.00,20,40,0,0,12,0,0),(2887,1,2,35232,'승무패','승무패',NULL,'2021-07-12 13:42:54','2022-11-16 18:25:48',NULL,0,13,3,1,1.05,0.00,3,10,0,0,1,1,1),(2888,3,2,35232,'핸디캡 연장 미포함','핸디캡 연장 미포함',NULL,'2021-07-12 13:42:54','2022-11-16 18:25:48',NULL,0,13,3,2,2.00,0.00,3,10,0,0,2,1,0),(2889,2,2,35232,'오버언더 연장 미포함','오버언더 연장 미포함',NULL,'2021-07-12 13:42:54','2022-11-16 18:25:48',NULL,0,13,3,3,1.50,0.00,3,10,0,0,3,1,0),(2890,41,2,35232,'1P 승무패','1P 승무패',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,1,1.05,0.00,1,5,0,0,4,1,0),(2891,64,2,35232,'1P 핸디캡','1P 핸디캡',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,2,2.00,0.00,1,5,0,0,5,1,0),(2892,21,2,35232,'1P 오버언더','1P 오버언더',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,3,1.40,0.00,1,5,0,0,6,1,0),(2893,42,2,35232,'2P 승무패','2P 승무패',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,1,1.05,0.00,2,5,0,0,7,1,0),(2894,65,2,35232,'2P 핸디캡','2P 핸디캡',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,2,2.00,0.00,2,5,0,0,8,1,0),(2895,45,2,35232,'2P 오버언더','2P 오버언더',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,3,1.40,0.00,2,5,0,0,9,1,0),(2896,43,2,35232,'3P 승무패','3P 승무패',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,1,1.05,0.00,3,10,0,0,10,1,0),(2897,66,2,35232,'3P 핸디캡','3P 핸디캡',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,2,2.00,0.00,3,10,0,0,11,1,0),(2898,46,2,35232,'3P 오버언더','3P 오버언더',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,3,1.40,0.00,3,10,0,0,12,1,0),(2899,221,2,35232,'홈팀 오버언더 연장포함','홈팀 오버언더 연장포함',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,3,1.50,0.00,3,10,0,0,13,1,0),(2900,220,2,35232,'원정팀 오버언더 연장포함','원정팀 오버언더 연장포함',NULL,'2021-07-12 13:42:55','2022-11-16 18:25:48',NULL,0,13,3,3,1.50,0.00,3,10,0,0,14,1,0),(2901,1,1,35232,'승무패','승무패',NULL,'2021-07-12 13:42:55','2022-10-28 02:11:50',NULL,0,-100,4,1,1.01,0.00,0,0,0,0,1,1,1),(2902,3,1,35232,'핸디캡 연장 미포함','핸디캡 연장 미포함',NULL,'2021-07-12 13:42:55','2022-10-28 02:11:50',NULL,0,-100,4,2,2.00,0.00,0,0,0,0,2,1,2),(2903,2,1,35232,'오버언더 연장 미포함','오버언더 연장 미포함',NULL,'2021-07-12 13:42:55','2022-10-28 02:11:50',NULL,0,-100,4,3,1.40,0.00,0,0,0,0,3,1,3),(2904,21,1,35232,'1P 오버언더','1P 오버언더',NULL,'2021-07-12 13:42:55','2022-10-28 02:11:50',NULL,0,-100,4,3,2.00,0.00,0,0,0,0,8,1,4),(2905,41,1,35232,'1P 승무패','1P 승무패',NULL,'2021-07-12 13:42:55','2022-10-28 02:11:50',NULL,0,-100,4,1,5.00,0.00,0,0,0,0,7,0,0),(2906,64,1,35232,'1P 핸디캡','1P 핸디캡',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,2,2.00,0.00,0,0,0,0,6,0,0),(2907,101,1,35232,'홈팀 오버언더','홈팀 오버언더',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,3,1.50,0.00,0,0,0,0,9,0,0),(2908,102,1,35232,'원정팀 오버언더','원정팀 오버언더',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,3,1.50,0.00,0,0,0,0,12,0,0),(2909,6,1,35232,'정확한스코어','정확한스코어',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,4,5.00,55.00,0,0,0,0,4,0,0),(2910,9,1,35232,'1P 정확한스코어','1P 정확한스코어',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,4,100.00,0.00,0,0,0,0,5,0,0),(2911,23,1,35232,'홈팀 스코어','홈팀 스코어',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,0.00,0,0,0,0,10,0,0),(2912,22,1,35232,'원정팀 스코어','원정팀 스코어',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,0.00,0,0,0,0,11,0,0),(2913,322,1,35232,'언더/동점/오버','언더/동점/오버',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,4,15.00,0.00,0,0,0,0,13,0,0),(2914,472,1,35232,'승부치기 여부','승부치기 여부',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,4,2.00,0.00,0,0,0,0,14,0,0),(2915,52,1,687890,'승패','승패',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,1,3.00,0.00,0,0,0,0,1,1,1),(2916,202,1,687890,'1세트 승패','1세트 승패',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,1,3.00,0.00,0,0,0,0,2,1,2),(2917,1170,1,687890,'1세트 첫용','1세트 첫용',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,1,3.00,0.00,0,0,0,0,3,1,3),(2918,669,1,687890,'1세트 첫킬','1세트 첫킬',NULL,'2021-07-12 13:42:56','2022-10-28 02:11:50',NULL,0,-100,4,1,3.00,0.00,0,0,0,0,4,1,4),(2919,52,2,687890,'승패','승패',NULL,'2021-07-12 13:42:56','2022-11-16 15:02:46',NULL,0,8,3,1,1.40,0.00,0,0,0,0,1,1,1),(2920,202,2,687890,'1세트 승패','1세트 승패',NULL,'2021-07-12 13:42:56','2022-11-16 15:02:46',NULL,1,8,3,1,0.00,0.00,0,-1,0,0,2,1,0),(2921,1170,2,687890,'1세트 첫용','1세트 첫용',NULL,'2021-07-12 13:42:56','2022-11-16 15:02:46',NULL,1,8,3,1,0.00,0.00,0,-1,0,0,3,1,0),(2922,669,2,687890,'1세트 첫킬','1세트 첫킬',NULL,'2021-07-12 13:42:57','2022-11-16 15:02:46',NULL,1,8,3,1,0.00,0.00,0,-1,0,0,4,1,0),(2923,203,2,687890,'2세트 승패','2세트 승패',NULL,'2021-07-12 13:42:57','2022-11-16 15:02:46',NULL,0,8,3,1,1.40,0.00,0,0,0,0,5,1,0),(2924,204,2,687890,'3세트 승패','3세트 승패',NULL,'2021-07-12 13:42:57','2022-11-16 15:02:46',NULL,0,8,3,1,1.40,0.00,0,0,0,0,6,1,0),(2925,52,1,154919,'승패','승패',NULL,'2021-07-12 13:42:57','2022-10-28 02:11:50',NULL,0,-100,4,1,0.00,0.00,0,0,0,0,1,1,1),(2926,13,2,6046,'핸디캡승무패','핸디캡승무패',NULL,'2021-07-12 13:42:57','2022-11-16 15:02:37',NULL,0,8,3,2,30.00,0.00,20,40,0,0,0,1,0),(2927,235,2,154914,'1~5이닝 승패','1~5이닝 승무패',NULL,'2021-07-12 13:42:57','2022-11-16 15:03:25',NULL,1,13,3,1,2.00,0.00,5,-1,0,0,0,1,0),(2928,281,2,154914,'1~5이닝 핸디캡','1~5이닝 핸디캡',NULL,'2021-07-12 13:42:57','2022-11-16 15:03:25',NULL,0,13,3,2,1.30,2.30,5,-1,0,0,5,1,0),(2930,236,2,154914,'1~5이닝 오버언더','1~5이닝 오버언더',NULL,'2021-07-30 10:11:28','2022-11-16 15:03:25',NULL,0,13,3,3,1.50,2.30,5,-1,0,0,6,1,0),(2931,226,2,154914,'승패(연장포함)','승패(연장포함)',NULL,'2021-08-12 10:38:00','2022-11-16 15:03:25',NULL,0,13,3,1,1.05,0.00,9,-1,0,0,1,1,1),(2932,342,2,154914,'핸디캡(연장포함)','핸디캡(연장포함)',NULL,'2021-08-12 10:38:00','2022-11-16 15:03:25',NULL,0,13,3,2,1.40,0.00,9,-1,0,0,2,1,0),(2933,28,2,154914,'오버언더(연장포함)','오버언더(연장포함)',NULL,'2021-08-12 10:38:00','2022-11-16 15:03:25',NULL,0,13,3,3,1.45,0.00,9,-1,0,0,3,1,0),(2934,1618,2,154914,'1~5이닝 승패','1~5이닝 승패',NULL,'2021-08-23 15:09:36','2022-11-16 15:03:25',NULL,0,13,3,1,1.30,0.00,5,-1,0,0,4,1,0),(2935,21,1,6046,'전반전 오버언더','',NULL,'2022-05-30 14:25:15','2022-10-28 02:11:50',NULL,0,-100,4,3,1.50,0.00,0,0,0,0,9,0,0),(2936,64,1,6046,'전반전 핸디캡','',NULL,'2022-05-30 14:25:15','2022-10-28 02:11:50',NULL,0,-100,4,2,1.50,0.00,0,0,0,0,8,0,0),(2937,5,1,6046,'총 득점 홀짝',NULL,NULL,'2022-06-10 23:00:42','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,0,13,0,0),(2938,1328,1,48242,'첫 3점슛',NULL,NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,0,11,0,4),(2939,1327,1,48242,'첫 2점슛',NULL,NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,0,10,0,3),(2940,1832,1,48242,'3점슛 언/오버','',NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,3,2.00,0.00,0,0,0,0,13,0,6),(2941,51,1,48242,'총 득점 홀짝 (연장포함)',NULL,NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,0,14,0,8),(2942,1332,1,48242,'첫 자유투',NULL,NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,0,12,0,5),(2943,51,1,154914,'총 득점 홀짝 (연장포함)',NULL,NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,4,0.00,0.00,0,0,0,0,12,1,12),(2944,2402,1,154914,'첫홈런',NULL,NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,1,-100,4,4,0.00,0.00,0,0,0,0,10,1,10),(2945,1677,1,154914,'마지막 득점팀 (연장포함)','',NULL,'2022-06-10 23:01:40','2022-10-28 02:11:50',NULL,0,-100,4,1,2.00,0.00,0,0,0,0,11,1,11),(2946,2681,2,154914,'1~7이닝 승패',NULL,NULL,'2022-06-10 23:01:41','2022-11-16 15:03:25',NULL,1,13,3,1,0.00,0.00,6,-1,0,0,5,0,0),(2947,525,2,154914,'1~7이닝 오버언더',NULL,NULL,'2022-06-10 23:01:41','2022-11-16 15:03:25',NULL,1,13,3,3,0.00,0.00,6,-1,0,0,6,0,0);

--
-- Dumping routines for database 'mydb'
--
/*!50003 DROP FUNCTION IF EXISTS `FN_ADM_MSG_SEND_ALL` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` FUNCTION `FN_ADM_MSG_SEND_ALL`(`$p_msg_idx` INT
) RETURNS int(11)
BEGIN

	DECLARE $ret 			VARCHAR(50);
	DECLARE $no_more_rows 		BOOL DEFAULT FALSE;

	DECLARE $db_user_idx			INTEGER DEFAULT 0;

	DECLARE cursor_1 CURSOR FOR
		SELECT idx FROM mydb.member WHERE status=1;
		
	DECLARE CONTINUE HANDLER FOR NOT FOUND
		SET $no_more_rows := true;

	OPEN cursor_1;
	LOOP1: loop
		FETCH cursor_1 INTO $db_user_idx;

		IF $no_more_rows THEN 
			CLOSE cursor_1;
			LEAVE LOOP1;
		END IF;
		
					
		INSERT INTO mydb.t_message(msg_idx,member_idx) VALUES($p_msg_idx,$db_user_idx);
		
	END loop LOOP1;
	
	SET $ret = 1000;

	RETURN $ret;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `FN_GET_IP_COUNTRY` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `FN_GET_IP_COUNTRY`(`$p_ip` VARCHAR(30)
) RETURNS varchar(50) CHARSET utf8
BEGIN

	DECLARE $ret 			VARCHAR(50);
	DECLARE $v_ip 			INT UNSIGNED DEFAULT 0;
	
	SET $ret = 'local';
	
	SELECT INET_ATON($p_ip) INTO $v_ip;
	SELECT country INTO $ret FROM t_ip_country WHERE $v_ip >= ip_start and $v_ip <= ip_end LIMIT 1;

	RETURN $ret;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `FN_STAT_CHARGE_TOTAL` */;
DELIMITER ;;
CREATE DEFINER=`kwin`@`%` FUNCTION `FN_STAT_CHARGE_TOTAL`(`$start_date` DATETIME,

	`$end_date` DATETIME,

	`$member_idx` INT

) RETURNS bigint(20)
    COMMENT '이번달 1일 부터 현재까지 충전합계 반환'
BEGIN

	DECLARE $charge_total BIGINT DEFAULT 0;

	DECLARE $start_time DATETIME;

	DECLARE $end_time DATETIME;

	

	SET $start_time = IFNULL($start_date, LAST_DAY(NOW() - interval 1 month) + interval 1 DAY);

	SET $end_time = IFNULL($end_date, NOW());



	SELECT IFNULL(SUM(MC.money),0)

	FROM member_money_charge_history AS MC WHERE status = 3 

	AND MC.update_dt >= $start_time

	AND MC.update_dt <= $end_time

	AND MC.member_idx = CASE

								WHEN $member_idx IS NULL THEN MC.member_idx

								ELSE $member_idx END

	INTO $charge_total;

	

	RETURN $charge_total;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `FN_STAT_DIFF_TOTAL` */;
DELIMITER ;;
CREATE DEFINER=`kwin`@`%` FUNCTION `FN_STAT_DIFF_TOTAL`(`$start_date` DATETIME,

	`$end_date` DATETIME,

	`$member_idx` INT

) RETURNS bigint(20)
    COMMENT '이번달 1일 부터 현재까지  차액 합계 반환'
BEGIN

	DECLARE $diff_total BIGINT DEFAULT 0;

	DECLARE $start_time DATETIME;

	DECLARE $end_time DATETIME;

	

	SET $start_time = IFNULL($start_date, LAST_DAY(NOW() - interval 1 month) + interval 1 DAY);

	SET $end_time = IFNULL($end_date, NOW());



	SELECT IFNULL(SUM(MC.money),0) -

	(SELECT IFNULL(SUM(ME.money),0)

	FROM member_money_exchange_history AS ME 

	WHERE status = 3 

	AND update_dt >= $start_time

	AND update_dt <= $end_time

	AND ME.member_idx = CASE

					WHEN $member_idx IS NULL THEN ME.member_idx

					ELSE $member_idx END)  AS diff_sum

	FROM member_money_charge_history AS MC

	WHERE status = 3 

	AND update_dt >= $start_time

	AND update_dt <= $end_time

	AND MC.member_idx = CASE

						WHEN $member_idx IS NULL THEN MC.member_idx

						ELSE $member_idx END

						

	INTO $diff_total;

	

	RETURN $diff_total;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `FN_STAT_EXCHANGE_TOTAL` */;
DELIMITER ;;
CREATE DEFINER=`kwin`@`%` FUNCTION `FN_STAT_EXCHANGE_TOTAL`(`$start_date` DATETIME,

	`$end_date` DATETIME,

	`$member_idx` INT

) RETURNS bigint(20)
    COMMENT '이번달 1일 부터 현재까지 환전합계 반환'
BEGIN

	DECLARE $exchange_total BIGINT DEFAULT 0;

	DECLARE $start_time DATETIME;

	DECLARE $end_time DATETIME;

	

	SET $start_time = IFNULL($start_date, LAST_DAY(NOW() - interval 1 month) + interval 1 DAY);

	SET $end_time = IFNULL($end_date, NOW());



	SELECT IFNULL(SUM(ME.money),0)

	FROM member_money_exchange_history AS ME WHERE status = 3 

	AND ME.update_dt >= $start_time

	AND ME.update_dt <= $end_time

	AND ME.member_idx = CASE

							WHEN $member_idx IS NULL THEN ME.member_idx

							ELSE $member_idx END

	INTO $exchange_total;

	

	RETURN $exchange_total;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `FN_STAT_USERS_BET_SUM` */;
DELIMITER ;;
CREATE DEFINER=`kwin`@`%` FUNCTION `FN_STAT_USERS_BET_SUM`(`$start_date` DATETIME,

	`$end_date` DATETIME,

	`$folder_type` CHAR(1),

	`$bet_type` INT,

	`$member_idx` INT

) RETURNS bigint(20)
    COMMENT '1일부터 현재까지 베팅 합계 (프리매치)'
BEGIN

	

	DECLARE $val_sum BIGINT DEFAULT 0;

	

	DECLARE $start_time DATETIME;

	DECLARE $end_time DATETIME;

	

	

	SET $start_time = IFNULL($start_date, LAST_DAY(NOW() - interval 1 month) + interval 1 DAY);

	SET $end_time = IFNULL($end_date, NOW());



	SELECT IFNULL(SUM(total_bet_money),0)

	FROM member_bet AS MB 

	WHERE bet_status = 3 

	AND MB.update_dt >= $start_time

	AND MB.update_dt <= $end_time

	AND MB.folder_type = CASE

				WHEN $folder_type IS NULL THEN MB.folder_type

				ELSE $folder_type END

	AND MB.bet_type = $bet_type

	AND MB.member_idx = CASE

						WHEN $member_idx IS NULL THEN MB.member_idx

						ELSE $member_idx END

	INTO $val_sum;

	

	RETURN $val_sum;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `FN_STAT_USERS_TAKE_SUM` */;
DELIMITER ;;
CREATE DEFINER=`kwin`@`%` FUNCTION `FN_STAT_USERS_TAKE_SUM`(`$start_date` DATETIME,

	`$end_date` DATETIME,

	`$folder_type` CHAR(1),

	`$bet_type` INT,

	`$member_idx` INT

) RETURNS bigint(20)
    COMMENT '1일부터 현재까지 당첨 합계 (프리매치)'
BEGIN

	

	DECLARE $val_sum BIGINT DEFAULT 0;

	

	DECLARE $start_time DATETIME;

	DECLARE $end_time DATETIME;

	

	SET $start_time = IFNULL($start_date, LAST_DAY(NOW() - interval 1 month) + interval 1 DAY);

	SET $end_time = IFNULL($end_date, NOW());



	SELECT IFNULL(SUM(take_money),0)

	FROM member_bet AS MB 

	WHERE bet_status = 3 

	AND MB.update_dt >= $start_time

	AND MB.update_dt <= $end_time

	AND MB.folder_type = CASE

				WHEN $folder_type IS NULL THEN MB.folder_type

				ELSE $folder_type END

	AND MB.bet_type = $bet_type

	AND MB.member_idx = CASE

					WHEN $member_idx IS NULL THEN MB.member_idx

					ELSE $member_idx END

	INTO $val_sum;

	

	RETURN $val_sum;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `backupDataLsports` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `backupDataLsports`(
in in_type varchar(10)
)
BEGIN

IF 'go_bet' = in_type THEN
    truncate lsports_bet_InnoDB;
	INSERT INTO lsports_bet_InnoDB
	SELECT * FROM lsports_bet;
ELSEIF 'go_policy' = in_type THEN
    truncate dividend_policy_innodb;
	INSERT INTO dividend_policy_innodb
	SELECT * FROM dividend_policy;
ELSEIF 'go_bet_sum' = in_type THEN
	truncate fixtures_bet_sum_innodb;
	INSERT INTO fixtures_bet_sum_innodb
	SELECT * FROM fixtures_bet_sum;
ELSEIF 'go_fixtures' = in_type THEN
    truncate lsports_fixtures_innodb;
	INSERT INTO lsports_fixtures_innodb
	SELECT * FROM lsports_fixtures;   
ELSEIF 'go_leagues' = in_type THEN
    truncate lsports_leagues_innodb;
	INSERT INTO lsports_leagues_innodb
	SELECT * FROM lsports_leagues;
ELSEIF 'go_locations' = in_type THEN
    truncate lsports_locations_innodb;
	INSERT INTO lsports_locations_innodb
	SELECT * FROM lsports_locations;
ELSEIF 'go_markets' = in_type THEN
    truncate lsports_markets_innodb;
	INSERT INTO lsports_markets_innodb
	SELECT * FROM lsports_markets;   
ELSEIF 'go_participant' = in_type THEN
    truncate lsports_participant_innodb;
	INSERT INTO lsports_participant_innodb
	SELECT * FROM lsports_participant;   
ELSEIF 'go_sports' = in_type THEN
    truncate lsports_sports_innodb;
	INSERT INTO lsports_sports_innodb
	SELECT * FROM lsports_sports;     
ELSEIF 'go_all' = in_type THEN
	truncate lsports_bet_InnoDB;
	INSERT INTO lsports_bet_InnoDB
	SELECT * FROM lsports_bet;

    truncate dividend_policy_innodb;
	INSERT INTO dividend_policy_innodb
	SELECT * FROM dividend_policy;
  
	truncate fixtures_bet_sum_innodb;
	INSERT INTO fixtures_bet_sum_innodb
	SELECT * FROM fixtures_bet_sum;

    truncate lsports_fixtures_innodb;
	INSERT INTO lsports_fixtures_innodb
	SELECT * FROM lsports_fixtures;   
 
    truncate lsports_leagues_innodb;
	INSERT INTO lsports_leagues_innodb
	SELECT * FROM lsports_leagues;
 
    truncate lsports_locations_innodb;
	INSERT INTO lsports_locations_innodb
	SELECT * FROM lsports_locations;
 
    truncate lsports_markets_innodb;
	INSERT INTO lsports_markets_innodb
	SELECT * FROM lsports_markets;   
 
    truncate lsports_participant_innodb;
	INSERT INTO lsports_participant_innodb
	SELECT * FROM lsports_participant;   

    truncate lsports_sports_innodb;
	INSERT INTO lsports_sports_innodb
	SELECT * FROM lsports_sports;     
 END IF;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `backupInnoDBSportsData` */;
DELIMITER ;;
CREATE DEFINER=`gambleadmin`@`%` PROCEDURE `backupInnoDBSportsData`(
in in_type varchar(10)
)
BEGIN

IF 'go_bet' = in_type THEN
   DROP TABLE  if exists `lsports_bet_backup`;
   CREATE TABLE IF NOT EXISTS `lsports_bet_backup` SELECT * FROM `lsports_bet_InnoDB`;
ELSEIF 'go_policy' = in_type THEN
   DROP TABLE  if exists `dividend_policy_backup`;
   CREATE TABLE IF NOT EXISTS `dividend_policy_backup` SELECT * FROM `dividend_policy_innodb`;
ELSEIF 'go_bet_sum' = in_type THEN
	DROP TABLE  if exists `fixtures_bet_sum_backup`;
   CREATE TABLE IF NOT EXISTS `fixtures_bet_sum_backup` SELECT * FROM `fixtures_bet_sum_innodb`;
ELSEIF 'go_fixtures' = in_type THEN
	DROP TABLE  if exists `lsports_fixtures_backup`;
   CREATE TABLE IF NOT EXISTS `lsports_fixtures_backup` SELECT * FROM `lsports_fixtures_innodb`;
ELSEIF 'go_leagues' = in_type THEN
	DROP TABLE  if exists `lsports_leagues_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_leagues_backup` SELECT * FROM `lsports_leagues_innodb`;
ELSEIF 'go_locations' = in_type THEN
	DROP TABLE  if exists `lsports_locations_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_locations_backup` SELECT * FROM `lsports_locations_innodb`;
ELSEIF 'go_markets' = in_type THEN
	DROP TABLE  if exists `lsports_markets_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_markets_backup` SELECT * FROM `lsports_markets_innodb`;
ELSEIF 'go_participant' = in_type THEN
	DROP TABLE  if exists `lsports_participant_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_participant_backup` SELECT * FROM `lsports_participant_innodb`;
ELSEIF 'go_sports' = in_type THEN
    DROP TABLE  if exists `lsports_sports_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_sports_backup` SELECT * FROM `lsports_sports_innodb`;
ELSEIF 'go_all' = in_type THEN
	DROP TABLE  if exists `lsports_bet_backup`;
	CREATE TABLE IF NOT EXISTS `lsports_bet_backup` SELECT * FROM `lsports_bet_InnoDB`;

	DROP TABLE  if exists `dividend_policy_backup`;
	CREATE TABLE IF NOT EXISTS `dividend_policy_backup` SELECT * FROM `dividend_policy_innodb`;

	DROP TABLE  if exists `fixtures_bet_sum_backup`;
	CREATE TABLE IF NOT EXISTS `fixtures_bet_sum_backup` SELECT * FROM `fixtures_bet_sum_innodb`;

	DROP TABLE  if exists `lsports_fixtures_backup`;
	CREATE TABLE IF NOT EXISTS `lsports_fixtures_backup` SELECT * FROM `lsports_fixtures_innodb`;

	DROP TABLE  if exists `lsports_leagues_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_leagues_backup` SELECT * FROM `lsports_leagues_innodb`;

	DROP TABLE  if exists `lsports_locations_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_locations_backup` SELECT * FROM `lsports_locations_innodb`;

	DROP TABLE  if exists `lsports_markets_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_markets_backup` SELECT * FROM `lsports_markets_innodb`;

	DROP TABLE  if exists `lsports_participant_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_participant_backup` SELECT * FROM `lsports_participant_innodb`;

    DROP TABLE  if exists `lsports_sports_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_sports_backup` SELECT * FROM `lsports_sports_innodb`;
 END IF;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `backupSportsData` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `backupSportsData`(
in in_type varchar(10)
)
BEGIN
 
IF 'go_bet' = in_type THEN
   DROP TABLE  if exists `lsports_bet_backup`;
   CREATE TABLE IF NOT EXISTS `lsports_bet_backup` SELECT * FROM `lsports_bet`;
ELSEIF 'go_policy' = in_type THEN
   DROP TABLE  if exists `dividend_policy_backup`;
   CREATE TABLE IF NOT EXISTS `dividend_policy_backup` SELECT * FROM `dividend_policy`;
ELSEIF 'go_bet_sum' = in_type THEN
	DROP TABLE  if exists `fixtures_bet_sum_backup`;
   CREATE TABLE IF NOT EXISTS `fixtures_bet_sum_backup` SELECT * FROM `fixtures_bet_sum`;
ELSEIF 'go_fixtures' = in_type THEN
	DROP TABLE  if exists `lsports_fixtures_backup`;
   CREATE TABLE IF NOT EXISTS `lsports_fixtures_backup` SELECT * FROM `lsports_fixtures`;
ELSEIF 'go_leagues' = in_type THEN
	DROP TABLE  if exists `lsports_leagues_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_leagues_backup` SELECT * FROM `lsports_leagues`;
ELSEIF 'go_locations' = in_type THEN
	DROP TABLE  if exists `lsports_locations_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_locations_backup` SELECT * FROM `lsports_locations`;
ELSEIF 'go_markets' = in_type THEN
	DROP TABLE  if exists `lsports_markets_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_markets_backup` SELECT * FROM `lsports_markets`;
ELSEIF 'go_participant' = in_type THEN
	DROP TABLE  if exists `lsports_participant_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_participant_backup` SELECT * FROM `lsports_participant`;
ELSEIF 'go_sports' = in_type THEN
    DROP TABLE  if exists `lsports_sports_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_sports_backup` SELECT * FROM `lsports_sports`;
ELSEIF 'go_day_cash' = in_type THEN
    DROP TABLE  if exists `total_day_cash_backup`;
    CREATE TABLE IF NOT EXISTS `total_day_cash_backup` SELECT * FROM `total_day_cash`;    
ELSEIF 'go_all' = in_type THEN
	DROP TABLE  if exists `lsports_bet_backup`;
	CREATE TABLE IF NOT EXISTS `lsports_bet_backup` SELECT * FROM `lsports_bet`;

	DROP TABLE  if exists `dividend_policy_backup`;
	CREATE TABLE IF NOT EXISTS `dividend_policy_backup` SELECT * FROM `dividend_policy`;

	DROP TABLE  if exists `fixtures_bet_sum_backup`;
	CREATE TABLE IF NOT EXISTS `fixtures_bet_sum_backup` SELECT * FROM `fixtures_bet_sum`;

	DROP TABLE  if exists `lsports_fixtures_backup`;
	CREATE TABLE IF NOT EXISTS `lsports_fixtures_backup` SELECT * FROM `lsports_fixtures`;

	DROP TABLE  if exists `lsports_leagues_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_leagues_backup` SELECT * FROM `lsports_leagues`;

	DROP TABLE  if exists `lsports_locations_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_locations_backup` SELECT * FROM `lsports_locations`;

	DROP TABLE  if exists `lsports_markets_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_markets_backup` SELECT * FROM `lsports_markets`;

	DROP TABLE  if exists `lsports_participant_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_participant_backup` SELECT * FROM `lsports_participant`;

    DROP TABLE  if exists `lsports_sports_backup`;
    CREATE TABLE IF NOT EXISTS `lsports_sports_backup` SELECT * FROM `lsports_sports`;
    
    -- DROP TABLE  if exists `total_day_cash_backup`;
    -- CREATE TABLE IF NOT EXISTS `total_day_cash_backup` SELECT * FROM `total_day_cash`;    
 END IF;
 


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `channel_roof` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `channel_roof`()
main : BEGIN

	DECLARE ret_code INT;
	DECLARE errno INT;
    DECLARE v_txt_error_msg text;
    
    DECLARE $next TEXT;
	DECLARE $value TEXT;
	DECLARE $DEL char(1) DEFAULT '/';
    
    declare v_idx int;
    DECLARE v_id varchar(20);
    DECLARE v_nick varchar(20);
    DECLARE v_account_bank varchar(20);
    DECLARE v_account_number varchar(20);
    DECLARE v_account_name varchar(20);
    DECLARE v_hp varchar(20);
    DECLARE v_memo varchar(2048);
   
    DECLARE done INTEGER DEFAULT 0;
    DEClARE openCursor CURSOR FOR SELECT id,nick,account_bank,account_number,account_name,hp,memo FROM mydb.temp_member;
 
    
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;
    
    DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
		GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO
		, v_txt_error_msg = MESSAGE_TEXT;
        set ret_code = -1000;
		SELECT ret_code,errno AS MYSQL_ERROR,v_txt_error_msg as MESSAGE_TEXT;
		ROLLBACK;
    END;
           
    START TRANSACTION;
        
        OPEN openCursor;

                  
                  read_loop: LOOP
                           
                           FETCH openCursor INTO v_id,v_nick,v_account_bank,v_account_number,v_account_name,v_hp,v_memo;
                           
                           IF done THEN
                                   LEAVE read_loop;
                           END IF;
                       
						   
                           
						   IF (select 1 = 1 from mydb.`member` where id = v_id) then
							   begin
								ITERATE read_loop;
							   end;
                           end if;
                           
                           IF (select 1 = 1 from mydb.`member` where account_bank = v_account_bank AND account_number = v_account_number) then
							   begin
								ITERATE read_loop;
							   end;
                           end if;
                           
                           
                           IF (select 1 = 1 from mydb.`member` where `call` = v_hp) then
							   begin
								ITERATE read_loop;
							   end;
                           end if;
                           
                           IF (select 1 = 1 from mydb.`member` where `nick_name` = v_nick ) then
							   begin
								 set v_nick = concat(v_nick,'_1');
							   end;
                           end if;
                                                      
                           insert into `mydb`.`member`(`id`,`nick_name`,`password`,`recommend_member`,`dis_id`,`call`,`account_bank`,`account_number`,`account_name`,`point`,`channel`,`status`) 
                           values(v_id,v_nick,'$2y$10$B7sJbgrhzpos38KneWa5W.TEDn.2g2ADRMggAQ2icWEsHGdHCG4.e',2849,'te01',v_hp,v_account_bank,v_account_number,v_account_name,20000,1,1);
                           set v_idx = LAST_INSERT_ID();
                           
                           insert into `member_game_type` (`member_idx`, `game_type`) values(v_idx, 1),(v_idx, 2),(v_idx, 3),(v_idx, 4),(v_idx, 5),(v_idx, 6),(v_idx, 7),(v_idx, 8);
                         
													 
							MAIN_BLOCK:
							LOOP
							  
							  IF CHAR_LENGTH(TRIM(v_memo)) = 0 OR v_memo IS NULL THEN
								LEAVE MAIN_BLOCK;
							  END IF;
							 
							  
							  SET $next = SUBSTRING_INDEX(v_memo, $DEL, 1);

							  
							  SET $value = TRIM($next);

							  
							  INSERT INTO t_member_memo (member_idx,content) VALUES (v_idx,$value);

							  
							  SET v_memo = INSERT(v_memo, 1, CHAR_LENGTH($next) + 1, '');
							END LOOP;

             

                  END LOOP read_loop;

         

         CLOSE openCursor;
    
    
	COMMIT;
END main ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `create_account` */;
DELIMITER ;;
CREATE DEFINER=`kwin`@`%` PROCEDURE `create_account`()
BEGIN
	
	DECLARE i INT DEFAULT 3;
    WHILE (i <= 100) DO 
        insert into member(id, nick_name, u_business, password, recommend_member, dis_id, `call`, account_bank, account_number, account_name, money) 
			values (concat('test_', i), concat('test_', i), 1, '$2y$10$SyAQNrQA/TQOjn1z/j4csONQ6/WA5cEA/U6S2OS9vk/525bOjCKlm', 1, 'test',
					concat('call_', i), concat('test_', i), concat('test_', i), concat('test_', i), 3000000);
        
        
        SET i = i + 1;
    END WHILE;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `insert_account_number` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `insert_account_number`()
BEGIN
  
		 DECLARE v_id varchar(45);
         DECLARE v_idx int;
         DECLARE v_account_number varchar(45);
         DECLARE v_account_name varchar(45);
         DECLARE done INTEGER DEFAULT 0;
         DEClARE openCursor CURSOR FOR SELECT id,account_number,account_name FROM mydb.temp_account_info;
 
         
         DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;

         
         OPEN openCursor;

                  
                  read_loop: LOOP
                           
                           FETCH openCursor INTO v_id,v_account_number,v_account_name;
                           
                           IF done THEN
                                   LEAVE read_loop;
                           END IF;
                           
                           IF (SELECT 1 = 1 FROM `member` where id = v_id limit 1) THEN
							BEGIN
								SELECT idx INTO v_idx from `member` where id = v_id limit 1;
                                
								insert into `personal_account_number` (`member_idx`, `account_number_1`, `account_name_1`) values(v_idx, v_account_number,v_account_name);
                            END;
                           END IF;
                          
				
                  END LOOP read_loop;

         
         CLOSE openCursor;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `insert_game_type` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `insert_game_type`()
BEGIN
  
		 DECLARE v_idx int;
         DECLARE done INTEGER DEFAULT 0;
         DEClARE openCursor CURSOR FOR SELECT idx FROM mydb.member;
 
         
         DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;

         
         OPEN openCursor;

                  
                  read_loop: LOOP
                           
                           FETCH openCursor INTO v_idx;

                           

                           IF done THEN

                                   LEAVE read_loop;

                           END IF;
                       
                           
                           insert into `member_game_type` (`member_idx`, `game_type`) values(v_idx, 1),(v_idx, 2),(v_idx, 3),(v_idx, 4),(v_idx, 5),(v_idx, 6),(v_idx, 7),(v_idx, 9),(v_idx, 10),(v_idx, 11),(v_idx, 12),(v_idx, 13);
                           
                           
                           
                           
                           
                           
                           

             

                  END LOOP read_loop;

         

         CLOSE openCursor;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `insert_total_member_cash` */;
DELIMITER ;;
CREATE DEFINER=`gambleadmin`@`%` 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  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) 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
		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 
		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
      ) AS mb_casino
    ON 
    mb.idx =  mb_casino.MBR_IDX 
    LEFT JOIN  -- 슬롯 
    (SELECT 
		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
      ) AS mb_slot
    ON 
    mb.idx =  mb_slot.MBR_IDX
    LEFT JOIN  -- 이스포츠
    (SELECT
		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
      ) AS mb_espt
    ON
    mb.idx =  mb_espt.MBR_IDX
    LEFT JOIN  -- 해시
    (SELECT
		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
      ) AS mb_hash
    ON
    mb.idx =  mb_hash.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;
                           -- 반복문종료시조건
                           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)
						   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)
                                                 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)
                                                 ;

             -- 반복문끝

                  END LOOP read_loop;

         -- 커서해제

         CLOSE openCursor;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `payAllUserItems` */;
DELIMITER ;;
CREATE DEFINER=`gambleadmin`@`%` PROCEDURE `payAllUserItems`()
BEGIN
	DECLARE ret_code INT;
	DECLARE errno INT;
    DECLARE v_txt_error_msg text;
    
    DECLARE $next TEXT;
	DECLARE $value TEXT;
    
    DECLARE ret_idx INT;
    DECLARE ret_money INT;
    DECLARE ret_point INT;
    DECLARE ret_g_money INT;
    DECLARE ret_id  VARCHAR(45);
       
    DECLARE add_idx BIGINT;
    
    
    DECLARE done INTEGER DEFAULT 0;
    DEClARE openCursor CURSOR FOR SELECT idx,id,money,`point`,g_money FROM member where `status` = 1 and level <> 9 and u_business = 1 AND  reg_time < '2022-10-01 00:00:00';
     
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;
    
    DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
		GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO
		, v_txt_error_msg = MESSAGE_TEXT;
        set ret_code = -1000;
		SELECT ret_code,errno AS MYSQL_ERROR,v_txt_error_msg as MESSAGE_TEXT;
		ROLLBACK;
    END;
           
    START TRANSACTION;
        OPEN openCursor;
                  read_loop: LOOP
                           FETCH openCursor INTO ret_idx,ret_id,ret_money,ret_point,ret_g_money;
                           
                           IF done THEN
                                   LEAVE read_loop;
                           END IF;
                             
                           insert into `member_item`(member_idx,item_id,item_value,`status`) 
                           values(ret_idx,4,0.05,0);
                           set add_idx = LAST_INSERT_ID();

	                       insert into `t_log_cash`(member_idx, ac_code,ac_idx,r_money, be_r_money, af_r_money, m_kind, coment,point,be_point,af_point,g_money) 
                           values(ret_idx,512,add_idx,0,ret_money,ret_money,'P','운영자 아이템 보상 지급',0,ret_point,ret_point,0);

                  END LOOP read_loop;
         CLOSE openCursor;
	COMMIT;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `rollbackBetInfo` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `rollbackBetInfo`(
in in_idx int
)
main: BEGIN
	
    declare ret_idx int default 0;
    declare ret_member_idx int default 0;
    declare ret_bet_status int default 0;
    declare ret_bet_type int default 0;
    declare ret_total_bet_money int default 0;
    declare ret_folder_type int default 0;
    declare ret_take_money int default 0;
    declare ret_take_point int default 0;
    declare ret_create_dt datetime default null;
    
   	DECLARE ret_code INT;
	DECLARE errno INT;
    DECLARE v_txt_error_msg text;


    BEGIN
		GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO
		, v_txt_error_msg = MESSAGE_TEXT;
        set ret_code = -1000;
		SELECT ret_code,errno AS MYSQL_ERROR,v_txt_error_msg as MESSAGE_TEXT;
		ROLLBACK;
    END;
           
    START TRANSACTION;
    
    select idx     , member_idx,    bet_status,     bet_type,     total_bet_money,     folder_type,     take_money,     take_point,     create_dt
    into   ret_idx, ret_member_idx, ret_bet_status, ret_bet_type, ret_total_bet_money, ret_folder_type, ret_take_money, ret_take_point, ret_create_dt
    from member_bet where idx = in_idx;
    
    if 3 <> ret_bet_status OR ret_take_money <> 0 then
		leave main;
    end if;
    
    INSERT INTO `member_bet_bakup` SELECT * FROM `member_bet` where idx = ret_idx;
    INSERT INTO `member_bet_detail_backup` SELECT * FROM `member_bet_detail` where bet_idx = ret_idx;
    INSERT INTO `t_log_cash_backup` SELECT * FROM `t_log_cash` where ac_idx = ret_idx;
    
    DELETE FROM `member_bet` WHERE idx = ret_idx;
    DELETE FROM `member_bet_detail` where bet_idx = ret_idx;
    DELETE FROM `t_log_cash` where ac_idx = ret_idx;
    
    UPDATE member SET money = money + ret_total_bet_money WHERE idx = ret_member_idx;
    
    COMMIT;
END main ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `rollbackDataSports` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `rollbackDataSports`(
in in_type varchar(10)
)
BEGIN

IF 'go_bet' = in_type THEN
    truncate lsports_bet;
	INSERT INTO lsports_bet
	SELECT * FROM lsports_bet_InnoDB;
ELSEIF 'go_policy' = in_type THEN
    truncate dividend_policy;
	INSERT INTO dividend_policy
	SELECT * FROM dividend_policy_innodb;
ELSEIF 'go_bet_sum' = in_type THEN
	truncate fixtures_bet_sum;
	INSERT INTO fixtures_bet_sum
	SELECT * FROM fixtures_bet_sum_innodb;
ELSEIF 'go_fixtures' = in_type THEN
    truncate lsports_fixtures;
	INSERT INTO lsports_fixtures
	SELECT * FROM lsports_fixtures_innodb;   
ELSEIF 'go_leagues' = in_type THEN
    truncate lsports_leagues;
	INSERT INTO lsports_leagues
	SELECT * FROM lsports_leagues_innodb;
ELSEIF 'go_locations' = in_type THEN
    truncate lsports_locations;
	INSERT INTO lsports_locations
	SELECT * FROM lsports_locations_innodb;
ELSEIF 'go_markets' = in_type THEN
    truncate lsports_markets;
	INSERT INTO lsports_markets
	SELECT * FROM lsports_markets_innodb;   
ELSEIF 'go_participant' = in_type THEN
    truncate lsports_participant;
	INSERT INTO lsports_participant
	SELECT * FROM lsports_participant_innodb;   
ELSEIF 'go_sports' = in_type THEN
    truncate lsports_sports;
	INSERT INTO lsports_sports
	SELECT * FROM lsports_sports_innodb;     
ELSEIF 'go_all' = in_type THEN
	truncate lsports_bet;
	INSERT INTO lsports_bet
	SELECT * FROM lsports_bet_InnoDB;

    truncate dividend_policy;
	INSERT INTO dividend_policy
	SELECT * FROM dividend_policy_innodb;
  
	truncate fixtures_bet_sum;
	INSERT INTO fixtures_bet_sum
	SELECT * FROM fixtures_bet_sum_innodb;

    truncate lsports_fixtures;
	INSERT INTO lsports_fixtures
	SELECT * FROM lsports_fixtures_innodb;   
 
    truncate lsports_leagues;
	INSERT INTO lsports_leagues
	SELECT * FROM lsports_leagues_innodb;
 
    truncate lsports_locations;
	INSERT INTO lsports_locations
	SELECT * FROM lsports_locations_innodb;
 
    truncate lsports_markets;
	INSERT INTO lsports_markets
	SELECT * FROM lsports_markets_innodb;   
 
    truncate lsports_participant;
	INSERT INTO lsports_participant
	SELECT * FROM lsports_participant_innodb;   

    truncate lsports_sports;
	INSERT INTO lsports_sports
	SELECT * FROM lsports_sports_innodb;     
 END IF;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `rollbackToMemoryDB` */;
DELIMITER ;;
CREATE DEFINER=`gambleadmin`@`%` PROCEDURE `rollbackToMemoryDB`(
in in_type varchar(10)
)
BEGIN
	
IF 'go_bet' = in_type THEN
    truncate lsports_bet;
	truncate lsports_bet_InnoDB;
	INSERT INTO lsports_bet
	SELECT * FROM lsports_bet_backup;
	
ELSEIF 'go_policy' = in_type THEN
    truncate dividend_policy;
	truncate dividend_policy_innodb;
	INSERT INTO dividend_policy
	SELECT * FROM dividend_policy_backup;
    
ELSEIF 'go_bet_sum' = in_type THEN
	truncate fixtures_bet_sum;
	truncate fixtures_bet_sum_innodb;
	INSERT INTO fixtures_bet_sum
	SELECT * FROM fixtures_bet_sum_backup;
    
ELSEIF 'go_fixtures' = in_type THEN
    truncate lsports_fixtures;
    truncate lsports_fixtures_innodb;
	INSERT INTO lsports_fixtures
	SELECT * FROM lsports_fixtures_backup;   
    
ELSEIF 'go_leagues' = in_type THEN
    truncate lsports_leagues;
	INSERT INTO lsports_leagues
	SELECT * FROM lsports_leagues_innodb;
    
ELSEIF 'go_locations' = in_type THEN
    truncate lsports_locations;
	truncate lsports_locations_innodb;
	INSERT INTO lsports_locations
	SELECT * FROM lsports_locations_backup;
    
ELSEIF 'go_markets' = in_type THEN
    truncate lsports_markets;
	truncate lsports_markets_innodb;
	INSERT INTO lsports_markets
	SELECT * FROM lsports_markets_backup;   
    
ELSEIF 'go_participant' = in_type THEN
    truncate lsports_participant;
	truncate lsports_participant_innodb;
	INSERT INTO lsports_participant
	SELECT * FROM lsports_participant_backup;   
    
ELSEIF 'go_sports' = in_type THEN
    truncate lsports_sports;
	truncate lsports_sports_innodb;
	INSERT INTO lsports_sports
	SELECT * FROM lsports_sports_backup;     
    
    
ELSEIF 'go_day_cash' = in_type THEN
    truncate total_day_cash;
	INSERT INTO total_day_cash
	SELECT * FROM total_day_cash_backup;     
    
ELSEIF 'go_all' = in_type THEN
	truncate lsports_bet;
    truncate lsports_bet_InnoDB;
	INSERT INTO lsports_bet
	SELECT * FROM lsports_bet_backup;
	
    
    truncate dividend_policy;
    truncate dividend_policy_innodb;
	INSERT INTO dividend_policy
	SELECT * FROM dividend_policy_backup;
    
    
	truncate fixtures_bet_sum;
    truncate fixtures_bet_sum_innodb;
	INSERT INTO fixtures_bet_sum
	SELECT * FROM fixtures_bet_sum_backup;
    
    
    truncate lsports_fixtures;
    truncate lsports_fixtures_innodb;
	INSERT INTO lsports_fixtures
	SELECT * FROM lsports_fixtures_backup;   
    
    
    truncate lsports_leagues;
	truncate lsports_leagues_innodb;
	INSERT INTO lsports_leagues
	SELECT * FROM lsports_leagues_backup;
    
    
    truncate lsports_locations;
    truncate lsports_locations_innodb;
	INSERT INTO lsports_locations
	SELECT * FROM lsports_locations_backup;
    
    
    truncate lsports_markets;
    truncate lsports_markets_innodb;
	INSERT INTO lsports_markets
	SELECT * FROM lsports_markets_backup;   
    
    
    truncate lsports_participant;
    truncate lsports_participant_innodb;
	INSERT INTO lsports_participant
	SELECT * FROM lsports_participant_backup;   
    
    
    truncate lsports_sports;
    truncate lsports_sports_innodb;
	INSERT INTO lsports_sports
	SELECT * FROM lsports_sports_backup;     
    
    
	truncate total_day_cash;
	INSERT INTO total_day_cash
	SELECT * FROM total_day_cash_backup;     
    
 END IF;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `spInsertUpdateODDLeagueInfo` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `spInsertUpdateODDLeagueInfo`(
	IN Iid INT
    , Iname VARCHAR(45)
    , IlocationId INT
    , IsportId INT
    , Iseason VARCHAR(45)
)
main: BEGIN

	INSERT INTO `mydb`.`lsports_leagues` (id, bet_type, `name`, location_id, sport_id, season, lang)
	VALUES (Iid, 1, Iname, IlocationId, IsportId, Iseason, 'ko')
	ON DUPLICATE KEY UPDATE `name` = VALUES(`name`), location_id = VALUES(location_id), sport_id = VALUES(sport_id), season = VALUES(season), lang = VALUES(lang);
		
	INSERT INTO `mydb`.`lsports_leagues` (id, bet_type, `name`, location_id, sport_id, season, lang)
	VALUES (Iid, 2, Iname, IlocationId, IsportId, Iseason, 'ko')
	ON DUPLICATE KEY UPDATE `name` = VALUES(`name`), location_id = VALUES(location_id), sport_id = VALUES(sport_id), season = VALUES(season), lang = VALUES(lang);
     
END main ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `spSelectFixtureMarketsBetType3Table` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `spSelectFixtureMarketsBetType3Table`(
	IN IbetType TINYINT
    , IfixtureId INT
)
main: BEGIN

    
	
    IF 1 = IbetType THEN
		SELECT fix.display_status, fix.fixture_start_date,
        fix.fixture_sport_id, fix.fixture_league_id,
        sports.deduction_refund_rate as sp_deduction_refund_rate, leagues.deduction_refund_rate as lg_deduction_refund_rate
		FROM lsports_fixtures as fix
		LEFT JOIN   lsports_sports as sports
		ON   fix.fixture_sport_id = sports.id   
		LEFT JOIN   lsports_leagues as leagues
		ON   fix.fixture_league_id = leagues.id   
		WHERE fix.fixture_id = IfixtureId AND fix.bet_type = IbetType
		AND sports.is_use = 1 AND sports.bet_type = IbetType AND leagues.bet_type = IbetType AND leagues.is_use = 1;
    ELSE
		SELECT fix.display_status, fix.fixture_start_date, fix.fixture_sport_id,
        fix.fixture_league_id,
        sports.deduction_refund_rate as sp_deduction_refund_rate, leagues.deduction_refund_rate as lg_deduction_refund_rate
		FROM lsports_fixtures as fix
		LEFT JOIN   lsports_sports as sports
		ON   fix.fixture_sport_id = sports.id   
		LEFT JOIN   lsports_leagues as leagues
		ON   fix.fixture_league_id = leagues.id   
		WHERE fix.fixture_id = IfixtureId AND fix.bet_type = IbetType
		AND sports.is_use = 1 AND sports.bet_type = IbetType AND leagues.bet_type = IbetType;
    END IF;
     
END main ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `spUpdateFixturesDataType2` */;
DELIMITER ;;
CREATE DEFINER=`kadminwin`@`%` PROCEDURE `spUpdateFixturesDataType2`(
	IN IbetType TINYINT
    , IfixtureId INT
    , IliveTime VARCHAR(45)
    , IliveCurrentPeriod INT
    , Istatus VARCHAR(2)
    , IdisplayStatus INT
    , Ivalue1 INT
    , Ivalue2 INT
    , IliveScore MEDIUMTEXT 
)
main: BEGIN

	DECLARE retcode INT DEFAULT 0;
	DECLARE tDisplayStatus INT DEFAULT 0;
	DECLARE tFixtureStartDate DATETIME DEFAULT 0;
	DECLARE tFixtureSportsId INT DEFAULT 0;
    
	IF 1 = IbetType THEN
		SELECT fixtures.display_status, fixtures.fixture_start_date, fixtures.fixture_sport_id INTO tDisplayStatus, tFixtureStartDate, tFixtureSportsId from `mydb`.`lsports_fixtures` as fixtures
		LEFT JOIN `mydb`.`lsports_leagues` as leagues ON fixtures.fixture_league_id = leagues.id AND fixtures.fixture_sport_id = leagues.sport_id
		WHERE fixtures.fixture_id = IfixtureId AND fixtures.display_status IN (1,2) AND fixtures.bet_type = IbetType AND leagues.is_use = 1 ORDER BY fixtures.fixture_start_date DESC LIMIT 1;
    ELSE
		SELECT fixtures.display_status,fixtures.fixture_start_date,fixtures.fixture_sport_id INTO tDisplayStatus, tFixtureStartDate, tFixtureSportsId from `mydb`.`lsports_fixtures` as fixtures
		WHERE fixtures.fixture_id = IfixtureId AND fixtures.display_status IN (1,2) AND fixtures.bet_type = IbetType ORDER BY fixtures.fixture_start_date DESC LIMIT 1;
    END IF;
    
    IF 0 != IdisplayStatus THEN
		SET tDisplayStatus = IdisplayStatus;
    END IF;


    IF 0 = tDisplayStatus AND 0 = tFixtureStartDate AND 0 = tFixtureSportsId THEN
		SET retcode = -1;
		SELECT retcode;
		LEAVE main;
    END IF;

    IF (1 = IdisplayStatus OR 2 = IdisplayStatus) AND 3 = tDisplayStatus THEN
		SET retcode = -2;
		SELECT retcode;
		LEAVE main;
    END IF;
    
    IF '2' = Istatus OR '3' = Istatus THEN
		IF now() < tFixtureStartDate THEN
			SET retcode = -3;
			SELECT retcode;
			LEAVE main;
		END IF;
    END IF;

    
	UPDATE `mydb`.`lsports_fixtures` 
    SET live_time_x = IliveTime, live_current_period_x = IliveCurrentPeriod, display_status = tDisplayStatus, fixture_status = Istatus, live_results_p1 = Ivalue1, live_results_p2 = Ivalue2,
	livescore = IliveScore
    WHERE fixture_id = IfixtureId AND bet_type = IbetType;
    
    SELECT retcode;
     
END main ;;
DELIMITER ;


