/*
 Navicat Premium Data Transfer

 Source Server         : 趣程支持
 Source Server Type    : MySQL
 Source Server Version : 50736
 Source Host           : 47.99.43.28:3306
 Source Schema         : db_mp_dw

 Target Server Type    : MySQL
 Target Server Version : 50736
 File Encoding         : 65001

 Date: 21/12/2021 15:36:23
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for dw_day
-- ----------------------------
DROP TABLE IF EXISTS `dw_day`;
CREATE TABLE `dw_day`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏数量',
  `agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '推广员数量',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `d_date_unique`(`date`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日统计表' ROW_FORMAT = COMPACT;

-- ----------------------------
-- Records of dw_day
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_agent
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_agent`;
CREATE TABLE `dw_day_agent`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `agent_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '渠道名称',
  `app_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏数量',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `da_daam_unique`(`date`, `agent_id`) USING BTREE,
  INDEX `da_agent_index`(`agent_id`) USING BTREE,
  INDEX `da_country_index`(`mobile_prefix`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日推广员统计表' ROW_FORMAT = COMPACT;

-- ----------------------------
-- Records of dw_day_agent
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_agent_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_agent_switch`;
CREATE TABLE `dw_day_agent_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `agent_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '渠道名称',
  `app_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏数量',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `da_daam_unique`(`date`, `agent_id`) USING BTREE,
  INDEX `da_agent_index`(`agent_id`) USING BTREE,
  INDEX `da_country_index`(`mobile_prefix`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日推广员统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_agent_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_game
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_game`;
CREATE TABLE `dw_day_game`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `app_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '游戏名称',
  `agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '推广员数量',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dgc_dg_unique`(`date`, `app_id`) USING BTREE,
  INDEX `dgc_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏统计表' ROW_FORMAT = COMPACT;

-- ----------------------------
-- Records of dw_day_game
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_game_agent
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_game_agent`;
CREATE TABLE `dw_day_game_agent`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `app_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '游戏名称',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `agent_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '渠道名称',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dga_dga_unique`(`date`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dga_game_index`(`app_id`) USING BTREE,
  INDEX `dga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏推广员统计表' ROW_FORMAT = COMPACT;

-- ----------------------------
-- Records of dw_day_game_agent
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_game_agent_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_game_agent_switch`;
CREATE TABLE `dw_day_game_agent_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `app_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '游戏名称',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `agent_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '渠道名称',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dga_dga_unique`(`date`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dga_game_index`(`app_id`) USING BTREE,
  INDEX `dga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏推广员统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_game_agent_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_game_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_game_switch`;
CREATE TABLE `dw_day_game_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `app_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '游戏名称',
  `agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '推广员数量',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dgc_dg_unique`(`date`, `app_id`) USING BTREE,
  INDEX `dgc_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_game_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_hga_temp
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_hga_temp`;
CREATE TABLE `dw_day_hga_temp`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏id',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dhga_dhga_unique`(`date`, `hour_key`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dhga_hour_index`(`hour_key`) USING BTREE,
  INDEX `dhga_game_index`(`app_id`) USING BTREE,
  INDEX `dhga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段渠道游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_hga_temp
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_hga_temp_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_hga_temp_switch`;
CREATE TABLE `dw_day_hga_temp_switch`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏id',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dhga_dhga_unique`(`date`, `hour_key`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dhga_hour_index`(`hour_key`) USING BTREE,
  INDEX `dhga_game_index`(`app_id`) USING BTREE,
  INDEX `dhga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段渠道游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_hga_temp_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_hour_temp
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_hour_temp`;
CREATE TABLE `dw_day_hour_temp`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `mem_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '玩家id',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '归属渠道',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `reg_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '玩家注册时间',
  `reg_days` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册天数',
  `reg_hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册时间key 1~24',
  `game_reg_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '玩家注册时间',
  `game_reg_days` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册天数',
  `game_reg_hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册时间key 1~24',
  `login_cnt` int(11) UNSIGNED NOT NULL DEFAULT 1 COMMENT '打开次数',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '累计充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '累计真实充值',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dh_date_mem_app_device_unique`(`date`, `hour_key`, `mem_id`, `app_id`) USING BTREE,
  INDEX `dh_mem_index`(`mem_id`) USING BTREE,
  INDEX `dh_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每时统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_hour_temp
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_hour_temp_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_hour_temp_switch`;
CREATE TABLE `dw_day_hour_temp_switch`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `mem_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '玩家id',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '归属渠道',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `reg_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '玩家注册时间',
  `reg_days` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册天数',
  `reg_hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册时间key 1~24',
  `game_reg_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '玩家注册时间',
  `game_reg_days` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册天数',
  `game_reg_hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册时间key 1~24',
  `login_cnt` int(11) UNSIGNED NOT NULL DEFAULT 1 COMMENT '打开次数',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '累计充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '累计真实充值',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dh_date_mem_app_device_unique`(`date`, `hour_key`, `mem_id`, `app_id`) USING BTREE,
  INDEX `dh_mem_index`(`mem_id`) USING BTREE,
  INDEX `dh_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每时统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_hour_temp_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_day_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_day_switch`;
CREATE TABLE `dw_day_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏数量',
  `agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '推广员数量',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `stay_time` bigint(20) NOT NULL DEFAULT 0 COMMENT '停留时间',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `d_date_unique`(`date`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_day_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour`;
CREATE TABLE `dw_hour`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dh_dh_unique`(`date`, `hour_key`) USING BTREE,
  INDEX `dh_hour_index`(`hour_key`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_agent
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_agent`;
CREATE TABLE `dw_hour_agent`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dha_dha_unique`(`date`, `hour_key`, `agent_id`) USING BTREE,
  INDEX `dha_hour_index`(`hour_key`) USING BTREE,
  INDEX `dha_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段渠道统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_agent
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_agent_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_agent_switch`;
CREATE TABLE `dw_hour_agent_switch`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dha_dha_unique`(`date`, `hour_key`, `agent_id`) USING BTREE,
  INDEX `dha_hour_index`(`hour_key`) USING BTREE,
  INDEX `dha_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段渠道统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_agent_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_game
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_game`;
CREATE TABLE `dw_hour_game`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏id',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dhg_dhg_unique`(`date`, `hour_key`, `app_id`) USING BTREE,
  INDEX `dhg_hour_index`(`hour_key`) USING BTREE,
  INDEX `dhg_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_game
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_game_agent
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_game_agent`;
CREATE TABLE `dw_hour_game_agent`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏id',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dhga_dhga_unique`(`date`, `hour_key`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dhga_hour_index`(`hour_key`) USING BTREE,
  INDEX `dhga_game_index`(`app_id`) USING BTREE,
  INDEX `dhga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段渠道游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_game_agent
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_game_agent_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_game_agent_switch`;
CREATE TABLE `dw_hour_game_agent_switch`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏id',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dhga_dhga_unique`(`date`, `hour_key`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dhga_hour_index`(`hour_key`) USING BTREE,
  INDEX `dhga_game_index`(`app_id`) USING BTREE,
  INDEX `dhga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段渠道游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_game_agent_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_game_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_game_switch`;
CREATE TABLE `dw_hour_game_switch`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏id',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dhg_dhg_unique`(`date`, `hour_key`, `app_id`) USING BTREE,
  INDEX `dhg_hour_index`(`hour_key`) USING BTREE,
  INDEX `dhg_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段游戏统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_game_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_hour_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_hour_switch`;
CREATE TABLE `dw_hour_switch`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',
  `hour_key` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '时间KEY值 1~24',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '登陆玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `sum_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总充值',
  `sum_real_money` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '总真实充值',
  `reg_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付总额',
  `reg_real_sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当日注册即付真实充值',
  `pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付玩家数量',
  `reg_pay_mem_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费玩家数',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dh_dh_unique`(`date`, `hour_key`) USING BTREE,
  INDEX `dh_hour_index`(`hour_key`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日时段统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_hour_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_agent
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_agent`;
CREATE TABLE `dw_ltv_agent`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `agent_id` int(10) UNSIGNED NOT NULL COMMENT '代理ID',
  `ads_id` smallint(5) UNSIGNED NOT NULL DEFAULT 0 COMMENT '1 CPA 2 CPS 3 CPC',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `lga_date_agent_unique`(`date`, `agent_id`) USING BTREE,
  INDEX `lga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日渠道LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_agent
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_agent_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_agent_switch`;
CREATE TABLE `dw_ltv_agent_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '代理ID',
  `ads_id` smallint(3) UNSIGNED NOT NULL DEFAULT 0 COMMENT '1 CPA 2 CPS 3 CPC',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `lga_date_agent_unique`(`date`, `agent_id`) USING BTREE,
  INDEX `lga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日渠道LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_agent_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_day
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_day`;
CREATE TABLE `dw_ltv_day`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ld_date_unique`(`date`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_day
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_day_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_day_switch`;
CREATE TABLE `dw_ltv_day_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ld_date_unique`(`date`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_day_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_game
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_game`;
CREATE TABLE `dw_ltv_game`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `app_id` int(10) UNSIGNED NOT NULL COMMENT '游戏ID',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `lg_date_game_unique`(`date`, `app_id`) USING BTREE,
  INDEX `lga_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_game
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_game_agent
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_game_agent`;
CREATE TABLE `dw_ltv_game_agent`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `app_id` int(10) UNSIGNED NOT NULL COMMENT '游戏ID',
  `agent_id` int(10) UNSIGNED NOT NULL COMMENT '代理ID',
  `ads_id` smallint(5) UNSIGNED NOT NULL DEFAULT 0 COMMENT '1 CPA 2 CPS 3 CPC',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `lga_date_game_agent_unique`(`date`, `app_id`, `agent_id`) USING BTREE,
  INDEX `lga_game_index`(`app_id`) USING BTREE,
  INDEX `lga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日渠道游戏LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_game_agent
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_game_agent_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_game_agent_switch`;
CREATE TABLE `dw_ltv_game_agent_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '代理ID',
  `ads_id` smallint(3) UNSIGNED NOT NULL DEFAULT 0 COMMENT '1 CPA 2 CPS 3 CPC',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `lga_date_game_agent_unique`(`date`, `app_id`, `agent_id`) USING BTREE,
  INDEX `lga_game_index`(`app_id`) USING BTREE,
  INDEX `lga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日渠道游戏LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_game_agent_switch
-- ----------------------------

-- ----------------------------
-- Table structure for dw_ltv_game_switch
-- ----------------------------
DROP TABLE IF EXISTS `dw_ltv_game_switch`;
CREATE TABLE `dw_ltv_game_switch`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL COMMENT '日期',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `costs` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '花费',
  `reg_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '新增设备数',
  `sum_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `day1` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '1日充值金额',
  `day2` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '2日充值金额',
  `day3` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '3日充值金额',
  `day4` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '4日充值金额',
  `day5` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '5日充值金额',
  `day6` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '6日充值金额',
  `day7` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '7日充值金额',
  `day8` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '8日充值金额',
  `day9` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '9日充值金额',
  `day10` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '10日充值金额',
  `day11` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '11日充值金额',
  `day12` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '12日充值金额',
  `day13` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '13日充值金额',
  `day14` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '14日充值金额',
  `day15` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '15日充值金额',
  `day16` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '16日充值金额',
  `day17` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '17日充值金额',
  `day18` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '18日充值金额',
  `day19` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '19日充值金额',
  `day20` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '20日充值金额',
  `day21` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '21日充值金额',
  `day22` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '22日充值金额',
  `day23` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '23日充值金额',
  `day24` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '24日充值金额',
  `day25` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '25日充值金额',
  `day26` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '26日充值金额',
  `day27` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '27日充值金额',
  `day28` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '28日充值金额',
  `day29` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '29日充值金额',
  `day30` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '30日充值金额',
  `day31` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '31日充值金额',
  `day32` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '32日充值金额',
  `day33` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '33日充值金额',
  `day34` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '34日充值金额',
  `day35` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '35日充值金额',
  `day36` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '36日充值金额',
  `day37` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '37日充值金额',
  `day38` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '38日充值金额',
  `day39` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '39日充值金额',
  `day40` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '40日充值金额',
  `day41` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '41日充值金额',
  `day42` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '42日充值金额',
  `day43` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '43日充值金额',
  `day44` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '44日充值金额',
  `day45` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '45日充值金额',
  `day46` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '46日充值金额',
  `day47` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '47日充值金额',
  `day48` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '48日充值金额',
  `day49` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '49日充值金额',
  `day50` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '50日充值金额',
  `day51` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '51日充值金额',
  `day52` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '52日充值金额',
  `day53` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '53日充值金额',
  `day54` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '54日充值金额',
  `day55` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '55日充值金额',
  `day56` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '56日充值金额',
  `day57` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '57日充值金额',
  `day58` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '58日充值金额',
  `day59` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '59日充值金额',
  `day60` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '60日充值金额',
  `day90` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至90日充值金额',
  `day120` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至120日充值金额',
  `day180` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至180日充值金额',
  `day270` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至270日充值金额',
  `day360` decimal(12, 2) UNSIGNED NOT NULL DEFAULT 0.00 COMMENT '至360日充值金额',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `lg_date_game_unique`(`date`, `app_id`) USING BTREE,
  INDEX `lga_game_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏LTV统计表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of dw_ltv_game_switch
-- ----------------------------

-- ----------------------------
-- Table structure for log_day_mem_temp
-- ----------------------------
DROP TABLE IF EXISTS `log_day_mem_temp`;
CREATE TABLE `log_day_mem_temp`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL DEFAULT '2020-01-01' COMMENT '日期',
  `mem_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '玩家ID',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '国家手机区号',
  `task_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '任务ID',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '归属渠道',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `reg_time` bigint(11) NOT NULL DEFAULT 0 COMMENT '玩家注册时间',
  `reg_days` int(11) NOT NULL DEFAULT 0 COMMENT '注册天数',
  `device_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '手机设备码',
  `new_device` tinyint(2) NOT NULL DEFAULT 1 COMMENT '2 新设备 1 非新',
  `device_cnt` int(11) NOT NULL DEFAULT 1 COMMENT '登陆的设备个数',
  `login_cnt` int(11) NOT NULL DEFAULT 1 COMMENT '登陆次数',
  `sum_money` double(12, 2) NOT NULL DEFAULT 0.00 COMMENT '累计充值',
  `sum_real_money` double(12, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_time` bigint(11) NOT NULL DEFAULT 0 COMMENT '第一笔充值时间',
  `last_pay_time` bigint(11) NOT NULL DEFAULT 0 COMMENT '最近充值时间',
  `last_money` double(12, 2) NOT NULL DEFAULT 0.00 COMMENT '最近充值金额',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '订单数量',
  `order_suc_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '支付成功订单数量',
  `last_login_ip` bigint(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '玩家最近登陆ip',
  `auth_cnt` int(11) NOT NULL DEFAULT 0 COMMENT '授权登陆次数',
  `is_cpa` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否计算cpa 1 否 2是',
  `is_auth` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否第三方注册 1否 2是',
  `reg_app_id` int(11) NOT NULL DEFAULT 0 COMMENT '注册游戏ID',
  `is_new_app` tinyint(4) NOT NULL DEFAULT 1 COMMENT '是否游戏新增注册玩家 1 否 2是',
  `is_new_role` tinyint(4) NOT NULL DEFAULT 1 COMMENT '是否游戏新增角色 1 否 2是',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ldmt_date_mem_app_unique`(`date`, `mem_id`, `app_id`) USING BTREE,
  INDEX `ldmt_ip_index`(`last_login_ip`) USING BTREE,
  INDEX `ldmt_agent_index`(`agent_id`) USING BTREE,
  INDEX `ldmt_app_index`(`app_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '玩家每日临时' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of log_day_mem_temp
-- ----------------------------

-- ----------------------------
-- Table structure for log_dgac_temp
-- ----------------------------
DROP TABLE IF EXISTS `log_dgac_temp`;
CREATE TABLE `log_dgac_temp`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL DEFAULT '2020-01-01' COMMENT '日期',
  `mobile_prefix` int(11) UNSIGNED NOT NULL DEFAULT 156 COMMENT '国家手机区号',
  `app_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏ID',
  `app_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '游戏名称',
  `agent_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '渠道ID',
  `agent_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '渠道名称',
  `share_agent_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享人数',
  `share_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '分享次数',
  `click_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击数',
  `click_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '点击人数',
  `today_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '今日游戏激活数',
  `page_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '落地页点击数',
  `active_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '游戏激活数',
  `down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载数',
  `down_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载人数',
  `real_down_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '真实下载数',
  `user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活跃玩家数量',
  `history_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计玩家数量',
  `wau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃人数',
  `mau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃人数',
  `ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'IP数量',
  `device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '设备数量',
  `history_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '累计设备数量',
  `dwau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近7天活跃设备数',
  `dmau` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最近30天活跃设备数',
  `reg_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册玩家数',
  `reg_device_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册设备数',
  `reg_ip_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册IP数',
  `pay_user_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家数',
  `order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成功订单数',
  `fail_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '失败订单数',
  `un_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '待支付订单数',
  `reg_order_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册订单数',
  `reg_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '注册即付费人数',
  `sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '充值金额',
  `sum_real_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '自然流水金额',
  `first_pay_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '首次付费人数',
  `first_pay_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '首付总额',
  `reg_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付总额',
  `reg_real_sum_money` decimal(20, 2) NOT NULL DEFAULT 0.00 COMMENT '注册即付自然流水总额',
  `cpa_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算cpa玩家数量',
  `openid_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '第三方注册玩家数量',
  `new_role_cnt` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增创角数',
  `day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `device_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二日留存量',
  `device_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '三日留存量',
  `device_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '四日留存量',
  `device_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '五日留存量',
  `device_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '六日留存量',
  `device_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '七日留存量',
  `device_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '八日留存量',
  `device_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '九日留存量',
  `device_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '十日留存量',
  `device_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '11日留存量',
  `device_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '12日留存量',
  `device_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '13日留存量',
  `device_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '14日留存量',
  `device_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '15日留存量',
  `device_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '21日留存量',
  `device_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '30日留存量',
  `device_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '60日留存量',
  `pay_day2` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家二日留存',
  `pay_day3` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家三日留存',
  `pay_day4` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家四日留存',
  `pay_day5` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家五日留存',
  `pay_day6` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家六日留存',
  `pay_day7` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家七日留存',
  `pay_day8` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家八日留存',
  `pay_day9` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家九日留存',
  `pay_day10` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家十日留存',
  `pay_day11` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家11日留存',
  `pay_day12` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家12日留存',
  `pay_day13` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家13日留存',
  `pay_day14` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家14日留存',
  `pay_day15` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家15日留存',
  `pay_day21` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家21日留存',
  `pay_day30` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家30日留存',
  `pay_day60` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '付费玩家60日留存',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `dga_dga_unique`(`date`, `app_id`, `agent_id`) USING BTREE,
  INDEX `dga_game_index`(`app_id`) USING BTREE,
  INDEX `dga_agent_index`(`agent_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '每日游戏推广员统计表' ROW_FORMAT = COMPACT;

-- ----------------------------
-- Records of log_dgac_temp
-- ----------------------------

-- ----------------------------
-- Procedure structure for rundaily
-- ----------------------------
DROP PROCEDURE IF EXISTS `rundaily`;
delimiter ;;
CREATE PROCEDURE `rundaily`(IN `iday` date)
BEGIN

DECLARE Tflag INT DEFAULT 0;

DECLARE Tappid INT;

DECLARE Tdate DATE;

DECLARE Tregday INT;

DECLARE Tagentid INT;

DECLARE Tmobile_prefix INT DEFAULT 156;

DECLARE Tregcnt INT;

DECLARE Tregpaycnt INT;

DECLARE Tagent_cnt INT;

DECLARE Tordercnt INT;

DECLARE Tcnt INT;

DECLARE Tregtime BIGINT;

DECLARE T30starttime BIGINT; 

DECLARE T7starttime BIGINT; 

DECLARE Tsummoney DOUBLE(20,2);

DECLARE Tsharemoney DOUBLE(20,2);

DECLARE Tratetype INT;

DECLARE Tmoney1 DOUBLE(20,2);

DECLARE Tmoney2 DOUBLE(20,2);

DECLARE Tmoney3 DOUBLE(20,2);

DECLARE Tmoney4 DOUBLE(20,2);

DECLARE Tmoney5 DOUBLE(20,2);

DECLARE Tmoney6 DOUBLE(20,2);

DECLARE Tmoney7 DOUBLE(20,2);

DECLARE Tmoney8 DOUBLE(20,2);

DECLARE Tagentrate DOUBLE(5,4);

DECLARE Trate1 DOUBLE(5,4);

DECLARE Trate2 DOUBLE(5,4);

DECLARE Trate3 DOUBLE(5,4);

DECLARE Trate4 DOUBLE(5,4);

DECLARE Trate5 DOUBLE(5,4);

DECLARE Trate6 DOUBLE(5,4);

DECLARE Trate7 DOUBLE(5,4);

DECLARE Trate8 DOUBLE(5,4);

DECLARE Tusercnt INT;

DECLARE Tpaycnt INT;

DECLARE Tdevice_cnt INT;

DECLARE Tsetdate DATE DEFAULT iday;

DECLARE Tstarttime INT;

DECLARE Tendtime INT;

DECLARE TdayFlag varchar(20);

DECLARE TdevicedayFlag varchar(20);

DECLARE TpaydayFlag varchar(20);

DECLARE Tregdate DATE;

DECLARE TformatDate DATE DEFAULT date_format(Tsetdate,'%Y-%m-%d');

DECLARE Tagcursor CURSOR FOR SELECT reg_time,app_id,agent_id,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY app_id,agent_id,mobile_prefix,reg_days;



DECLARE Tacursor CURSOR FOR SELECT reg_time,agent_id,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY agent_id,mobile_prefix,reg_days;



DECLARE Tgcursor CURSOR FOR SELECT reg_time,app_id,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY app_id,mobile_prefix,reg_days;



DECLARE Tcursor CURSOR FOR SELECT reg_time,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY mobile_prefix,reg_days;



DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Tflag = 1;



SET Tstarttime=unix_timestamp(Tsetdate);

SET T30starttime=Tstarttime-86400*29;

SET T7starttime=Tstarttime-86400*6;

SET Tendtime=Tstarttime+86400;



SET @Ttable = CONCAT('db_mp_log.log_log_day_mem_',date_format(Tsetdate,'%Y%m') );





CREATE TABLE IF NOT EXISTS `log_day_mem_temp` (

    `id` int(11) NOT NULL AUTO_INCREMENT,

    `date` date NOT NULL DEFAULT '2020-01-01' COMMENT '日期',

    `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家ID',

    `mobile_prefix` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '国家手机区号',

    `task_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '任务ID',

    `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',

    `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

    `reg_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

    `reg_days` int(11) NOT NULL DEFAULT '0' COMMENT '注册天数',

    `device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '手机设备码',

    `new_device` tinyint(2)  NOT NULL DEFAULT '1' COMMENT '2 新设备 1 非新',

    `device_cnt` int(11) NOT NULL DEFAULT '1' COMMENT '登陆的设备个数',

    `login_cnt` int(11) NOT NULL DEFAULT '1' COMMENT '登陆次数',

    `sum_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '累计充值',

    `sum_real_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

    `first_pay_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '第一笔充值时间',

    `last_pay_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '最近充值时间',

    `last_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '最近充值金额',

    `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',

    `order_suc_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '支付成功订单数量',

    `last_login_ip` bigint(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家最近登陆ip',

    `auth_cnt` int(11) NOT NULL DEFAULT '0' COMMENT '授权登陆次数',

    `is_cpa` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否计算cpa 1 否 2是',

    `is_auth` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否第三方注册 1否 2是',

	`reg_app_id` int(11) NOT NULL DEFAULT '0' COMMENT '注册游戏ID',

    `is_new_app` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否游戏新增注册玩家 1 否 2是',

    `is_new_role` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否游戏新增角色 1 否 2是',

    PRIMARY KEY (`id`),

    UNIQUE KEY `ldmt_date_mem_app_unique` (`date`,`mem_id`,`app_id`),

    KEY `ldmt_ip_index` (`last_login_ip`),

    KEY `ldmt_agent_index` (`agent_id`),

    KEY `ldmt_app_index` (`app_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='玩家每日临时';





TRUNCATE `log_day_mem_temp`;

ALTER TABLE `log_day_mem_temp` DISABLE KEYS;



SET @ldmt_sql = "REPLACE INTO `log_day_mem_temp`  (`date`,`mem_id`,`mobile_prefix`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,`new_device`,`device_cnt`,`login_cnt`,`sum_money`,`sum_real_money`,`first_pay_time`,`last_pay_time`,`last_money`,`order_cnt`,`order_suc_cnt`,`last_login_ip`,`auth_cnt`,`is_cpa`,`is_auth`,`reg_app_id`,`is_new_app`,`is_new_role`) SELECT `date`,`mem_id`,156,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,1,`device_cnt`,`login_cnt`,`sum_money`,`sum_real_money`,`first_pay_time`,`last_pay_time`,`last_money`,`order_cnt`,`order_suc_cnt`,`last_login_ip`,0,is_cpa,is_auth,reg_app_id,is_new_app,is_new_role";



SET  @ldmt_sql = concat(@ldmt_sql, ' FROM ',@Ttable,' where `date`=\'',Tsetdate,'\'');



PREPARE ldmt_sql_ex FROM @ldmt_sql;

EXECUTE ldmt_sql_ex;

ALTER TABLE log_day_mem_temp ENABLE KEYS;





DROP TABLE IF EXISTS log_dgac_temp;

CREATE TABLE IF NOT EXISTS `log_dgac_temp` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `date` date NOT NULL DEFAULT '2020-01-01' COMMENT '日期',

  `mobile_prefix` int(11) unsigned NOT NULL DEFAULT '156' COMMENT '国家手机区号',

  `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

  `app_name` varchar(128) NOT NULL DEFAULT '' COMMENT '游戏名称',

  `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',

  `agent_name` varchar(128) NOT NULL DEFAULT '' COMMENT '渠道名称',

  `share_agent_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '分享人数',

  `share_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '分享次数',

  `click_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击数',

  `click_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击人数',

  `today_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '今日游戏激活数',

  `page_down_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '落地页点击数',

  `active_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏激活数',

  `down_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '下载数',

  `down_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '下载人数',

  `real_down_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '真实下载数',

  `user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '活跃玩家数量',

  `history_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '累计玩家数量',

  `wau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近7天活跃人数',

  `mau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近30天活跃人数',

  `ip_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'IP数量',

  `device_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '设备数量',

  `history_device_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '累计设备数量',

  `dwau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近7天活跃设备数',

  `dmau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近30天活跃设备数',

  `reg_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册玩家数',

  `reg_device_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册设备数',

  `reg_ip_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册IP数',

  `pay_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家数',

  `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '成功订单数',

  `fail_order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '失败订单数',

  `un_order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '待支付订单数',

  `reg_order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册订单数',

  `reg_pay_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册即付费人数',

  `sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '充值金额',

  `sum_real_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

  `first_pay_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '首次付费人数',

  `first_pay_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '首付总额',

  `reg_sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '注册即付总额',

  `reg_real_sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '注册即付自然流水总额',

  `cpa_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '计算cpa玩家数量',

  `openid_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '第三方注册玩家数量',

  `new_role_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '新增创角数',

  `day2` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '二日留存量',

  `day3` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '三日留存量',

  `day4` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '四日留存量',

  `day5` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '五日留存量',

  `day6` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '六日留存量',

  `day7` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '七日留存量',

  `day8` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '八日留存量',

  `day9` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '九日留存量',

  `day10` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '十日留存量',

  `day11` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '11日留存量',

  `day12` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '12日留存量',

  `day13` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '13日留存量',

  `day14` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '14日留存量',

  `day15` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '15日留存量',

  `day21` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '21日留存量',

  `day30` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '30日留存量',

  `day60` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '60日留存量',

  `device_day2` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '二日留存量',

  `device_day3` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '三日留存量',

  `device_day4` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '四日留存量',

  `device_day5` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '五日留存量',

  `device_day6` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '六日留存量',

  `device_day7` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '七日留存量',

  `device_day8` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '八日留存量',

  `device_day9` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '九日留存量',

  `device_day10` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '十日留存量',

  `device_day11` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '11日留存量',

  `device_day12` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '12日留存量',

  `device_day13` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '13日留存量',

  `device_day14` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '14日留存量',

  `device_day15` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '15日留存量',

  `device_day21` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '21日留存量',

  `device_day30` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '30日留存量',

  `device_day60` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '60日留存量',

  `pay_day2` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家二日留存',

  `pay_day3` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家三日留存',

  `pay_day4` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家四日留存',

  `pay_day5` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家五日留存',

  `pay_day6` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家六日留存',

  `pay_day7` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家七日留存',

  `pay_day8` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家八日留存',

  `pay_day9` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家九日留存',

  `pay_day10` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家十日留存',

  `pay_day11` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家11日留存',

  `pay_day12` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家12日留存',

  `pay_day13` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家13日留存',

  `pay_day14` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家14日留存',

  `pay_day15` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家15日留存',

  `pay_day21` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家21日留存',

  `pay_day30` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家30日留存',

  `pay_day60` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家60日留存',

  PRIMARY KEY (`id`) USING BTREE,

  UNIQUE KEY `dga_dga_unique` (`date`,`app_id`,`agent_id`) USING BTREE,

  KEY `dga_game_index` (`app_id`) USING BTREE,

  KEY `dga_agent_index` (`agent_id`) USING BTREE

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='每日游戏推广员统计表';









TRUNCATE `log_dgac_temp`;

ALTER TABLE log_dgac_temp DISABLE KEYS;

REPLACE INTO `log_dgac_temp`

(

    `date`,

    `app_id`,

    `agent_id`,

    `mobile_prefix`,

    `active_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(ldmt.`date`,TformatDate) AS `date`,       

    IFNULL(ldmt.`app_id`,0) AS `app_id`,      

    IFNULL(ldmt.`agent_id`,0) AS `agent_id`,       

    IFNULL(ldmt.mobile_prefix,Tmobile_prefix) AS `mobile_prefix`,    

    COUNT(DISTINCT(ldmt.`mem_id`)) AS `active_cnt`,    

    COUNT(DISTINCT(CASE WHEN ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,    

    0 AS `history_user_cnt`, 

    COUNT(DISTINCT(ldmt.`last_login_ip`)) AS `ip_cnt`,    

    COUNT(DISTINCT(ldmt.`device_id`)) AS `device_cnt` , 

    0 AS `history_device_cnt` , 

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`is_new_app` = 2  AND ldmt.`mem_id` > 0 ) THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`device_id` <> '' AND ldmt.`app_id` = ldmt.`reg_app_id`) OR  (ldmt.`is_new_app` = 2 AND ldmt.`device_id` <> '') THEN `device_id` END)) AS `reg_device_cnt`,

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR  ldmt.`is_new_app` = 2 THEN `last_login_ip` END)) AS `reg_ip_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`sum_money`>0 THEN `mem_id` END)) AS `pay_user_cnt`,    

    IFNULL(SUM(ldmt.`order_suc_cnt`),0) AS `order_cnt`,    

    0 AS `fail_order_cnt` , 

    0 AS `un_order_cnt` , 

    IFNULL(SUM(CASE  WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR ldmt.`is_new_app` = 2 THEN ldmt.`order_suc_cnt` ELSE 0 END),0) AS `reg_order_cnt`,    

    COUNT(DISTINCT(CASE  WHEN (ldmt.`reg_days`=0 AND ldmt.`sum_money`>0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`is_new_app` = 2 AND ldmt.`sum_money`>0 ) THEN ldmt.`mem_id` END)) AS `reg_pay_cnt`,    

    IFNULL(SUM(ldmt.`sum_money`),0) AS `sum_money` , 

    SUM(ldmt.`sum_real_money`) AS `sum_real_money` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`mem_id` END)) AS `first_pay_cnt`, 

    IFNULL(SUM(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `first_pay_money` , 

    IFNULL(SUM(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR ldmt.`is_new_app` = 2 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `reg_sum_money` , 

    IFNULL(SUM(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR ldmt.`is_new_app` = 2 THEN ldmt.`sum_real_money`  ELSE 0.00 END),0.00) AS `reg_real_sum_money`, 

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_cpa = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`is_new_app` = 2 AND ldmt.`mem_id` > 0 AND ldmt.is_cpa = 2)  THEN `mem_id` END)) AS `cpa_cnt`	,

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_auth = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`mem_id` > 0 AND ldmt.is_auth = 2 AND ldmt.is_auth = 2)  THEN `mem_id` END)) AS `openid_cnt` ,	

    0	

FROM log_day_mem_temp ldmt

GROUP BY agent_id, app_id;

ALTER TABLE log_dgac_temp ENABLE KEYS;





ALTER TABLE dw_day_game_agent DISABLE KEYS;

REPLACE INTO `dw_day_game_agent`

(

    `date`,

    `app_id`,

    `app_name`,

    `agent_id`,

    `agent_name`,

    `mobile_prefix`,

    `share_cnt`,

    `click_cnt`,

    `click_user_cnt`,

    `page_down_cnt`,

    `active_cnt`,

    `down_cnt`,

    `down_user_cnt`,

    `real_down_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `wau`,

    `mau`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `dwau`,

    `dmau`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`app_id`,0) AS `app_id`, 

    IFNULL(`app_name`,'') AS `app_name`, 

    IFNULL(`agent_id`,0) AS `agent_id`, 

    IFNULL(`agent_name`,'') AS `agent_name`, 

    IFNULL(mobile_prefix,Tmobile_prefix) AS `mobile_prefix`, 

    IFNULL(`share_cnt`,0) AS `share_cnt`, 

    IFNULL(`click_cnt`,0)  AS `click_cnt`, 

    IFNULL(`click_user_cnt`,0) AS `click_user_cnt`, 

    IFNULL(`page_down_cnt`,0) AS `page_down_cnt`, 

    IFNULL(`active_cnt`,0) AS `active_cnt`, 

    IFNULL(`down_cnt`,0) AS `down_cnt`, 

    IFNULL(`down_user_cnt`,0) AS `down_user_cnt`, 

    IFNULL(`real_down_cnt`,0) AS `real_down_cnt`, 

    IFNULL(`user_cnt`,0) AS `user_cnt`, 

    IFNULL(`history_user_cnt`,0) AS `history_user_cnt`, 

    IFNULL(`wau`,0) AS `wau`, 

    IFNULL(`mau`,0) AS `mau`, 

    IFNULL(`ip_cnt`,0) AS `ip_cnt`, 

    IFNULL(`device_cnt`,0) AS `device_cnt`, 

    IFNULL(`history_device_cnt`,0) AS `history_device_cnt`, 

    IFNULL(`dwau`,0) AS `dwau`, 

    IFNULL(`dmau`,0) AS `dmau`, 

    IFNULL(`reg_cnt`,0) AS `reg_cnt`, 

    IFNULL(`reg_device_cnt`,0) AS `reg_device_cnt`, 

    IFNULL(`reg_ip_cnt`,0) AS `reg_ip_cnt`, 

    IFNULL(`pay_user_cnt`,0) AS `pay_user_cnt`, 

    IFNULL(`order_cnt`,0) AS `order_cnt`, 

    IFNULL(`fail_order_cnt`,0) AS `fail_order_cnt`, 

    IFNULL(`un_order_cnt`,0) AS `un_order_cnt`, 

    IFNULL(`reg_order_cnt`,0) AS `reg_order_cnt`, 

    IFNULL(`reg_pay_cnt`,0) AS `reg_pay_cnt`, 

    IFNULL(`sum_money`,0.00) AS `sum_money`, 

    IFNULL(`sum_real_money`,0.00) AS `sum_real_money`, 

    IFNULL(`first_pay_cnt`,0) AS `first_pay_cnt`, 

    IFNULL(`first_pay_money`,0.00) AS `first_pay_money`, 

    IFNULL(`reg_sum_money`,0.00) AS `reg_sum_money`, 

    IFNULL(`reg_real_sum_money`,0.00) AS `reg_real_sum_money`, 

    IFNULL(`cpa_cnt`,0) AS `cpa_cnt`, 

    IFNULL(`openid_cnt`,0) AS `openid_cnt`, 

    IFNULL(`new_role_cnt`,0) AS `new_role_cnt` 

FROM log_dgac_temp;

ALTER TABLE dw_day_game_agent ENABLE KEYS;



   



ALTER TABLE dw_day_agent DISABLE KEYS;

REPLACE INTO `dw_day_agent`

(

    `date`,

    `agent_id`,

    `mobile_prefix`,

    `app_cnt`,

    `active_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(ldmt.`date`,TformatDate) AS `date`,       

    ldmt.`agent_id` AS `agent_id`,       

    IFNULL(ldmt.mobile_prefix,Tmobile_prefix) AS `mobile_prefix`,    

    COUNT(DISTINCT(ldmt.app_id)) AS `app_cnt`,    

    COUNT(DISTINCT(ldmt.`mem_id`)) AS `active_cnt`,    

    COUNT(DISTINCT(CASE WHEN ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,    

    0 AS `history_user_cnt`, 

    COUNT(DISTINCT(ldmt.`last_login_ip`)) AS `ip_cnt`,    

    COUNT(DISTINCT(ldmt.`device_id`)) AS `device_cnt` , 

    0 AS `history_device_cnt` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `mem_id` END)) AS `reg_cnt`	,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`device_id` <> '' AND ldmt.`app_id` = ldmt.`reg_app_id`   THEN `device_id` END)) AS `reg_device_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `last_login_ip` END)) AS `reg_ip_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`sum_money`>0 THEN `mem_id` END)) AS `pay_user_cnt`,    

    IFNULL(SUM(ldmt.`order_suc_cnt`),0) AS `order_cnt`,    

    0 AS `fail_order_cnt` , 

    0 AS `un_order_cnt` , 

    IFNULL(SUM(CASE  WHEN ldmt.`reg_days`=0 THEN ldmt.`order_suc_cnt` ELSE 0 END),0) AS `reg_order_cnt`,    

    COUNT(DISTINCT(CASE  WHEN ldmt.`reg_days`=0 AND ldmt.`sum_money`>0 THEN ldmt.`mem_id` END)) AS `reg_pay_cnt`,    

    IFNULL(SUM(ldmt.`sum_money`),0.00) AS `sum_money` , 

    IFNULL(SUM(ldmt.`sum_real_money`),0.00) AS `sum_real_money` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`mem_id` END)) AS `first_pay_cnt`, 

    IFNULL(SUM(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `first_pay_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `reg_sum_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN ldmt.`sum_real_money`  ELSE 0.00 END),0.00) AS `reg_real_sum_money`, 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_cpa = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `mem_id` END)) AS `cpa_cnt`	,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_auth = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `mem_id` END)) AS `openid_cnt` ,	

    0	

FROM log_day_mem_temp ldmt

GROUP BY agent_id;

ALTER TABLE dw_day_agent ENABLE KEYS;







ALTER TABLE dw_day_game DISABLE KEYS;

REPLACE INTO `dw_day_game`

(

    `date`,

    `app_id`,

    `app_name`,

    `agent_cnt`,

    `mobile_prefix`,

    `share_agent_cnt`,

    `share_cnt`,

    `click_cnt`,

    `click_user_cnt`,

    `page_down_cnt`,

    `active_cnt`,

    `down_cnt`,

    `down_user_cnt`,

    `real_down_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `wau`,

    `mau`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `dwau`,

    `dmau`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`app_id`,0) AS `app_id`, 

    IFNULL(`app_name`,'') AS `app_name`, 

    COUNT(DISTINCT(agent_id)) AS `agent_cnt`, 

    IFNULL(`mobile_prefix`,Tmobile_prefix) AS `mobile_prefix`, 

    COUNT(DISTINCT(CASE WHEN share_cnt>0 THEN `agent_id` END))  AS `share_agent_cnt`, 

    SUM(`share_cnt`) AS `share_cnt`, 

    SUM(`click_cnt`)  AS `click_cnt`, 

    SUM(`click_user_cnt`) AS `click_user_cnt`, 

    SUM(`page_down_cnt`) AS `page_down_cnt`, 

    SUM(`active_cnt`) AS `active_cnt`, 

    SUM(`down_cnt`) AS `down_cnt`, 

    SUM(`down_user_cnt`) AS `down_user_cnt`, 

    SUM(`real_down_cnt`) AS `real_down_cnt`, 

    SUM(`user_cnt`) AS `user_cnt`, 

    SUM(`history_user_cnt`) AS `history_user_cnt`, 

    SUM(`wau`) AS `wau`, 

    SUM(`mau`) AS `mau`, 

    SUM(`ip_cnt`) AS `ip_cnt`, 

    SUM(`device_cnt`) AS `device_cnt`, 

    SUM(`history_device_cnt`) AS `history_device_cnt`, 

    SUM(`dwau`) AS `dwau`, 

    SUM(`dmau`) AS `dmau`, 

    SUM(`reg_cnt`) AS `reg_cnt`, 

    SUM(`reg_device_cnt`) AS `reg_device_cnt`, 

    SUM(`reg_ip_cnt`) AS `reg_ip_cnt`, 

    SUM(`pay_user_cnt`) AS `pay_user_cnt`, 

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`, 

    SUM(`fail_order_cnt`) AS `fail_order_cnt`, 

    SUM(`un_order_cnt`) AS `un_order_cnt`, 

    IFNULL(SUM(`reg_order_cnt`),0) AS `reg_order_cnt`, 

    SUM(`reg_pay_cnt`) AS `reg_pay_cnt`, 

    IFNULL(SUM(`sum_money`),0.00) AS `sum_money`, 

    IFNULL(SUM(`sum_real_money`),0.00) AS `sum_real_money`, 

    SUM(`first_pay_cnt`) AS `first_pay_cnt`, 

    IFNULL(SUM(`first_pay_money`),0.00) AS `first_pay_money`, 

    IFNULL(SUM(`reg_sum_money`),0.00) AS `reg_sum_money`, 

    IFNULL(SUM(`reg_real_sum_money`),0.00) AS `reg_real_sum_money`, 

    IFNULL(SUM(`cpa_cnt`),0) AS `cpa_cnt`,

    IFNULL(SUM(`openid_cnt`),0) AS `openid_cnt`, 

    IFNULL(SUM(`new_role_cnt`),0) AS `new_role_cnt` 

FROM log_dgac_temp

GROUP BY app_id,mobile_prefix;

ALTER TABLE dw_day_game ENABLE KEYS;









ALTER TABLE dw_day DISABLE KEYS;

REPLACE INTO `dw_day`

(

    `date`,

    `mobile_prefix`,

    `agent_cnt`,

    `app_cnt`,

    `active_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(ldmt.`date`,TformatDate) AS `date`,       

    IFNULL(ldmt.mobile_prefix,Tmobile_prefix) AS `mobile_prefix`,    

    COUNT(DISTINCT(ldmt.agent_id)) AS `agent_cnt`,    

    COUNT(DISTINCT(ldmt.app_id)) AS `app_cnt`,    

    COUNT(DISTINCT(ldmt.`mem_id`)) AS `active_cnt`,    

    COUNT(DISTINCT(CASE WHEN ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,    

    

    0 AS `history_user_cnt`, 

    COUNT(DISTINCT(ldmt.`last_login_ip`)) AS `ip_cnt`,    

    COUNT(DISTINCT(ldmt.`device_id`)) AS `device_cnt` , 

    

    0 AS `history_device_cnt` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `reg_cnt`	,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`device_id` <> ''  THEN `device_id` END)) AS `reg_device_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 THEN `last_login_ip` END)) AS `reg_ip_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`sum_money`>0 THEN `mem_id` END)) AS `pay_user_cnt`,    

    IFNULL(SUM(ldmt.`order_suc_cnt`),0) AS `order_cnt`,    

    0 AS `fail_order_cnt` , 

    

    0 AS `un_order_cnt` , 

    IFNULL(SUM(CASE  WHEN ldmt.`reg_days`=0 THEN ldmt.`order_suc_cnt` ELSE 0 END),0) AS `reg_order_cnt`,    

    COUNT(DISTINCT(CASE  WHEN ldmt.`reg_days`=0 AND ldmt.`sum_money`>0 THEN ldmt.`mem_id` END)) AS `reg_pay_cnt`,    

    IFNULL(SUM(ldmt.`sum_money`),0.00) AS `sum_money` , 

    IFNULL(SUM(ldmt.`sum_real_money`),0.00) AS `sum_real_money` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`mem_id` END)) AS `first_pay_cnt`, 

    IFNULL(SUM(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `first_pay_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `reg_sum_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 THEN ldmt.`sum_real_money`  ELSE 0.00 END),0.00) AS `reg_real_sum_money`, 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND is_cpa=2 THEN `mem_id` END)) AS `cpa_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND is_auth=2 THEN `mem_id` END)) AS `openid_cnt`,

   0

FROM log_day_mem_temp ldmt;

ALTER TABLE dw_day_agent ENABLE KEYS;





SET Tflag=0;

OPEN Tagcursor;

    FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 OR Tpaycnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6';

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;



            SET @sqlstr=CONCAT('update dw_day_game_agent SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''), ' AND agent_id=',Tagentid,' AND app_id=',Tappid, ' AND mobile_prefix=',Tmobile_prefix);

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;



            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tagcursor;







SET Tflag=0;

OPEN Tacursor;

    FETCH Tacursor INTO Tregtime,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6';

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;



            SET @sqlstr=CONCAT('update dw_day_agent SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''), ' AND agent_id=',Tagentid);

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;



            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tacursor INTO Tregtime,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tacursor;









SET Tflag=0;

OPEN Tgcursor;

    FETCH Tgcursor INTO Tregtime,Tappid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6';

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;



            SET @sqlstr=CONCAT('update dw_day_game SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''), ' AND app_id=',Tappid);

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;



            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tgcursor INTO Tregtime,Tappid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tgcursor;









SET Tflag=0;

OPEN Tcursor;

    FETCH Tcursor INTO Tregtime,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6'; 

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;

            SET @sqlstr=CONCAT('update dw_day SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''));

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;

            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tcursor INTO Tregtime,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tcursor;

END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for rundailyswitch
-- ----------------------------
DROP PROCEDURE IF EXISTS `rundailyswitch`;
delimiter ;;
CREATE PROCEDURE `rundailyswitch`(IN `iday` date)
BEGIN

DECLARE Tflag INT DEFAULT 0;

DECLARE Tappid INT;

DECLARE Tdate DATE;

DECLARE Tregday INT;

DECLARE Tagentid INT;

DECLARE Tmobile_prefix INT DEFAULT 156;

DECLARE Tregcnt INT;

DECLARE Tregpaycnt INT;

DECLARE Tagent_cnt INT;

DECLARE Tordercnt INT;

DECLARE Tcnt INT;

DECLARE Tregtime BIGINT;

DECLARE T30starttime BIGINT; 

DECLARE T7starttime BIGINT; 

DECLARE Tsummoney DOUBLE(20,2);

DECLARE Tsharemoney DOUBLE(20,2);

DECLARE Tratetype INT;

DECLARE Tmoney1 DOUBLE(20,2);

DECLARE Tmoney2 DOUBLE(20,2);

DECLARE Tmoney3 DOUBLE(20,2);

DECLARE Tmoney4 DOUBLE(20,2);

DECLARE Tmoney5 DOUBLE(20,2);

DECLARE Tmoney6 DOUBLE(20,2);

DECLARE Tmoney7 DOUBLE(20,2);

DECLARE Tmoney8 DOUBLE(20,2);

DECLARE Tagentrate DOUBLE(5,4);

DECLARE Trate1 DOUBLE(5,4);

DECLARE Trate2 DOUBLE(5,4);

DECLARE Trate3 DOUBLE(5,4);

DECLARE Trate4 DOUBLE(5,4);

DECLARE Trate5 DOUBLE(5,4);

DECLARE Trate6 DOUBLE(5,4);

DECLARE Trate7 DOUBLE(5,4);

DECLARE Trate8 DOUBLE(5,4);

DECLARE Tusercnt INT;

DECLARE Tpaycnt INT;

DECLARE Tdevice_cnt INT;

DECLARE Tsetdate DATE DEFAULT iday;

DECLARE Tstarttime INT;

DECLARE Tendtime INT;

DECLARE TdayFlag varchar(20);

DECLARE TdevicedayFlag varchar(20);

DECLARE TpaydayFlag varchar(20);

DECLARE Tregdate DATE;

DECLARE TformatDate DATE DEFAULT date_format(Tsetdate,'%Y-%m-%d');

DECLARE Tagcursor CURSOR FOR SELECT reg_time,app_id,agent_id,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp_switch` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY app_id,agent_id,mobile_prefix,reg_days;



DECLARE Tacursor CURSOR FOR SELECT reg_time,agent_id,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp_switch` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY agent_id,mobile_prefix,reg_days;



DECLARE Tgcursor CURSOR FOR SELECT reg_time,app_id,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp_switch` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY app_id,mobile_prefix,reg_days;



DECLARE Tcursor CURSOR FOR SELECT reg_time,mobile_prefix,reg_days,COUNT(DISTINCT(`mem_id`)) AS `user_cnt`,COUNT(DISTINCT(`device_id`)) AS `device_cnt`,COUNT(DISTINCT(CASE  WHEN (`sum_money`>0 ) THEN `mem_id` END)) AS `pay_cnt` FROM `log_day_mem_temp_switch` WHERE reg_days in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,20,29,59) AND login_cnt > 0 GROUP BY mobile_prefix,reg_days;



DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Tflag = 1;



SET Tstarttime=unix_timestamp(Tsetdate);

SET T30starttime=Tstarttime-86400*29;

SET T7starttime=Tstarttime-86400*6;

SET Tendtime=Tstarttime+86400;



SET @Ttable = CONCAT('db_mp_log.log_log_day_mem_switch_',date_format(Tsetdate,'%Y%m') );



CREATE TABLE IF NOT EXISTS `log_day_mem_temp_switch` (

    `id` int(11) NOT NULL AUTO_INCREMENT,

    `date` date NOT NULL DEFAULT '0000-00-00' COMMENT '日期',

    `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家ID',

    `mobile_prefix` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '国家手机区号',

    `task_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '任务ID',

    `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',

    `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

    `reg_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

    `reg_days` int(11) NOT NULL DEFAULT '0' COMMENT '注册天数',

    `device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '手机设备码',

    `new_device` tinyint(2)  NOT NULL DEFAULT '1' COMMENT '2 新设备 1 非新',

    `device_cnt` int(11) NOT NULL DEFAULT '1' COMMENT '登陆的设备个数',

    `login_cnt` int(11) NOT NULL DEFAULT '1' COMMENT '登陆次数',

    `sum_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '累计充值',

    `sum_real_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

    `first_pay_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '第一笔充值时间',

    `last_pay_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '最近充值时间',

    `last_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '最近充值金额',

    `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',

    `order_suc_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '支付成功订单数量',

    `last_login_ip` bigint(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家最近登陆ip',

    `auth_cnt` int(11) NOT NULL DEFAULT '0' COMMENT '授权登陆次数',

    `is_cpa` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否计算cpa 1 否 2是',

    `is_auth` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否第三方注册 1否 2是',

	`reg_app_id` int(11) NOT NULL DEFAULT '0' COMMENT '注册游戏ID',

    `is_new_app` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否游戏新增注册玩家 1 否 2是',

    `is_new_role` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否游戏新增角色 1 否 2是',

    PRIMARY KEY (`id`),

    UNIQUE KEY `ldmt_date_mem_app_unique` (`date`,`mem_id`,`app_id`),

    KEY `ldmt_ip_index` (`last_login_ip`),

    KEY `ldmt_agent_index` (`agent_id`),

    KEY `ldmt_app_index` (`app_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='玩家每日临时';





TRUNCATE `log_day_mem_temp_switch`;

ALTER TABLE `log_day_mem_temp_switch` DISABLE KEYS;



SET @ldmt_sql = "REPLACE INTO `log_day_mem_temp_switch`  (`date`,`mem_id`,`mobile_prefix`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,`new_device`,`device_cnt`,`login_cnt`,`sum_money`,`sum_real_money`,`first_pay_time`,`last_pay_time`,`last_money`,`order_cnt`,`order_suc_cnt`,`last_login_ip`,`auth_cnt`,`is_cpa`,`is_auth`,`reg_app_id`,`is_new_app`,`is_new_role`) SELECT `date`,`mem_id`,156,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,1,`device_cnt`,`login_cnt`,`sum_money`,`sum_real_money`,`first_pay_time`,`last_pay_time`,`last_money`,`order_cnt`,`order_suc_cnt`,`last_login_ip`,0,is_cpa,is_auth,reg_app_id,is_new_app,is_new_role";



SET  @ldmt_sql = concat(@ldmt_sql, ' FROM ',@Ttable,' where `date`=\'',Tsetdate,'\'');



PREPARE ldmt_sql_ex FROM @ldmt_sql;

EXECUTE ldmt_sql_ex;

ALTER TABLE log_day_mem_temp_switch ENABLE KEYS;





DROP TABLE IF EXISTS log_dgac_temp_switch;

CREATE TABLE IF NOT EXISTS `log_dgac_temp_switch` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `date` date NOT NULL DEFAULT '0000-00-00' COMMENT '日期',

  `mobile_prefix` int(11) unsigned NOT NULL DEFAULT '156' COMMENT '国家手机区号',

  `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

  `app_name` varchar(128) NOT NULL DEFAULT '' COMMENT '游戏名称',

  `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',

  `agent_name` varchar(128) NOT NULL DEFAULT '' COMMENT '渠道名称',

  `share_agent_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '分享人数',

  `share_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '分享次数',

  `click_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击数',

  `click_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击人数',

  `page_down_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '落地页点击数',

  `active_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏激活数',

  `down_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '下载数',

  `down_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '下载人数',

  `real_down_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '真实下载数',

  `user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '活跃玩家数量',

  `history_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '累计玩家数量',

  `wau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近7天活跃人数',

  `mau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近30天活跃人数',

  `ip_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'IP数量',

  `device_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '设备数量',

  `history_device_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '累计设备数量',

  `dwau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近7天活跃设备数',

  `dmau` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最近30天活跃设备数',

  `reg_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册玩家数',

  `reg_device_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册设备数',

  `reg_ip_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册IP数',

  `pay_user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家数',

  `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '成功订单数',

  `fail_order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '失败订单数',

  `un_order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '待支付订单数',

  `reg_order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册订单数',

  `reg_pay_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册即付费人数',

  `sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '充值金额',

  `sum_real_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

  `first_pay_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '首次付费人数',

  `first_pay_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '首付总额',

  `reg_sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '注册即付总额',

  `reg_real_sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '注册即付自然流水总额',

  `cpa_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '计算cpa玩家数量',

  `openid_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '第三方注册玩家数量',

  `new_role_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '新增创角数',

  `day2` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '二日留存量',

  `day3` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '三日留存量',

  `day4` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '四日留存量',

  `day5` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '五日留存量',

  `day6` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '六日留存量',

  `day7` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '七日留存量',

  `day8` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '八日留存量',

  `day9` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '九日留存量',

  `day10` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '十日留存量',

  `day11` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '11日留存量',

  `day12` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '12日留存量',

  `day13` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '13日留存量',

  `day14` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '14日留存量',

  `day15` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '15日留存量',

  `day21` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '21日留存量',

  `day30` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '30日留存量',

  `day60` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '60日留存量',

  `device_day2` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '二日留存量',

  `device_day3` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '三日留存量',

  `device_day4` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '四日留存量',

  `device_day5` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '五日留存量',

  `device_day6` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '六日留存量',

  `device_day7` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '七日留存量',

  `device_day8` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '八日留存量',

  `device_day9` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '九日留存量',

  `device_day10` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '十日留存量',

  `device_day11` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '11日留存量',

  `device_day12` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '12日留存量',

  `device_day13` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '13日留存量',

  `device_day14` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '14日留存量',

  `device_day15` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '15日留存量',

  `device_day21` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '21日留存量',

  `device_day30` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '30日留存量',

  `device_day60` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '60日留存量',

  `pay_day2` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家二日留存',

  `pay_day3` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家三日留存',

  `pay_day4` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家四日留存',

  `pay_day5` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家五日留存',

  `pay_day6` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家六日留存',

  `pay_day7` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家七日留存',

  `pay_day8` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家八日留存',

  `pay_day9` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家九日留存',

  `pay_day10` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家十日留存',

  `pay_day11` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家11日留存',

  `pay_day12` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家12日留存',

  `pay_day13` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家13日留存',

  `pay_day14` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家14日留存',

  `pay_day15` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家15日留存',

  `pay_day21` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家21日留存',

  `pay_day30` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家30日留存',

  `pay_day60` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付费玩家60日留存',

  PRIMARY KEY (`id`) USING BTREE,

  UNIQUE KEY `dga_dga_unique` (`date`,`app_id`,`agent_id`) USING BTREE,

  KEY `dga_game_index` (`app_id`) USING BTREE,

  KEY `dga_agent_index` (`agent_id`) USING BTREE

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='每日游戏推广员统计表';









TRUNCATE `log_dgac_temp_switch`;

ALTER TABLE log_dgac_temp_switch DISABLE KEYS;

REPLACE INTO `log_dgac_temp_switch`

(

    `date`,

    `app_id`,

    `agent_id`,

    `mobile_prefix`,

    `active_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(ldmt.`date`,TformatDate) AS `date`,       

    IFNULL(ldmt.`app_id`,0) AS `app_id`,      

    IFNULL(ldmt.`agent_id`,0) AS `agent_id`,       

    IFNULL(ldmt.mobile_prefix,Tmobile_prefix) AS `mobile_prefix`,    

    COUNT(DISTINCT(ldmt.`mem_id`)) AS `active_cnt`,    

    COUNT(DISTINCT(CASE WHEN ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,    

    0 AS `history_user_cnt`, 

    COUNT(DISTINCT(ldmt.`last_login_ip`)) AS `ip_cnt`,    

    COUNT(DISTINCT(ldmt.`device_id`)) AS `device_cnt` , 

    0 AS `history_device_cnt` , 

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`is_new_app` = 2  AND ldmt.`mem_id` > 0 ) THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`device_id` <> '' AND ldmt.`app_id` = ldmt.`reg_app_id`) OR  (ldmt.`is_new_app` = 2 AND ldmt.`device_id` <> '') THEN `device_id` END)) AS `reg_device_cnt`,

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR  ldmt.`is_new_app` = 2 THEN `last_login_ip` END)) AS `reg_ip_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`sum_money`>0 THEN `mem_id` END)) AS `pay_user_cnt`,    

    IFNULL(SUM(ldmt.`order_suc_cnt`),0) AS `order_cnt`,    

    0 AS `fail_order_cnt` , 

    0 AS `un_order_cnt` , 

    IFNULL(SUM(CASE  WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR ldmt.`is_new_app` = 2 THEN ldmt.`order_suc_cnt` ELSE 0 END),0) AS `reg_order_cnt`,    

    COUNT(DISTINCT(CASE  WHEN (ldmt.`reg_days`=0 AND ldmt.`sum_money`>0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`is_new_app` = 2 AND ldmt.`sum_money`>0 ) THEN ldmt.`mem_id` END)) AS `reg_pay_cnt`,    

    IFNULL(SUM(ldmt.`sum_money`),0) AS `sum_money` , 

    SUM(ldmt.`sum_real_money`) AS `sum_real_money` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`mem_id` END)) AS `first_pay_cnt`, 

    IFNULL(SUM(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `first_pay_money` , 

    IFNULL(SUM(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR ldmt.`is_new_app` = 2 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `reg_sum_money` , 

    IFNULL(SUM(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR ldmt.`is_new_app` = 2 THEN ldmt.`sum_real_money`  ELSE 0.00 END),0.00) AS `reg_real_sum_money`, 

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_cpa = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`is_new_app` = 2 AND ldmt.`mem_id` > 0 AND ldmt.is_cpa = 2)  THEN `mem_id` END)) AS `cpa_cnt`	,

    COUNT(DISTINCT(CASE WHEN (ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_auth = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`) OR (ldmt.`mem_id` > 0 AND ldmt.is_auth = 2 AND ldmt.is_auth = 2)  THEN `mem_id` END)) AS `openid_cnt` ,	

    0	

FROM log_day_mem_temp_switch ldmt

GROUP BY agent_id, app_id;

ALTER TABLE log_dgac_temp_switch ENABLE KEYS;





ALTER TABLE dw_day_game_agent_switch DISABLE KEYS;

REPLACE INTO `dw_day_game_agent_switch`

(

    `date`,

    `app_id`,

    `app_name`,

    `agent_id`,

    `agent_name`,

    `mobile_prefix`,

    `share_cnt`,

    `click_cnt`,

    `click_user_cnt`,

    `page_down_cnt`,

    `active_cnt`,

    `down_cnt`,

    `down_user_cnt`,

    `real_down_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `wau`,

    `mau`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `dwau`,

    `dmau`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`app_id`,0) AS `app_id`, 

    IFNULL(`app_name`,'') AS `app_name`, 

    IFNULL(`agent_id`,0) AS `agent_id`, 

    IFNULL(`agent_name`,'') AS `agent_name`, 

    IFNULL(mobile_prefix,Tmobile_prefix) AS `mobile_prefix`, 

    IFNULL(`share_cnt`,0) AS `share_cnt`, 

    IFNULL(`click_cnt`,0)  AS `click_cnt`, 

    IFNULL(`click_user_cnt`,0) AS `click_user_cnt`, 

    IFNULL(`page_down_cnt`,0) AS `page_down_cnt`, 

    IFNULL(`active_cnt`,0) AS `active_cnt`, 

    IFNULL(`down_cnt`,0) AS `down_cnt`, 

    IFNULL(`down_user_cnt`,0) AS `down_user_cnt`, 

    IFNULL(`real_down_cnt`,0) AS `real_down_cnt`, 

    IFNULL(`user_cnt`,0) AS `user_cnt`, 

    IFNULL(`history_user_cnt`,0) AS `history_user_cnt`, 

    IFNULL(`wau`,0) AS `wau`, 

    IFNULL(`mau`,0) AS `mau`, 

    IFNULL(`ip_cnt`,0) AS `ip_cnt`, 

    IFNULL(`device_cnt`,0) AS `device_cnt`, 

    IFNULL(`history_device_cnt`,0) AS `history_device_cnt`, 

    IFNULL(`dwau`,0) AS `dwau`, 

    IFNULL(`dmau`,0) AS `dmau`, 

    IFNULL(`reg_cnt`,0) AS `reg_cnt`, 

    IFNULL(`reg_device_cnt`,0) AS `reg_device_cnt`, 

    IFNULL(`reg_ip_cnt`,0) AS `reg_ip_cnt`, 

    IFNULL(`pay_user_cnt`,0) AS `pay_user_cnt`, 

    IFNULL(`order_cnt`,0) AS `order_cnt`, 

    IFNULL(`fail_order_cnt`,0) AS `fail_order_cnt`, 

    IFNULL(`un_order_cnt`,0) AS `un_order_cnt`, 

    IFNULL(`reg_order_cnt`,0) AS `reg_order_cnt`, 

    IFNULL(`reg_pay_cnt`,0) AS `reg_pay_cnt`, 

    IFNULL(`sum_money`,0.00) AS `sum_money`, 

    IFNULL(`sum_real_money`,0.00) AS `sum_real_money`, 

    IFNULL(`first_pay_cnt`,0) AS `first_pay_cnt`, 

    IFNULL(`first_pay_money`,0.00) AS `first_pay_money`, 

    IFNULL(`reg_sum_money`,0.00) AS `reg_sum_money`, 

    IFNULL(`reg_real_sum_money`,0.00) AS `reg_real_sum_money`, 

    IFNULL(`cpa_cnt`,0) AS `cpa_cnt`, 

    IFNULL(`openid_cnt`,0) AS `openid_cnt`, 

    IFNULL(`new_role_cnt`,0) AS `new_role_cnt` 

FROM log_dgac_temp_switch;

ALTER TABLE dw_day_game_agent_switch ENABLE KEYS;



ALTER TABLE dw_day_agent_switch DISABLE KEYS;

REPLACE INTO `dw_day_agent_switch`

(

    `date`,

    `agent_id`,

    `mobile_prefix`,

    `app_cnt`,

    `active_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(ldmt.`date`,TformatDate) AS `date`,       

    ldmt.`agent_id` AS `agent_id`,       

    IFNULL(ldmt.mobile_prefix,Tmobile_prefix) AS `mobile_prefix`,    

    COUNT(DISTINCT(ldmt.app_id)) AS `app_cnt`,    

    COUNT(DISTINCT(ldmt.`mem_id`)) AS `active_cnt`,    

    COUNT(DISTINCT(CASE WHEN ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,    

    0 AS `history_user_cnt`, 

    COUNT(DISTINCT(ldmt.`last_login_ip`)) AS `ip_cnt`,    

    COUNT(DISTINCT(ldmt.`device_id`)) AS `device_cnt` , 

    0 AS `history_device_cnt` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `mem_id` END)) AS `reg_cnt`	,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`device_id` <> '' AND ldmt.`app_id` = ldmt.`reg_app_id`   THEN `device_id` END)) AS `reg_device_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `last_login_ip` END)) AS `reg_ip_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`sum_money`>0 THEN `mem_id` END)) AS `pay_user_cnt`,    

    IFNULL(SUM(ldmt.`order_suc_cnt`),0) AS `order_cnt`,    

    0 AS `fail_order_cnt` , 

    0 AS `un_order_cnt` , 

    IFNULL(SUM(CASE  WHEN ldmt.`reg_days`=0 THEN ldmt.`order_suc_cnt` ELSE 0 END),0) AS `reg_order_cnt`,    

    COUNT(DISTINCT(CASE  WHEN ldmt.`reg_days`=0 AND ldmt.`sum_money`>0 THEN ldmt.`mem_id` END)) AS `reg_pay_cnt`,    

    IFNULL(SUM(ldmt.`sum_money`),0.00) AS `sum_money` , 

    IFNULL(SUM(ldmt.`sum_real_money`),0.00) AS `sum_real_money` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`mem_id` END)) AS `first_pay_cnt`, 

    IFNULL(SUM(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `first_pay_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `reg_sum_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN ldmt.`sum_real_money`  ELSE 0.00 END),0.00) AS `reg_real_sum_money`, 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_cpa = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `mem_id` END)) AS `cpa_cnt`	,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND ldmt.is_auth = 2 AND ldmt.`app_id` = ldmt.`reg_app_id`  THEN `mem_id` END)) AS `openid_cnt` ,	

    0	

FROM log_day_mem_temp_switch ldmt

GROUP BY agent_id;

ALTER TABLE dw_day_agent_switch ENABLE KEYS;







ALTER TABLE dw_day_game_switch DISABLE KEYS;

REPLACE INTO `dw_day_game_switch`

(

    `date`,

    `app_id`,

    `app_name`,

    `agent_cnt`,

    `mobile_prefix`,

    `share_agent_cnt`,

    `share_cnt`,

    `click_cnt`,

    `click_user_cnt`,

    `page_down_cnt`,

    `active_cnt`,

    `down_cnt`,

    `down_user_cnt`,

    `real_down_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `wau`,

    `mau`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `dwau`,

    `dmau`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`app_id`,0) AS `app_id`, 

    IFNULL(`app_name`,'') AS `app_name`, 

    COUNT(DISTINCT(agent_id)) AS `agent_cnt`, 

    IFNULL(`mobile_prefix`,Tmobile_prefix) AS `mobile_prefix`, 

    COUNT(DISTINCT(CASE WHEN share_cnt>0 THEN `agent_id` END))  AS `share_agent_cnt`, 

    SUM(`share_cnt`) AS `share_cnt`, 

    SUM(`click_cnt`)  AS `click_cnt`, 

    SUM(`click_user_cnt`) AS `click_user_cnt`, 

    SUM(`page_down_cnt`) AS `page_down_cnt`, 

    SUM(`active_cnt`) AS `active_cnt`, 

    SUM(`down_cnt`) AS `down_cnt`, 

    SUM(`down_user_cnt`) AS `down_user_cnt`, 

    SUM(`real_down_cnt`) AS `real_down_cnt`, 

    SUM(`user_cnt`) AS `user_cnt`, 

    SUM(`history_user_cnt`) AS `history_user_cnt`, 

    SUM(`wau`) AS `wau`, 

    SUM(`mau`) AS `mau`, 

    SUM(`ip_cnt`) AS `ip_cnt`, 

    SUM(`device_cnt`) AS `device_cnt`, 

    SUM(`history_device_cnt`) AS `history_device_cnt`, 

    SUM(`dwau`) AS `dwau`, 

    SUM(`dmau`) AS `dmau`, 

    SUM(`reg_cnt`) AS `reg_cnt`, 

    SUM(`reg_device_cnt`) AS `reg_device_cnt`, 

    SUM(`reg_ip_cnt`) AS `reg_ip_cnt`, 

    SUM(`pay_user_cnt`) AS `pay_user_cnt`, 

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`, 

    SUM(`fail_order_cnt`) AS `fail_order_cnt`, 

    SUM(`un_order_cnt`) AS `un_order_cnt`, 

    IFNULL(SUM(`reg_order_cnt`),0) AS `reg_order_cnt`, 

    SUM(`reg_pay_cnt`) AS `reg_pay_cnt`, 

    IFNULL(SUM(`sum_money`),0.00) AS `sum_money`, 

    IFNULL(SUM(`sum_real_money`),0.00) AS `sum_real_money`, 

    SUM(`first_pay_cnt`) AS `first_pay_cnt`, 

    IFNULL(SUM(`first_pay_money`),0.00) AS `first_pay_money`, 

    IFNULL(SUM(`reg_sum_money`),0.00) AS `reg_sum_money`, 

    IFNULL(SUM(`reg_real_sum_money`),0.00) AS `reg_real_sum_money`, 

    IFNULL(SUM(`cpa_cnt`),0) AS `cpa_cnt`,

    IFNULL(SUM(`openid_cnt`),0) AS `openid_cnt`, 

    IFNULL(SUM(`new_role_cnt`),0) AS `new_role_cnt` 

FROM log_dgac_temp_switch

GROUP BY app_id,mobile_prefix;

ALTER TABLE dw_day_game_switch ENABLE KEYS;









ALTER TABLE dw_day_switch DISABLE KEYS;

REPLACE INTO `dw_day_switch`

(

    `date`,

    `mobile_prefix`,

    `agent_cnt`,

    `app_cnt`,

    `active_cnt`,

    `user_cnt`,

    `history_user_cnt`,

    `ip_cnt`,

    `device_cnt`,

    `history_device_cnt`,

    `reg_cnt`,

    `reg_device_cnt`,

    `reg_ip_cnt`,

    `pay_user_cnt`,

    `order_cnt`,

    `fail_order_cnt`,

    `un_order_cnt`,

    `reg_order_cnt`,

    `reg_pay_cnt`,

    `sum_money`,

    `sum_real_money`,

    `first_pay_cnt`,

    `first_pay_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `cpa_cnt`,

    `openid_cnt`,

    `new_role_cnt`

)

SELECT

    IFNULL(ldmt.`date`,TformatDate) AS `date`,       

    IFNULL(ldmt.mobile_prefix,Tmobile_prefix) AS `mobile_prefix`,    

    COUNT(DISTINCT(ldmt.agent_id)) AS `agent_cnt`,    

    COUNT(DISTINCT(ldmt.app_id)) AS `app_cnt`,    

    COUNT(DISTINCT(ldmt.`mem_id`)) AS `active_cnt`,    

    COUNT(DISTINCT(CASE WHEN ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,    

    

    0 AS `history_user_cnt`, 

    COUNT(DISTINCT(ldmt.`last_login_ip`)) AS `ip_cnt`,    

    COUNT(DISTINCT(ldmt.`device_id`)) AS `device_cnt` , 

    

    0 AS `history_device_cnt` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `reg_cnt`	,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`device_id` <> ''  THEN `device_id` END)) AS `reg_device_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 THEN `last_login_ip` END)) AS `reg_ip_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`sum_money`>0 THEN `mem_id` END)) AS `pay_user_cnt`,    

    IFNULL(SUM(ldmt.`order_suc_cnt`),0) AS `order_cnt`,    

    0 AS `fail_order_cnt` , 

    

    0 AS `un_order_cnt` , 

    IFNULL(SUM(CASE  WHEN ldmt.`reg_days`=0 THEN ldmt.`order_suc_cnt` ELSE 0 END),0) AS `reg_order_cnt`,    

    COUNT(DISTINCT(CASE  WHEN ldmt.`reg_days`=0 AND ldmt.`sum_money`>0 THEN ldmt.`mem_id` END)) AS `reg_pay_cnt`,    

    IFNULL(SUM(ldmt.`sum_money`),0.00) AS `sum_money` , 

    IFNULL(SUM(ldmt.`sum_real_money`),0.00) AS `sum_real_money` , 

    COUNT(DISTINCT(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`mem_id` END)) AS `first_pay_cnt`, 

    IFNULL(SUM(CASE WHEN ldmt.`first_pay_time`>0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `first_pay_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 THEN ldmt.`sum_money`  ELSE 0.00 END),0.00) AS `reg_sum_money` , 

    IFNULL(SUM(CASE WHEN ldmt.`reg_days`=0 THEN ldmt.`sum_real_money`  ELSE 0.00 END),0.00) AS `reg_real_sum_money`, 

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND is_cpa=2 THEN `mem_id` END)) AS `cpa_cnt`,

    COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 AND is_auth=2 THEN `mem_id` END)) AS `openid_cnt`,

   0

FROM log_day_mem_temp_switch ldmt;

ALTER TABLE dw_day_agent_switch ENABLE KEYS;





SET Tflag=0;

OPEN Tagcursor;

    FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 OR Tpaycnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6';

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;



            SET @sqlstr=CONCAT('update dw_day_game_agent_switch SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''), ' AND agent_id=',Tagentid,' AND app_id=',Tappid, ' AND mobile_prefix=',Tmobile_prefix);

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;



            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tagcursor;







SET Tflag=0;

OPEN Tacursor;

    FETCH Tacursor INTO Tregtime,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6';

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;



            SET @sqlstr=CONCAT('update dw_day_agent_switch SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''), ' AND agent_id=',Tagentid);

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;



            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tacursor INTO Tregtime,Tagentid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tacursor;









SET Tflag=0;

OPEN Tgcursor;

    FETCH Tgcursor INTO Tregtime,Tappid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6';

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;



            SET @sqlstr=CONCAT('update dw_day_game_switch SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''), ' AND app_id=',Tappid);

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;



            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tgcursor INTO Tregtime,Tappid,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tgcursor;





SET Tflag=0;

OPEN Tcursor;

    FETCH Tcursor INTO Tregtime,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    WHILE Tflag<>1 DO

        IF Tusercnt>0  OR Tdevice_cnt>0 THEN

            CASE Tregday

                WHEN 1 THEN

                    SET TdayFlag = 'day2';

                    SET TdevicedayFlag = 'device_day2';

                    SET TpaydayFlag = 'pay_day2';

                    SET Tdate = date_sub(Tsetdate,interval 1 day);

                WHEN 2 THEN

                    SET TdayFlag = 'day3';

                    SET TdevicedayFlag = 'device_day3';

                    SET TpaydayFlag = 'pay_day3';

                    SET Tdate = date_sub(Tsetdate,interval 2 day);

                WHEN 3 THEN

                    SET TdayFlag = 'day4';

                    SET TdevicedayFlag = 'device_day4';

                    SET TpaydayFlag = 'pay_day4';

                    SET Tdate = date_sub(Tsetdate,interval 3 day);

                WHEN 4 THEN

                    SET TdayFlag = 'day5';

                    SET TdevicedayFlag = 'device_day5';

                    SET TpaydayFlag = 'pay_day5';

                    SET Tdate = date_sub(Tsetdate,interval 4 day);

                WHEN 5 THEN

                    SET TdayFlag = 'day6';

                    SET TdevicedayFlag = 'device_day6';

                    SET TpaydayFlag = 'pay_day6'; 

                    SET Tdate = date_sub(Tsetdate,interval 5 day);

                WHEN 6 THEN

                    SET TdayFlag = 'day7';

                    SET TdevicedayFlag = 'device_day7';

                    SET TpaydayFlag = 'pay_day7';

                    SET Tdate = date_sub(Tsetdate,interval 6 day);

                WHEN 7 THEN

                    SET TdayFlag = 'day8';

                    SET TdevicedayFlag = 'device_day8';

                    SET TpaydayFlag = 'pay_day8';

                    SET Tdate = date_sub(Tsetdate,interval 7 day);

                WHEN 8 THEN

                    SET TdayFlag = 'day9';

                    SET TdevicedayFlag = 'device_day9';

                    SET TpaydayFlag = 'pay_day9';

                    SET Tdate = date_sub(Tsetdate,interval 8 day);

                WHEN 9 THEN

                    SET TdayFlag = 'day10';

                    SET TdevicedayFlag = 'device_day10';

                    SET TpaydayFlag = 'pay_day10';

                    SET Tdate = date_sub(Tsetdate,interval 9 day);

                WHEN 10 THEN

                    SET TdayFlag = 'day11';

                    SET TdevicedayFlag = 'device_day11';

                    SET TpaydayFlag = 'pay_day11';

                    SET Tdate = date_sub(Tsetdate,interval 10 day);

                WHEN 11 THEN

                    SET TdayFlag = 'day12';

                    SET TdevicedayFlag = 'device_day12';

                    SET TpaydayFlag = 'pay_day12';

                    SET Tdate = date_sub(Tsetdate,interval 11 day);

                WHEN 12 THEN

                    SET TdayFlag = 'day13';

                    SET TdevicedayFlag = 'device_day13';

                    SET TpaydayFlag = 'pay_day13';

                    SET Tdate = date_sub(Tsetdate,interval 12 day);

                WHEN 13 THEN

                    SET TdayFlag = 'day14';

                    SET TdevicedayFlag = 'device_day14';

                    SET TpaydayFlag = 'pay_day14';

                    SET Tdate = date_sub(Tsetdate,interval 13 day);

                WHEN 14 THEN

                    SET TdayFlag = 'day15';

                    SET TdevicedayFlag = 'device_day15';

                    SET TpaydayFlag = 'pay_day15';

                    SET Tdate = date_sub(Tsetdate,interval 14 day);

                WHEN 20 THEN

                    SET TdayFlag = 'day21';

                    SET TdevicedayFlag = 'device_day21';

                    SET TpaydayFlag = 'pay_day21';

                    SET Tdate = date_sub(Tsetdate,interval 20 day);

                WHEN 29 THEN

                    SET TdayFlag = 'day30';

                    SET TdevicedayFlag = 'device_day30';

                    SET TpaydayFlag = 'pay_day30';

                    SET Tdate = date_sub(Tsetdate,interval 29 day);

                WHEN 59 THEN

                    SET TdayFlag = 'day60';

                    SET TdevicedayFlag = 'device_day60';

                    SET TpaydayFlag = 'pay_day60';

                    SET Tdate = date_sub(Tsetdate,interval 59 day);

            END CASE;

            SET @sqlstr=CONCAT('update dw_day_switch SET ',TdayFlag,'=',Tusercnt,',',TdevicedayFlag,'=',Tdevice_cnt,',',TpaydayFlag,'=',Tpaycnt,' WHERE date=',CONCAT('\'',Tdate,'\''));

            PREPARE stmt FROM @sqlstr;

            EXECUTE stmt;

            DEALLOCATE PREPARE stmt;

        END IF;

        FETCH Tcursor INTO Tregtime,Tmobile_prefix,Tregday,Tusercnt,Tdevice_cnt,Tpaycnt;

    END WHILE;

CLOSE  Tcursor;

END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for runhourdata
-- ----------------------------
DROP PROCEDURE IF EXISTS `runhourdata`;
delimiter ;;
CREATE PROCEDURE `runhourdata`(IN `iday` date,IN `ihour` tinyint)
  COMMENT '每时数据统计'
BEGIN

DECLARE Tsetdate DATE DEFAULT iday;

DECLARE Thour INT DEFAULT ihour;

DECLARE TformatDate DATE DEFAULT date_format(Tsetdate,'%Y-%m-%d');



#创建临时表

CREATE TABLE IF NOT EXISTS `dw_day_hour_temp` (

  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',

  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',

  `hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '时间KEY值 1~24',

  `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家id',

  `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',

  `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

  `reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

  `reg_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册天数',

  `reg_hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间key 1~24',

  `game_reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

  `game_reg_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册天数',

  `game_reg_hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间key 1~24',

  `login_cnt` int(11) unsigned NOT NULL DEFAULT '1' COMMENT '打开次数',

  `sum_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计充值',

  `sum_real_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计真实充值',

  `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',

  PRIMARY KEY (`id`),

  UNIQUE KEY `dh_date_mem_app_device_unique` (`date`,`hour_key`,`mem_id`,`app_id`),

  KEY `dh_mem_index` (`mem_id`),

  KEY `dh_game_index` (`app_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每时统计表';



CREATE TABLE IF NOT EXISTS `dw_day_hga_temp` (

  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',

  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',

  `hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '时间KEY值 1~24',

  `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏id',

  `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',

  `reg_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册玩家数',

  `user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '登陆玩家数',

  `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',

  `sum_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总充值',

  `sum_real_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总真实充值',

  `reg_sum_money` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '当日注册即付总额',

  `reg_real_sum_money` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '当日注册即付真实充值',

  `pay_mem_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '支付玩家数量',

  `reg_pay_mem_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册即付费玩家数',

  PRIMARY KEY (`id`),

  UNIQUE KEY `dhga_dhga_unique` (`date`,`hour_key`,`app_id`,`agent_id`),

  KEY `dhga_hour_index` (`hour_key`),

  KEY `dhga_game_index` (`app_id`),

  KEY `dhga_agent_index` (`agent_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每日时段渠道游戏统计表';



#清除数据

SET @Ttable = CONCAT('db_mp_log.log_day_hour_',date_format(Tsetdate,'%Y%m') );

TRUNCATE `dw_day_hour_temp`;

ALTER TABLE `dw_day_hour_temp` DISABLE KEYS;

SET @ddhdtt_sql = "REPLACE INTO `dw_day_hour_temp`  (`date`,`hour_key`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`reg_hour_key`,`game_reg_time`,`game_reg_days`,`game_reg_hour_key`,`login_cnt`,`sum_money`,`sum_real_money`,`order_cnt`) SELECT `date`,`hour_key`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`reg_hour_key`,`game_reg_time`,`game_reg_days`,`game_reg_hour_key`,`login_cnt`,`sum_money`,`sum_real_money`,`order_cnt`";

SET  @ddhdtt_sql = concat(@ddhdtt_sql, ' FROM ',@Ttable,' where `date`=\'',Tsetdate,'\' AND `hour_key`=',Thour);

PREPARE ddhdtt_sql_ex FROM @ddhdtt_sql;

EXECUTE ddhdtt_sql_ex;

ALTER TABLE dw_day_hour_temp ENABLE KEYS;





#写入订单每时临时数据

TRUNCATE `dw_day_hga_temp`;

ALTER TABLE dw_day_hga_temp DISABLE KEYS;

REPLACE INTO `dw_day_hga_temp`

(

    `date`,

    `hour_key`,

    `app_id`,

    `agent_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`,

    IFNULL(`hour_key`,Thour) AS `app_id`,

    IFNULL(`app_id`,0) AS `app_id`,

    IFNULL(`agent_id`,0) AS `agent_id`,

    COUNT(DISTINCT(CASE WHEN `game_reg_days`=0 AND `mem_id` > 0 AND `game_reg_hour_key` = `hour_key` THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN `mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(CASE WHEN `game_reg_days`=0 AND `mem_id` > 0 AND `game_reg_hour_key` = Thour THEN `sum_money` END),0) AS `reg_sum_money`,

    IFNULL(SUM(CASE WHEN `game_reg_days`=0 AND `mem_id` > 0 AND `game_reg_hour_key` = Thour THEN `sum_real_money` END),0) AS `reg_real_sum_money`,

    COUNT(DISTINCT(CASE WHEN `sum_money`>0 THEN `mem_id` END)) AS `pay_mem_cnt`, 

    COUNT(DISTINCT(CASE  WHEN `game_reg_days`=0 AND `sum_money`>0 AND `game_reg_hour_key` = Thour  THEN `mem_id` END)) AS `reg_pay_cnt` 

FROM dw_day_hour_temp

GROUP BY agent_id,app_id;

ALTER TABLE dw_day_hga_temp ENABLE KEYS;





#写入每日每时游戏渠道

ALTER TABLE dw_hour_game_agent DISABLE KEYS;

REPLACE INTO `dw_hour_game_agent`

(              

    `date`,

    `hour_key`,

    `app_id`,

    `agent_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`hour_key`,Thour) AS `hour_key`,

    IFNULL(`app_id`,0) AS `app_id`,

    IFNULL(`agent_id`,0) AS `agent_id`,

    IFNULL(`reg_cnt`,0) AS `reg_cnt`,

    IFNULL(`user_cnt`,0) AS `user_cnt`,

    IFNULL(`order_cnt`,0) AS `order_cnt`,

    IFNULL(`sum_money`,0) AS `sum_money`,

    IFNULL(`sum_real_money`,0) AS `sum_real_money`,

    IFNULL(`reg_sum_money`,0) AS `reg_sum_money`,

    IFNULL(`reg_real_sum_money`,0) AS `reg_real_sum_money`,

    IFNULL(`pay_mem_cnt`,0) AS `pay_mem_cnt`,

    IFNULL(`reg_pay_mem_cnt`,0) AS `reg_pay_mem_cnt`

   

FROM dw_day_hga_temp;

ALTER TABLE dw_hour_game_agent ENABLE KEYS;





#写入每日每时渠道

ALTER TABLE dw_hour_agent DISABLE KEYS;

REPLACE INTO `dw_hour_agent`

(              

    `date`,

    `hour_key`,

    `agent_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`,

    IFNULL(`hour_key`,Thour) AS `app_id`,

    IFNULL(`agent_id`,0) AS `agent_id`,

    COUNT(DISTINCT(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN `mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_money` END),0) AS `reg_sum_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_real_money` END),0) AS `reg_real_sum_money`,

    COUNT(DISTINCT(CASE WHEN `sum_money`>0 THEN `mem_id` END)) AS `pay_mem_cnt`, 

    COUNT(DISTINCT(CASE  WHEN `reg_days`=0 AND `sum_money`>0 AND `reg_hour_key` = `hour_key`  THEN `mem_id` END)) AS `reg_pay_cnt` 

FROM dw_day_hour_temp 

GROUP BY agent_id;

ALTER TABLE dw_hour_agent ENABLE KEYS;







#写入每日每时游戏

ALTER TABLE dw_hour_game DISABLE KEYS;

REPLACE INTO `dw_hour_game`

(                          

    `date`,

    `hour_key`,

    `app_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`hour_key`,Thour) AS `hour_key`,

    IFNULL(`app_id`,0) AS `app_id`,

    IFNULL(SUM(`reg_cnt`),0) AS `reg_cnt`,

    IFNULL(SUM(`user_cnt`),0) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(`reg_sum_money`),0) AS `reg_sum_money`,

    IFNULL(SUM(`reg_real_sum_money`),0) AS `reg_real_sum_money`,

    IFNULL(SUM(`pay_mem_cnt`),0) AS `pay_mem_cnt`,

    IFNULL(SUM(`reg_pay_mem_cnt`),0) AS `reg_pay_mem_cnt`

FROM dw_day_hga_temp 

GROUP BY hour_key,app_id;

ALTER TABLE dw_hour_agent ENABLE KEYS;



#写入每日每时

ALTER TABLE dw_hour DISABLE KEYS;

REPLACE INTO `dw_hour`

(           

    `date`,

    `hour_key`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`,

    IFNULL(`hour_key`,Thour) AS `app_id`,

    COUNT(DISTINCT(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN `mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_money` END),0) AS `reg_sum_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_real_money` END),0) AS `reg_real_sum_money`,

    COUNT(DISTINCT(CASE WHEN `sum_money`>0 THEN `mem_id` END)) AS `pay_mem_cnt`, 

    COUNT(DISTINCT(CASE  WHEN `reg_days`=0 AND `sum_money`>0 AND `reg_hour_key` = `hour_key`  THEN `mem_id` END)) AS `reg_pay_cnt` 

FROM dw_day_hour_temp 

GROUP BY hour_key;

ALTER TABLE dw_hour ENABLE KEYS;



END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for runhourdataswitch
-- ----------------------------
DROP PROCEDURE IF EXISTS `runhourdataswitch`;
delimiter ;;
CREATE PROCEDURE `runhourdataswitch`(IN `iday` date,IN `ihour` tinyint)
  COMMENT '每时数据统计'
BEGIN

DECLARE Tsetdate DATE DEFAULT iday;

DECLARE Thour INT DEFAULT ihour;

DECLARE TformatDate DATE DEFAULT date_format(Tsetdate,'%Y-%m-%d');



#创建临时表

CREATE TABLE IF NOT EXISTS `dw_day_hour_temp_switch` (

  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',

  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',

  `hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '时间KEY值 1~24',

  `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家id',

  `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',

  `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

  `reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

  `reg_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册天数',

  `reg_hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间key 1~24',

  `game_reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

  `game_reg_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册天数',

  `game_reg_hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间key 1~24',

  `login_cnt` int(11) unsigned NOT NULL DEFAULT '1' COMMENT '打开次数',

  `sum_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计充值',

  `sum_real_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计真实充值',

  `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',

  PRIMARY KEY (`id`),

  UNIQUE KEY `dh_date_mem_app_device_unique` (`date`,`hour_key`,`mem_id`,`app_id`),

  KEY `dh_mem_index` (`mem_id`),

  KEY `dh_game_index` (`app_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每时统计表';



CREATE TABLE IF NOT EXISTS `dw_day_hga_temp_switch` (

  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',

  `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',

  `hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '时间KEY值 1~24',

  `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏id',

  `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',

  `reg_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册玩家数',

  `user_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '登陆玩家数',

  `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',

  `sum_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总充值',

  `sum_real_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总真实充值',

  `reg_sum_money` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '当日注册即付总额',

  `reg_real_sum_money` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '当日注册即付真实充值',

  `pay_mem_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '支付玩家数量',

  `reg_pay_mem_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册即付费玩家数',

  PRIMARY KEY (`id`),

  UNIQUE KEY `dhga_dhga_unique` (`date`,`hour_key`,`app_id`,`agent_id`),

  KEY `dhga_hour_index` (`hour_key`),

  KEY `dhga_game_index` (`app_id`),

  KEY `dhga_agent_index` (`agent_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每日时段渠道游戏统计表';



#清除数据

SET @Ttable = CONCAT('db_mp_log.log_day_hour_switch_',date_format(Tsetdate,'%Y%m') );

TRUNCATE `dw_day_hour_temp_switch`;

ALTER TABLE `dw_day_hour_temp_switch` DISABLE KEYS;

SET @ddhdtt_sql = "REPLACE INTO `dw_day_hour_temp_switch`  (`date`,`hour_key`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`reg_hour_key`,`game_reg_time`,`game_reg_days`,`game_reg_hour_key`,`login_cnt`,`sum_money`,`sum_real_money`,`order_cnt`) SELECT `date`,`hour_key`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`reg_hour_key`,`game_reg_time`,`game_reg_days`,`game_reg_hour_key`,`login_cnt`,`sum_money`,`sum_real_money`,`order_cnt`";

SET  @ddhdtt_sql = concat(@ddhdtt_sql, ' FROM ',@Ttable,' where `date`=\'',Tsetdate,'\' AND `hour_key`=',Thour);

PREPARE ddhdtt_sql_ex FROM @ddhdtt_sql;

EXECUTE ddhdtt_sql_ex;

ALTER TABLE dw_day_hour_temp_switch ENABLE KEYS;





#写入订单每时临时数据

TRUNCATE `dw_day_hga_temp_switch`;

ALTER TABLE dw_day_hga_temp_switch DISABLE KEYS;

REPLACE INTO `dw_day_hga_temp_switch`

(

    `date`,

    `hour_key`,

    `app_id`,

    `agent_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`,

    IFNULL(`hour_key`,Thour) AS `app_id`,

    IFNULL(`app_id`,0) AS `app_id`,

    IFNULL(`agent_id`,0) AS `agent_id`,

    COUNT(DISTINCT(CASE WHEN `game_reg_days`=0 AND `mem_id` > 0 AND `game_reg_hour_key` = `hour_key` THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN `mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(CASE WHEN `game_reg_days`=0 AND `mem_id` > 0 AND `game_reg_hour_key` = Thour THEN `sum_money` END),0) AS `reg_sum_money`,

    IFNULL(SUM(CASE WHEN `game_reg_days`=0 AND `mem_id` > 0 AND `game_reg_hour_key` = Thour THEN `sum_real_money` END),0) AS `reg_real_sum_money`,

    COUNT(DISTINCT(CASE WHEN `sum_money`>0 THEN `mem_id` END)) AS `pay_mem_cnt`, 

    COUNT(DISTINCT(CASE  WHEN `game_reg_days`=0 AND `sum_money`>0 AND `game_reg_hour_key` = Thour  THEN `mem_id` END)) AS `reg_pay_cnt` 

FROM dw_day_hour_temp_switch

GROUP BY agent_id,app_id;

ALTER TABLE dw_day_hga_temp_switch ENABLE KEYS;





#写入每日每时游戏渠道

ALTER TABLE dw_hour_game_agent_switch DISABLE KEYS;

REPLACE INTO `dw_hour_game_agent_switch`

(              

    `date`,

    `hour_key`,

    `app_id`,

    `agent_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`hour_key`,Thour) AS `hour_key`,

    IFNULL(`app_id`,0) AS `app_id`,

    IFNULL(`agent_id`,0) AS `agent_id`,

    IFNULL(`reg_cnt`,0) AS `reg_cnt`,

    IFNULL(`user_cnt`,0) AS `user_cnt`,

    IFNULL(`order_cnt`,0) AS `order_cnt`,

    IFNULL(`sum_money`,0) AS `sum_money`,

    IFNULL(`sum_real_money`,0) AS `sum_real_money`,

    IFNULL(`reg_sum_money`,0) AS `reg_sum_money`,

    IFNULL(`reg_real_sum_money`,0) AS `reg_real_sum_money`,

    IFNULL(`pay_mem_cnt`,0) AS `pay_mem_cnt`,

    IFNULL(`reg_pay_mem_cnt`,0) AS `reg_pay_mem_cnt`

   

FROM dw_day_hga_temp_switch;

ALTER TABLE dw_hour_game_agent_switch ENABLE KEYS;





#写入每日每时渠道

ALTER TABLE dw_hour_agent_switch DISABLE KEYS;

REPLACE INTO `dw_hour_agent_switch`

(              

    `date`,

    `hour_key`,

    `agent_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`,

    IFNULL(`hour_key`,Thour) AS `app_id`,

    IFNULL(`agent_id`,0) AS `agent_id`,

    COUNT(DISTINCT(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN `mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_money` END),0) AS `reg_sum_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_real_money` END),0) AS `reg_real_sum_money`,

    COUNT(DISTINCT(CASE WHEN `sum_money`>0 THEN `mem_id` END)) AS `pay_mem_cnt`, 

    COUNT(DISTINCT(CASE  WHEN `reg_days`=0 AND `sum_money`>0 AND `reg_hour_key` = `hour_key`  THEN `mem_id` END)) AS `reg_pay_cnt` 

FROM dw_day_hour_temp_switch 

GROUP BY agent_id;

ALTER TABLE dw_hour_agent_switch ENABLE KEYS;







#写入每日每时游戏

ALTER TABLE dw_hour_game_switch DISABLE KEYS;

REPLACE INTO `dw_hour_game_switch`

(                          

    `date`,

    `hour_key`,

    `app_id`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`, 

    IFNULL(`hour_key`,Thour) AS `hour_key`,

    IFNULL(`app_id`,0) AS `app_id`,

    IFNULL(SUM(`reg_cnt`),0) AS `reg_cnt`,

    IFNULL(SUM(`user_cnt`),0) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(`reg_sum_money`),0) AS `reg_sum_money`,

    IFNULL(SUM(`reg_real_sum_money`),0) AS `reg_real_sum_money`,

    IFNULL(SUM(`pay_mem_cnt`),0) AS `pay_mem_cnt`,

    IFNULL(SUM(`reg_pay_mem_cnt`),0) AS `reg_pay_mem_cnt`

FROM dw_day_hga_temp 

GROUP BY hour_key,app_id;

ALTER TABLE dw_hour_agent_switch ENABLE KEYS;



#写入每日每时

ALTER TABLE dw_hour_switch DISABLE KEYS;

REPLACE INTO `dw_hour_switch`

(           

    `date`,

    `hour_key`,

    `reg_cnt`,

    `user_cnt`,

    `order_cnt`,

    `sum_money`,

    `sum_real_money`,

    `reg_sum_money`,

    `reg_real_sum_money`,

    `pay_mem_cnt`,

    `reg_pay_mem_cnt`

)

SELECT

    IFNULL(`date`,TformatDate) AS `date`,

    IFNULL(`hour_key`,Thour) AS `app_id`,

    COUNT(DISTINCT(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `mem_id` END)) AS `reg_cnt`,

    COUNT(DISTINCT(CASE WHEN `mem_id` > 0 THEN `mem_id` END)) AS `user_cnt`,

    IFNULL(SUM(`order_cnt`),0) AS `order_cnt`,

    IFNULL(SUM(`sum_money`),0) AS `sum_money`,

    IFNULL(SUM(`sum_real_money`),0) AS `sum_real_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_money` END),0) AS `reg_sum_money`,

    IFNULL(SUM(CASE WHEN `reg_days`=0 AND `mem_id` > 0 AND `reg_hour_key` = `hour_key` THEN `sum_real_money` END),0) AS `reg_real_sum_money`,

    COUNT(DISTINCT(CASE WHEN `sum_money`>0 THEN `mem_id` END)) AS `pay_mem_cnt`, 

    COUNT(DISTINCT(CASE  WHEN `reg_days`=0 AND `sum_money`>0 AND `reg_hour_key` = `hour_key`  THEN `mem_id` END)) AS `reg_pay_cnt` 

FROM dw_day_hour_temp_switch 

GROUP BY hour_key;

ALTER TABLE dw_hour_switch ENABLE KEYS;



END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for runltv
-- ----------------------------
DROP PROCEDURE IF EXISTS `runltv`;
delimiter ;;
CREATE PROCEDURE `runltv`(IN `iday` date)
BEGIN

        DECLARE Tflag INT DEFAULT 0;

        DECLARE Tappid INT;

        DECLARE Tdate DATE;

        DECLARE Tregtime INT;

        DECLARE Tregday INT;

        DECLARE Tagentid INT;

        DECLARE Tmobile_prefix INT DEFAULT 156;

        DECLARE Tregcnt INT;

        DECLARE Tsummoney DECIMAL(12,2);

        DECLARE Tsetdate DATE DEFAULT iday;

        DECLARE Tstarttime INT;

        DECLARE Tendtime INT;

        DECLARE TdayFlag varchar(20);

        DECLARE Tdata_exist CHAR(2);

        DECLARE TformatDate DATE DEFAULT date_format(Tsetdate,'%Y-%m-%d');





        DECLARE Tagcursor CURSOR FOR SELECT reg_time,app_id,agent_id,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp` WHERE reg_days < 361 AND sum_money > 0 GROUP BY app_id,agent_id,reg_days;



        DECLARE Tacursor CURSOR FOR SELECT reg_time,agent_id,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp` WHERE reg_days < 361 AND sum_money > 0 GROUP BY agent_id,reg_days;



        DECLARE Tgcursor CURSOR FOR SELECT reg_time,app_id,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp` WHERE reg_days < 361 AND sum_money > 0 GROUP BY app_id,reg_days;



        DECLARE Tcursor CURSOR FOR SELECT reg_time,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp` WHERE reg_days < 361 AND sum_money > 0 GROUP BY reg_days;



        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Tflag = 1;



        SET Tstarttime=unix_timestamp(Tsetdate);

        SET Tendtime=Tstarttime+86400;



        SET @Ttable = CONCAT('db_mp_log.log_log_day_mem_',date_format(Tsetdate,'%Y%m') );





        CREATE TABLE IF NOT EXISTS `log_ltv_day_mem_temp` (

            `id` int(11) NOT NULL AUTO_INCREMENT,

            `date` date NOT NULL DEFAULT '0000-00-00' COMMENT '日期',

            `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家ID',

            `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',

            `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

            `reg_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

            `reg_days` int(11) NOT NULL DEFAULT '0' COMMENT '注册天数',

            `device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '手机设备码',

            `sum_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '累计充值',

            `sum_real_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

	`reg_app_id` int(11) NOT NULL DEFAULT '0' COMMENT '注册游戏ID',

						`is_new_app` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否游戏新增注册玩家 1 否 2是',

            PRIMARY KEY (`id`),

            UNIQUE KEY `lldmt_date_mem_app_unique` (`date`,`mem_id`,`app_id`),

            KEY `ldmt_agent_index` (`agent_id`),

            KEY `ldmt_app_index` (`app_id`)

        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ltv玩家每日临时';





        TRUNCATE `log_ltv_day_mem_temp`;

        ALTER TABLE `log_ltv_day_mem_temp` DISABLE KEYS;



        SET @ldmt_sql = "REPLACE INTO `log_ltv_day_mem_temp`  (`date`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,`sum_money`,`sum_real_money`,`reg_app_id`,`is_new_app`) SELECT `date`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,`sum_money`,`sum_real_money`,`reg_app_id`,`is_new_app`";



        SET  @ldmt_sql = concat(@ldmt_sql, ' FROM ',@Ttable,' where `date`=\'',Tsetdate,'\'');



        PREPARE ldmt_sql_ex FROM @ldmt_sql;

        EXECUTE ldmt_sql_ex;

        ALTER TABLE log_ltv_day_mem_temp ENABLE KEYS;





        DROP TABLE IF EXISTS log_ltv_dgac_temp;

        CREATE TABLE IF NOT EXISTS `log_ltv_dgac_temp` (

            `id` int(11) NOT NULL AUTO_INCREMENT,

            `date` date NOT NULL DEFAULT '0000-00-00' COMMENT '日期',

            `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

            `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',

            `reg_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册玩家数',

            `sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '充值金额',

            `sum_real_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

            PRIMARY KEY (`id`) USING BTREE,

            UNIQUE KEY `dga_dga_unique` (`date`,`app_id`,`agent_id`) USING BTREE,

            KEY `dga_game_index` (`app_id`) USING BTREE,

            KEY `dga_agent_index` (`agent_id`) USING BTREE

        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='ltv每日游戏推广员统计表';









        TRUNCATE `log_ltv_dgac_temp`;

        ALTER TABLE log_ltv_dgac_temp DISABLE KEYS;

        REPLACE INTO `log_ltv_dgac_temp`

        (

            `date`,

            `app_id`,

            `agent_id`,

            `reg_cnt`,

            `sum_money`,

            `sum_real_money`

        )

            SELECT

                IFNULL(lldmt.`date`,TformatDate) AS `date`,

                IFNULL(lldmt.`app_id`,0) AS `app_id`,

                IFNULL(lldmt.`agent_id`,0) AS `agent_id`,

                COUNT(DISTINCT(CASE WHEN (lldmt.`reg_days`=0 AND lldmt.`mem_id` > 0 AND lldmt.`app_id` = lldmt.`reg_app_id`) OR lldmt.is_new_app = 2 THEN `mem_id` END)) AS `reg_cnt`	,

                IFNULL(SUM(lldmt.`sum_money`),0) AS `sum_money` ,

                SUM(lldmt.`sum_real_money`) AS `sum_real_money`

            FROM log_ltv_day_mem_temp lldmt

            GROUP BY agent_id, app_id;

        ALTER TABLE log_ltv_dgac_temp ENABLE KEYS;







        ALTER TABLE dw_ltv_game_agent DISABLE KEYS;

        REPLACE INTO `dw_ltv_game_agent`

        (

            `date`,

            `app_id`,

            `agent_id`,

            `reg_cnt`

        )

            SELECT

                IFNULL(`date`,TformatDate) AS `date`,

                IFNULL(`app_id`,0) AS `app_id`,

                IFNULL(`agent_id`,0) AS `agent_id`,

                IFNULL(`reg_cnt`,0) AS `reg_cnt`

            FROM log_ltv_dgac_temp

            WHERE `reg_cnt`>0;

        ALTER TABLE dw_ltv_game_agent ENABLE KEYS;







        ALTER TABLE dw_ltv_agent DISABLE KEYS;

        REPLACE INTO `dw_ltv_agent`

        (

            `date`,

            `agent_id`,

            `reg_cnt`

        )

            SELECT

                IFNULL(ldmt.`date`,TformatDate) AS `date`,

                ldmt.`agent_id` AS `agent_id`,

                COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `reg_cnt`

            FROM log_ltv_day_mem_temp ldmt

            WHERE ldmt.`reg_days` = 0 AND ldmt.`mem_id` > 0

            GROUP BY agent_id;

        ALTER TABLE dw_ltv_agent ENABLE KEYS;







        ALTER TABLE dw_ltv_game DISABLE KEYS;

        REPLACE INTO `dw_ltv_game`

        (

            `date`,

            `app_id`,

            `reg_cnt`

        )

            SELECT

                IFNULL(`date`,TformatDate) AS `date`,

                IFNULL(`app_id`,0) AS `app_id`,

                SUM(`reg_cnt`) AS `reg_cnt`

            FROM log_ltv_dgac_temp

            WHERE `reg_cnt`>0

            GROUP BY app_id;

        ALTER TABLE dw_ltv_game ENABLE KEYS;









        ALTER TABLE dw_ltv_day DISABLE KEYS;

        REPLACE INTO `dw_ltv_day`

        (

            `date`,

            `reg_cnt`

        )

            SELECT

                IFNULL(ldmt.`date`,TformatDate) AS `date`,

                COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `reg_cnt`

            FROM log_ltv_day_mem_temp ldmt

            WHERE ldmt.`reg_days` = 0 AND ldmt.`mem_id` > 0;

        ALTER TABLE dw_ltv_day ENABLE KEYS;







        SET Tflag=0;

        OPEN Tagcursor;

        FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_game_agent` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') AND `agent_id`=Tagentid AND `app_id`=Tappid limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_game_agent` (`date`,`app_id`,`agent_id`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),',Tappid,',',Tagentid,',1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_game_agent SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d") AND agent_id=',Tagentid,' AND app_id=',Tappid);

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tagcursor;





        SET Tflag=0;

        OPEN Tacursor;

        FETCH Tacursor INTO Tregtime,Tagentid,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_agent` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') AND `agent_id`=Tagentid limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_agent` (`date`,`agent_id`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),',Tagentid,',1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_agent SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d") AND agent_id=',Tagentid);

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tacursor INTO Tregtime,Tagentid,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tacursor;







        SET Tflag=0;

        OPEN Tgcursor;

        FETCH Tgcursor INTO Tregtime,Tappid,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_game` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') AND `app_id`=Tappid limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_game` (`date`,`app_id`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),',Tappid,',1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_game SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d") AND app_id=',Tappid);

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tgcursor INTO Tregtime,Tappid,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tgcursor;





        SET Tflag=0;

        OPEN Tcursor;

        FETCH Tcursor INTO Tregtime,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_day` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_day` (`date`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_day SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d")');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tcursor INTO Tregtime,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tcursor;



    END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for runltvswitch
-- ----------------------------
DROP PROCEDURE IF EXISTS `runltvswitch`;
delimiter ;;
CREATE PROCEDURE `runltvswitch`(IN `iday` date)
BEGIN

        DECLARE Tflag INT DEFAULT 0;

        DECLARE Tappid INT;

        DECLARE Tdate DATE;

        DECLARE Tregtime INT;

        DECLARE Tregday INT;

        DECLARE Tagentid INT;

        DECLARE Tmobile_prefix INT DEFAULT 156;

        DECLARE Tregcnt INT;

        DECLARE Tsummoney DECIMAL(12,2);

        DECLARE Tsetdate DATE DEFAULT iday;

        DECLARE Tstarttime INT;

        DECLARE Tendtime INT;

        DECLARE TdayFlag varchar(20);

        DECLARE Tdata_exist CHAR(2);

        DECLARE TformatDate DATE DEFAULT date_format(Tsetdate,'%Y-%m-%d');





        DECLARE Tagcursor CURSOR FOR SELECT reg_time,app_id,agent_id,reg_days,sum_money FROM `log_ltv_day_mem_temp_switch` WHERE reg_days < 361 AND sum_money > 0 GROUP BY app_id,agent_id,reg_days;



        DECLARE Tacursor CURSOR FOR SELECT reg_time,agent_id,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp_switch` WHERE reg_days < 361 AND sum_money > 0 GROUP BY agent_id,reg_days;



        DECLARE Tgcursor CURSOR FOR SELECT reg_time,app_id,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp_switch` WHERE reg_days < 361 AND sum_money > 0 GROUP BY app_id,reg_days;



        DECLARE Tcursor CURSOR FOR SELECT reg_time,reg_days,SUM(sum_money) as sum_money FROM `log_ltv_day_mem_temp_switch` WHERE reg_days < 361 AND sum_money > 0 GROUP BY reg_days;



        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Tflag = 1;



        SET Tstarttime=unix_timestamp(Tsetdate);

        SET Tendtime=Tstarttime+86400;



        SET @Ttable = CONCAT('db_mp_log.log_log_day_mem_switch_',date_format(Tsetdate,'%Y%m') );





        CREATE TABLE IF NOT EXISTS `log_ltv_day_mem_temp_switch` (

            `id` int(11) NOT NULL AUTO_INCREMENT,

            `date` date NOT NULL DEFAULT '0000-00-00' COMMENT '日期',

            `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家ID',

            `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',

            `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

            `reg_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',

            `reg_days` int(11) NOT NULL DEFAULT '0' COMMENT '注册天数',

            `device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '手机设备码',

            `sum_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '累计充值',

            `sum_real_money` double(12,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

						`is_new_app` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否游戏新增注册玩家 1 否 2是',

            PRIMARY KEY (`id`),

            UNIQUE KEY `lldmt_date_mem_app_unique` (`date`,`mem_id`,`app_id`),

            KEY `ldmt_agent_index` (`agent_id`),

            KEY `ldmt_app_index` (`app_id`)

        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ltv玩家每日临时';





        TRUNCATE `log_ltv_day_mem_temp_switch`;

        ALTER TABLE `log_ltv_day_mem_temp_switch` DISABLE KEYS;



        SET @ldmt_sql = "REPLACE INTO `log_ltv_day_mem_temp_switch`  (`date`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,`sum_money`,`sum_real_money`,`is_new_app`) SELECT `date`,`mem_id`,`agent_id`,`app_id`,`reg_time`,`reg_days`,`device_id`,`sum_money`,`sum_real_money`,`is_new_app`";



        SET  @ldmt_sql = concat(@ldmt_sql, ' FROM ',@Ttable,' where `date`=\'',Tsetdate,'\'');



        PREPARE ldmt_sql_ex FROM @ldmt_sql;

        EXECUTE ldmt_sql_ex;

        ALTER TABLE log_ltv_day_mem_temp_switch ENABLE KEYS;





        DROP TABLE IF EXISTS log_ltv_dgac_temp_switch;

        CREATE TABLE IF NOT EXISTS `log_ltv_dgac_temp_switch` (

            `id` int(11) NOT NULL AUTO_INCREMENT,

            `date` date NOT NULL DEFAULT '0000-00-00' COMMENT '日期',

            `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',

            `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',

            `reg_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册玩家数',

            `sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '充值金额',

            `sum_real_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '自然流水金额',

            PRIMARY KEY (`id`) USING BTREE,

            UNIQUE KEY `dga_dga_unique` (`date`,`app_id`,`agent_id`) USING BTREE,

            KEY `dga_game_index` (`app_id`) USING BTREE,

            KEY `dga_agent_index` (`agent_id`) USING BTREE

        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='ltv每日游戏推广员统计表';









        TRUNCATE `log_ltv_dgac_temp_switch`;

        ALTER TABLE log_ltv_dgac_temp_switch DISABLE KEYS;

        REPLACE INTO `log_ltv_dgac_temp_switch`

        (

            `date`,

            `app_id`,

            `agent_id`,

            `reg_cnt`,

            `sum_money`,

            `sum_real_money`

        )

            SELECT

                IFNULL(lldmt.`date`,TformatDate) AS `date`,

                IFNULL(lldmt.`app_id`,0) AS `app_id`,

                IFNULL(lldmt.`agent_id`,0) AS `agent_id`,

                COUNT(DISTINCT(CASE WHEN (lldmt.`reg_days`=0 AND lldmt.`mem_id` > 0) OR lldmt.is_new_app = 2 THEN `mem_id` END)) AS `reg_cnt`	,

                IFNULL(SUM(lldmt.`sum_money`),0) AS `sum_money` ,

                SUM(lldmt.`sum_real_money`) AS `sum_real_money`

            FROM log_ltv_day_mem_temp_switch lldmt

            GROUP BY agent_id, app_id;

        ALTER TABLE log_ltv_dgac_temp_switch ENABLE KEYS;







        ALTER TABLE dw_ltv_game_agent_switch DISABLE KEYS;

        REPLACE INTO `dw_ltv_game_agent_switch`

        (

            `date`,

            `app_id`,

            `agent_id`,

            `reg_cnt`

        )

            SELECT

                IFNULL(`date`,TformatDate) AS `date`,

                IFNULL(`app_id`,0) AS `app_id`,

                IFNULL(`agent_id`,0) AS `agent_id`,

                IFNULL(`reg_cnt`,0) AS `reg_cnt`

            FROM log_ltv_dgac_temp_switch

            WHERE `reg_cnt`>0;

        ALTER TABLE dw_ltv_game_agent_switch ENABLE KEYS;







        ALTER TABLE dw_ltv_agent_switch DISABLE KEYS;

        REPLACE INTO `dw_ltv_agent_switch`

        (

            `date`,

            `agent_id`,

            `reg_cnt`

        )

            SELECT

                IFNULL(ldmt.`date`,TformatDate) AS `date`,

                ldmt.`agent_id` AS `agent_id`,

                COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `reg_cnt`

            FROM log_ltv_day_mem_temp_switch ldmt

            WHERE ldmt.`reg_days` = 0 AND ldmt.`mem_id` > 0

            GROUP BY agent_id;

        ALTER TABLE dw_ltv_agent_switch ENABLE KEYS;







        ALTER TABLE dw_ltv_game_switch DISABLE KEYS;

        REPLACE INTO `dw_ltv_game_switch`

        (

            `date`,

            `app_id`,

            `reg_cnt`

        )

            SELECT

                IFNULL(`date`,TformatDate) AS `date`,

                IFNULL(`app_id`,0) AS `app_id`,

                SUM(`reg_cnt`) AS `reg_cnt`

            FROM log_ltv_dgac_temp_switch

            WHERE `reg_cnt`>0

            GROUP BY app_id;

        ALTER TABLE dw_ltv_game_switch ENABLE KEYS;









        ALTER TABLE dw_ltv_day_switch DISABLE KEYS;

        REPLACE INTO `dw_ltv_day_switch`

        (

            `date`,

            `reg_cnt`

        )

            SELECT

                IFNULL(ldmt.`date`,TformatDate) AS `date`,

                COUNT(DISTINCT(CASE WHEN ldmt.`reg_days`=0 AND ldmt.`mem_id` > 0 THEN `mem_id` END)) AS `reg_cnt`

            FROM log_ltv_day_mem_temp_switch ldmt

            WHERE ldmt.`reg_days` = 0 AND ldmt.`mem_id` > 0;

        ALTER TABLE dw_ltv_day_switch ENABLE KEYS;







        SET Tflag=0;

        OPEN Tagcursor;

        FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_game_agent_switch` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') AND `agent_id`=Tagentid AND `app_id`=Tappid limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_game_agent_switch` (`date`,`app_id`,`agent_id`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),',Tappid,',',Tagentid,',1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_game_agent_switch SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d") AND agent_id=',Tagentid,' AND app_id=',Tappid);

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tagcursor INTO Tregtime,Tappid,Tagentid,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tagcursor;





        SET Tflag=0;

        OPEN Tacursor;

        FETCH Tacursor INTO Tregtime,Tagentid,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_agent_switch` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') AND `agent_id`=Tagentid limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_agent_switch` (`date`,`agent_id`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),',Tagentid,',1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_agent_switch SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d") AND agent_id=',Tagentid);

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tacursor INTO Tregtime,Tagentid,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tacursor;







        SET Tflag=0;

        OPEN Tgcursor;

        FETCH Tgcursor INTO Tregtime,Tappid,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_game_switch` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') AND `app_id`=Tappid limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_game_switch` (`date`,`app_id`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),',Tappid,',1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_game_switch SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d") AND app_id=',Tappid);

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tgcursor INTO Tregtime,Tappid,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tgcursor;





        SET Tflag=0;

        OPEN Tcursor;

        FETCH Tcursor INTO Tregtime,Tregday,Tsummoney;

        WHILE Tflag<>1 DO

            IF Tregday < 360 THEN

                IF Tregday < 60 THEN

                    CASE Tregday

                        WHEN 0 THEN

                        SET TdayFlag = 'day1';

                        WHEN 1 THEN

                        SET TdayFlag = 'day2';

                        WHEN 2 THEN

                        SET TdayFlag = 'day3';

                        WHEN 3 THEN

                        SET TdayFlag = 'day4';

                        WHEN 4 THEN

                        SET TdayFlag = 'day5';

                        WHEN 5 THEN

                        SET TdayFlag = 'day6';

                        WHEN 6 THEN

                        SET TdayFlag = 'day7';

                        WHEN 7 THEN

                        SET TdayFlag = 'day8';

                        WHEN 8 THEN

                        SET TdayFlag = 'day9';

                        WHEN 9 THEN

                        SET TdayFlag = 'day10';

                        WHEN 10 THEN

                        SET TdayFlag = 'day11';

                        WHEN 11 THEN

                        SET TdayFlag = 'day12';

                        WHEN 12 THEN

                        SET TdayFlag = 'day13';

                        WHEN 13 THEN

                        SET TdayFlag = 'day14';

                        WHEN 14 THEN

                        SET TdayFlag = 'day15';

                        WHEN 15 THEN

                        SET TdayFlag = 'day16';

                        WHEN 16 THEN

                        SET TdayFlag = 'day17';

                        WHEN 17 THEN

                        SET TdayFlag = 'day18';

                        WHEN 18 THEN

                        SET TdayFlag = 'day19';

                        WHEN 19 THEN

                        SET TdayFlag = 'day20';

                        WHEN 20 THEN

                        SET TdayFlag = 'day21';

                        WHEN 21 THEN

                        SET TdayFlag = 'day22';

                        WHEN 22 THEN

                        SET TdayFlag = 'day23';

                        WHEN 23 THEN

                        SET TdayFlag = 'day24';

                        WHEN 24 THEN

                        SET TdayFlag = 'day25';

                        WHEN 25 THEN

                        SET TdayFlag = 'day26';

                        WHEN 26 THEN

                        SET TdayFlag = 'day27';

                        WHEN 27 THEN

                        SET TdayFlag = 'day28';

                        WHEN 28 THEN

                        SET TdayFlag = 'day29';

                        WHEN 29 THEN

                        SET TdayFlag = 'day30';

                        WHEN 30 THEN

                        SET TdayFlag = 'day31';

                        WHEN 31 THEN

                        SET TdayFlag = 'day32';

                        WHEN 32 THEN

                        SET TdayFlag = 'day33';

                        WHEN 33 THEN

                        SET TdayFlag = 'day34';

                        WHEN 34 THEN

                        SET TdayFlag = 'day35';

                        WHEN 35 THEN

                        SET TdayFlag = 'day36';

                        WHEN 36 THEN

                        SET TdayFlag = 'day37';

                        WHEN 37 THEN

                        SET TdayFlag = 'day38';

                        WHEN 38 THEN

                        SET TdayFlag = 'day39';

                        WHEN 39 THEN

                        SET TdayFlag = 'day40';

                        WHEN 40 THEN

                        SET TdayFlag = 'day41';

                        WHEN 41 THEN

                        SET TdayFlag = 'day42';

                        WHEN 42 THEN

                        SET TdayFlag = 'day43';

                        WHEN 43 THEN

                        SET TdayFlag = 'day44';

                        WHEN 44 THEN

                        SET TdayFlag = 'day45';

                        WHEN 45 THEN

                        SET TdayFlag = 'day46';

                        WHEN 46 THEN

                        SET TdayFlag = 'day47';

                        WHEN 47 THEN

                        SET TdayFlag = 'day48';

                        WHEN 48 THEN

                        SET TdayFlag = 'day49';

                        WHEN 49 THEN

                        SET TdayFlag = 'day50';

                        WHEN 50 THEN

                        SET TdayFlag = 'day51';

                        WHEN 51 THEN

                        SET TdayFlag = 'day52';

                        WHEN 52 THEN

                        SET TdayFlag = 'day53';

                        WHEN 53 THEN

                        SET TdayFlag = 'day54';

                        WHEN 54 THEN

                        SET TdayFlag = 'day55';

                        WHEN 55 THEN

                        SET TdayFlag = 'day56';

                        WHEN 56 THEN

                        SET TdayFlag = 'day57';

                        WHEN 57 THEN

                        SET TdayFlag = 'day58';

                        WHEN 58 THEN

                        SET TdayFlag = 'day59';

                        WHEN 59 THEN

                        SET TdayFlag = 'day60';

                    END CASE;

                ELSEIF Tregday < 90 THEN

                    SET TdayFlag = 'day90';

                ELSEIF Tregday < 120 THEN

                    SET TdayFlag = 'day120';

                ELSEIF Tregday < 180 THEN

                    SET TdayFlag = 'day180';

                ELSEIF Tregday < 270 THEN

                    SET TdayFlag = 'day270';

                ELSE

                    SET TdayFlag = 'day360';

                END IF;





                SELECT IFNULL((SELECT 'Y' from `dw_ltv_day_switch` where `date`=FROM_UNIXTIME(Tregtime,'%Y-%m-%d') limit 1),'N') INTO Tdata_exist;

                IF 'N' = Tdata_exist THEN



                    SET @sqlstr=CONCAT('INSERT INTO `dw_ltv_day_switch` (`date`,`reg_cnt`,`sum_money`,',TdayFlag,') VALUES (FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d"),1,',Tsummoney,',',Tsummoney,')');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                ELSE

                    SET @sqlstr=CONCAT('update dw_ltv_day_switch SET ',TdayFlag,'=',TdayFlag,'+',Tsummoney,', sum_money = sum_money + ',Tsummoney,' WHERE date=FROM_UNIXTIME(',Tregtime,',"%Y-%m-%d")');

                    PREPARE stmt FROM @sqlstr;

                    EXECUTE stmt;

                    DEALLOCATE PREPARE stmt;

                END IF;

            END IF;

            FETCH Tcursor INTO Tregtime,Tregday,Tsummoney;

        END WHILE;

        CLOSE  Tcursor;



    END
;;
delimiter ;

SET FOREIGN_KEY_CHECKS = 1;
