=', $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'); } }