GameRecord.php 11 KB

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