소스 검색

统计脚本

PC-202304251453\Administrator 5 달 전
부모
커밋
12e86b3958
5개의 변경된 파일185개의 추가작업 그리고 29개의 파일을 삭제
  1. 29 1
      app/process/CreateTables.php
  2. 41 0
      app/process/dataReport/GameRegPay.php
  3. 0 27
      app/process/dataReport/GameRegPayMonth.php
  4. 114 0
      app/v1/logic/tool/GameRegPayDayLogic.php
  5. 1 1
      config/process.php

+ 29 - 1
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();
         });
     }
@@ -25,6 +25,7 @@ class CreateTables
             $this->base_total_day,
             $this->base_total_hour,
             $this->basic_active_day,
+            $this->game_reg_pay_day
         ];
 
         foreach ($centerTablesSqlList as $sql){
@@ -155,6 +156,33 @@ class CreateTables
   KEY `site_id` (`site_id`) USING BTREE,
   KEY `game_id` (`game_id`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+
+    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 '登录日期',

+ 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);
-    }
-}

+ 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();
+    }
+}

+ 1 - 1
config/process.php

@@ -72,7 +72,7 @@ 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\GameTotal::class,