Jelajahi Sumber

优化代码

aiden 3 bulan lalu
induk
melakukan
8541e6897f

+ 4 - 4
app/controller/Game.php

@@ -62,7 +62,7 @@ class Game extends BaseController
         }
         
         try {
-            $game = GameModel::getGameDetail($id, $userInfo['merchant_id']);
+            $game = GameModel::getGameDetail($userInfo['merchant_id'], ['id' => $id]);
             if (!$game) {
                 return json_error([], '游戏不存在');
             }
@@ -90,7 +90,7 @@ class Game extends BaseController
         }
         
         // 检查游戏是否存在且属于当前商户
-        $game = GameModel::getGameDetail($id, $userInfo['merchant_id']);
+        $game = GameModel::getGameDetail($userInfo['merchant_id'], ['id' => $id]);
         if (!$game) {
             return json_error([], '游戏不存在');
         }
@@ -130,7 +130,7 @@ class Game extends BaseController
         }
         
         try {
-            GameModel::updateGame($id, $updateData, $userInfo['merchant_id']);
+            GameModel::updateGame($userInfo['merchant_id'], $id, $updateData);
             return json_success([], '更新游戏成功');
         } catch (\Exception $e) {
             return json_error([], '更新游戏失败:' . $e->getMessage());
@@ -161,7 +161,7 @@ class Game extends BaseController
         }
         
         try {
-            $result = GameModel::updateGameStatus($ids, $userInfo['merchant_id'], $status);
+            $result = GameModel::updateGameStatus($userInfo['merchant_id'], $ids, $status);
             if ($result) {
                 return json_success([], '状态更新成功');
             } else {

+ 4 - 123
app/controller/GameOrder.php

@@ -5,7 +5,7 @@ namespace app\controller;
 
 use app\BaseController;
 use think\facade\Request;
-use app\model\GameOrderModel;
+use app\model\GameBetOrderModel;
 use app\model\GameModel;
 use app\model\GameCheckBetOrder;
 use app\model\GameResultBetOrder;
@@ -54,7 +54,7 @@ class GameOrder extends BaseController
         
         try {
             // 获取主订单列表
-            $result = GameOrderModel::getBetOrderList($userInfo['merchant_id'], $page, $limit, $filters);
+            $result = GameBetOrderModel::getBetOrderList($userInfo['merchant_id'], $page, $limit, $filters);
             
             if (empty($result['list'])) {
                 return json_success($result, '获取成功');
@@ -123,109 +123,7 @@ class GameOrder extends BaseController
             return json_error([], '获取订单记录失败:' . $e->getMessage());
         }
     }
-    
-    /**
-     * 获取订单详情
-     */
-    public function detail()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        $id = Request::get('id', 0, 'intval');
-        if (!$id) {
-            return json_error([], '订单ID不能为空');
-        }
-        
-        try {
-            $order = GameOrderModel::getOrderDetail($id, $userInfo['merchant_id']);
-            
-            if (!$order) {
-                return json_error([], '订单不存在');
-            }
-            
-            return json_success($order, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取订单详情失败:' . $e->getMessage());
-        }
-    }
-    
-    /**
-     * 获取订单统计信息
-     */
-    public function statistics()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        // 筛选条件
-        $filters = [
-            'start_time' => Request::get('start_time', '', 'trim'),
-            'end_time' => Request::get('end_time', '', 'trim'),
-        ];
-        
-        // 如果没有指定时间范围,默认获取今天
-        if (empty($filters['start_time']) && empty($filters['end_time'])) {
-            $filters['start_time'] = date('Y-m-d');
-            $filters['end_time'] = date('Y-m-d');
-        }
-        
-        try {
-            $statistics = GameOrderModel::getOrderStatistics($userInfo['merchant_id'], $filters);
-            
-            return json_success([
-                'statistics' => $statistics,
-                'date_range' => [
-                    'start_time' => $filters['start_time'],
-                    'end_time' => $filters['end_time']
-                ]
-            ], '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取统计信息失败:' . $e->getMessage());
-        }
-    }
-    
-    /**
-     * 获取游戏列表(用于筛选下拉框)
-     */
-    public function getGames()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        try {
-            $gameIds = GameOrderModel::getAllGameIds($userInfo['merchant_id']);
-            
-            // 构建游戏列表
-            $games = [];
-            foreach ($gameIds as $gameId) {
-                $games[] = [
-                    'game_id' => $gameId,
-                    'game_name' => $this->getGameName($gameId)
-                ];
-            }
-            
-            return json_success($games, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取游戏列表失败:' . $e->getMessage());
-        }
-    }
-    
-    /**
-     * 获取订单原因列表(用于筛选下拉框)
-     */
-    public function getOrderReasons()
-    {
-        try {
-            $reasons = [
-                ['reason_id' => GameOrderModel::ACTION_TYPE_BET, 'reason_name' => '下注'],
-                ['reason_id' => GameOrderModel::ACTION_TYPE_SETTLE, 'reason_name' => '结算'],
-                ['reason_id' => GameOrderModel::ACTION_TYPE_CANCEL, 'reason_name' => '取消'],
-            ];
-            
-            return json_success($reasons, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取订单原因列表失败:' . $e->getMessage());
-        }
-    }
-    
+                
     /**
      * 导出订单记录
      */
@@ -248,7 +146,7 @@ class GameOrder extends BaseController
         
         try {
             // 获取所有符合条件的数据(不分页)
-            $result = GameOrderModel::getOrderRecords($userInfo['merchant_id'], 1, 100000, $filters);
+            $result = GameBetOrderModel::getOrderRecords($userInfo['merchant_id'], 1, 100000, $filters);
             
             // 生成CSV数据
             $csvData = "序号,母单号,子单号,牌局编号,平台昵称,玩家ID,所属商户,平台ID," .
@@ -291,23 +189,6 @@ class GameOrder extends BaseController
         }
     }
     
-    /**
-     * 获取游戏名称
-     */
-    private function getGameName($gameId)
-    {
-        // 这里可以根据实际情况配置游戏ID对应的名称
-        $gameNames = [
-            'tiger' => '老虎机',
-            'fortue_tiger' => '财富老虎',
-            'dragon_tiger' => '龙虎斗',
-            'baccarat' => '百家乐',
-            // 可以继续添加其他游戏
-        ];
-        
-        return $gameNames[$gameId] ?? $gameId;
-    }
-
    // 格式化信息
     private function formatItemDataText($item = [])
     {

+ 4 - 156
app/controller/GameRecord.php

@@ -5,7 +5,7 @@ namespace app\controller;
 
 use app\BaseController;
 use think\facade\Request;
-use app\model\GameRecordModel;
+use app\model\GameBetGameModel;
 use app\model\GameModel;
 use app\common\CommonUtils;
 
@@ -46,7 +46,7 @@ class GameRecord extends BaseController
         
         try {
             // 获取游戏记录列表
-            $result = GameRecordModel::getBetGameList($userInfo['merchant_id'], $page, $limit, $filters);
+            $result = GameBetGameModel::getBetGameList($userInfo['merchant_id'], $page, $limit, $filters);
             
             if (empty($result['list'])) {
                 return json_success($result, '获取成功');
@@ -67,7 +67,7 @@ class GameRecord extends BaseController
 
             $childOrderList = [];
             if(count($thirdGids) > 0) {
-                $tempCheckList = GameRecordModel::where([ ['third_gid', 'in', $thirdGids], ['action_type','=',2] ])->withoutField('result')->select()->toArray();
+                $tempCheckList = GameBetGameModel::where([ ['third_gid', 'in', $thirdGids], ['action_type','=',2] ])->withoutField('result')->select()->toArray();
                 foreach ($tempCheckList as $item) {
                     if(!isset($childOrderList[$item['third_gid']])) {
                         $childOrderList[$item['third_gid']] = [];
@@ -115,159 +115,7 @@ class GameRecord extends BaseController
         }
     }
     
-    /**
-     * 获取游戏记录详情
-     */
-    public function detail()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        $id = Request::get('id', 0, 'intval');
-        if (!$id) {
-            return json_error([], '记录ID不能为空');
-        }
-        
-        try {
-            $record = GameRecordModel::getGameRecordDetail($id, $userInfo['merchant_id']);
-            
-            if (!$record) {
-                return json_error([], '记录不存在');
-            }
-            
-            // 获取游戏信息
-            $gameInfo = GameModel::where('game_id', $record['game_id'])
-                ->where('merchant_id', $userInfo['merchant_id'])
-                ->field(['title', 'title_en', 'image', 'image_en'])
-                ->find();
-            
-            if ($gameInfo) {
-                $record['game_name'] = $gameInfo['title'];
-                $record['game_name_en'] = $gameInfo['title_en'];
-                $record['game_icon'] = $gameInfo['image'];
-                $record['game_icon_en'] = $gameInfo['image_en'];
-            } else {
-                $record['game_name'] = $record['game_id'];
-                $record['game_name_en'] = '';
-                $record['game_icon'] = '';
-                $record['game_icon_en'] = '';
-            }
-            
-            return json_success($record, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取记录详情失败:' . $e->getMessage());
-        }
-    }
-    
-    /**
-     * 获取游戏统计信息
-     */
-    public function statistics()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        // 筛选条件
-        $filters = [
-            'start_time' => Request::get('start_time', '', 'trim'),
-            'end_time' => Request::get('end_time', '', 'trim'),
-        ];
-        
-        // 如果没有指定时间范围,默认获取今天
-        if (empty($filters['start_time']) && empty($filters['end_time'])) {
-            $filters['start_time'] = date('Y-m-d');
-            $filters['end_time'] = date('Y-m-d');
-        }
-        
-        try {
-            $statistics = GameRecordModel::getGameStatistics($userInfo['merchant_id'], $filters);
-            
-            return json_success([
-                'statistics' => $statistics,
-                'date_range' => [
-                    'start_time' => $filters['start_time'],
-                    'end_time' => $filters['end_time']
-                ]
-            ], '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取统计信息失败:' . $e->getMessage());
-        }
-    }
-    
-    /**
-     * 获取游戏列表(用于筛选下拉框)
-     */
-    public function getGames()
-    {
-        $userInfo = $this->request->userInfo;
         
-        try {
-            $gameIds = GameRecordModel::getAllGameIds($userInfo['merchant_id']);
-            
-            // 从GameModel获取游戏详细信息
-            $gameInfos = GameModel::whereIn('game_id', $gameIds)
-                ->where('merchant_id', $userInfo['merchant_id'])
-                ->field(['game_id', 'title', 'title_en', 'image', 'image_en'])
-                ->select()
-                ->toArray();
-            
-            // 创建游戏ID到游戏信息的映射
-            $gameMap = [];
-            foreach ($gameInfos as $gameInfo) {
-                $gameMap[$gameInfo['game_id']] = $gameInfo;
-            }
-            
-            // 构建游戏列表
-            $games = [];
-            foreach ($gameIds as $gameId) {
-                if (isset($gameMap[$gameId])) {
-                    $games[] = [
-                        'game_id' => $gameId,
-                        'game_name' => $gameMap[$gameId]['title'],
-                        'game_name_en' => $gameMap[$gameId]['title_en'],
-                        'game_icon' => $gameMap[$gameId]['image'],
-                        'game_icon_en' => $gameMap[$gameId]['image_en']
-                    ];
-                } else {
-                    $games[] = [
-                        'game_id' => $gameId,
-                        'game_name' => $this->getGameName($gameId),
-                        'game_name_en' => '',
-                        'game_icon' => '',
-                        'game_icon_en' => ''
-                    ];
-                }
-            }
-            
-            return json_success($games, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取游戏列表失败:' . $e->getMessage());
-        }
-    }
-    
-    /**
-     * 获取玩法列表(用于筛选下拉框)
-     */
-    public function getPlayMethods()
-    {
-        $userInfo = $this->request->userInfo;
-        
-        try {
-            $playMethods = GameRecordModel::getAllPlayMethods($userInfo['merchant_id']);
-            
-            // 构建玩法列表
-            $methods = [];
-            foreach ($playMethods as $method) {
-                $methods[] = [
-                    'method_id' => $method,
-                    'method_name' => $this->getPlayMethodName($method)
-                ];
-            }
-            
-            return json_success($methods, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取玩法列表失败:' . $e->getMessage());
-        }
-    }
-    
     /**
      * 导出游戏记录
      */
@@ -289,7 +137,7 @@ class GameRecord extends BaseController
         
         try {
             // 获取所有符合条件的数据(不分页)
-            $result = GameRecordModel::getGameRecords($userInfo['merchant_id'], 1, 100000, $filters);
+            $result = GameBetGameModel::getGameRecords($userInfo['merchant_id'], 1, 100000, $filters);
             
             // 获取游戏信息映射
             $gameIds = array_unique(array_column($result['list'], 'game_id'));

+ 104 - 0
app/model/GameBetGameModel.php

@@ -0,0 +1,104 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+use think\facade\Db;
+
+/**
+ * 游戏记录模型 - 基于tp_game_bet_game表
+ */
+class GameBetGameModel extends Model
+{
+    protected $name = 'game_bet_game';
+    protected $connection = 'fortue_tiger';
+    protected $pk = 'id';
+    
+    // 动作类型常量
+    const ACTION_TYPE_BET = 1;      // 下注
+    const ACTION_TYPE_RESULT = 2;   // 结算
+    
+    // 状态常量
+    const STATUS_PENDING = 0;       // 待处理
+    const STATUS_SUCCESS = 1;       // 成功
+    const STATUS_FAILED = 2;        // 失败
+    
+    // 游戏类型常量
+    const GAME_TYPE_SLOT = 1;       // 老虎机
+    const GAME_TYPE_TABLE = 2;      // 桌面游戏
+    const GAME_TYPE_LIVE = 3;       // 真人游戏
+    
+    /**
+     * 获取游戏记录列表(参考apiAdminBetGameList方法)
+     */
+    public static function getBetGameList($appId, $page = 1, $limit = 20, $filters = [])
+    {
+        $wheres = [];
+        $wheres[] = ['action_type', '=', 1]; // 只查询下注记录
+        $wheres[] = ['app_id', '=', $appId];
+        
+        // 时间筛选
+        if (!empty($filters['start_time'])) {
+            $startTime = strtotime($filters['start_time'] . ' 00:00:00');
+            $wheres[] = ['create_time', '>=', $startTime];
+        }
+        
+        if (!empty($filters['end_time'])) {
+            $endTime = strtotime($filters['end_time'] . ' 23:59:59');
+            $wheres[] = ['create_time', '<=', $endTime];
+        }
+        
+        // 游戏ID筛选
+        if (!empty($filters['game_id'])) {
+            $wheres[] = ['game_id', '=', $filters['game_id']];
+        }
+        
+        // 牌局编号筛选
+        if (!empty($filters['third_round_id'])) {
+            $wheres[] = ['third_round_id', '=', $filters['third_round_id']];
+        }
+        
+        // 用户ID筛选
+        if (!empty($filters['player_id'])) {
+            $wheres[] = ['user_id', '=', $filters['user_id']];
+        }
+        
+        // 游戏玩法类型筛选
+        if (!empty($filters['bet_game_play_type'])) {
+            if ($filters['bet_game_play_type'] == 2) {
+                $wheres[] = ['bet_game_play_type', 'in', [1, 2]];
+            } else {
+                $wheres[] = ['bet_game_play_type', '=', $filters['bet_game_play_type']];
+            }
+        }
+        
+        $query = self::where($wheres);
+        
+        // 统计总数
+        $total = $query->count();
+        
+        // 获取列表数据(不包含result字段)
+        $list = $query->withoutField('result')
+            ->order('id', 'desc')
+            ->page($page, $limit)
+            ->select()
+            ->toArray();
+        
+        if (empty($list)) {
+            return [
+                'list' => [],
+                'total' => $total,
+                'page' => $page,
+                'limit' => $limit
+            ];
+        }
+                
+        return [
+            'list' => $list,
+            'total' => $total,
+            'page' => $page,
+            'limit' => $limit
+        ];
+    }
+}

+ 128 - 0
app/model/GameBetOrderModel.php

@@ -0,0 +1,128 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+use think\facade\Db;
+use app\model\GameModel;
+
+/**
+ * 游戏订单模型 - 基于tp_game_bet_order表
+ */
+class GameBetOrderModel extends Model
+{
+    protected $name = 'game_bet_order';
+    protected $connection = 'fortue_tiger';
+    protected $pk = 'id';
+    
+    // 状态常量
+    const STATUS_PENDING = 0;       // 待处理
+    const STATUS_SUCCESS = 1;       // 成功
+    const STATUS_FAILED = 2;        // 失败
+    const STATUS_CANCELLED = 3;     // 已取消
+    
+    // 动作类型常量
+    const ACTION_TYPE_BET = 1;      // 下注
+    const ACTION_TYPE_SETTLE = 2;   // 结算
+    const ACTION_TYPE_CANCEL = 3;   // 取消
+    const ACTION_TYPE_CHECK = 4;    // 检查
+    const ACTION_TYPE_RESULT = 5;   // 结果
+    
+    // 游戏类型常量
+    const GAME_TYPE_SLOT = 1;       // 老虎机
+    const GAME_TYPE_TABLE = 2;      // 桌面游戏
+    const GAME_TYPE_LIVE = 3;       // 真人游戏
+    
+    /**
+     * 获取下注订单列表(参考apiAdminBetOrderList方法)
+     */
+    public static function getBetOrderList($appId, $page = 1, $limit = 20, $filters = [])
+    {
+        $where = [
+            ['app_id', '=', $appId]
+        ];
+        
+        // 时间筛选
+        if (!empty($filters['start_time'])) {
+            $startTime = strtotime($filters['start_time'] . ' 00:00:00');
+            $where[] = ['create_time', '>=', $startTime];
+        }
+        
+        if (!empty($filters['end_time'])) {
+            $endTime = strtotime($filters['end_time'] . ' 23:59:59');
+            $where[] = ['create_time', '<=', $endTime];
+        }
+        
+        // 游戏筛选
+        if (!empty($filters['game_id'])) {
+            $where[] = ['game_id', '=', $filters['game_id']];
+        }
+        
+        // 订单原因筛选(动作类型)
+        if (!empty($filters['order_reason'])) {
+            $where[] = ['action_type', '=', $filters['order_reason']];
+        }
+        
+        // 平台ID筛选
+        if (!empty($filters['uname'])) {
+            $where[] = ['uname', '=', $filters['uname']];
+        }
+
+        // 平台昵称筛选
+        if (!empty($filters['nickname'])) {
+            $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
+        }        
+        
+        // 玩家id筛选
+        if (!empty($filters['player_id'])) {
+            $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
+        }
+        
+        // 订单状态筛选
+        if ($filters['order_status'] !== '') {
+            $where[] = ['status', '=', $filters['order_status']];
+        }
+                
+        // 订单编号筛选
+        if (!empty($filters['third_order_id'])) {
+            $where[] = ['third_order_id', 'like', '%' . $filters['third_order_id'] . '%'];
+        }
+        
+        // 母单号筛选
+        if (!empty($filters['third_gid'])) {
+            $where[] = ['third_gid', 'like', '%' . $filters['third_gid'] . '%'];
+        }
+        
+        // 牌局编号筛选
+        if (!empty($filters['third_round_id'])) {
+            $where[] = ['third_round_id', 'like', '%' . $filters['third_round_id'] . '%'];
+        }
+        
+        $query = self::where($where);
+        
+        // 统计总数
+        $total = $query->count();
+        
+        // 获取列表数据
+        $list = $query->field([
+                'id', 'user_id', 'app_id', 'uname', 'nickname', 
+                'third_gid', 'third_order_id', 'third_round_id', 'parent_id',
+                'game_id', 'game_type', 'status', 'message',
+                'amount', 'bet', 'prev_amount', 'next_amount',
+                'action_type', 'ip', 'err_desc', 'create_time',
+                'total_win_amount', 'total_amount'
+            ])
+            ->order('id', 'desc')
+            ->page($page, $limit)
+            ->select()
+            ->toArray();
+                
+        return [
+            'list' => $list,
+            'total' => $total,
+            'page' => $page,
+            'limit' => $limit
+        ];
+    }
+}

+ 16 - 19
app/model/GameModel.php

@@ -183,17 +183,24 @@ class GameModel extends Model
     /**
      * 获取游戏详情
      */
-    public static function getGameDetail($id, $merchantId)
+    public static function getGameDetail($merchantId, $filters = [])
     {
-        return self::where('id', $id)
-            ->where('merchant_id', $merchantId)
-            ->find();
+        $query = self::where('merchant_id', $merchantId);
+        if (!empty($filters['id'])) {
+            $query->where('id', $filters['id']);
+        }
+
+        if (!empty($filters['game_id'])) {
+            $query->where('game_id', $filters['game_id']);
+        }
+
+        return $query->select()->toArray();
     }
 
     /**
      * 创建游戏
      */
-    public static function createGame($data, $merchantId)
+    public static function createGame($merchantId, $data)
     {
         // 处理押注配置
         if (isset($data['deposit_list']) && is_array($data['deposit_list'])) {
@@ -209,7 +216,7 @@ class GameModel extends Model
     /**
      * 更新游戏
      */
-    public static function updateGame($id, $data, $merchantId)
+    public static function updateGame($merchantId, $id, $data)
     {
         // 处理押注配置
         if (isset($data['deposit_list']) && is_array($data['deposit_list'])) {
@@ -224,17 +231,7 @@ class GameModel extends Model
     /**
      * 更新游戏状态
      */
-    public static function updateGameStatus($ids, $merchantId, $status)
-    {
-        return self::whereIn('id', $ids)
-            ->where('merchant_id', $merchantId)
-            ->update(['status' => $status]);
-    }
-
-    /**
-     * 批量更新游戏状态
-     */
-    public static function batchUpdateStatus($ids, $status, $merchantId)
+    public static function updateGameStatus($merchantId, $ids, $status)
     {
         return self::whereIn('id', $ids)
             ->where('merchant_id', $merchantId)
@@ -313,7 +310,7 @@ class GameModel extends Model
     /**
      * 检查游戏ID是否已存在
      */
-    public static function checkGameIdExists($gameId, $merchantId, $excludeId = null): bool
+    public static function checkGameIdExists($merchantId, $gameId, $excludeId = null): bool
     {
         $query = self::where('game_id', $gameId)
             ->where('merchant_id', $merchantId);
@@ -326,7 +323,7 @@ class GameModel extends Model
     /**
      * 删除游戏
      */
-    public static function deleteGame($id, $merchantId): bool
+    public static function deleteGame($merchantId, $id): bool
     {
         return self::where('id', $id)
             ->where('merchant_id', $merchantId)

+ 0 - 267
app/model/GameOrderModel.php

@@ -1,267 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\model;
-
-use think\Model;
-use think\facade\Db;
-
-/**
- * 游戏订单模型 - 基于tp_game_bet_order表
- */
-class GameOrderModel extends Model
-{
-    protected $name = 'game_bet_order';
-    protected $connection = 'fortue_tiger';
-    protected $pk = 'id';
-    
-    // 状态常量
-    const STATUS_PENDING = 0;       // 待处理
-    const STATUS_SUCCESS = 1;       // 成功
-    const STATUS_FAILED = 2;        // 失败
-    const STATUS_CANCELLED = 3;     // 已取消
-    
-    // 动作类型常量
-    const ACTION_TYPE_BET = 1;      // 下注
-    const ACTION_TYPE_SETTLE = 2;   // 结算
-    const ACTION_TYPE_CANCEL = 3;   // 取消
-    const ACTION_TYPE_CHECK = 4;    // 检查
-    const ACTION_TYPE_RESULT = 5;   // 结果
-    
-    // 游戏类型常量
-    const GAME_TYPE_SLOT = 1;       // 老虎机
-    const GAME_TYPE_TABLE = 2;      // 桌面游戏
-    const GAME_TYPE_LIVE = 3;       // 真人游戏
-    
-    /**
-     * 获取下注订单列表(参考apiAdminBetOrderList方法)
-     */
-    public static function getBetOrderList($appId, $page = 1, $limit = 20, $filters = [])
-    {
-        $where = [
-            ['app_id', '=', $appId]
-        ];
-        
-        // 时间筛选
-        if (!empty($filters['start_time'])) {
-            $startTime = strtotime($filters['start_time'] . ' 00:00:00');
-            $where[] = ['create_time', '>=', $startTime];
-        }
-        
-        if (!empty($filters['end_time'])) {
-            $endTime = strtotime($filters['end_time'] . ' 23:59:59');
-            $where[] = ['create_time', '<=', $endTime];
-        }
-        
-        // 游戏筛选
-        if (!empty($filters['game_id'])) {
-            $where[] = ['game_id', '=', $filters['game_id']];
-        }
-        
-        // 订单原因筛选(动作类型)
-        if (!empty($filters['order_reason'])) {
-            $where[] = ['action_type', '=', $filters['order_reason']];
-        }
-        
-        // 平台ID筛选
-        if (!empty($filters['uname'])) {
-            $where[] = ['uname', '=', $filters['uname']];
-        }
-
-        // 平台昵称筛选
-        if (!empty($filters['nickname'])) {
-            $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%'];
-        }        
-        
-        // 玩家id筛选
-        if (!empty($filters['player_id'])) {
-            $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%'];
-        }
-        
-        // 订单状态筛选
-        if ($filters['order_status'] !== '') {
-            $where[] = ['status', '=', $filters['order_status']];
-        }
-                
-        // 订单编号筛选
-        if (!empty($filters['third_order_id'])) {
-            $where[] = ['third_order_id', 'like', '%' . $filters['third_order_id'] . '%'];
-        }
-        
-        // 母单号筛选
-        if (!empty($filters['third_gid'])) {
-            $where[] = ['third_gid', 'like', '%' . $filters['third_gid'] . '%'];
-        }
-        
-        // 牌局编号筛选
-        if (!empty($filters['third_round_id'])) {
-            $where[] = ['third_round_id', 'like', '%' . $filters['third_round_id'] . '%'];
-        }
-        
-        $query = self::where($where);
-        
-        // 统计总数
-        $total = $query->count();
-        
-        // 获取列表数据
-        $list = $query->field([
-                'id', 'user_id', 'app_id', 'uname', 'nickname', 
-                'third_gid', 'third_order_id', 'third_round_id', 'parent_id',
-                'game_id', 'game_type', 'status', 'message',
-                'amount', 'bet', 'prev_amount', 'next_amount',
-                'action_type', 'ip', 'err_desc', 'create_time',
-                'total_win_amount', 'total_amount'
-            ])
-            ->order('id', 'desc')
-            ->page($page, $limit)
-            ->select()
-            ->toArray();
-                
-        return [
-            'list' => $list,
-            'total' => $total,
-            'page' => $page,
-            'limit' => $limit
-        ];
-    }
-       
-    /**
-     * 获取订单详情
-     */
-    public static function getOrderDetail($id, $appId)
-    {
-        $order = self::where('id', $id)
-            ->where('app_id', $appId)
-            ->find();
-            
-        if (!$order) {
-            return null;
-        }
-        
-        $order = $order->toArray();
-        $order = self::formatItemData($order);
-        
-        // 获取相关的子订单
-        if (!empty($order['third_gid'])) {
-            $childOrders = self::getChildOrders([$order['third_gid']], $appId);
-            $order['children'] = $childOrders;
-        }
-        
-        // 游戏名称
-        $order['game_name'] = self::getGameName($order['game_id']);
-        
-        return $order;
-    }
-    
-    /**
-     * 获取订单统计信息
-     */
-    public static function getOrderStatistics($appId, $filters = [])
-    {
-        $where = [
-            ['app_id', '=', $appId],
-            ['status', '=', 1]
-        ];
-        
-        // 时间筛选
-        if (!empty($filters['start_time'])) {
-            $startTime = strtotime($filters['start_time'] . ' 00:00:00');
-            $where[] = ['create_time', '>=', $startTime];
-        }
-        
-        if (!empty($filters['end_time'])) {
-            $endTime = strtotime($filters['end_time'] . ' 23:59:59');
-            $where[] = ['create_time', '<=', $endTime];
-        }
-        
-        $statistics = self::where($where)
-            ->field([
-                'COUNT(*) as total_orders',
-                'COUNT(DISTINCT uname) as total_players',
-                'SUM(CASE WHEN action_type = 1 THEN bet ELSE 0 END) as total_bet_amount',
-                'SUM(total_win_amount) as total_win_amount',
-                'SUM(CASE WHEN amount > 0 THEN amount ELSE 0 END) as total_profit',
-                'SUM(CASE WHEN amount < 0 THEN ABS(amount) ELSE 0 END) as total_loss',
-                'SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as success_orders',
-                'SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as failed_orders',
-                'SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) as cancelled_orders'
-            ])
-            ->find()
-            ->toArray();
-        
-        // 格式化金额
-        $statistics['total_bet_amount_yuan'] = self::convertBalance($statistics['total_bet_amount']);
-        $statistics['total_win_amount_yuan'] = self::convertBalance($statistics['total_win_amount']);
-        $statistics['total_profit_yuan'] = self::convertBalance($statistics['total_profit']);
-        $statistics['total_loss_yuan'] = self::convertBalance($statistics['total_loss']);
-        $net_amount = $statistics['total_bet_amount'] - $statistics['total_win_amount'];
-        $statistics['net_amount_yuan'] = self::convertBalance($net_amount);
-        
-        // 计算成功率
-        if ($statistics['total_orders'] > 0) {
-            $statistics['success_rate'] = round(($statistics['success_orders'] / $statistics['total_orders']) * 100, 2);
-        } else {
-            $statistics['success_rate'] = 0;
-        }
-        
-        return $statistics;
-    }
-    
-    /**
-     * 获取所有游戏ID列表
-     */
-    public static function getAllGameIds($appId)
-    {
-        return self::where('app_id', $appId)
-            ->distinct(true)
-            ->column('game_id');
-    }
-    
-    /**
-     * 获取状态文本
-     */
-    public static function getStatusText($status)
-    {
-        $statusMap = [
-            self::STATUS_PENDING => '待处理',
-            self::STATUS_SUCCESS => '成功',
-            self::STATUS_FAILED => '失败',
-            self::STATUS_CANCELLED => '已取消'
-        ];
-        
-        return $statusMap[$status] ?? '未知';
-    }
-    
-    /**
-     * 获取动作类型文本
-     */
-    public static function getActionTypeText($actionType)
-    {
-        $actionTypeMap = [
-            self::ACTION_TYPE_BET => '下注',
-            self::ACTION_TYPE_SETTLE => '结算',
-            self::ACTION_TYPE_CANCEL => '取消',
-            self::ACTION_TYPE_CHECK => '检查',
-            self::ACTION_TYPE_RESULT => '结果'
-        ];
-        
-        return $actionTypeMap[$actionType] ?? '其他';
-    }
-        
-    /**
-     * 获取游戏名称
-     */
-    private static function getGameName($gameId)
-    {
-        // 这里可以根据实际情况配置游戏ID对应的名称
-        $gameNames = [
-            'tiger' => '老虎机',
-            'fortue_tiger' => '财富老虎',
-            'dragon_tiger' => '龙虎斗',
-            'baccarat' => '百家乐',
-            // 可以继续添加其他游戏
-        ];
-        
-        return $gameNames[$gameId] ?? $gameId;
-    }
-}

+ 0 - 244
app/model/GameRecordModel.php

@@ -1,244 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\model;
-
-use think\Model;
-use think\facade\Db;
-
-/**
- * 游戏记录模型 - 基于tp_game_bet_game表
- */
-class GameRecordModel extends Model
-{
-    protected $name = 'game_bet_game';
-    protected $connection = 'fortue_tiger';
-    protected $pk = 'id';
-    
-    // 动作类型常量
-    const ACTION_TYPE_BET = 1;      // 下注
-    const ACTION_TYPE_RESULT = 2;   // 结算
-    
-    // 状态常量
-    const STATUS_PENDING = 0;       // 待处理
-    const STATUS_SUCCESS = 1;       // 成功
-    const STATUS_FAILED = 2;        // 失败
-    
-    // 游戏类型常量
-    const GAME_TYPE_SLOT = 1;       // 老虎机
-    const GAME_TYPE_TABLE = 2;      // 桌面游戏
-    const GAME_TYPE_LIVE = 3;       // 真人游戏
-    
-    /**
-     * 获取游戏记录列表(参考apiAdminBetGameList方法)
-     */
-    public static function getBetGameList($appId, $page = 1, $limit = 20, $filters = [])
-    {
-        $wheres = [];
-        $wheres[] = ['action_type', '=', 1]; // 只查询下注记录
-        $wheres[] = ['app_id', '=', $appId];
-        
-        // 时间筛选
-        if (!empty($filters['start_time'])) {
-            $startTime = strtotime($filters['start_time'] . ' 00:00:00');
-            $wheres[] = ['create_time', '>=', $startTime];
-        }
-        
-        if (!empty($filters['end_time'])) {
-            $endTime = strtotime($filters['end_time'] . ' 23:59:59');
-            $wheres[] = ['create_time', '<=', $endTime];
-        }
-        
-        // 游戏ID筛选
-        if (!empty($filters['game_id'])) {
-            $wheres[] = ['game_id', '=', $filters['game_id']];
-        }
-        
-        // 牌局编号筛选
-        if (!empty($filters['third_round_id'])) {
-            $wheres[] = ['third_round_id', '=', $filters['third_round_id']];
-        }
-        
-        // 用户ID筛选
-        if (!empty($filters['player_id'])) {
-            $wheres[] = ['user_id', '=', $filters['user_id']];
-        }
-        
-        // 游戏玩法类型筛选
-        if (!empty($filters['bet_game_play_type'])) {
-            if ($filters['bet_game_play_type'] == 2) {
-                $wheres[] = ['bet_game_play_type', 'in', [1, 2]];
-            } else {
-                $wheres[] = ['bet_game_play_type', '=', $filters['bet_game_play_type']];
-            }
-        }
-        
-        $query = self::where($wheres);
-        
-        // 统计总数
-        $total = $query->count();
-        
-        // 获取列表数据(不包含result字段)
-        $list = $query->withoutField('result')
-            ->order('id', 'desc')
-            ->page($page, $limit)
-            ->select()
-            ->toArray();
-        
-        if (empty($list)) {
-            return [
-                'list' => [],
-                'total' => $total,
-                'page' => $page,
-                'limit' => $limit
-            ];
-        }
-                
-        return [
-            'list' => $list,
-            'total' => $total,
-            'page' => $page,
-            'limit' => $limit
-        ];
-    }
-    
-    /**
-     * 获取子订单列表(action_type = 2的记录)
-     */
-    public static function getChildBetGameOrders($thirdGids, $appId)
-    {
-        if (empty($thirdGids)) {
-            return [];
-        }
-        
-        $childOrders = self::where([
-                ['third_gid', 'in', $thirdGids],
-                ['action_type', '=', 2],
-                ['app_id', '=', $appId]
-            ])
-            ->withoutField('result')
-            ->select()
-            ->toArray();
-        
-        return $childOrders;
-    }
-    
-    /**
-     * 获取商户信息映射
-     */
-    private static function getMerchantsInfoMap($appIds)
-    {
-        if (empty($appIds)) {
-            return [];
-        }
-        
-        // 这里可以从商户表获取信息,暂时返回基本信息
-        $map = [];
-        foreach ($appIds as $appId) {
-            $map[$appId] = [
-                'app_id' => $appId,
-                'nickname' => '商户' . $appId
-            ];
-        }
-        
-        return $map;
-    }
-        
-    /**
-     * 获取游戏记录详情
-     */
-    public static function getGameRecordDetail($id, $appId)
-    {
-        $record = self::where('id', $id)
-            ->where('app_id', $appId)
-            ->find();
-            
-        if (!$record) {
-            return null;
-        }
-        
-        $record = $record->toArray();
-        
-        // 获取商户信息
-        $merchantsMap = self::getMerchantsInfoMap([$record['app_id']]);
-        $record = self::formatBetGameData($record, $merchantsMap);
-        
-        // 获取相关的子订单
-        if (!empty($record['third_gid'])) {
-            $childOrders = self::getChildBetGameOrders([$record['third_gid']], $appId);
-            $record['children'] = $childOrders;
-        }
-        
-        return $record;
-    }
-    
-    /**
-     * 获取游戏统计信息
-     */
-    public static function getGameStatistics($appId, $filters = [])
-    {
-        $where = [
-            ['app_id', '=', $appId],
-            ['action_type', '=', 1]
-        ];
-        
-        // 时间筛选
-        if (!empty($filters['start_time'])) {
-            $startTime = strtotime($filters['start_time'] . ' 00:00:00');
-            $where[] = ['create_time', '>=', $startTime];
-        }
-        
-        if (!empty($filters['end_time'])) {
-            $endTime = strtotime($filters['end_time'] . ' 23:59:59');
-            $where[] = ['create_time', '<=', $endTime];
-        }
-        
-        $statistics = self::where($where)
-            ->field([
-                'COUNT(*) as total_records',
-                'COUNT(DISTINCT uname) as total_players',
-                'SUM(bet) as total_bet_amount',
-                'SUM(total_win_amount) as total_win_amount',
-                'COUNT(DISTINCT game_id) as total_games'
-            ])
-            ->find()
-            ->toArray();
-        
-        // 格式化金额
-        $statistics['total_bet_amount_yuan'] = self::convertBalance($statistics['total_bet_amount']);
-        $statistics['total_win_amount_yuan'] = self::convertBalance($statistics['total_win_amount']);
-        $net_amount = $statistics['total_bet_amount'] - $statistics['total_win_amount'];
-        $statistics['net_amount_yuan'] = self::convertBalance($net_amount);
-        
-        // 计算RTP
-        if ($statistics['total_bet_amount'] > 0) {
-            $statistics['rtp'] = round(($statistics['total_win_amount'] / $statistics['total_bet_amount']) * 100, 2);
-        } else {
-            $statistics['rtp'] = 0;
-        }
-        
-        return $statistics;
-    }
-    
-    /**
-     * 获取所有游戏ID列表
-     */
-    public static function getAllGameIds($appId)
-    {
-        return self::where('app_id', $appId)
-            ->where('action_type', 1)
-            ->distinct(true)
-            ->column('game_id');
-    }
-    
-    /**
-     * 获取所有游戏玩法列表
-     */
-    public static function getAllPlayMethods($appId)
-    {
-        return self::where('app_id', $appId)
-            ->where('action_type', 1)
-            ->distinct(true)
-            ->column('bet_game_play_type');
-    }
-}