ith5 5 месяцев назад
Родитель
Сommit
663d20faf8

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

@@ -25,4 +25,17 @@ class AnalyseController extends BaseController
         $data['data'] = $this->logic->trandformListColumn($data['data'],['game']);
         return $this->success($data);
     }
+
+    // 注册按时s
+    public function getRegHourDataList(Request $request){
+        $where = $request->more([
+            ['game_id', ''],
+            ['reg_date', '']
+        ]);
+        $data = $this->logic->getRegHourDataList($where);
+        $data['data'] = $this->logic->trandformListColumn($data['data'],['game']);
+        return $this->success($data);
+    }
+
+
 }

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

@@ -11,6 +11,7 @@ use support\think\Db;
 class AnalyseLogic extends BaseLogic
 {
 
+    // 注册按日
     public function getRegDayDataList($where){
       $params = $this->searchByAuth($where);
       $whereSql = $this->generateWhereSql($params);
@@ -74,6 +75,53 @@ class AnalyseLogic extends BaseLogic
       return $result;
     }
 
+    // 注册按时
+    public function getRegHourDataList($where){
+      $params = $this->searchByAuth($where);
+     
+      $field = "SUM(role_create_user) AS role_create_user, tdate,game_id,thour";
+      $regDate = $where['reg_date'];
+      // 将$regDate转化为年月格式,如202509
+      $ym = date('Ym', strtotime($regDate));
+
+      $tableName = 'base_total_hour_'.$ym;
+    
+      $whereSql = 'WHERE 1=1';
+      if(!empty($params['game_id'])){
+        $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
+      }
+      if(!empty($params['reg_date'])){
+        $whereSql .= " AND tdate = '" .$params['reg_date']. "'";
+      }
+      $sql = "SELECT {$field} FROM {$tableName} {$whereSql}  GROUP BY game_id,thour,tdate";
+      $baseData = Db::connect('db_data_report')->query($sql);
+      $data = [];
+      foreach($baseData as &$row){
+        $game_id = $row['game_id'];
+        $thour = $row['thour'];
+        $data[$game_id]['h'.$thour] = $row['role_create_user'];
+        $data[$game_id]['total'] = !empty($data[$game_id]['total']) ? $data[$game_id]['total'] + $row['role_create_user'] : $row['role_create_user'];
+        $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;
+        }
+      }
+
+      $result['data'] = $list;
+      $result['totalRow'] = $totalRow;
+      return $result;
+    }
+