| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <?php
- declare (strict_types = 1);
- namespace app\controller;
- use app\BaseController;
- use think\facade\Request;
- use app\model\GameBetGameModel;
- use app\model\GameModel;
- use app\common\CommonUtils;
- /**
- * 游戏记录控制器
- */
- class GameRecord extends BaseController
- {
- /**
- * 获取游戏记录列表
- */
- public function list()
- {
- $userInfo = $this->request->userInfo;
-
- // 获取查询参数
- $page = Request::get('page', 1, 'intval');
- $limit = Request::get('limit', 20, 'intval');
-
- // 筛选条件
- $filters = [
- // 时间筛选
- 'start_time' => Request::get('start_time', '', 'trim'),
- 'end_time' => Request::get('end_time', '', 'trim'),
- // 游戏筛选
- 'game_id' => Request::get('game_id', '', 'trim'),
- // 牌局编号筛选
- 'third_round_id' => Request::get('third_round_id', '', 'trim'),
- // 平台ID筛选
- 'uname' => Request::get('uname', '', 'trim'),
- // 玩家ID筛选
- 'player_id' => Request::get('user_id', '', 'trim'),
- // 平台昵称
- 'nickname' => Request::get('nickname', '', 'trim'),
- // 游戏玩法类型筛选
- 'bet_game_play_type' => Request::get('bet_game_play_type', '', 'trim'),
- ];
-
- try {
- // 获取游戏记录列表
- $result = GameBetGameModel::getBetGameList($userInfo['merchant_id'], $page, $limit, $filters);
-
- if (empty($result['list'])) {
- return json_success($result, '获取成功');
- }
-
-
- // 获取游戏信息信息
- $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;
- }
-
- // 获取母单号列表
- $thirdGids = array_unique(array_column($result['list'], 'third_gid'));
- $childOrderList = [];
- if(count($thirdGids) > 0) {
- $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']] = [];
- }
- $item = $this->formatItemDataText($item);
- $item['id'] = 'm_' . $item['id'];
- $childOrderList[$item['third_gid']][] = $item;
- }
- }
-
- // 格式化数据并添加子订单
- $newDataList = [];
- foreach ($result['list'] as $item) {
- $thirdGid = $item['third_gid'];
- $game_id = $item['game_id'];
- $gameInfo = $gameInfoMap[$item['game_id']] ?? [];
- if (!empty($gameInfo))
- {
- $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
- }
- $item['game_image_url'] = $gameImages['image_url'] ?? '';
- $item['game_title'] = $gameInfo['title'] ?? '';
- $item['game_type_text'] = CommonUtils::getGameTypeConfig($item['game_type']);
-
- if(isset($childOrderList[$thirdGid])) {
- $item['children'] = [];
- $childList = $childOrderList[$thirdGid];
- foreach ($childList as $citem) {
- $citem['game_type_text'] = $item['game_type_text'];
- $citem['game_image_url'] = $item['game_image_url'];
- $citem['game_title'] = $item['game_title'];
- $item['children'][] = $citem;
- }
- }
- $item['c_count'] = count($childOrderList[$thirdGid] ?? []);
- $item['view_layout_url'] = "/history/{$game_id}.html?sid={$thirdGid}&pf=1&lang=zh&api=".Request::host()."%2Fweb-api%2Fgame-proxy%2Fv2%2FBetDetails%2FGet";
- $newDataList[] = $item;
- }
-
- $result['list'] = $newDataList;
- return json_success($result, '获取成功');
- } catch (\Exception $e) {
- echo $e->getTraceAsString();
- return json_error([], '获取游戏记录失败:' . $e->getMessage());
- }
- }
-
-
- /**
- * 导出游戏记录
- */
- public function export()
- {
- $userInfo = $this->request->userInfo;
-
- // 筛选条件
- $filters = [
- 'start_time' => Request::get('start_time', '', 'trim'),
- 'end_time' => Request::get('end_time', '', 'trim'),
- 'platform_id' => Request::get('platform_id', '', 'trim'),
- 'game_id' => Request::get('game_id', '', 'trim'),
- 'play_status' => Request::get('play_status', ''),
- 'play_method' => Request::get('play_method', '', 'trim'),
- 'trigger_method' => Request::get('trigger_method', '', 'trim'),
- 'round_number' => Request::get('round_number', '', 'trim'),
- ];
-
- try {
- // 获取所有符合条件的数据(不分页)
- $result = GameBetGameModel::getGameRecords($userInfo['merchant_id'], 1, 100000, $filters);
-
- // 获取游戏信息映射
- $gameIds = array_unique(array_column($result['list'], 'game_id'));
- $gameInfoMap = $this->getGameInfoMap($gameIds, $userInfo['merchant_id']);
-
- // 生成CSV数据
- $csvData = "序号,父局号,牌局ID,创建时间,牌局编号,平台昵称,玩家ID,所属商户," .
- "平台ID,游戏名称,游戏玩法,调控状态,免费触发,RTP,下注金额," .
- "应下注,应返奖,玩家输赢,下注前,结算后,总输赢,最后结算金额,操作\n";
-
- foreach ($result['list'] as $index => $record) {
- $gameInfo = $gameInfoMap[$record['game_id']] ?? null;
- $gameName = $gameInfo ? $gameInfo['title'] : $this->getGameName($record['game_id']);
-
- $csvData .= sprintf(
- "%d,%s,%s,%s,%s,%s,%d,%s,%d,%s,%s,%s,%s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%s\n",
- $index + 1, // 序号
- $record['third_gid'], // 父局号
- $record['id'], // 牌局ID
- $record['create_time_text'], // 创建时间
- $record['third_round_id'], // 牌局编号
- $record['nickname'], // 平台昵称
- $record['uname'], // 玩家ID
- $userInfo['merchant_id'], // 所属商户
- $record['user_id'], // 平台ID
- $gameName, // 游戏名称
- $this->getPlayMethodName($record['bet_game_play_type']), // 游戏玩法
- $record['status_text'], // 调控状态
- '', // 免费触发(暂时为空)
- '', // RTP(暂时为空)
- $record['bet_amount_yuan'], // 下注金额
- 0.00, // 应下注
- 0.00, // 应返奖
- $record['amount_yuan'], // 玩家输赢
- $record['prev_amount_yuan'], // 下注前
- $record['next_amount_yuan'], // 结算后
- $record['amount_yuan'], // 总输赢
- $record['balance_amount_yuan'], // 最后结算金额
- $record['action_type_text'] // 操作
- );
- }
-
- // 返回CSV数据
- return response($csvData)
- ->header(['Content-Type' => 'text/csv; charset=utf-8'])
- ->header(['Content-Disposition' => 'attachment; filename="game_records_' . date('YmdHis') . '.csv"'])
- ->header(['Cache-Control' => 'no-cache, must-revalidate']);
-
- } catch (\Exception $e) {
- return json_error([], '导出游戏记录失败:' . $e->getMessage());
- }
- }
-
- /**
- * 获取游戏名称
- */
- private function getGameName($gameId)
- {
- // 这里可以根据实际情况配置游戏ID对应的名称
- $gameNames = [
- 'tiger' => '老虎机',
- 'fortue_tiger' => '财富老虎',
- // 可以继续添加其他游戏
- ];
-
- return $gameNames[$gameId] ?? $gameId;
- }
-
- /**
- * 获取玩法名称
- */
- private function getPlayMethodName($methodId)
- {
- // 这里可以根据实际情况配置玩法ID对应的名称
- $methodNames = [
- 1 => '普通模式',
- 2 => '免费模式',
- 3 => '特殊模式',
- // 可以继续添加其他玩法
- ];
-
- return $methodNames[$methodId] ?? '未知玩法';
- }
-
- /**
- * 获取游戏信息映射
- */
- private function getGameInfoMap($gameIds, $merchantId)
- {
- if (empty($gameIds)) {
- return [];
- }
-
- $gameInfos = GameModel::whereIn('game_id', $gameIds)
- ->where('merchant_id', $merchantId)
- ->field(['game_id', 'title', 'title_en', 'image', 'image_en'])
- ->select()
- ->toArray();
-
- $map = [];
- foreach ($gameInfos as $gameInfo) {
- $map[$gameInfo['game_id']] = $gameInfo;
- }
-
- return $map;
- }
- // 格式化信息
- private function formatItemDataText($item = [])
- {
- $item['bet'] = CommonUtils::convertBalance($item['bet'], false);
- $item['prev_amount'] = CommonUtils::convertBalance($item['prev_amount'], false);
- $item['next_amount'] = CommonUtils::convertBalance($item['next_amount'], false);
- $item['total_amount'] = COmmonUtils::convertBalance($item['total_amount'], false);
- $item['win_amount'] = COmmonUtils::convertBalance($item['win_amount'], false);
- $item['total_win_amount'] = COmmonUtils::convertBalance($item['total_win_amount'], false);
- $item['res_multiple'] = $item['res_multiple'] / 100;
- $item['bet_game_play_type'] = CommonUtils::getGamePlayType($item['bet_game_play_type']);
- return $item;
- }
- }
|