Browse Source

数据统计脚本

PC-202304251453\Administrator 6 tháng trước cách đây
mục cha
commit
d46a5714a0

+ 4 - 4
app/process/BaseTotal.php → app/process/dataReport/BaseTotal.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\process;
+namespace app\process\dataReport;
 use app\v1\logic\tool\BaseTotalDayLogic;
 use app\v1\logic\tool\BaseTotalHourLogic;
 use Workerman\Crontab\Crontab;
@@ -23,17 +23,17 @@ class BaseTotal
         });
     }
 
-    // {"type":"day","sdate":"2025-06-25","edate":"2025-06-26"}
+    // {"type":"day","date":["2025-06-25","2025-06-26"]}
     public function run($args)
     {
         $params = $args ? json_decode($args, true) : [];
 
         if(!empty($params["type"]) && $params["type"] == "day"){
-            return (new BaseTotalDayLogic())->run();
+            return (new BaseTotalDayLogic())->run($params);
         }
 
         if(!empty($params["type"]) && $params["type"] == "hour"){
-            return (new BaseTotalHourLogic())->run();
+            return (new BaseTotalHourLogic())->run($params);
         }
 
         return "无执行内容";

+ 27 - 0
app/process/dataReport/BasicLoginTotal.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\process\dataReport;
+use app\v1\logic\tool\BasicLoginTotalLogic;
+use Workerman\Crontab\Crontab;
+
+/**
+ * 基础登录统计
+ */
+class BasicLoginTotal
+{
+    public function onWorkerStart(): void
+    {
+        // 每1小时执行一次
+        new Crontab('10 */1 * * *', function() {
+            (new BasicLoginTotalLogic())->run();
+        });
+    }
+
+    // {"type":"day","date":["2025-06-25","2025-06-26"]}
+    public function run($args)
+    {
+        $params = $args ? json_decode($args, true) : [];
+
+        return (new BasicLoginTotalLogic())->run($params);
+    }
+}

+ 192 - 144
app/process/CreateTables.php → app/process/dataReport/CreateTables.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\process;
+namespace app\process\dataReport;
 use support\think\Db;
 use Workerman\Crontab\Crontab;
 
@@ -12,7 +12,7 @@ class CreateTables
     public function onWorkerStart(): void
     {
         // 每天的0点10执行,注意这里省略了秒位
-        new Crontab('10 0 * * *', function(){
+        new Crontab('18 * * * *', function(){
             $this->initStart();
         });
     }
@@ -21,30 +21,49 @@ class CreateTables
     {
         echo "开始创建表\n";
 
-        $createTablesSqlList = [
+        $centerTablesSqlList = [
             $this->base_total_day,
-            $this->basic_login_total,
             $this->base_total_hour,
-            $this->basic_login_total_game,
-            $this->basic_login_total_server,
-            $this->basic_reg_total,
-            $this->game_active_hour,
-            $this->server_total_day,
-            $this->server_total_hour,
+            $this->basic_login_total,
+            $this->game_active_day,
         ];
 
-        foreach ($createTablesSqlList as $sql){
+        foreach ($centerTablesSqlList as $sql){
             try {
-                $year = date('Y', strtotime('+1 year'));
+                $year  = date('Y', strtotime('+1 year'));
                 $month = date('Ym', strtotime('+1 month'));
+
                 $sql = str_replace('{{YEAR}}', $year, $sql);
                 $sql = str_replace('{{MONTH}}', $month, $sql);
-                // echo "创建表:".$sql."\n";
+
                 Db::connect("db_data_report")->execute($sql);
             }catch (\Exception $e){
                 echo $e->getMessage();
             }
         }
+
+
+        $logTablesSqlList = [
+            $this->sdk_active_info,
+            $this->sdk_reg_log,
+            $this->sdk_login_log,
+            $this->sdk_order,
+            $this->role_log,
+        ];
+
+        foreach ($logTablesSqlList as $sql){
+            try {
+                $year  = date('Y', strtotime('+1 year'));
+                $month = date('Ym', strtotime('+1 month'));
+
+                $sql = str_replace('{{YEAR}}', $year, $sql);
+                $sql = str_replace('{{MONTH}}', $month, $sql);
+
+                Db::connect("db_game_log")->execute($sql);
+            }catch (\Exception $e){
+                echo $e->getMessage();
+            }
+        }
     }
 
     protected string $base_total_day = "CREATE TABLE IF NOT EXISTS `base_total_day_{{YEAR}}` (
@@ -89,24 +108,7 @@ class CreateTables
           KEY `auth_id` (`auth_id`) USING BTREE,
           KEY `media_id` (`media_id`) USING BTREE
         ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
-    protected string $basic_login_total = "CREATE TABLE IF NOT EXISTS `basic_login_total_{{YEAR}}` (
-      `id` int(11) NOT NULL AUTO_INCREMENT,
-      `tdate` date NOT NULL COMMENT '登录时间',
-      `agent_id` int(11) NOT NULL COMMENT '渠道ID',
-      `site_id` int(11) NOT NULL DEFAULT '0' COMMENT '广告位ID',
-      `cplaceid` varchar(50) DEFAULT NULL COMMENT '子ID',
-      `adid` varchar(20) DEFAULT NULL COMMENT '创意ID',
-      `turn` int(10) unsigned NOT NULL COMMENT '轮数ID',
-      `login_count` int(11) NOT NULL COMMENT '账号数',
-      `active` int(10) unsigned NOT NULL COMMENT '活跃天数(0:当天)',
-      `plat_id` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '平台ID',
-      PRIMARY KEY (`id`) USING BTREE,
-      KEY `tdate` (`tdate`) USING BTREE,
-      KEY `agent_id` (`agent_id`) USING BTREE,
-      KEY `site_id` (`site_id`) USING BTREE,
-      KEY `plat_id` (`plat_id`) USING BTREE,
-      KEY `active` (`active`) USING BTREE
-    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+
     protected string $base_total_hour = "CREATE TABLE IF NOT EXISTS `base_total_hour_{{MONTH}}` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `tdate` date NOT NULL COMMENT '日期',
@@ -153,27 +155,7 @@ class CreateTables
   KEY `site_id` (`site_id`) USING BTREE,
   KEY `game_id` (`game_id`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
-    protected string $basic_login_total_game = "CREATE TABLE IF NOT EXISTS `basic_login_total_game_{{YEAR}}` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `tdate` date NOT NULL COMMENT '登录时间',
-  `agent_id` int(11) NOT NULL COMMENT '渠道ID',
-  `site_id` int(11) NOT NULL DEFAULT '0' COMMENT '广告位ID',
-  `cplaceid` varchar(50) DEFAULT NULL COMMENT '子ID',
-  `adid` varchar(20) DEFAULT NULL COMMENT '创意ID',
-  `game_id` int(10) unsigned NOT NULL COMMENT '游戏ID',
-  `turn` int(10) unsigned NOT NULL COMMENT '轮数ID',
-  `login_count` int(11) NOT NULL COMMENT '账号数',
-  `active` int(10) unsigned NOT NULL COMMENT '活跃天数(0:当天)',
-  `plat_id` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '平台ID',
-  PRIMARY KEY (`id`) USING BTREE,
-  KEY `tdate` (`tdate`) USING BTREE,
-  KEY `agent_id` (`agent_id`) USING BTREE,
-  KEY `site_id` (`site_id`) USING BTREE,
-  KEY `game_id` (`game_id`) USING BTREE,
-  KEY `plat_id` (`plat_id`) USING BTREE,
-  KEY `active` (`active`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;";
-    protected string $basic_login_total_server = "CREATE TABLE IF NOT EXISTS `basic_login_total_server_{{YEAR}}` (
+    protected string $basic_login_total = "CREATE TABLE IF NOT EXISTS `basic_login_total_{{YEAR}}` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `tdate` date NOT NULL COMMENT '登录时间',
   `agent_id` int(11) NOT NULL COMMENT '渠道ID',
@@ -181,7 +163,6 @@ class CreateTables
   `cplaceid` varchar(50) DEFAULT NULL COMMENT '子ID',
   `adid` varchar(20) DEFAULT NULL COMMENT '创意ID',
   `game_id` int(10) unsigned NOT NULL COMMENT '游戏ID',
-  `server_id` int(11) NOT NULL DEFAULT '0' COMMENT '服务器ID',
   `turn` int(10) unsigned NOT NULL COMMENT '轮数ID',
   `login_count` int(11) NOT NULL COMMENT '账号数',
   `active` int(10) unsigned NOT NULL COMMENT '活跃天数(0:当天)',
@@ -191,36 +172,11 @@ class CreateTables
   KEY `agent_id` (`agent_id`) USING BTREE,
   KEY `site_id` (`site_id`) USING BTREE,
   KEY `game_id` (`game_id`) USING BTREE,
-  KEY `server_id` (`server_id`) USING BTREE,
   KEY `plat_id` (`plat_id`) USING BTREE,
   KEY `active` (`active`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;";
-    protected string $basic_reg_total = "CREATE TABLE IF NOT EXISTS `basic_reg_total_{{YEAR}}` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `tdate` date NOT NULL COMMENT '日期',
-  `thour` tinyint(4) NOT NULL COMMENT '小时',
-  `agent_id` int(11) NOT NULL COMMENT '渠道ID',
-  `site_id` int(11) NOT NULL COMMENT '广告位ID',
-  `adid` varchar(100) DEFAULT '' COMMENT '创意ID',
-  `turn` int(11) DEFAULT '0' COMMENT '轮数',
-  `cplaceid` varchar(100) DEFAULT '' COMMENT '子ID',
-  `reg_count` int(11) NOT NULL DEFAULT '0' COMMENT '注册数',
-  `login_count` int(11) NOT NULL DEFAULT '0' COMMENT '登录数',
-  `game_id` int(11) NOT NULL COMMENT '游戏ID',
-  `server_id` int(11) NOT NULL DEFAULT '0' COMMENT '服务器ID',
-  `plat_id` tinyint(4) NOT NULL DEFAULT '0' COMMENT '平台ID',
-  PRIMARY KEY (`id`) USING BTREE,
-  KEY `tdate` (`tdate`) USING BTREE,
-  KEY `thour` (`thour`) USING BTREE,
-  KEY `agent_id` (`agent_id`) USING BTREE,
-  KEY `site_id` (`site_id`) USING BTREE,
-  KEY `game_id` (`game_id`) USING BTREE,
-  KEY `server_id` (`server_id`) USING BTREE,
-  KEY `adid` (`adid`) USING BTREE,
-  KEY `cplaceid` (`cplaceid`) USING BTREE,
-  KEY `plat_id` (`plat_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='注册日志基础统计表';";
-    protected string $game_active_hour = "CREATE TABLE IF NOT EXISTS `game_active_hour_{{MONTH}}` (
+
+    protected string $game_active_day = "CREATE TABLE IF NOT EXISTS `game_active_day_{{YEAR}}` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `game_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',
   `media_id` int(11) NOT NULL DEFAULT '0' COMMENT '媒体ID',
@@ -228,81 +184,173 @@ class CreateTables
   `site_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告位ID',
   `auth_id` int(10) NOT NULL DEFAULT '0' COMMENT '负责人ID',
   `reg_date` date NOT NULL COMMENT '日期',
-  `thour` tinyint(3) unsigned NOT NULL COMMENT '小时',
   `days` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '活跃天数(0当天登陆)',
   `active_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '活跃数',
-  `active_reg_game` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '活跃数(注册游戏相同)',
-  `pay_total` float NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`) USING BTREE,
-  UNIQUE KEY `select_index` (`reg_date`,`thour`,`days`,`agent_id`,`site_id`,`game_id`) USING BTREE,
+  UNIQUE KEY `select_index` (`reg_date`, `days`,`agent_id`,`site_id`,`game_id`) USING BTREE,
   KEY `reg_date` (`reg_date`) USING BTREE,
-  KEY `thour` (`thour`) USING BTREE,
   KEY `agent_id` (`agent_id`) USING BTREE,
   KEY `site_id` (`site_id`) USING BTREE,
   KEY `media_id` (`media_id`) USING BTREE,
   KEY `auth_id` (`auth_id`) USING BTREE,
   KEY `game_id` (`game_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='注册活跃表(按小时统计)';";
-    protected string $server_total_day = "CREATE TABLE IF NOT EXISTS `server_total_day_{{YEAR}}` (
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='活跃表';";
+
+    protected string $sdk_active_info = "CREATE TABLE IF NOT EXISTS `sdk_active_info_{{MONTH}}` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
-  `tdate` date NOT NULL COMMENT '日期',
-  `game_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',
+  `tdate` date NOT NULL,
+  `user_name` varchar(50) NOT NULL,
+  `uid` int(11) NOT NULL DEFAULT '0',
+  `agent_id` int(11) NOT NULL DEFAULT '0',
+  `site_id` int(11) NOT NULL DEFAULT '0',
+  `game_id` int(11) NOT NULL DEFAULT '0',
+  `active` int(11) NOT NULL DEFAULT '0' COMMENT '(登录减注册的天数)',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `tdate_2` (`game_id`,`tdate`,`uid`),
+  KEY `tdate` (`tdate`),
+  KEY `user_name` (`user_name`),
+  KEY `uid` (`uid`),
+  KEY `game_id` (`game_id`),
+  KEY `agent_id` (`agent_id`),
+  KEY `site_id` (`site_id`),
+  KEY `active` (`active`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户活跃表';";
+
+
+    protected string $sdk_reg_log = "CREATE TABLE IF NOT EXISTS `sdk_reg_log_{{MONTH}}` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `user_name` varchar(20) DEFAULT '',
+  `uid` bigint(20) NOT NULL DEFAULT '0',
+  `game_id` int(11) NOT NULL COMMENT '游戏game_id',
   `media_id` int(11) NOT NULL DEFAULT '0' COMMENT '媒体ID',
-  `agent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',
-  `site_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告位ID',
-  `auth_id` int(10) NOT NULL DEFAULT '0' COMMENT '负责人ID',
-  `server_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '区服ID',
-  `user_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '登陆用户数(数据上报)',
-  `new_user_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '新登陆用户(进入游戏)',
-  `reg_user_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册登陆数(数据上报)',
-  `role_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏角色登陆数',
-  `role_create_user` int(10) unsigned DEFAULT '0' COMMENT '创建角色用户数',
-  `role_create_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏创角数',
-  `pay_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '充值人数',
-  `pay_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '充值金额',
-  `reg_pay_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册付费人数',
-  `reg_pay_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册付费金额',
-  `gf_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '衮服登陆用户数',
-  `gf_pay_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '衮服付费数',
-  `gf_pay_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '衮服付费金额',
-  PRIMARY KEY (`id`) USING BTREE,
-  UNIQUE KEY `select_index` (`tdate`,`agent_id`,`site_id`,`game_id`,`server_id`) USING BTREE,
-  KEY `tdate` (`tdate`) USING BTREE,
-  KEY `agent_id` (`agent_id`) USING BTREE,
-  KEY `site_id` (`site_id`) USING BTREE,
-  KEY `game_id` (`game_id`) USING BTREE,
-  KEY `media_id` (`media_id`) USING BTREE,
-  KEY `auth_id` (`auth_id`) USING BTREE,
-  KEY `server_id` (`server_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='按区服统计总表';";
-    protected string $server_total_hour = "CREATE TABLE IF NOT EXISTS `server_total_hour_{{MONTH}}` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `tdate` date NOT NULL COMMENT '日期',
-  `thour` tinyint(4) NOT NULL COMMENT '小时',
-  `game_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',
+  `agent_id` int(10) unsigned NOT NULL DEFAULT '1000' COMMENT '渠道id',
+  `site_id` int(10) unsigned NOT NULL DEFAULT '1000' COMMENT '广告位id',
+  `auth_id` int(11) NOT NULL DEFAULT '0' COMMENT '负责人ID',
+  `reg_time` int(11) NOT NULL,
+  `imei` varchar(64) DEFAULT '' COMMENT 'imei/idfa',
+  `oaid` varchar(128) DEFAULT '' COMMENT 'oaid/cid',
+  `ip` varchar(128) NOT NULL DEFAULT '',
+  `vt` tinyint(4) NOT NULL DEFAULT '1' COMMENT '0:模拟器1:真机2:未知',
+  `cpu` varchar(32) DEFAULT '' COMMENT 'cpu',
+  `brand` varchar(32) DEFAULT '' COMMENT '品牌',
+  `model` varchar(32) DEFAULT '' COMMENT '机型',
+  `system_version` varchar(32) DEFAULT '' COMMENT '系统版本',
+  `sdk_version` varchar(32) DEFAULT '' COMMENT 'sdk版本',
+  `packname` varchar(64) DEFAULT '' COMMENT '包名',
+  `os` varchar(10) NOT NULL DEFAULT 'android',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `user_name` (`user_name`),
+  KEY `imei` (`imei`),
+  KEY `reg_time` (`reg_time`),
+  KEY `agent_id` (`agent_id`),
+  KEY `game_id` (`game_id`),
+  KEY `site_id` (`site_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='注册日志';";
+
+    protected string $sdk_login_log = "CREATE TABLE IF NOT EXISTS `sdk_login_log_{{MONTH}}` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `user_name` varchar(20) DEFAULT '',
+  `uid` bigint(20) NOT NULL DEFAULT '0',
+  `game_id` int(11) NOT NULL COMMENT '游戏game_id',
   `media_id` int(11) NOT NULL DEFAULT '0' COMMENT '媒体ID',
-  `agent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '渠道ID',
-  `site_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告位ID',
-  `auth_id` int(10) NOT NULL DEFAULT '0' COMMENT '负责人ID',
-  `server_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '区服ID',
-  `user_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '登陆用户数(数据上报)',
-  `new_user_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '新登陆用户(进入游戏)',
-  `reg_user_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册登陆数(数据上报)',
-  `role_login_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏角色登陆数',
-  `role_create_user` int(10) unsigned DEFAULT '0' COMMENT '创建角色用户数',
-  `role_create_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏创角数',
-  `pay_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '充值人数',
-  `pay_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '充值金额',
-  PRIMARY KEY (`id`) USING BTREE,
-  UNIQUE KEY `select_index` (`tdate`,`thour`,`agent_id`,`site_id`,`game_id`,`server_id`) USING BTREE,
-  KEY `tdate` (`tdate`) USING BTREE,
-  KEY `thour` (`thour`) USING BTREE,
-  KEY `agent_id` (`agent_id`) USING BTREE,
-  KEY `site_id` (`site_id`) USING BTREE,
-  KEY `game_id` (`game_id`) USING BTREE,
-  KEY `media_id` (`media_id`) USING BTREE,
-  KEY `auth_id` (`auth_id`) USING BTREE,
-  KEY `server_id` (`server_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='按区服统计小时总表';";
+  `agent_id` int(10) unsigned NOT NULL DEFAULT '1000' COMMENT '渠道id',
+  `site_id` int(10) unsigned NOT NULL DEFAULT '1000' COMMENT '广告位id',
+  `auth_id` int(11) NOT NULL DEFAULT '0' COMMENT '负责人ID',
+  `ip` varchar(128) NOT NULL DEFAULT '',
+  `login_time` int(10) unsigned NOT NULL,
+  `reg_time` int(10) unsigned NOT NULL,
+  `imei` varchar(64) DEFAULT '' COMMENT 'imei/idfa',
+  `oaid` varchar(128) DEFAULT '' COMMENT 'oaid/cid',
+  `vt` tinyint(4) NOT NULL DEFAULT '1' COMMENT '0:模拟器1:真机2:未知',
+  `brand` varchar(32) DEFAULT '' COMMENT '品牌',
+  `model` varchar(32) DEFAULT '' COMMENT '机型',
+  `system_version` varchar(32) DEFAULT '' COMMENT '系统版本',
+  `sdk_version` varchar(32) DEFAULT '' COMMENT 'sdk版本',
+  `packname` varchar(64) DEFAULT '' COMMENT '包名',
+  PRIMARY KEY (`id`),
+  KEY `user_name` (`user_name`),
+  KEY `agent_id` (`agent_id`),
+  KEY `game_id` (`game_id`),
+  KEY `ip` (`ip`),
+  KEY `login_time` (`login_time`),
+  KEY `reg_time` (`reg_time`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='登录日志';";
+
+    protected string $role_log = "CREATE TABLE IF NOT EXISTS `role_log_{{MONTH}}` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `game_id` int(11) NOT NULL COMMENT '游戏game_id',
+  `media_id` int(11) NOT NULL DEFAULT '0' COMMENT '媒体ID',
+  `agent_id` int(10) unsigned NOT NULL DEFAULT '1000' COMMENT '渠道id',
+  `site_id` int(10) unsigned NOT NULL DEFAULT '1000' COMMENT '广告位id',
+  `auth_id` int(11) NOT NULL DEFAULT '0' COMMENT '负责人ID',
+  `data_type` tinyint(4) NOT NULL COMMENT '调用时机:1选服 2创角 3进入 4升级 5退出',
+  `server_id` int(11) NOT NULL COMMENT '服务器ID',
+  `server_name` varchar(15) NOT NULL COMMENT '服务器名称',
+  `user_name` varchar(30) NOT NULL COMMENT '用户账号',
+  `uid` bigint(20) NOT NULL COMMENT '用户ID',
+  `role_id` varchar(64) NOT NULL COMMENT '角色ID',
+  `role_name` varchar(64) NOT NULL COMMENT '角色名',
+  `role_level` int(11) NOT NULL COMMENT '角色等级',
+  `ip` varchar(128) NOT NULL COMMENT 'IP',
+  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  PRIMARY KEY (`id`),
+  KEY `game_id` (`game_id`),
+  KEY `user_name` (`user_name`),
+  KEY `uid` (`uid`),
+  KEY `data_type` (`data_type`),
+  KEY `role_id` (`role_id`),
+  KEY `agent_id` (`agent_id`),
+  KEY `site_id` (`site_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色日志';";
+
+    protected string $sdk_order = "CREATE TABLE IF NOT EXISTS `sdk_order_{{MONTH}}` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `orderid` varchar(60) NOT NULL COMMENT '我方订单号',
+  `tradeid` varchar(60) DEFAULT '' COMMENT '交易流水号',
+  `cp_orderid` varchar(60) NOT NULL COMMENT '研发订单号',
+  `ext` varchar(200) DEFAULT NULL COMMENT 'CP扩展参数',
+  `pay_channel` smallint(6) NOT NULL,
+  `money` float NOT NULL COMMENT '面额(元)',
+  `paid_amount` float unsigned NOT NULL COMMENT '净额(元)',
+  `game_id` int(11) NOT NULL DEFAULT '0',
+  `media_id` int(11) NOT NULL DEFAULT '0' COMMENT '媒体ID',
+  `auth_id` int(11) NOT NULL DEFAULT '0' COMMENT '负责人ID',
+  `agent_id` int(11) NOT NULL DEFAULT '0',
+  `site_id` int(11) NOT NULL DEFAULT '0',
+  `uid` int(11) NOT NULL,
+  `user_name` varchar(30) NOT NULL,
+  `user_ip` varchar(128) NOT NULL DEFAULT '' COMMENT '用户IP',
+  `server_id` int(11) NOT NULL,
+  `server_name` varchar(20) DEFAULT '',
+  `role_id` varchar(32) DEFAULT '',
+  `role_name` varchar(32) DEFAULT '',
+  `payname` varchar(50) DEFAULT '',
+  `pay_date` datetime NOT NULL COMMENT '支付时间',
+  `sync_date` datetime DEFAULT NULL COMMENT '支付通知时间',
+  `sync_data` text COMMENT '支付回调信息',
+  `sync_result` varchar(200) DEFAULT '' COMMENT '第三方支付返回值',
+  `sync_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '支付回调状态 0未支付, 1已支付, 2异常回调',
+  `send_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '发货状态 0未发货, 1已发货',
+  `other_data` varchar(1000) DEFAULT '' COMMENT '其他数据',
+  `imei` varchar(64) DEFAULT '' COMMENT 'imei/idfa',
+  `oaid` varchar(128) DEFAULT '' COMMENT 'oaid/cid',
+  `model` varchar(32) DEFAULT '' COMMENT '手机型号',
+  `system_version` varchar(32) DEFAULT '' COMMENT '系统版本',
+  `sdk_version` varchar(32) DEFAULT '' COMMENT 'SDK版本',
+  `product_id` varchar(64) DEFAULT NULL COMMENT '充值商品ID',
+  `product_name` varchar(64) DEFAULT NULL COMMENT '充值商品名',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `orderid` (`orderid`),
+  KEY `uid` (`uid`),
+  KEY `user_name` (`user_name`),
+  KEY `tradeid` (`tradeid`),
+  KEY `cp_orderid` (`cp_orderid`),
+  KEY `game_id` (`game_id`),
+  KEY `sync_status` (`sync_status`),
+  KEY `send_status` (`send_status`),
+  KEY `auth_id` (`auth_id`),
+  KEY `role_id` (`role_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='订单记录表';";
+
 
 }

+ 31 - 0
app/process/dataReport/GameActive.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace app\process\dataReport;
+use app\v1\logic\tool\GameActiveDayLogic;
+use Workerman\Crontab\Crontab;
+
+/**
+ * 游戏活跃统计
+ */
+class GameActive
+{
+    public function onWorkerStart(): void
+    {
+        // 每2小时执行一次
+        new Crontab('20 */2 * * *', function() {
+            (new GameActiveDayLogic())->run();
+        });
+    }
+
+    // {"type":"day","date":["2025-06-25","2025-06-26"]}
+    public function run($args)
+    {
+        $params = $args ? json_decode($args, true) : [];
+
+        if(!empty($params["type"]) && $params["type"] == "day"){
+            return (new GameActiveDayLogic())->run($params);
+        }
+
+        return "无执行内容";
+    }
+}

+ 27 - 0
app/process/dataReport/GameRegPayMonth.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\process\dataReport;
+use app\v1\logic\tool\GameRegPayMonthLogic;
+use Workerman\Crontab\Crontab;
+
+/**
+ * 注册付费按月
+ */
+class GameRegPayMonth
+{
+    public function onWorkerStart(): void
+    {
+        // 每2小时执行一次
+        new Crontab('0 */2 * * *', function() {
+            (new GameRegPayMonthLogic())->run();
+        });
+    }
+
+    // {"date":["2025-06-25","2025-06-26"]}
+    public function run($args)
+    {
+        $params = $args ? json_decode($args, true) : [];
+
+        return (new GameRegPayMonthLogic())->run($params);
+    }
+}

+ 27 - 0
app/process/dataReport/GameTotalMonth.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\process\dataReport;
+use app\v1\logic\tool\GameTotalMonthLogic;
+use Workerman\Crontab\Crontab;
+
+/**
+ * 注册付费按月
+ */
+class GameTotalMonth
+{
+    public function onWorkerStart(): void
+    {
+        // 每2小时执行一次
+        new Crontab('0 */2 * * *', function() {
+            (new GameTotalMonthLogic())->run();
+        });
+    }
+
+    // {"date":["2025-06-25","2025-06-26"]}
+    public function run($args)
+    {
+        $params = $args ? json_decode($args, true) : [];
+
+        return (new GameTotalMonthLogic())->run($params);
+    }
+}

+ 74 - 25
app/v1/logic/tool/BaseTotalDayLogic.php

@@ -15,8 +15,13 @@ class BaseTotalDayLogic
     protected string $date;
     public function run($params=[])
     {
-        $sDate = $params['sdate'] ?? date('Y-m-d');
-        $eDate = $params['edate'] ?? date('Y-m-d');
+        if(!empty($params['date'])){
+            $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
+            $eDate = is_array($params['date']) ? $params['date'][1] : $params['date'];
+        }else{
+            $sDate = date('Y-m-d');
+            $eDate = date('Y-m-d');
+        }
 
         for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 day'))){
             $this->date = $date;
@@ -29,9 +34,38 @@ class BaseTotalDayLogic
             }
         }
 
+        $this->reRun();
+
         return json_encode(["status"=>"success", "msg"=>""], 256);
     }
 
+    // 重跑
+    protected function reRun(): void
+    {
+        $day = date('d');
+        $hour = date('H');
+        $i = date('i');
+        $t = date('t');
+
+        // 月末,重跑整月
+        if($day==$t){
+            if($hour==1 && $i<10){
+                for ($d=1; $d<=$t; $d++){
+                    $this->date = date('Y-m-d', strtotime("-{$d} day"));
+                    $this->initStart();
+                }
+            }
+        }else{
+            // 重跑前3天
+            if($hour==8 && $i<10){
+                for ($d=1; $d<=3; $d++){
+                    $this->date = date('Y-m-d', strtotime("-{$d} day"));
+                    $this->initStart();
+                }
+            }
+        }
+    }
+
     protected function initStart(): void
     {
         // 重置数据
@@ -41,13 +75,13 @@ class BaseTotalDayLogic
 
         $this->loginData();
 
-        $this->oldLoginData();
+        $this->oldLogin();
 
-        $this->payRegData();
+        $this->regPay();
 
-        $this->payTotalData();
+        $this->payTotal();
 
-        $this->roleCreateData();
+        $this->roleCreate();
 
         $this->siteAuth();
 
@@ -56,43 +90,57 @@ class BaseTotalDayLogic
 
     protected function regData()
     {
-        $regTotalTb = "basic_reg_total_" . date('Y', strtotime($this->date));
-        $filed = "{$this->group}, sum(reg_count) as reg_total, sum(login_count) as reg_login_total";
-        $where = ['tdate' => $this->date];
-        $result = Db::connect('db_data_report')->table($regTotalTb)->field($filed)->where($where)->group($this->group)->select();
+        $sTime = strtotime("{$this->date} 00:00:00");
+        $eTime = strtotime("{$this->date} 23:59:59");
+
+        $regTotalTb = "sdk_reg_log_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group}, count(distinct uid) as reg_total, count(distinct imei) as reg_dev";
+
+        $where = [
+            ['reg_time', 'between', [$sTime, $eTime]],
+        ];
+        $result = Db::connect('db_game_log')->table($regTotalTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
     protected function loginData()
     {
-        $loginGameTb = "basic_login_total_game_" . date('Y', strtotime($this->date));
-        $filed = "{$this->group},sum(login_count) as login_total";
-        $where = ['tdate' => $this->date];
-        $result = Db::connect('db_data_report')->table($loginGameTb)->field($filed)->where($where)->group($this->group)->select();
+        $sTime = strtotime("{$this->date} 00:00:00");
+        $eTime = strtotime("{$this->date} 23:59:59");
+
+        $loginTb = "sdk_login_log_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group},count(distinct uid) as login_total";
+        $where = [
+            ['login_time', 'between', [$sTime, $eTime]],
+        ];
+        $result = Db::connect('db_game_log')->table($loginTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
-    protected function oldLoginData()
+    protected function oldLogin()
     {
-        $loginGameTb = "basic_login_total_game_" . date('Y', strtotime($this->date));
-        $filed = "{$this->group},sum(login_count) as old_login_total";
+        $sTime = strtotime("{$this->date} 00:00:00");
+        $eTime = strtotime("{$this->date} 23:59:59");
+
+        $loginTb = "sdk_login_log_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group},count(distinct uid) as old_login_total";
         $where = [
-            'tdate' => $this->date,
-            ['active', '>', 0]
+            ['login_time', 'between', [$sTime, $eTime]],
+            ['reg_time', '<', strtotime($this->date)],
         ];
-        $result = Db::connect('db_data_report')->table($loginGameTb)->field($filed)->where($where)->group('agent_id,site_id,game_id')->select();
+        $result = Db::connect('db_game_log')->table($loginTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
     // 付费统计 - 当天注册
-    protected function payRegData()
+    protected function regPay()
     {
         $tb = "sdk_order_success";
 
         $sDate = "{$this->date} 00:00:00";
         $eDate = "{$this->date} 23:59:59";
 
-        $filed = "{$this->group}, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct user_name) as reg_pay_num";
+        $filed = "{$this->group}, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct uid) as reg_pay_num";
 
         $where = [
             ['reg_date', 'between', [$sDate, $eDate]],
@@ -104,14 +152,14 @@ class BaseTotalDayLogic
     }
 
     // 付费统计 - 总
-    protected function payTotalData(): void
+    protected function payTotal(): void
     {
         $tb = "sdk_order_success";
 
         $sDate = "{$this->date} 00:00:00";
         $eDate = "{$this->date} 23:59:59";
 
-        $filed = "{$this->group}, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct user_name) as pay_num";
+        $filed = "{$this->group}, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num";
 
         $where = [
             ['pay_date', 'between', [$sDate, $eDate]],
@@ -125,7 +173,7 @@ class BaseTotalDayLogic
     /**
      * role_create_user 创建角色用户数
      */
-    protected function roleCreateData(): void
+    protected function roleCreate(): void
     {
         $sTime = $this->date . " 00:00:00";
         $eTime = $this->date . " 23:59:59";
@@ -151,6 +199,7 @@ class BaseTotalDayLogic
 
         if($this->data){
             foreach ($this->data as &$item){
+                $item['tdate'] = $this->date;
                 $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
                 $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
             }

+ 96 - 37
app/v1/logic/tool/BaseTotalHourLogic.php

@@ -7,31 +7,61 @@ use support\think\Db;
 
 class BaseTotalHourLogic
 {
-    protected string $table = "base_total_day";
+    protected string $table = "base_total_hour";
     protected string $group = 'game_id, agent_id, site_id';
 
     protected array $data;
 
     protected string $date;
+    protected string $hour;
+
     public function run($params=[])
     {
-        $sDate = $params['sdate'] ?? date('Y-m-d');
-        $eDate = $params['edate'] ?? date('Y-m-d');
+        if(!empty($params['date'])){
+            $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
+            $eDate = is_array($params['date']) ? $params['date'][1] : $params['date'];
+            $runDate = 1;
+        }else{
+            $sDate = date('Y-m-d');
+            $eDate = date('Y-m-d');
+            $runDate = 0;
+        }
 
         for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 day'))){
             $this->date = $date;
-            $this->table = $this->table . "_" . date('Y', strtotime($this->date));
+            $this->table = $this->table . "_" . date('Ym', strtotime($this->date));
 
             try {
-                $this->initStart();
+                if($runDate){
+                    for ($hour = 0; $hour <= 23; $hour++){
+                        $this->hour = $hour;
+                        $this->initStart();
+                    }
+                }else{
+                    $this->hour = date("H", time()-480);
+                    $this->initStart();
+                }
             }catch (\Exception $e){
                 return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256);
             }
         }
 
+        $this->reRun();
+
         return json_encode(["status"=>"success", "msg"=>""], 256);
     }
 
+    // 重跑
+    protected function reRun(): void
+    {
+        if (date('H') == 8 && date('i') < 10) {
+            for ($sHour = 0; $sHour <= 23; $sHour++) {
+                $this->hour = $sHour;
+                $this->initStart();
+            }
+        }
+    }
+
     protected function initStart(): void
     {
         // 重置数据
@@ -41,13 +71,15 @@ class BaseTotalHourLogic
 
         $this->loginData();
 
-        $this->oldLoginData();
+        $this->oldLogin();
+
+        $this->regPay();
 
-        $this->payRegData();
+        $this->payTotal();
 
-        $this->payTotalData();
+        $this->roleCreate();
 
-        $this->roleCreateData();
+        $this->mediaCost();
 
         $this->siteAuth();
 
@@ -56,47 +88,60 @@ class BaseTotalHourLogic
 
     protected function regData()
     {
-        $regTotalTb = "basic_reg_total_" . date('Y', strtotime($this->date));
-        $filed = "{$this->group}, sum(reg_count) as reg_total, sum(login_count) as reg_login_total";
-        $where = ['tdate' => $this->date];
+        $sTime = strtotime("{$this->date} {$this->hour}:00:00");
+        $eTime = strtotime("{$this->date} {$this->hour}:59:59");
+
+        $regTotalTb = "sdk_reg_log_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group}, count(distinct uid) as reg_total, count(distinct imei) as reg_dev";
+        $where = [
+            ['reg_time', 'between', [$sTime, $eTime]],
+        ];
         $result = Db::connect('db_data_report')->table($regTotalTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
     protected function loginData()
     {
-        $loginGameTb = "basic_login_total_game_" . date('Y', strtotime($this->date));
-        $filed = "{$this->group},sum(login_count) as login_total";
-        $where = ['tdate' => $this->date];
-        $result = Db::connect('db_data_report')->table($loginGameTb)->field($filed)->where($where)->group($this->group)->select();
+        $sTime = strtotime("{$this->date} {$this->hour}:00:00");
+        $eTime = strtotime("{$this->date} {$this->hour}:59:59");
+
+        $loginTb = "sdk_login_log_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group},count(distinct uid) as login_total";
+        $where = [
+            ['login_time', 'between', [$sTime, $eTime]],
+        ];
+        $result = Db::connect('db_game_log')->table($loginTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
-    protected function oldLoginData()
+    protected function oldLogin()
     {
-        $loginGameTb = "basic_login_total_game_" . date('Y', strtotime($this->date));
-        $filed = "{$this->group},sum(login_count) as old_login_total";
+        $sTime = strtotime("{$this->date} {$this->hour}:00:00");
+        $eTime = strtotime("{$this->date} {$this->hour}:59:59");
+
+        $loginTb = "sdk_login_log_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group},count(distinct uid) as old_login_total";
         $where = [
-            'tdate' => $this->date,
-            ['active', '>', 0]
+            ['login_time', 'between', [$sTime, $eTime]],
+            ['reg_time', '<', strtotime($this->date)],
         ];
-        $result = Db::connect('db_data_report')->table($loginGameTb)->field($filed)->where($where)->group('agent_id,site_id,game_id')->select();
+        $result = Db::connect('db_data_report')->table($loginTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
     // 付费统计 - 当天注册
-    protected function payRegData()
+    protected function regPay()
     {
         $tb = "sdk_order_success";
 
-        $sDate = "{$this->date} 00:00:00";
-        $eDate = "{$this->date} 23:59:59";
+        $sTime = "{$this->date} {$this->hour}:00:00";
+        $eTime = "{$this->date} {$this->hour}:59:59";
 
-        $filed = "{$this->group}, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct user_name) as reg_pay_num";
+        $filed = "{$this->group}, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct uid) as reg_pay_num";
 
         $where = [
-            ['reg_date', 'between', [$sDate, $eDate]],
-            ['pay_date', 'between', [$sDate, $eDate]],
+            ['reg_date', 'between', [$sTime, $eTime]],
+            ['pay_date', 'between', [$sTime, $eTime]],
         ];
 
         $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select();
@@ -104,17 +149,17 @@ class BaseTotalHourLogic
     }
 
     // 付费统计 - 总
-    protected function payTotalData(): void
+    protected function payTotal(): void
     {
         $tb = "sdk_order_success";
 
-        $sDate = "{$this->date} 00:00:00";
-        $eDate = "{$this->date} 23:59:59";
+        $sTime = "{$this->date} {$this->hour}:00:00";
+        $eTime = "{$this->date} {$this->hour}:59:59";
 
-        $filed = "{$this->group}, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct user_name) as pay_num";
+        $filed = "{$this->group}, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num";
 
         $where = [
-            ['pay_date', 'between', [$sDate, $eDate]],
+            ['pay_date', 'between', [$sTime, $eTime]],
         ];
 
         $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select();
@@ -125,10 +170,10 @@ class BaseTotalHourLogic
     /**
      * role_create_user 创建角色用户数
      */
-    protected function roleCreateData(): void
+    protected function roleCreate(): void
     {
-        $sTime = $this->date . " 00:00:00";
-        $eTime = $this->date . " 23:59:59";
+        $sTime = "{$this->date} {$this->hour}:00:00";
+        $eTime = "{$this->date} {$this->hour}:59:59";
 
         $filed = "{$this->group}, COUNT(DISTINCT uid) as role_create_user";
         $where = [
@@ -144,6 +189,18 @@ class BaseTotalHourLogic
         $this->pushData($result);
     }
 
+    protected function mediaCost(): void
+    {
+        $filed = "{$this->group}, SUM(money) as cost";
+        $where = [
+            "tdate" => $this->date,
+            "thour" => $this->hour,
+        ];
+
+        $result = Db::connect('db_advert')->table("media_cost_hour")->field($filed)->where($where)->group($this->group)->select();
+        $this->pushData($result);
+    }
+
     protected function siteAuth(): void
     {
         $agentList = Db::connect('db_advert')->table("agent")->column("id, media_id, auth_id");
@@ -151,6 +208,8 @@ class BaseTotalHourLogic
 
         if($this->data){
             foreach ($this->data as &$item){
+                $item['tdate'] = $this->date;
+                $item['thour'] = $this->hour;
                 $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
                 $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
             }
@@ -160,7 +219,7 @@ class BaseTotalHourLogic
     protected function replaceData(): bool
     {
         // 先删除,再写入
-        Db::connect('db_data_report')->table($this->table)->where(['tdate' => $this->date])->delete();
+        Db::connect('db_data_report')->table($this->table)->where(['tdate' => $this->date, 'thour' => $this->hour])->delete();
 
         return Db::connect('db_data_report')->table($this->table)->insertAll($this->data) !== false;
     }

+ 132 - 0
app/v1/logic/tool/BasicLoginTotalLogic.php

@@ -0,0 +1,132 @@
+<?php
+
+namespace app\v1\logic\tool;
+
+
+use support\think\Db;
+
+class BasicLoginTotalLogic
+{
+    protected string $table = "basic_login_total";
+
+    protected string $group = 'game_id, agent_id, site_id, active';
+
+    protected array $data;
+
+    protected string $date;
+    public function run($params=[])
+    {
+        if(!empty($params['date'])){
+            $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
+            $eDate = is_array($params['date']) ? $params['date'][1] : $params['date'];
+        }else{
+            $sDate = date('Y-m-d');
+            $eDate = date('Y-m-d');
+        }
+
+        for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 day'))){
+            $this->date = $date;
+            $this->table = $this->table . "_" . date('Y', strtotime($this->date));
+
+            try {
+                $this->initStart();
+            }catch (\Exception $e){
+                return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256);
+            }
+        }
+
+        $this->reRun();
+
+        return json_encode(["status"=>"success", "msg"=>""], 256);
+    }
+
+    // 重跑
+    protected function reRun(): void
+    {
+        $day = date('d');
+        $hour = date('H');
+        $i = date('i');
+        $t = date('t');
+
+        // 月末,重跑整月
+        if($day==$t){
+            if($hour==1 && $i<10){
+                for ($d=1; $d<=$t; $d++){
+                    $this->date = date('Y-m-d', strtotime("-{$d} day"));
+                    $this->initStart();
+                }
+            }
+        }else{
+            // 重跑前3天
+            if($hour==8 && $i<10){
+                for ($d=1; $d<=3; $d++){
+                    $this->date = date('Y-m-d', strtotime("-{$d} day"));
+                    $this->initStart();
+                }
+            }
+        }
+    }
+
+    protected function initStart(): void
+    {
+        // 重置数据
+        $this->data = [];
+
+        $this->loginTotalByGame();
+
+        $this->siteAuth();
+
+        $this->replaceData();
+    }
+
+    protected function loginTotalByGame()
+    {
+        $table = "sdk_active_info_" . date('Ym', strtotime($this->date));
+        $filed = "{$this->group}, count(distinct uid) as login_count";
+
+        $where = [
+            'tdate' => $this->date,
+        ];
+        $result = Db::connect('db_game_log')->table($table)->field($filed)->where($where)->group($this->group)->select();
+        $this->pushData($result);
+    }
+
+    protected function siteAuth(): void
+    {
+        $agentList = Db::connect('db_advert')->table("agent")->column("id, media_id, auth_id");
+        $agentListMap = array_column($agentList, null, "id");
+
+        if($this->data){
+            foreach ($this->data as &$item){
+                $item['tdate'] = $this->date;
+                $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
+                $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
+            }
+        }
+    }
+
+    protected function replaceData(): bool
+    {
+        // 先删除,再写入
+        Db::connect('db_data_report')->table($this->table)->where(['tdate' => $this->date])->delete();
+
+        return Db::connect('db_data_report')->table($this->table)->insertAll($this->data) !== false;
+    }
+
+    protected function pushData($rows): void
+    {
+        if ($rows) {
+            foreach ($rows as $row) {
+                $groupArr = explode(',', $this->group);
+                $uniqueKey = "";
+                foreach ($groupArr as $groupKey){
+                    $uniqueKey .= $row[$groupKey] . "-";
+                }
+
+                foreach ($row as $k => $v) {
+                    $this->data[$uniqueKey][$k] = !empty($this->data[$uniqueKey][$k]) ? $this->data[$uniqueKey][$k] + $v :$v;
+                }
+            }
+        }
+    }
+}

+ 121 - 0
app/v1/logic/tool/GameActiveDayLogic.php

@@ -0,0 +1,121 @@
+<?php
+
+namespace app\v1\logic\tool;
+
+
+use support\think\Db;
+
+class GameActiveDayLogic
+{
+    protected string $table = "base_total_day";
+    protected string $group = 'game_id, agent_id, site_id';
+
+    protected array $data;
+
+    protected string $date;
+    public function run($params=[])
+    {
+        if(!empty($params['date'])){
+            $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
+            $eDate = is_array($params['date']) ? $params['date'][1] : $params['date'];
+        }else{
+            $sDate = date('Y-m-d');
+            $eDate = date('Y-m-d');
+        }
+
+        for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 day'))){
+            $this->date = $date;
+            $this->table = $this->table . "_" . date('Y', strtotime($this->date));
+
+            try {
+                $this->initStart();
+            }catch (\Exception $e){
+                return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256);
+            }
+        }
+
+        $this->reRun();
+
+        return json_encode(["status"=>"success", "msg"=>""], 256);
+    }
+
+    // 重跑
+    protected function reRun(): void
+    {
+        $hour = date('H');
+        $i = date('i');
+
+        // 重跑前3天
+        if($hour==4 && $i<40){
+            for ($d=1; $d<=3; $d++){
+                $this->date = date('Y-m-d', strtotime("-{$d} day"));
+                $this->initStart();
+            }
+        }
+    }
+
+    protected function initStart(): void
+    {
+        // 重置数据
+        $this->data = [];
+
+        $this->activeTotalData();
+
+        $this->siteAuth();
+
+        $this->replaceData();
+    }
+
+    protected function activeTotalData()
+    {
+        $tb = "basic_login_total_game_" . date('Y', strtotime($this->date));
+        $filed = "{$this->group}, active as days, sum(login_count) as active_total";
+
+        $where = [
+            "tdate" => $this->date,
+        ];
+        $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group("$this->group, days")->select();
+        $this->pushData($result);
+    }
+
+    protected function siteAuth(): void
+    {
+        $agentList = Db::connect('db_advert')->table("agent")->column("id, media_id, auth_id");
+        $agentListMap = array_column($agentList, null, "id");
+
+        if($this->data){
+            foreach ($this->data as &$item){
+                $item['tdate'] = $this->date;
+                $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
+                $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
+            }
+        }
+    }
+
+    protected function replaceData(): bool
+    {
+        // 先删除,再写入
+        Db::connect('db_data_report')->table($this->table)->where(['tdate' => $this->date])->delete();
+
+        return Db::connect('db_data_report')->table($this->table)->insertAll($this->data) !== false;
+    }
+
+    protected function pushData($rows): void
+    {
+        if ($rows) {
+            foreach ($rows as $row) {
+                $this->group = $this->group . ", days";
+
+                $groupArr = explode(',', $this->group);
+                $uniqueKey = "";
+                foreach ($groupArr as $groupKey){
+                    $uniqueKey .= $row[$groupKey] . "-";
+                }
+
+                foreach ($row as $k => $v) {
+                    $this->data[$uniqueKey][$k] = !empty($this->data[$uniqueKey][$k]) ? $this->data[$uniqueKey][$k] + $v :$v;
+                }
+            }
+        }
+    }
+}

+ 146 - 0
app/v1/logic/tool/GameRegPayMonthLogic.php

@@ -0,0 +1,146 @@
+<?php
+
+namespace app\v1\logic\tool;
+
+
+use support\think\Db;
+
+class GameRegPayMonthLogic
+{
+    protected string $table = "game_reg_pay_month";
+
+    protected string $group = 'game_id, agent_id, site_id';
+
+    protected array $data;
+
+    protected string $month;
+    public function run($params=[])
+    {
+        if(!empty($params['date'])){
+            $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
+            $eDate = is_array($params['date']) ? $params['date'][1] : $params['date'];
+        }else{
+            $sDate = date('Y-m');
+            $eDate = date('Y-m');
+        }
+
+        for ($date = $sDate; $date <= $eDate; $date = date('Y-m', strtotime($date . '+1 month'))){
+            $this->month = $date;
+
+            try {
+                $this->initStart();
+            }catch (\Exception $e){
+                return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256);
+            }
+        }
+
+        $this->reRun();
+
+        return json_encode(["status"=>"success", "msg"=>""], 256);
+    }
+
+    // 重跑
+    protected function reRun(): void
+    {
+        $day = date('d');
+        $hour = date('H');
+        $i = date('i');
+
+        // 重跑上个整月
+        if(($day==1 || $day==15) && $hour==4 && $i<10){
+            $this->month = date('Y-m', strtotime("-1 month"));
+            $this->initStart();
+        }
+    }
+
+    protected function initStart(): void
+    {
+        // 重置数据
+        $this->data = [];
+
+        $this->regPay();
+
+        $this->siteAuth();
+
+        $this->replaceData();
+    }
+
+    protected function regPay(): void
+    {
+        $tb = "sdk_order_success";
+
+        $sDate = "{$this->month}-01 00:00:00";
+        $eDate = date('Y-m-t 23:59:59', strtotime($this->month));
+
+        $filed = "{$this->group}, DATE_FORMAT(reg_date,'%Y-%m') as reg_month, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num";
+
+        $where = [
+            ['pay_date', 'between', [$sDate, $eDate]],
+        ];
+
+        $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group("{$this->group}, DATE_FORMAT(reg_date,'%Y-%m')")->select()->toArray();
+        $this->pushData($result);
+
+        $regMonthList = array_column($result, 'reg_month');
+        foreach ($regMonthList as $regMonth){
+            $res = $this->addupTotalMonth($regMonth);
+            if($res) $this->pushData($res);
+        }
+    }
+
+    protected function addupTotalMonth($regMonth)
+    {
+        $tb = "sdk_order_success";
+
+        $filed = "{$this->group},$regMonth as reg_month, sum(money) as addup_pay_total, sum(paid_amount) as addup_pay_amount, count(distinct uid) as addup_pay_num";
+
+        $srData = $regMonth."-01 00:00:00";
+        $erDate = date('Y-m-t 23:59:59', strtotime($srData));
+        $epDate = date('Y-m-t 23:59:59', strtotime($this->month));
+        $where = array(
+            'reg_date' => ['between', [$srData, $erDate]],
+            'pay_date' => ['between', [$srData, $epDate]],
+        );
+
+        return Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group_by($this->group.", reg_month")->select();
+    }
+
+    protected function siteAuth(): void
+    {
+        $agentList = Db::connect('db_advert')->table("agent")->column("id, media_id, auth_id");
+        $agentListMap = array_column($agentList, null, "id");
+
+        if($this->data){
+            foreach ($this->data as &$item){
+                $item['tdate'] = $this->month;
+                $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
+                $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
+            }
+        }
+    }
+
+    protected function replaceData(): bool
+    {
+        // 先删除,再写入
+        Db::connect('db_data_report')->table($this->table)->where(['reg_month' => $this->month, 'pay_month'=>$this->month])->delete();
+
+        return Db::connect('db_data_report')->table($this->table)->insertAll($this->data) !== false;
+    }
+
+    protected function pushData($rows): void
+    {
+        if ($rows) {
+            foreach ($rows as $row) {
+                $groupArr = explode(',', $this->group);
+                $uniqueKey = "";
+                foreach ($groupArr as $groupKey){
+                    $uniqueKey .= $row[$groupKey] . "-";
+                }
+
+                foreach ($row as $k => $v) {
+                    $this->data[$uniqueKey][$k] = !empty($this->data[$uniqueKey][$k]) ? $this->data[$uniqueKey][$k] + $v :$v;
+                }
+            }
+        }
+    }
+}

+ 209 - 0
app/v1/logic/tool/GameTotalMonthLogic.php

@@ -0,0 +1,209 @@
+<?php
+
+namespace app\v1\logic\tool;
+
+
+use support\think\Db;
+
+class GameTotalMonthLogic
+{
+    protected string $table = "game_total_month";
+
+    protected string $group = 'game_id, agent_id, site_id';
+
+    protected array $data;
+
+    protected string $month;
+    public function run($params=[])
+    {
+        if(!empty($params['date'])){
+            $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
+            $eDate = is_array($params['date']) ? $params['date'][1] : $params['date'];
+        }else{
+            $sDate = date('Y-m');
+            $eDate = date('Y-m');
+        }
+
+        for ($date = $sDate; $date <= $eDate; $date = date('Y-m', strtotime($date . '+1 month'))){
+            $this->month = $date;
+
+            try {
+                $this->initStart();
+            }catch (\Exception $e){
+                return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256);
+            }
+        }
+
+        $this->reRun();
+
+        return json_encode(["status"=>"success", "msg"=>""], 256);
+    }
+
+    // 重跑
+    protected function reRun(): void
+    {
+        $day = date('d');
+        $hour = date('H');
+        $i = date('i');
+
+        // 重跑上个整月
+        if(($day==1 || $day==15) && $hour==4 && $i<10){
+            $this->month = date('Y-m', strtotime("-1 month"));
+            $this->initStart();
+        }
+    }
+
+    protected function initStart(): void
+    {
+        // 重置数据
+        $this->data = [];
+
+        $this->regMonth();
+        $this->loginMonth();
+        $this->regPay();
+        $this->payTotal();
+        $this->roleCreate();
+        $this->mediaCost();
+
+        $this->siteAuth();
+
+        $this->replaceData();
+    }
+
+    protected function regMonth()
+    {
+        $sTime = strtotime("{$this->month}-01 00:00:00");
+        $eTime = strtotime(date('Y-m-t 23:59:59', strtotime($sTime)));
+
+        $regTotalTb = "sdk_reg_log_" . date('Ym', strtotime($this->month));
+        $filed = "{$this->group}, count(distinct uid) as reg_total, count(distinct imei) as reg_dev";
+
+        $where = [
+            ['reg_time', 'between', [$sTime, $eTime]],
+        ];
+        $result = Db::connect('db_game_log')->table($regTotalTb)->field($filed)->where($where)->group($this->group)->select();
+
+        $this->pushData($result);
+    }
+
+
+    protected function loginMonth()
+    {
+        $tb = "sdk_active_info_" . date('Ym', strtotime($this->month)); // 按天去重
+        $filed = "{$this->group}, count(distinct uid) as login_total";
+
+        $result = Db::connect('db_game_log')->table($tb)->field($filed)->group($this->group)->select();
+
+        $this->pushData($result);
+    }
+
+    protected function regPay()
+    {
+        $tb = "sdk_order_success";
+
+        $sDate = "{$this->month}-01 00:00:00";
+        $eDate = date('Y-m-t 23:59:59', strtotime($this->month));
+
+        $filed = "{$this->group}, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct uid) as reg_pay_num";
+
+        $where = [
+            'reg_date' => ['between', [$sDate, $eDate]],
+            'pay_date' => ['between', [$sDate, $eDate]],
+        ];
+
+        $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
+
+        $this->pushData($result);
+    }
+
+    protected function payTotal()
+    {
+        $tb = "sdk_order_success";
+
+        $sDate = "{$this->month}-01 00:00:00";
+        $eDate = date('Y-m-t 23:59:59', strtotime($this->month));
+
+        $filed = "{$this->group}, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num";
+
+        $where = [
+            'pay_date' => ['between', [$sDate, $eDate]],
+        ];
+
+        $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
+
+        $this->pushData($result);
+    }
+
+    protected function roleCreate(): void
+    {
+        $sDate = "{$this->month}-01 00:00:00";
+        $eDate = date('Y-m-t 23:59:59', strtotime($this->month));
+
+        $filed = "{$this->group}, COUNT(DISTINCT uid) as role_create_user";
+        $where = [
+            ['create_time', 'between', [$sDate, $eDate]],
+        ];
+
+        // 安卓
+        $result = Db::connect('db_game_log')->table("role_data_and")->field($filed)->where($where)->group($this->group)->select();
+        $this->pushData($result);
+
+        // iOS
+        $result = Db::connect('db_game_log')->table("role_data_ios")->field($filed)->where($where)->group($this->group)->select();
+        $this->pushData($result);
+    }
+
+    protected function mediaCost(): void
+    {
+        $sDate = "{$this->month}-01";
+        $eDate = date('Y-m-t', strtotime($this->month));
+
+        $filed = "{$this->group}, SUM(money) as cost";
+        $where = [
+            'tdate' => ['between', [$sDate, $eDate]],
+        ];
+
+        $result = Db::connect('db_advert')->table("media_cost")->field($filed)->where($where)->group($this->group)->select();
+
+        $this->pushData($result);
+    }
+
+    protected function siteAuth(): void
+    {
+        $agentList = Db::connect('db_advert')->table("agent")->column("id, media_id, auth_id");
+        $agentListMap = array_column($agentList, null, "id");
+
+        if($this->data){
+            foreach ($this->data as &$item){
+                $item['tdate'] = $this->month;
+                $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
+                $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
+            }
+        }
+    }
+
+    protected function replaceData(): bool
+    {
+        // 先删除,再写入
+        Db::connect('db_data_report')->table($this->table)->where(['tmonth' => $this->month])->delete();
+
+        return Db::connect('db_data_report')->table($this->table)->insertAll($this->data) !== false;
+    }
+
+    protected function pushData($rows): void
+    {
+        if ($rows) {
+            foreach ($rows as $row) {
+                $groupArr = explode(',', $this->group);
+                $uniqueKey = "";
+                foreach ($groupArr as $groupKey){
+                    $uniqueKey .= $row[$groupKey] . "-";
+                }
+
+                foreach ($row as $k => $v) {
+                    $this->data[$uniqueKey][$k] = !empty($this->data[$uniqueKey][$k]) ? $this->data[$uniqueKey][$k] + $v :$v;
+                }
+            }
+        }
+    }
+}

+ 1 - 1
config/plugin/webman/push/app.php

@@ -1,6 +1,6 @@
 <?php
 return [
-    'enable'       => true,
+    'enable'       => false,
     'websocket'    => 'websocket://0.0.0.0:3131',
     'api'          => 'http://0.0.0.0:3232',
     'app_key'      => '8f5695dcc12c3270cecb11e028ac1a35',

+ 18 - 2
config/process.php

@@ -12,9 +12,9 @@
  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
+use app\process\Http;
 use support\Log;
 use support\Request;
-use app\process\Http;
 
 global $argv;
 
@@ -60,6 +60,22 @@ return [
         ]
     ],
     'create_tables' => [
-        'handler' => app\process\CreateTables::class,
+        'handler' => \app\process\dataReport\CreateTables::class,
+    ],
+    'game_active' => [
+        'handler' => \app\process\dataReport\GameActive::class,
+    ],
+    'base_total' => [
+        'handler' => \app\process\dataReport\BaseTotal::class,
     ],
+    'basic_login_total' => [
+        'handler' => \app\process\dataReport\BasicLoginTotal::class,
+    ],
+    'game_reg_pay_month' => [
+        'handler' => \app\process\dataReport\GameRegPayMonth::class,
+    ],
+    'game_total_month' =>  [
+        'handler' => \app\process\dataReport\GameTotalMonth::class,
+    ]
+
 ];

+ 37 - 37
plugin/saiadmin/app/logic/tool/CrontabLogic.php

@@ -122,43 +122,43 @@ class CrontabLogic extends BaseLogic
         $data['target'] = $info->target;
         $data['parameter'] = $info->parameter;
         switch ($info->type) {
-            case 1:
-                // URL任务GET
-                $httpClient = new Client([
-                    'timeout' => 5,
-                    'verify' => false,
-                ]);
-                try {
-                    $httpClient->request('GET', $info->target);
-                    $data['status'] = 1;
-                    CrontabLog::create($data);
-                    return true;
-                } catch (GuzzleException $e) {
-                    $data['status'] = 2;
-                    $data['exception_info'] = $e->getMessage();
-                    CrontabLog::create($data);
-                    return false;
-                }
-            case 2:
-                // URL任务POST
-                $httpClient = new Client([
-                    'timeout' => 5,
-                    'verify' => false,
-                ]);
-                try {
-                    $res = $httpClient->request('POST', $info->target, [
-                        'form_params' => json_decode($info->parameter ?? '',true)
-                    ]);
-                    $data['status'] = 1;
-                    $data['exception_info'] = $res->getBody();
-                    CrontabLog::create($data);
-                    return true;
-                } catch (GuzzleException $e) {
-                    $data['status'] = 2;
-                    $data['exception_info'] = $e->getMessage();
-                    CrontabLog::create($data);
-                    return false;
-                }
+//            case 1:
+//                // URL任务GET
+//                $httpClient = new Client([
+//                    'timeout' => 5,
+//                    'verify' => false,
+//                ]);
+//                try {
+//                    $httpClient->request('GET', $info->target);
+//                    $data['status'] = 1;
+//                    CrontabLog::create($data);
+//                    return true;
+//                } catch (GuzzleException $e) {
+//                    $data['status'] = 2;
+//                    $data['exception_info'] = $e->getMessage();
+//                    CrontabLog::create($data);
+//                    return false;
+//                }
+//            case 2:
+//                // URL任务POST
+//                $httpClient = new Client([
+//                    'timeout' => 5,
+//                    'verify' => false,
+//                ]);
+//                try {
+//                    $res = $httpClient->request('POST', $info->target, [
+//                        'form_params' => json_decode($info->parameter ?? '',true)
+//                    ]);
+//                    $data['status'] = 1;
+//                    $data['exception_info'] = $res->getBody();
+//                    CrontabLog::create($data);
+//                    return true;
+//                } catch (GuzzleException $e) {
+//                    $data['status'] = 2;
+//                    $data['exception_info'] = $e->getMessage();
+//                    CrontabLog::create($data);
+//                    return false;
+//                }
             case 3:
                 // 类任务
                 $class_name = $info->target;

+ 4 - 3
plugin/saiadmin/config/process.php

@@ -1,6 +1,7 @@
 <?php
 return [
-    'task'  => [
-        'handler'  => plugin\saiadmin\process\Task::class
-    ],
+    # 因为是顺序执行同时间执行会等待,同时考虑安全性,关闭该自动脚本执行
+//    'task'  => [
+//        'handler'  => plugin\saiadmin\process\Task::class
+//    ],
 ];