Pārlūkot izejas kodu

Merge commit '14831ade4f579378fa3a3a91c03b5f6aaefacf09' into dev

ith5 5 mēneši atpakaļ
vecāks
revīzija
dd1445801e

+ 44 - 36
app/process/CreateTables.php

@@ -12,7 +12,7 @@ class CreateTables
     public function onWorkerStart(): void
     {
         // 每天的0点10执行,注意这里省略了秒位
-        new Crontab('18 * * * *', function(){
+        new Crontab('5 * * * *', function(){
             $this->initStart();
         });
     }
@@ -24,8 +24,8 @@ class CreateTables
         $centerTablesSqlList = [
             $this->base_total_day,
             $this->base_total_hour,
-            $this->basic_login_total,
-            $this->game_active_day,
+            $this->basic_active_day,
+            $this->game_reg_pay_day
         ];
 
         foreach ($centerTablesSqlList as $sql){
@@ -156,26 +156,51 @@ 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 = "CREATE TABLE IF NOT EXISTS `basic_login_total_{{YEAR}}` (
+
+    protected string $game_reg_pay_day = "CREATE TABLE IF NOT EXISTS `game_reg_pay_day_{{YEAR}}` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `reg_date` varchar(10) NOT NULL COMMENT '注册月份',
+  `pay_date` varchar(10) NOT NULL COMMENT '充值月份',
+  `game_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏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',
+  `pay_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '充值人数',
+  `pay_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '充值金额',
+  `pay_amount` float unsigned NOT NULL DEFAULT '0' COMMENT '付费金额(分成)',
+  `addup_pay_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册累计付费',
+  `addup_pay_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册累计付费金额',
+  `addup_pay_amount` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册总充值(扣除分成)',
+  PRIMARY KEY (`id`) USING BTREE,
+  UNIQUE KEY `select_index` (`reg_date`,`pay_date`,`agent_id`,`site_id`,`game_id`) USING BTREE,
+  KEY `reg_date` (`reg_date`) USING BTREE,
+  KEY `pay_date` (`pay_date`) 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 $basic_active_day = "CREATE TABLE IF NOT EXISTS `basic_active_day_{{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 '账号数',
+  `tdate` date NOT NULL COMMENT '登录日期',
+  `game_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '游戏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',
+  `reg_date` date NOT NULL COMMENT '日期',
   `active` int(10) unsigned NOT NULL COMMENT '活跃天数(0:当天)',
-  `plat_id` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '平台ID',
+  `login_count` int(11) NOT NULL COMMENT '登录账号数',
   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;";
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='用户活跃统计';";
 
     protected string $sdk_active_info = "CREATE TABLE IF NOT EXISTS `sdk_active_log_{{MONTH}}` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
@@ -201,26 +226,6 @@ class CreateTables
   KEY `active` (`active`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户活跃表';";
 
-    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',
-  `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',
-  `reg_date` date NOT NULL COMMENT '日期',
-  `days` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '活跃天数(0当天登陆)',
-  `active_total` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '活跃数',
-  PRIMARY KEY (`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 `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 $sdk_activate_log = "CREATE TABLE IF NOT EXISTS `sdk_activate_log_{{MONTH}}` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
@@ -335,7 +340,7 @@ class CreateTables
   `trade_id` varchar(60) DEFAULT '' COMMENT '交易流水号',
   `cp_order_id` varchar(60) NOT NULL COMMENT '研发订单号',
   `ext` varchar(200) DEFAULT NULL COMMENT 'CP扩展参数',
-  `pay_channel_id` smallint(6) NOT NULL COMMENT '支付渠道ID',
+  `pay_channel_id` smallint(6) DEFAULT '0' COMMENT '支付渠道ID',
   `money` float NOT NULL COMMENT '面额(元)',
   `paid_amount` float unsigned NOT NULL COMMENT '净额(元)',
   `game_id` int(11) NOT NULL DEFAULT '0',
@@ -350,6 +355,7 @@ class CreateTables
   `server_name` varchar(20) DEFAULT '',
   `role_id` varchar(32) DEFAULT '',
   `role_name` varchar(32) DEFAULT '',
+  `reg_date`  datetime DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间',
   `pay_date`  datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
   `sync_date` datetime DEFAULT NULL COMMENT '支付通知时间',
   `sync_data` text COMMENT '支付回调信息',
@@ -366,6 +372,8 @@ class CreateTables
   `product_id` varchar(64) DEFAULT NULL COMMENT '充值商品ID',
   `product_name` varchar(64) DEFAULT NULL COMMENT '充值商品名',
   `package_name` varchar(64) DEFAULT NULL COMMENT '包名',
+  `reg_time` int(10) unsigned NOT NULL COMMENT '注册时间',
+  `login_time` int(10) unsigned NOT NULL COMMENT '登录时间',
   PRIMARY KEY (`id`),
   UNIQUE KEY `order_id` (`order_id`),
   KEY `uid` (`uid`),

+ 6 - 6
app/process/dataReport/BasicLoginTotal.php → app/process/dataReport/BasicActiveDay.php

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

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

@@ -1,31 +0,0 @@
-<?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 "无执行内容";
-    }
-}

+ 41 - 0
app/process/dataReport/GameRegPay.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace app\process\dataReport;
+use app\v1\logic\tool\GameRegPayDayLogic;
+use app\v1\logic\tool\GameRegPayMonthLogic;
+use Workerman\Crontab\Crontab;
+
+/**
+ * 注册付费按月
+ */
+class GameRegPay
+{
+    public function onWorkerStart(): void
+    {
+        // 每2小时执行一次
+        new Crontab('0 */2 * * *', function() {
+            (new GameRegPayMonthLogic())->run();
+        });
+
+        // 每5分钟执行一次
+        new Crontab('0 */5 * * * *', function() {
+            (new GameRegPayDayLogic())->run();
+        });
+    }
+
+    // {"date":["2025-06-25","2025-06-26"]}
+    public function run($args)
+    {
+        $params = $args ? json_decode($args, true) : [];
+
+        if(!empty($params["type"]) && $params["type"] == "month"){
+            return (new GameRegPayMonthLogic())->run($params);
+        }
+
+        if(!empty($params["type"]) && $params["type"] == "day"){
+            return (new GameRegPayDayLogic())->run($params);
+        }
+
+        return "无执行内容";
+    }
+}

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

@@ -1,27 +0,0 @@
-<?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);
-    }
-}

+ 4 - 4
app/process/dataReport/GameTotalMonth.php → app/process/dataReport/GameTotal.php

@@ -5,9 +5,9 @@ use app\v1\logic\tool\GameTotalMonthLogic;
 use Workerman\Crontab\Crontab;
 
 /**
- * 注册付费按月
+ * 统计总表
  */
-class GameTotalMonth
+class GameTotal
 {
     public function onWorkerStart(): void
     {
@@ -20,8 +20,8 @@ class GameTotalMonth
     // {"date":["2025-06-25","2025-06-26"]}
     public function run($args)
     {
-        $params = $args ? json_decode($args, true) : [];
+         $params = $args ? json_decode($args, true) : [];
 
-        return (new GameTotalMonthLogic())->run($params);
+         return (new GameTotalMonthLogic())->run($params);
     }
 }

+ 81 - 0
app/v1/logic/tool/BaseLogic.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace app\v1\logic\tool;
+
+
+use support\think\Db;
+
+class BaseLogic
+{
+
+    protected function replaceData($where): bool
+    {
+        // 设置归属人
+        $this->siteAuth();
+
+        // 先删除,再写入
+        Db::connect('db_data_report')->table($this->table)->where($where)->delete();
+
+        // 保持每个子数组键一致,无值则填充0
+        $insertData = $this->normalizeArrayKeys($this->data);
+
+        return Db::connect('db_data_report')->table($this->table)->insertAll($insertData) !== false;
+    }
+
+    protected function pushData($rows): void
+    {
+        if ($rows) {
+            foreach ($rows as $row) {
+                $groupArr = explode(',', str_replace(' ', '', $this->group));
+                $uniqueKey = [];
+                foreach ($groupArr as $groupKey){
+                    $groupKey = trim($groupKey);
+                    $kk = $row[$groupKey] ?? "";
+                    $uniqueKey[] = $kk;
+                }
+                $uniqueKey = implode("_", $uniqueKey);
+                foreach ($row as $k => $v) {
+                    if(in_array($k, $groupArr)){
+                        $this->data[$uniqueKey][$k] = $v;
+                    }else{
+                        $this->data[$uniqueKey][$k] = !empty($this->data[$uniqueKey][$k]) ? $this->data[$uniqueKey][$k] + $v :$v;
+                    }
+                }
+            }
+        }
+    }
+
+    protected function siteAuth(): void
+    {
+        $agentList = Db::connect('db_advert')->table("agent_list")->column("id, media_id, auth_id");
+        $agentListMap = array_column($agentList, null, "id");
+
+        if($this->data){
+            foreach ($this->data as &$item){
+                $item['auth_id'] = $agentListMap[$item['agent_id']]['auth_id'] ?? 0;    // 负责人
+                $item['media_id'] = $agentListMap[$item['agent_id']]['media_id'] ?? 0;  // 媒体
+            }
+        }
+    }
+
+    protected function normalizeArrayKeys(array $data): array {
+        // 收集所有可能的键
+        $allKeys = [];
+        foreach ($data as $item) {
+            $allKeys = array_merge($allKeys, array_keys($item));
+        }
+        $allKeys = array_unique($allKeys);
+
+        // 标准化每个子数组
+        $result = [];
+        foreach ($data as $item) {
+            $normalizedItem = [];
+            foreach ($allKeys as $key) {
+                $normalizedItem[$key] = $item[$key] ?? 0;
+            }
+            $result[] = $normalizedItem;
+        }
+
+        return $result;
+    }
+}

+ 11 - 50
app/v1/logic/tool/BaseTotalDayLogic.php

@@ -5,10 +5,11 @@ namespace app\v1\logic\tool;
 
 use support\think\Db;
 
-class BaseTotalDayLogic
+class BaseTotalDayLogic extends BaseLogic
 {
     protected string $table = "base_total_day";
-    protected string $group = 'game_id, agent_id, site_id';
+
+    protected string $group = 'game_id, agent_id, site_id, tdate';
 
     protected array $data;
 
@@ -83,9 +84,7 @@ class BaseTotalDayLogic
 
         $this->roleCreate();
 
-        $this->siteAuth();
-
-        $this->replaceData();
+        $this->replaceData(['tdate'=>$this->date]);
     }
 
     protected function regData()
@@ -94,7 +93,7 @@ class BaseTotalDayLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, count(distinct uid) as reg_total, count(distinct imei) as reg_dev";
 
         $where = [
             ['reg_time', 'between', [$sTime, $eTime]],
@@ -109,7 +108,7 @@ class BaseTotalDayLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate,count(distinct uid) as login_total";
         $where = [
             ['login_time', 'between', [$sTime, $eTime]],
         ];
@@ -123,7 +122,7 @@ class BaseTotalDayLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate,count(distinct uid) as old_login_total";
         $where = [
             ['login_time', 'between', [$sTime, $eTime]],
             ['reg_time', '<', strtotime($this->date)],
@@ -140,7 +139,7 @@ class BaseTotalDayLogic
         $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 uid) as reg_pay_num";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, 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]],
@@ -148,6 +147,7 @@ class BaseTotalDayLogic
         ];
 
         $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select();
+
         $this->pushData($result);
     }
 
@@ -159,7 +159,7 @@ class BaseTotalDayLogic
         $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 uid) as pay_num";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num";
 
         $where = [
             ['pay_date', 'between', [$sDate, $eDate]],
@@ -178,7 +178,7 @@ class BaseTotalDayLogic
         $sTime = $this->date . " 00:00:00";
         $eTime = $this->date . " 23:59:59";
 
-        $filed = "{$this->group}, COUNT(DISTINCT uid) as role_create_user";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, COUNT(DISTINCT uid) as role_create_user";
         $where = [
             ['create_time', 'between', [$sTime, $eTime]],
         ];
@@ -191,43 +191,4 @@ class BaseTotalDayLogic
         $result = Db::connect('db_game_log')->table("role_data_ios")->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;
-                }
-            }
-        }
-    }
 }

+ 13 - 54
app/v1/logic/tool/BaseTotalHourLogic.php

@@ -5,10 +5,11 @@ namespace app\v1\logic\tool;
 
 use support\think\Db;
 
-class BaseTotalHourLogic
+class BaseTotalHourLogic extends BaseLogic
 {
     protected string $table = "base_total_hour";
-    protected string $group = 'game_id, agent_id, site_id';
+    
+    protected string $group = 'game_id, agent_id, site_id, tdate, thour';
 
     protected array $data;
 
@@ -81,9 +82,7 @@ class BaseTotalHourLogic
 
         $this->mediaCost();
 
-        $this->siteAuth();
-
-        $this->replaceData();
+        $this->replaceData(['tdate'=>$this->date, 'thour'=>$this->hour]);
     }
 
     protected function regData()
@@ -92,11 +91,11 @@ class BaseTotalHourLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, 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();
+        $result = Db::connect('db_game_log')->table($regTotalTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
@@ -106,7 +105,7 @@ class BaseTotalHourLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour,count(distinct uid) as login_total";
         $where = [
             ['login_time', 'between', [$sTime, $eTime]],
         ];
@@ -120,12 +119,12 @@ class BaseTotalHourLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour,count(distinct uid) as old_login_total";
         $where = [
             ['login_time', 'between', [$sTime, $eTime]],
             ['reg_time', '<', strtotime($this->date)],
         ];
-        $result = Db::connect('db_data_report')->table($loginTb)->field($filed)->where($where)->group($this->group)->select();
+        $result = Db::connect('db_game_log')->table($loginTb)->field($filed)->where($where)->group($this->group)->select();
         $this->pushData($result);
     }
 
@@ -137,7 +136,7 @@ class BaseTotalHourLogic
         $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 uid) as reg_pay_num";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct uid) as reg_pay_num";
 
         $where = [
             ['reg_date', 'between', [$sTime, $eTime]],
@@ -156,7 +155,7 @@ class BaseTotalHourLogic
         $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 uid) as pay_num";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num";
 
         $where = [
             ['pay_date', 'between', [$sTime, $eTime]],
@@ -175,7 +174,7 @@ class BaseTotalHourLogic
         $sTime = "{$this->date} {$this->hour}:00:00";
         $eTime = "{$this->date} {$this->hour}:59:59";
 
-        $filed = "{$this->group}, COUNT(DISTINCT uid) as role_create_user";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, COUNT(DISTINCT uid) as role_create_user";
         $where = [
             ['create_time', 'between', [$sTime, $eTime]],
         ];
@@ -191,7 +190,7 @@ class BaseTotalHourLogic
 
     protected function mediaCost(): void
     {
-        $filed = "{$this->group}, SUM(money) as cost";
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, SUM(money) as cost";
         $where = [
             "tdate" => $this->date,
             "thour" => $this->hour,
@@ -200,44 +199,4 @@ class BaseTotalHourLogic
         $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");
-        $agentListMap = array_column($agentList, null, "id");
-
-        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;  // 媒体
-            }
-        }
-    }
-
-    protected function replaceData(): bool
-    {
-        // 先删除,再写入
-        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;
-    }
-
-    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;
-                }
-            }
-        }
-    }
 }

+ 9 - 45
app/v1/logic/tool/BasicLoginTotalLogic.php → app/v1/logic/tool/BasicActiveDayLogic.php

@@ -5,11 +5,11 @@ namespace app\v1\logic\tool;
 
 use support\think\Db;
 
-class BasicLoginTotalLogic
+class BasicActiveDayLogic extends BaseLogic
 {
-    protected string $table = "basic_login_total";
+    protected string $table = "basic_active_day";
 
-    protected string $group = 'game_id, agent_id, site_id, active';
+    protected string $group = 'game_id, agent_id, site_id, tdate, active';
 
     protected array $data;
 
@@ -74,59 +74,23 @@ class BasicLoginTotalLogic
 
         $this->loginTotalByGame();
 
-        $this->siteAuth();
-
-        $this->replaceData();
+        $this->replaceData(['tdate'=>$this->date]);
     }
 
     protected function loginTotalByGame()
     {
         $table = "sdk_active_log_" . date('Ym', strtotime($this->date));
-        $filed = "{$this->group}, count(distinct uid) as login_count";
+        $filed = "game_id, agent_id, site_id, {$this->date} as tdate, active, 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);
-    }
+        $result = Db::connect('db_game_log')->table($table)->field($filed)->where($where)->group($this->group)->select()->toArray();
 
-    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;  // 媒体
-            }
+        if($result) foreach ($result as &$vv){
+            $vv['reg_date'] = date('Y-m-d', strtotime("{$this->date} -{$vv['days']}days"));
         }
-    }
-
-    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;
-                }
-            }
-        }
+        $this->pushData($result);
     }
 }

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

@@ -1,121 +0,0 @@
-<?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;
-                }
-            }
-        }
-    }
-}

+ 114 - 0
app/v1/logic/tool/GameRegPayDayLogic.php

@@ -0,0 +1,114 @@
+<?php
+
+namespace app\v1\logic\tool;
+
+
+use support\think\Db;
+
+class GameRegPayDayLogic extends BaseLogic
+{
+    protected string $table = "game_reg_pay_day";
+
+    protected string $group = 'game_id, agent_id, site_id, reg_date, pay_date';
+
+    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 days'))){
+            $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');
+
+        // 重跑上个
+        if(($day==1 || $day==15) && $hour==4 && $i<10){
+            $this->date = date('Y-m-d', strtotime("-1 days"));
+            $this->initStart();
+        }
+    }
+
+    protected function initStart(): void
+    {
+        // 重置数据
+        $this->data = [];
+
+        $this->regPay();
+
+        $this->replaceData(['reg_date'=>$this->date]);
+    }
+
+    protected function regPay(): void
+    {
+        $tb = "sdk_order_success";
+
+        $sDate = "{$this->date} 00:00:00";
+        $eDate = date('Y-m-t 23:59:59', strtotime($this->date));
+
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as pay_date, DATE_FORMAT(reg_date,'%Y-%m-%d') as reg_date, 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();
+
+        if($result){
+            $this->pushData($result);
+
+            $regDateList = array_unique(array_column($result, 'reg_date'));
+
+            foreach ($regDateList as $regDate){
+                $res = $this->addupTotalDay($regDate);
+                if($res){
+                    $this->pushData($res);
+                }
+            }
+        }
+
+    }
+
+    protected function addupTotalDay($regDate)
+    {
+        $tb = "sdk_order_success";
+
+        $filed = "game_id, agent_id, site_id, '{$this->date}' as pay_date,'{$regDate}' as reg_date, sum(money) as addup_pay_total, sum(paid_amount) as addup_pay_amount, count(distinct uid) as addup_pay_num";
+
+        $srData = $regDate." 00:00:00";
+        $erDate = date('Y-m-t 23:59:59', strtotime($srData));
+        $epDate = date('Y-m-t 23:59:59', strtotime($this->date));
+        $where = [
+            ['reg_date', 'between', [$srData, $erDate]],
+            ['pay_date', 'between', [$srData, $epDate]],
+        ];
+
+        return Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
+    }
+}

+ 24 - 57
app/v1/logic/tool/GameRegPayMonthLogic.php

@@ -5,15 +5,16 @@ namespace app\v1\logic\tool;
 
 use support\think\Db;
 
-class GameRegPayMonthLogic
+class GameRegPayMonthLogic extends BaseLogic
 {
     protected string $table = "game_reg_pay_month";
 
-    protected string $group = 'game_id, agent_id, site_id';
+    protected string $group = 'game_id, agent_id, site_id, reg_month, pay_month';
 
     protected array $data;
 
     protected string $month;
+
     public function run($params=[])
     {
         if(!empty($params['date'])){
@@ -60,9 +61,7 @@ class GameRegPayMonthLogic
 
         $this->regPay();
 
-        $this->siteAuth();
-
-        $this->replaceData();
+        $this->replaceData(['reg_month'=>$this->month]);
     }
 
     protected function regPay(): void
@@ -72,75 +71,43 @@ class GameRegPayMonthLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as pay_month, 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);
+        $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
+
+        if($result){
+            $this->pushData($result);
+
+            $regMonthList = array_unique(array_column($result, 'reg_month'));
 
-        $regMonthList = array_column($result, 'reg_month');
-        foreach ($regMonthList as $regMonth){
-            $res = $this->addupTotalMonth($regMonth);
-            if($res) $this->pushData($res);
+            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";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as pay_month,'{$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] . "-";
-                }
+        $where = [
+            ['reg_date', 'between', [$srData, $erDate]],
+            ['pay_date', 'between', [$srData, $epDate]],
+        ];
 
-                foreach ($row as $k => $v) {
-                    $this->data[$uniqueKey][$k] = !empty($this->data[$uniqueKey][$k]) ? $this->data[$uniqueKey][$k] + $v :$v;
-                }
-            }
-        }
+        return Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
     }
 }

+ 18 - 54
app/v1/logic/tool/GameTotalMonthLogic.php

@@ -5,11 +5,11 @@ namespace app\v1\logic\tool;
 
 use support\think\Db;
 
-class GameTotalMonthLogic
+class GameTotalMonthLogic extends BaseLogic
 {
     protected string $table = "game_total_month";
 
-    protected string $group = 'game_id, agent_id, site_id';
+    protected string $group = 'game_id, agent_id, site_id, tmonth';
 
     protected array $data;
 
@@ -59,15 +59,18 @@ class GameTotalMonthLogic
         $this->data = [];
 
         $this->regMonth();
+
         $this->loginMonth();
+
         $this->regPay();
+
         $this->payTotal();
+
         $this->roleCreate();
-        $this->mediaCost();
 
-        $this->siteAuth();
+        $this->mediaCost();
 
-        $this->replaceData();
+        $this->replaceData(['tmonth'=>$this->month]);
     }
 
     protected function regMonth()
@@ -76,7 +79,7 @@ class GameTotalMonthLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as tmonth, count(distinct uid) as reg_total, count(distinct imei) as reg_dev";
 
         $where = [
             ['reg_time', 'between', [$sTime, $eTime]],
@@ -90,7 +93,7 @@ class GameTotalMonthLogic
     protected function loginMonth()
     {
         $tb = "sdk_active_log_" . date('Ym', strtotime($this->month)); // 按天去重
-        $filed = "{$this->group}, count(distinct uid) as login_total";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as tmonth, count(distinct uid) as login_total";
 
         $result = Db::connect('db_game_log')->table($tb)->field($filed)->group($this->group)->select();
 
@@ -104,11 +107,11 @@ class GameTotalMonthLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as tmonth, 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', [$sDate, $eDate]],
+            ['pay_date', 'between', [$sDate, $eDate]],
         ];
 
         $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
@@ -123,10 +126,10 @@ class GameTotalMonthLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as tmonth, 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', [$sDate, $eDate]],
         ];
 
         $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray();
@@ -139,7 +142,7 @@ class GameTotalMonthLogic
         $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";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as tmonth, COUNT(DISTINCT uid) as role_create_user";
         $where = [
             ['create_time', 'between', [$sDate, $eDate]],
         ];
@@ -158,52 +161,13 @@ class GameTotalMonthLogic
         $sDate = "{$this->month}-01";
         $eDate = date('Y-m-t', strtotime($this->month));
 
-        $filed = "{$this->group}, SUM(money) as cost";
+        $filed = "game_id, agent_id, site_id, '{$this->month}' as tmonth, SUM(money) as cost";
         $where = [
-            'tdate' => ['between', [$sDate, $eDate]],
+            ['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;
-                }
-            }
-        }
-    }
 }

+ 2 - 2
config/process.php

@@ -72,10 +72,10 @@ return [
 //        'handler' => \app\process\dataReport\BasicLoginTotal::class,
 //    ],
 //    'game_reg_pay_month' => [
-//        'handler' => \app\process\dataReport\GameRegPayMonth::class,
+//        'handler' => \app\process\dataReport\GameRegPay::class,
 //    ],
 //    'game_total_month' =>  [
-//        'handler' => \app\process\dataReport\GameTotalMonth::class,
+//        'handler' => \app\process\dataReport\GameTotal::class,
 //    ]
 
 ];

+ 2 - 2
plugin/saiadmin/app/controller/tool/CrontabController.php

@@ -77,8 +77,8 @@ class CrontabController extends BaseController
     protected function afterChange($type, $args): void
     {
         if (in_array($type, ['save', 'update', 'changeStatus'])) {
-            $task = new \plugin\saiadmin\process\Task();
-            $task->reload();
+            // $task = new \plugin\saiadmin\process\Task();
+            // $task->reload();
         }
     }
 

+ 7 - 0
test.php

@@ -0,0 +1,7 @@
+#!/usr/bin/env php
+<?php
+
+$data = [
+        ['a'=>1],
+    ['b'=>2]
+];