GameRecord.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\controller;
  4. use app\BaseController;
  5. use think\facade\Request;
  6. use app\model\GameBetGameModel;
  7. use app\model\GameModel;
  8. use app\common\CommonUtils;
  9. /**
  10. * 游戏记录控制器
  11. */
  12. class GameRecord extends BaseController
  13. {
  14. /**
  15. * 获取游戏记录列表
  16. */
  17. public function list()
  18. {
  19. $userInfo = $this->request->userInfo;
  20. // 获取查询参数
  21. $page = Request::get('page', 1, 'intval');
  22. $limit = Request::get('limit', 20, 'intval');
  23. // 筛选条件
  24. $filters = [
  25. // 时间筛选
  26. 'start_time' => Request::get('start_time', '', 'trim'),
  27. 'end_time' => Request::get('end_time', '', 'trim'),
  28. // 游戏筛选
  29. 'game_id' => Request::get('game_id', '', 'trim'),
  30. // 牌局编号筛选
  31. 'third_round_id' => Request::get('third_round_id', '', 'trim'),
  32. // 平台ID筛选
  33. 'uname' => Request::get('uname', '', 'trim'),
  34. // 玩家ID筛选
  35. 'player_id' => Request::get('user_id', '', 'trim'),
  36. // 平台昵称
  37. 'nickname' => Request::get('nickname', '', 'trim'),
  38. // 游戏玩法类型筛选
  39. 'bet_game_play_type' => Request::get('bet_game_play_type', '', 'trim'),
  40. ];
  41. try {
  42. // 获取游戏记录列表
  43. $result = GameBetGameModel::getBetGameList($userInfo['merchant_id'], $page, $limit, $filters);
  44. if (empty($result['list'])) {
  45. return json_success($result, '获取成功');
  46. }
  47. // 获取游戏信息信息
  48. $game_ids = array_unique(array_column($result['list'], 'game_id'));
  49. $tempGameList = GameModel::where([['merchant_id', '=', $userInfo['merchant_id']], ['game_id', 'in', $game_ids]])->field(['game_id','title','image'])->select()->toArray();
  50. $gameList = [];
  51. foreach ($tempGameList as $item) {
  52. $game_id = $item['game_id'];
  53. $gameList[$game_id] = $item;
  54. }
  55. // 获取母单号列表
  56. $thirdGids = array_unique(array_column($result['list'], 'third_gid'));
  57. $childOrderList = [];
  58. if(count($thirdGids) > 0) {
  59. $tempCheckList = GameBetGameModel::where([ ['third_gid', 'in', $thirdGids], ['action_type','=',2] ])->withoutField('result')->select()->toArray();
  60. foreach ($tempCheckList as $item) {
  61. if(!isset($childOrderList[$item['third_gid']])) {
  62. $childOrderList[$item['third_gid']] = [];
  63. }
  64. $item = $this->formatItemDataText($item);
  65. $item['id'] = 'm_' . $item['id'];
  66. $childOrderList[$item['third_gid']][] = $item;
  67. }
  68. }
  69. // 格式化数据并添加子订单
  70. $newDataList = [];
  71. foreach ($result['list'] as $item) {
  72. $thirdGid = $item['third_gid'];
  73. $game_id = $item['game_id'];
  74. $gameInfo = $gameInfoMap[$item['game_id']] ?? [];
  75. if (!empty($gameInfo))
  76. {
  77. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  78. }
  79. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  80. $item['game_title'] = $gameInfo['title'] ?? '';
  81. $item['game_type_text'] = CommonUtils::getGameTypeConfig($item['game_type']);
  82. if(isset($childOrderList[$thirdGid])) {
  83. $item['children'] = [];
  84. $childList = $childOrderList[$thirdGid];
  85. foreach ($childList as $citem) {
  86. $citem['game_type_text'] = $item['game_type_text'];
  87. $citem['game_image_url'] = $item['game_image_url'];
  88. $citem['game_title'] = $item['game_title'];
  89. $item['children'][] = $citem;
  90. }
  91. }
  92. $item['c_count'] = count($childOrderList[$thirdGid] ?? []);
  93. $item['view_layout_url'] = "/history/{$game_id}.html?sid={$thirdGid}&pf=1&lang=zh&api=".Request::host()."%2Fweb-api%2Fgame-proxy%2Fv2%2FBetDetails%2FGet";
  94. $newDataList[] = $item;
  95. }
  96. $result['list'] = $newDataList;
  97. return json_success($result, '获取成功');
  98. } catch (\Exception $e) {
  99. echo $e->getTraceAsString();
  100. return json_error([], '获取游戏记录失败:' . $e->getMessage());
  101. }
  102. }
  103. /**
  104. * 导出游戏记录
  105. */
  106. public function export()
  107. {
  108. $userInfo = $this->request->userInfo;
  109. // 筛选条件
  110. $filters = [
  111. 'start_time' => Request::get('start_time', '', 'trim'),
  112. 'end_time' => Request::get('end_time', '', 'trim'),
  113. 'platform_id' => Request::get('platform_id', '', 'trim'),
  114. 'game_id' => Request::get('game_id', '', 'trim'),
  115. 'play_status' => Request::get('play_status', ''),
  116. 'play_method' => Request::get('play_method', '', 'trim'),
  117. 'trigger_method' => Request::get('trigger_method', '', 'trim'),
  118. 'round_number' => Request::get('round_number', '', 'trim'),
  119. ];
  120. try {
  121. // 获取所有符合条件的数据(不分页)
  122. $result = GameBetGameModel::getGameRecords($userInfo['merchant_id'], 1, 100000, $filters);
  123. // 获取游戏信息映射
  124. $gameIds = array_unique(array_column($result['list'], 'game_id'));
  125. $gameInfoMap = $this->getGameInfoMap($gameIds, $userInfo['merchant_id']);
  126. // 生成CSV数据
  127. $csvData = "序号,父局号,牌局ID,创建时间,牌局编号,平台昵称,玩家ID,所属商户," .
  128. "平台ID,游戏名称,游戏玩法,调控状态,免费触发,RTP,下注金额," .
  129. "应下注,应返奖,玩家输赢,下注前,结算后,总输赢,最后结算金额,操作\n";
  130. foreach ($result['list'] as $index => $record) {
  131. $gameInfo = $gameInfoMap[$record['game_id']] ?? null;
  132. $gameName = $gameInfo ? $gameInfo['title'] : $this->getGameName($record['game_id']);
  133. $csvData .= sprintf(
  134. "%d,%s,%s,%s,%s,%s,%d,%s,%d,%s,%s,%s,%s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%s\n",
  135. $index + 1, // 序号
  136. $record['third_gid'], // 父局号
  137. $record['id'], // 牌局ID
  138. $record['create_time_text'], // 创建时间
  139. $record['third_round_id'], // 牌局编号
  140. $record['nickname'], // 平台昵称
  141. $record['uname'], // 玩家ID
  142. $userInfo['merchant_id'], // 所属商户
  143. $record['user_id'], // 平台ID
  144. $gameName, // 游戏名称
  145. $this->getPlayMethodName($record['bet_game_play_type']), // 游戏玩法
  146. $record['status_text'], // 调控状态
  147. '', // 免费触发(暂时为空)
  148. '', // RTP(暂时为空)
  149. $record['bet_amount_yuan'], // 下注金额
  150. 0.00, // 应下注
  151. 0.00, // 应返奖
  152. $record['amount_yuan'], // 玩家输赢
  153. $record['prev_amount_yuan'], // 下注前
  154. $record['next_amount_yuan'], // 结算后
  155. $record['amount_yuan'], // 总输赢
  156. $record['balance_amount_yuan'], // 最后结算金额
  157. $record['action_type_text'] // 操作
  158. );
  159. }
  160. // 返回CSV数据
  161. return response($csvData)
  162. ->header(['Content-Type' => 'text/csv; charset=utf-8'])
  163. ->header(['Content-Disposition' => 'attachment; filename="game_records_' . date('YmdHis') . '.csv"'])
  164. ->header(['Cache-Control' => 'no-cache, must-revalidate']);
  165. } catch (\Exception $e) {
  166. return json_error([], '导出游戏记录失败:' . $e->getMessage());
  167. }
  168. }
  169. /**
  170. * 获取游戏名称
  171. */
  172. private function getGameName($gameId)
  173. {
  174. // 这里可以根据实际情况配置游戏ID对应的名称
  175. $gameNames = [
  176. 'tiger' => '老虎机',
  177. 'fortue_tiger' => '财富老虎',
  178. // 可以继续添加其他游戏
  179. ];
  180. return $gameNames[$gameId] ?? $gameId;
  181. }
  182. /**
  183. * 获取玩法名称
  184. */
  185. private function getPlayMethodName($methodId)
  186. {
  187. // 这里可以根据实际情况配置玩法ID对应的名称
  188. $methodNames = [
  189. 1 => '普通模式',
  190. 2 => '免费模式',
  191. 3 => '特殊模式',
  192. // 可以继续添加其他玩法
  193. ];
  194. return $methodNames[$methodId] ?? '未知玩法';
  195. }
  196. /**
  197. * 获取游戏信息映射
  198. */
  199. private function getGameInfoMap($gameIds, $merchantId)
  200. {
  201. if (empty($gameIds)) {
  202. return [];
  203. }
  204. $gameInfos = GameModel::whereIn('game_id', $gameIds)
  205. ->where('merchant_id', $merchantId)
  206. ->field(['game_id', 'title', 'title_en', 'image', 'image_en'])
  207. ->select()
  208. ->toArray();
  209. $map = [];
  210. foreach ($gameInfos as $gameInfo) {
  211. $map[$gameInfo['game_id']] = $gameInfo;
  212. }
  213. return $map;
  214. }
  215. // 格式化信息
  216. private function formatItemDataText($item = [])
  217. {
  218. $item['bet'] = CommonUtils::convertBalance($item['bet'], false);
  219. $item['prev_amount'] = CommonUtils::convertBalance($item['prev_amount'], false);
  220. $item['next_amount'] = CommonUtils::convertBalance($item['next_amount'], false);
  221. $item['total_amount'] = COmmonUtils::convertBalance($item['total_amount'], false);
  222. $item['win_amount'] = COmmonUtils::convertBalance($item['win_amount'], false);
  223. $item['total_win_amount'] = COmmonUtils::convertBalance($item['total_win_amount'], false);
  224. $item['res_multiple'] = $item['res_multiple'] / 100;
  225. $item['bet_game_play_type'] = CommonUtils::getGamePlayType($item['bet_game_play_type']);
  226. return $item;
  227. }
  228. }