浏览代码

feat:趋势数据接口

aiden 3 月之前
父节点
当前提交
12f5e38cd9
共有 4 个文件被更改,包括 200 次插入133 次删除
  1. 0 92
      app/controller/.php
  2. 95 1
      app/controller/TrendStatis.php
  3. 95 40
      app/model/TrendStatisModel.php
  4. 10 0
      route/app.php

+ 0 - 92
app/controller/.php

@@ -1,92 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\controller;
-
-use app\BaseController;
-use app\model\GameStatisModel;
-use app\common\CommonUtils;
-use app\model\GameModel;
-use think\facade\Request;
-
-class TrendStatis extends BaseController
-{    
-    /**
-     * 在线走势
-     */
-    public function Online()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        // 获取查询参数
-        $page = Request::get('page', 1, 'intval');
-        $limit = Request::get('limit', 10, 'intval');
-
-        // 筛选条件
-        $filters = [
-            // 时间筛选
-            'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
-            'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
-            'game_id' => Request::get('game_id', '', 'trim'),
-        ];
-        
-        try {
-            // 获取游戏每日数据
-            $result = GameStatisModel::getGameDailyList(
-                $userInfo['merchant_id'],
-                $page, 
-                $limit,
-                $filters,
-            );
-
-            // 获取游戏信息信息
-            $game_ids = array_unique(array_column($result['list'], 'game_id'));
-            $tempGameList = GameModel::where([['merchant_id', '=', $userInfo['merchant_id']], ['game_id', 'in', $game_ids]])->field(['game_id','title','image'])->select()->toArray();
-            $gameList = [];
-            foreach ($tempGameList as $item) {
-                $game_id = $item['game_id'];
-                $gameList[$game_id] = $item;
-            }            
-            
-            // 格式化数据
-            foreach ($result['list'] as &$item) {
-                $item['game_profit'] = CommonUtils::convertBalance($item['game_profit'], false);
-                $item['bet_amount'] = CommonUtils::convertBalance($item['bet_amount'], false);
-                $item['commission_amount'] = CommonUtils::convertBalance($item['game_profit'] * 0.08, false);
-                $item['platform_fee'] = CommonUtils::convertBalance($item['bet_amount'] * 0.08, false);
-                $item['buy_free_bet'] = 0;
-                $item['game_title'] = $gameList[$item['game_id']]['title'] ?? '';
-            }
-            
-            return json_success($result, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取游戏每日数据失败:' . $e->getMessage());
-        }
-    }  
-    
-    /**
-     * 游戏走势
-     */
-    public function Game() {
-
-    }
-
-    /**
-     * 输赢走势
-     */
-    public function Win() {
-
-    }
-    
-    /**
-     * 返奖倍数走势
-     */
-    public function PrizeMultiple() {
-
-    }
-
-    /**
-     * 
-     */
-    
-}

+ 95 - 1
app/controller/TrendStatis.php

@@ -5,6 +5,7 @@ namespace app\controller;
 
 use app\BaseController;
 use app\model\GameStatisModel;
+use app\model\TrendStatisModel;
 use app\common\CommonUtils;
 use app\model\GameModel;
 use think\facade\Request;
@@ -75,18 +76,111 @@ class TrendStatis extends BaseController
      * 输赢走势
      */
     public function Win() {
+        $userInfo = $this->request->userInfo;
+        
+        // 获取查询参数
+        $filters = [
+            'date' => Request::get('date', '', 'trim'),
+            'game_id' => Request::get('game_id', '', 'trim'),
+            'currency' => Request::get('currency', 'USDT', 'trim')
+        ];
+        
+        try {
+            // 获取输赢走势数据
+            $list = TrendStatisModel::getWinLoseTrend(
+                $userInfo['merchant_id'],
+                $filters
+            );
 
+            if ($list) {
+                foreach ($list as &$item) {  
+                    $item['hour']  = (int) $item['hour'];          
+                    $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
+                }
+            }
+                        
+            usort($list, function ($a, $b) {
+                return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;                
+            });
+            return json_success($list, '获取成功');
+        } catch (\Exception $e) {
+            return json_error([], '获取输赢走势失败:' . $e->getMessage());
+        }
     }
     
     /**
      * 返奖倍数走势
      */
     public function PrizeMultiple() {
+        $userInfo = $this->request->userInfo;
+        
+        // 获取查询参数
+        $filters = [
+            'date' => Request::get('date', '', 'trim'),
+            'game_id' => Request::get('game_id', '', 'trim'),
+            'currency' => Request::get('currency', 'USDT', 'trim')
+        ];
+        
+        try {
+            // 获取输赢走势数据
+            $list = TrendStatisModel::getMultipleTrend(
+                $userInfo['merchant_id'],
+                $filters
+            );
 
+            if ($list) {
+                foreach ($list as &$item) {  
+                    $item['hour']  = (int) $item['hour'];          
+                    $item['total_multiple'] = (int) $item['total_multiple'];
+                }
+            }
+                        
+            usort($list, function ($a, $b) {
+                return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;                
+            });
+            return json_success($list, '获取成功');
+        } catch (\Exception $e) {
+            return json_error([], '获取返奖倍数走势失败:' . $e->getMessage());
+        }
     }
 
     /**
-     * 
+     * 商户每日走势
      */
+    public function MerchantDaily() {
+        $userInfo = $this->request->userInfo;
+        
+        // 筛选条件
+        $filters = [
+            'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
+            'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
+            'game_id' => Request::get('game_id', '', 'trim') 
+        ];
+        
+        try {
+            // 获取商户每日走势数据
+            $list = TrendStatisModel::getMerchantDailyTrend(
+                $userInfo['merchant_id'],
+                $filters
+            );
+
+            if ($list) {
+                foreach ($list as &$item) {  
+                    $item['hour']  = (int) $item['hour'];          
+                    $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
+                    $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
+                    $item['bet_count'] = (int) $item['bet_count'];
+                    $item['bet_users'] = (int) $item['bet_users'];
+                }
+            }            
+            
+            usort($list, function ($a, $b) {
+                return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;                
+            });
+            return json_success($list, '获取成功');
+        } catch (\Exception $e) {
+            return json_error([], '获取商户每日走势失败:' . $e->getMessage());
+        }
+    }
     
 }

+ 95 - 40
app/model/TrendStatisModel.php

@@ -17,63 +17,118 @@ class TrendStatisModel extends Model
     protected $connection = 'fortue_tiger';
     
     /**
-     * 获取游戏每日数据列表
+     * 获取输赢走势数据
      */
-    public static function getGameDailyList($merchantId, $page = 1, $limit = 20, $filters = [])
+    public static function getWinLoseTrend($appId, $filters = [])
     {
-        $where = [
-            ['app_id', '=', $merchantId]
-        ];
+        $wheres = [];
+        $wheres[] = ['action_type', '=', 1];
+        $wheres[] = ['app_id', '=', $appId];
+        
+        // 时间筛选
+        $startTime = !empty($filters['date']) ? strtotime($filters['date']) : strtotime(date('Ymd'));
+        $endTime = $startTime + 86400;
+        
+        $wheres[] = ['create_time', '>=', $startTime];
+        $wheres[] = ['create_time', '<=', $endTime];
+        
+        // 游戏ID筛选
+        if (!empty($filters['game_id'])) {
+            $filters['game_id'] = implode(',', $filters['game_id']);
+            $wheres[] = ['game_id', 'IN', $filters['game_id']];
+        }
+        
+        // 货币类型筛选
+        if (!empty($filters['currency'])) {
+            // 这里可能需要关联其他表来获取货币类型,暂时忽略
+        }
+
+        $query = self::where($wheres);
+        // 获取列表数据
+        $data = $query->field([
+                    "from_unixtime(create_time, '%k') AS hour",
+                    'SUM(total_win_amount) as total_win',
+            ])
+            ->group('hour')
+            ->select()
+            ->toArray();        
+        
+        return $data;
+    }
+    
+    /**
+     * 获取返奖倍数走势数据(RTP走势)
+     */
+    public static function getMultipleTrend($appId, $filters = [])
+    {
+        $wheres = [];
+        $wheres[] = ['action_type', '=', 1];
+        $wheres[] = ['app_id', '=', $appId];
+        
+        // 时间筛选
+        $startTime = !empty($filters['date']) ? strtotime($filters['date']) : strtotime(date('Ymd'));
+        $endTime = $startTime + 86400;
+        
+        $wheres[] = ['create_time', '>=', $startTime];
+        $wheres[] = ['create_time', '<=', $endTime];
+        
+        // 游戏ID筛选
+        if (!empty($filters['game_id'])) {
+            $filters['game_id'] = implode(',', $filters['game_id']);
+            $wheres[] = ['game_id', 'IN', $filters['game_id']];
+        }
+
+        $query = self::where($wheres);
+        // 获取列表数据
+        $data = $query->field([
+                    "from_unixtime(create_time, '%k') AS hour",
+                    'SUM(res_multiple) as total_multiple',
+            ])
+            ->group('hour')
+            ->select()
+            ->toArray();        
+        
+        return $data;
+    }
+    
+    /**
+     * 获取商户每日走势数据
+     */
+    public static function getMerchantDailyTrend($appId, $filters = [])
+    {
+        $wheres = [];
+        $wheres[] = ['action_type', '=', 1];
+        $wheres[] = ['app_id', '=', $appId];
         
         // 时间筛选
         if (!empty($filters['start_time'])) {
             $startTime = strtotime($filters['start_time']);
-            $where[] = ['create_time', '>=', $startTime];
+            $wheres[] = ['create_time', '>=', $startTime];
         }
         
         if (!empty($filters['end_time'])) {
             $endTime = strtotime($filters['end_time']);
-            $where[] = ['create_time', '<=', $endTime];
-        }
-
+            $wheres[] = ['create_time', '<=', $endTime];
+        } 
+        
+        // 游戏ID筛选
         if (!empty($filters['game_id'])) {
-            $gameId = is_array($filters['game_id']) ? $filters['game_id'] : explode(',', $filters['game_id']);
-            $where[] = ['game_id', 'in', $gameId];
+            $wheres[] = ['game_id', 'IN', $filters['game_id']];
         }
         
-        $query = self::where($where);
-        // 统计总数
-        $total = $query->count();
+        $query = self::where($wheres);
         // 获取列表数据
-        $list = $query->field([
-                    "FROM_UNIXTIME(create_time, '%Y-%m-%d') as date", // 日期
-                    'game_id',  //游戏id
-                    'AVG(rtp) AS rtp', // 平均RTP
+        $data = $query->field([
+                    "from_unixtime(create_time, '%k') AS hour",
+                    'SUM(total_win_amount) as total_win',
+                    'SUM(bet) as total_bet',
+                    'COUNT(*) as bet_count', // 注单数
                     'COUNT(DISTINCT uname) as bet_users',  // 投注用户数
-                    'COUNT(id) as bet_count',  // 注单数
-                    'SUM(bet) as bet_amount',  // 注单金额(下注分数)
-                    'SUM(total_win_amount) as game_profit',  // 游戏输赢(金额变化)
             ])
-            ->order('date', 'desc')
-            ->group('date, game_id')
-            ->page($page, $limit)
+            ->group('hour')
             ->select()
-            ->toArray();
-
-        // 获取登录用户、注册用户    
-        $merchantsUserStatic = MerchantsUserModel::getPlayerStatistics($merchantId, $filters);
-        
-        foreach ($list as &$row)
-        {
-            $row['login_users'] = $merchantsUserStatic[$row['date']]['login_users'] ?? 0;
-            $row['register_users'] = $merchantsUserStatic[$row['date']]['register_users'] ?? 0;
-        }
+            ->toArray(); 
         
-        return [
-            'list' => $list,
-            'total' => $total,
-            'page' => $page,
-            'limit' => $limit
-        ];
+        return $data;
     }
 }

+ 10 - 0
route/app.php

@@ -121,6 +121,16 @@ Route::group('game_statis', function () {
     Route::get('daily', 'GameStatis/Daily');
 })->middleware([\app\middleware\AuthMiddleware::class, \app\middleware\BehaviorLogMiddleware::class]);
 
+// 走势数据相关路由
+Route::group('trend_statis', function () {
+    // 输赢走势
+    Route::get('win', 'TrendStatis/Win');
+    // 返奖倍数走势
+    Route::get('prize_multiple', 'TrendStatis/PrizeMultiple');
+    // 商户每日走势
+    Route::get('merchant_daily', 'TrendStatis/MerchantDaily');
+})->middleware([\app\middleware\AuthMiddleware::class, \app\middleware\BehaviorLogMiddleware::class]);
+
 // 排笔榜相关路由
 Route::group('rank_list', function () {
     // 赢钱榜