=', $startTime]; } if (!empty($filters['end_time'])) { $endTime = strtotime($filters['end_time'] . ' 23:59:59'); $where[] = ['create_time', '<=', $endTime]; } // 平台ID筛选 if (!empty($filters['platform_id'])) { $where[] = ['user_id', '=', $filters['platform_id']]; } // 游戏筛选 if (!empty($filters['game_id'])) { $where[] = ['game_id', '=', $filters['game_id']]; } // 玩家状态筛选 if ($filters['play_status'] !== '') { $where[] = ['status', '=', $filters['play_status']]; } // 玩法筛选 if (!empty($filters['play_method'])) { $where[] = ['bet_game_play_type', '=', $filters['play_method']]; } // 触发方式筛选 if (!empty($filters['trigger_method'])) { $where[] = ['action_type', '=', $filters['trigger_method']]; } // 牌局编号筛选 if (!empty($filters['round_number'])) { $where[] = ['third_round_id', 'like', '%' . $filters['round_number'] . '%']; } $query = self::where($where); // 统计总数 $total = $query->count(); // 获取列表数据 $list = $query->field([ 'id', 'user_id', 'uname', 'nickname', 'third_gid', 'third_round_id', 'game_id', 'game_type', 'bet_game_play_type', 'amount', 'bet_amount', 'prev_amount', 'next_amount', 'balance_amount', 'action_type', 'status', 'ip', 'create_time' ]) ->order('create_time', 'desc') ->page($page, $limit) ->select() ->toArray(); // 格式化数据 foreach ($list as &$item) { // 格式化金额(除以10000) $item['amount'] = bcdiv((string)$item['amount'], '10000', 2); $item['bet_amount'] = bcdiv((string)$item['bet_amount'], '10000', 2); $item['prev_amount'] = bcdiv((string)$item['prev_amount'], '10000', 2); $item['next_amount'] = bcdiv((string)$item['next_amount'], '10000', 2); $item['balance_amount'] = bcdiv((string)$item['balance_amount'], '10000', 2); // 状态文本 $item['status_text'] = self::getStatusText($item['status']); // 动作类型文本 $item['action_type_text'] = self::getActionTypeText($item['action_type']); } return [ 'list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit ]; } /** * 获取游戏记录详情 */ public static function getGameRecordDetail($id, $appId) { $record = self::where('id', $id) ->where('app_id', $appId) ->find(); if (!$record) { return null; } $record = $record->toArray(); // 格式化数据 $record['create_time_text'] = date('Y-m-d H:i:s', $record['create_time']); $record['update_time_text'] = date('Y-m-d H:i:s', $record['update_time']); // 格式化金额 $record['amount_yuan'] = bcdiv((string)$record['amount'], '10000', 2); $record['bet_amount_yuan'] = bcdiv((string)$record['bet_amount'], '10000', 2); $record['prev_amount_yuan'] = bcdiv((string)$record['prev_amount'], '10000', 2); $record['next_amount_yuan'] = bcdiv((string)$record['next_amount'], '10000', 2); $record['balance_amount_yuan'] = bcdiv((string)$record['balance_amount'], '10000', 2); // 状态文本 $record['status_text'] = self::getStatusText($record['status']); // 动作类型文本 $record['action_type_text'] = self::getActionTypeText($record['action_type']); // 解析开奖结果 $record['result_data'] = !empty($record['result']) ? json_decode($record['result'], true) : []; return $record; } /** * 获取游戏统计信息 */ public static function getGameStatistics($appId, $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]; } $statistics = self::where($where) ->field([ 'COUNT(*) as total_records', 'COUNT(DISTINCT uname) as total_players', 'SUM(CASE WHEN action_type = 1 THEN bet_amount ELSE 0 END) as total_bet_amount', 'SUM(CASE WHEN action_type = 2 THEN amount ELSE 0 END) as total_win_amount', 'SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as success_records', 'SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as failed_records' ]) ->find() ->toArray(); // 格式化金额 $statistics['total_bet_amount_yuan'] = bcdiv((string)$statistics['total_bet_amount'], '10000', 2); $statistics['total_win_amount_yuan'] = bcdiv((string)$statistics['total_win_amount'], '10000', 2); $net_amount = bcsub((string)$statistics['total_bet_amount'], (string)$statistics['total_win_amount']); $statistics['net_amount_yuan'] = bcdiv($net_amount, '10000', 2); // 计算成功率 if ($statistics['total_records'] > 0) { $rate = bcdiv((string)$statistics['success_records'], (string)$statistics['total_records'], 4); $statistics['success_rate'] = bcmul($rate, '100', 2); } else { $statistics['success_rate'] = '0.00'; } return $statistics; } /** * 获取所有游戏ID列表 */ public static function getAllGameIds($appId) { return self::where('app_id', $appId) ->distinct(true) ->column('game_id'); } /** * 获取所有游戏玩法列表 */ public static function getAllPlayMethods($appId) { return self::where('app_id', $appId) ->distinct(true) ->column('bet_game_play_type'); } /** * 获取状态文本 */ public static function getStatusText($status) { $statusMap = [ self::STATUS_PENDING => '待处理', self::STATUS_SUCCESS => '成功', self::STATUS_FAILED => '失败' ]; return $statusMap[$status] ?? '未知'; } /** * 获取动作类型文本 */ public static function getActionTypeText($actionType) { $actionTypeMap = [ self::ACTION_TYPE_BET => '下注', self::ACTION_TYPE_WIN => '中奖', self::ACTION_TYPE_RETURN => '退还' ]; return $actionTypeMap[$actionType] ?? '其他'; } }