ith5 5 месяцев назад
Родитель
Сommit
634b93bb0c
2 измененных файлов с 171 добавлено и 0 удалено
  1. 28 0
      app/v1/controller/gameLog/AnalyseController.php
  2. 143 0
      app/v1/logic/gameLog/AnalyseLogic.php

+ 28 - 0
app/v1/controller/gameLog/AnalyseController.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * 运营分析
+ */
+namespace app\v1\controller\gameLog;
+use app\v1\logic\gameLog\AnalyseLogic;
+use plugin\saiadmin\basic\BaseController;
+use support\Request;
+use support\Response;
+class AnalyseController extends BaseController
+{
+    public function __construct()
+    {
+        $this->logic = new AnalyseLogic();
+        parent::__construct();
+    }
+
+    // 注册按日
+    public function getRegDayDataList(Request $request){
+        $where = $request->more([
+            ['game_id', ''],
+            ['reg_date', '']
+        ]);
+        $data = $this->logic->getRegDayDataList($where);
+        $data['data'] = $this->logic->trandformListColumn($data['data'],['game']);
+        return $this->success($data);
+    }
+}

+ 143 - 0
app/v1/logic/gameLog/AnalyseLogic.php

@@ -0,0 +1,143 @@
+<?php
+
+// 玩家日志逻
+
+namespace app\v1\logic\gameLog;
+
+use app\v1\logic\tool\ToolLogic;
+use plugin\saiadmin\basic\BaseLogic;
+use support\think\Db;
+
+class AnalyseLogic extends BaseLogic
+{
+
+    public function getRegDayDataList($where){
+      $params = $this->searchByAuth($where);
+      $whereSql = $this->generateWhereSql($params);
+      $field = "SUM(reg_total) AS reg_total, tdate,game_id";
+      $baseData = $this->generateYearUnionList('base_total_day_',$where['reg_date'],$whereSql,$field,'game_id,tdate');
+
+
+      $data=[];
+      foreach($baseData as $row){
+        $tdate = $row['tdate'];
+        $game_id = $row['game_id'];
+        $data[$game_id][$tdate] = $row['reg_total'];
+        $data[$game_id]['total'] = !empty($data[$game_id]['total']) ? $data[$game_id]['total'] + $row['reg_total'] : $row['reg_total'];
+        $data[$game_id]['game_id'] = $game_id;
+      }
+
+      $list = array_values($data);
+ 
+      $totalRow = ['game_id'=>'合计'];
+      foreach($list as &$row){
+        $totalRow['total'] = !empty($totalRow['total']) ? $totalRow['total'] + $row['total'] : $row['total'];
+        foreach ($row as $key => $value) {
+          if($key == 'total' || $key == 'game_id'){
+            continue;
+          }
+          $totalRow[$key] = !empty($totalRow[$key]) ? $totalRow[$key] + $value : $value;
+        }
+      }
+
+      // 获取两个注册日期之间的日期列表
+      $dateList = ToolLogic::getDatesBetween($where['reg_date'][0],$where['reg_date'][1]);
+      $columnsData = [
+        [
+          'title' => '游戏ID',
+          'dataIndex' => 'game_id',
+          'width' => 120,
+        ],
+        [
+          'title' => '游戏',
+          'dataIndex' => 'game_name',
+          'width' => 120,
+        ],
+        [
+          'title' => '合计',
+          'dataIndex' => 'total',
+          'width' => 120,
+        ]
+      ];
+      foreach($dateList as $date){
+        $columnsData[] = [
+          'title' => $date,
+          'dataIndex' => $date,
+          'width' => 120,
+        ];
+      }
+
+      $result['data'] = $list;
+      $result['totalRow'] = $totalRow;
+      $result['columns'] = $columnsData;
+
+      return $result;
+    }
+
+
+
+
+    // 生成基础日统计表的联合查询列表
+    public function generateYearUnionList($namePrefix, $regDate,$whereSql='',$field='*',$group=null){
+
+        $tableNames = ToolLogic::getYearlyTableNames($namePrefix, $regDate[0],$regDate[1]);
+        $sqlParts = [];
+        foreach ($tableNames as $tableName){
+            $sqlParts[] = "SELECT * FROM {$tableName} WHERE 1=1 {$whereSql}";
+        }
+        $unionSql = implode(" UNION ALL ", $sqlParts);
+        $finalSql = "
+            SELECT {$field} FROM ( {$unionSql} ) AS all_total_day
+        ";
+        if (!empty($group)) {
+            $finalSql .= " GROUP BY {$group}";
+        }
+        $baseData = Db::connect('db_data_report')->query($finalSql);
+        return $baseData;
+    }
+
+
+    // 生成wheresql
+    public function generateWhereSql($params){
+
+        $whereSql = "";
+        // 游戏id
+        if(!empty($params['game_id'])){
+            if (is_array($params['game_id'])) {
+                $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
+            } else {
+                $whereSql .= " AND game_id = {$params['game_id']}";
+            }
+        }
+        // 媒体id
+        if(!empty($params['media_id'])){
+            $whereSql .= " AND media_id = {$params['media_id']}";
+        }
+        // 渠道id
+        if(!empty($params['agent_id'])){
+            $whereSql .= " AND agent_id = {$params['agent_id']}";
+        }
+        // 广告位id
+        if(!empty($params['site_id'])){
+            if (is_array($params['site_id'])) {
+                $whereSql .= " AND site_id IN(" . implode(',', $params['site_id']) . ")";
+            } else {
+                $whereSql .= " AND site_id = {$params['site_id']}";
+            }
+        }
+        // 负责人
+        if(!empty($params['auth_id'])){
+            if (is_array($params['auth_id'])) {
+                $whereSql .= " AND auth_id IN(" . implode(',', $params['auth_id']) . ")";
+            } else {
+                $whereSql .= " AND auth_id = {$params['auth_id']}";
+            }
+        }
+        // 注册日期
+        if(!empty($params['reg_date'])??null){
+            $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
+        }
+
+        return $whereSql;
+    }
+}