GameRecord.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 = $gameList[$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. $item['c_count'] = count($childOrderList[$thirdGid] ?? []);
  84. $item['view_layout_url'] = $GLOBALS['gameGameLayoutDomain'] . "/{$game_id}.html?sid={$thirdGid}&pf=1&lang=zh&api=".Request::host()."%2Fweb-api%2Fgame-proxy%2Fv2%2FBetDetails%2FGet";
  85. $children = [];
  86. if (isset($childOrderList[$thirdGid])) {
  87. $childList = $childOrderList[$thirdGid];
  88. foreach ($childList as $citem) {
  89. $citem['game_type_text'] = $item['game_type_text'];
  90. $citem['game_image_url'] = $item['game_image_url'];
  91. $citem['game_title'] = $item['game_title'];
  92. $children[] = $citem;
  93. }
  94. }
  95. $newDataList[] = $item;
  96. $newDataList = array_merge($newDataList, $children);
  97. }
  98. $result['list'] = $newDataList;
  99. if ($compress == 1)
  100. {
  101. $return = [
  102. 'state' => 1,
  103. 'code' => 0,
  104. 'data' => $result,
  105. 'message' => "获取成功"
  106. ];
  107. return base64_encode(gzcompress(json_encode($return)));
  108. }
  109. return json_success($result, '获取成功');
  110. } catch (\Exception $e) {
  111. return json_error([], '获取游戏记录失败:' . $e->getMessage());
  112. }
  113. }
  114. public function layout()
  115. {
  116. $game_id = Request::param('gid', '');
  117. $sid = Request::param('sid', '');
  118. if (empty($game_id) || empty($sid)) {
  119. return CommonUtils::gameJsonError();
  120. }
  121. $model = new GameBetGameModel();
  122. $wheres = [
  123. ['game_id', '=', $game_id],
  124. ['third_round_id', '=', $sid],
  125. ['action_type', '=', 1],
  126. ];
  127. $bet_game_info = $model->where($wheres)->find();
  128. if (empty($bet_game_info)) {
  129. return CommonUtils::gameJsonError();
  130. }
  131. $bet_game_info = $bet_game_info->toArray();
  132. $dataList = [$bet_game_info];
  133. $result = json_decode($bet_game_info['result'],true);
  134. $ge = [];
  135. foreach ($result as $key => $res) {
  136. $ge = array_merge($ge, $res['ge']);
  137. }
  138. $ge = array_values(array_unique($ge));
  139. array_map(function ($value) {
  140. return $value * 1;
  141. }, $ge);
  142. $thirdGidList = array_column($dataList, 'third_gid');
  143. $newFilter = [
  144. ['third_gid', 'in', $thirdGidList],
  145. ['action_type','=', 2],
  146. ];
  147. $tempDataList = $model->where($newFilter)->select()->toArray();
  148. $childDataConfig = [];
  149. foreach ($tempDataList as $item) {
  150. $third_gid = $item['third_gid'];
  151. if(!isset($childDataConfig[$third_gid])) {
  152. $childDataConfig[$third_gid]= [];
  153. }
  154. $childDataConfig[$third_gid][] = $item;
  155. }
  156. $newDataList = [];
  157. foreach ($dataList as $item) {
  158. $third_gid = $item['third_gid'];
  159. $result = json_decode($item['result'], true);
  160. $ge = [];
  161. foreach ($result as $key => $res) {
  162. $ge = array_merge($ge, $res['ge']);
  163. }
  164. $ge = array_values( array_unique($ge));
  165. array_map(function ($value) {
  166. return $value * 1;
  167. }, $ge);
  168. $childData = $childDataConfig[$third_gid] ?? [];
  169. if (!empty($result) && count($result) > 0){
  170. $firstResult = $result[0];
  171. $tempItem = array_merge($item, [
  172. 'result' => json_encode($firstResult),
  173. ]);
  174. array_unshift($childData, $tempItem);
  175. }
  176. $mgcc = 0;
  177. $bd = [];
  178. foreach ($childData as $index => $citem) {
  179. $result = json_decode($citem['result'], true);
  180. $result['cs'] *= 1;
  181. $result['ml'] *= 1;
  182. if($result['nst'] == 4) {
  183. $mgcc += 1;
  184. }
  185. $bd[] = [
  186. 'bl' => CommonUtils::convertBalance( $citem['balance_amount'], false),
  187. 'bt' => strtotime($citem['create_time']) * 1000,
  188. 'tba' => CommonUtils::convertBalance( $citem['bet'], false),
  189. 'twla' => CommonUtils::convertBalance( $citem['win_amount'], false),
  190. 'tid' => $citem['third_round_id'],
  191. 'gd' => array_merge(CommonUtils::formatResultData($result, false), [
  192. 'bl' => CommonUtils::convertBalance( $item['balance_amount'], false),
  193. 'blb' => CommonUtils::convertBalance( $item['prev_amount'], false),
  194. 'blab' => CommonUtils::convertBalance( $item['next_amount'], false),
  195. 'irs' => $result['irs'] ?? null,
  196. 'sid' => $citem['third_round_id'],
  197. 'psid' => $item['third_round_id'],
  198. ])
  199. ];
  200. }
  201. $newDataList[] = [
  202. 'bd' => $bd,
  203. 'bt' => strtotime($item['create_time']) * 1000,
  204. 'cc' => '',
  205. 'fscc' => 0,
  206. 'ge' => $ge,
  207. 'gid' => $item['game_id'],
  208. 'gtba' => CommonUtils::convertBalance( $item['bet'], false),
  209. 'gtwla' => CommonUtils::convertBalance( $item['total_win_amount'], false),
  210. 'mgcc' => $mgcc,
  211. 'tid' => $third_gid
  212. ];
  213. }
  214. return CommonUtils::gameJsonSuccess([
  215. 'bh' => $newDataList[0]
  216. ]);
  217. }
  218. // 格式化信息
  219. private function formatItemDataText($item = [])
  220. {
  221. $item['bet'] = CommonUtils::convertBalance($item['bet'], false);
  222. $item['prev_amount'] = CommonUtils::convertBalance($item['prev_amount'], false);
  223. $item['next_amount'] = CommonUtils::convertBalance($item['next_amount'], false);
  224. $item['total_amount'] = COmmonUtils::convertBalance($item['total_amount'], false);
  225. $item['win_amount'] = COmmonUtils::convertBalance($item['win_amount'], false);
  226. $item['total_win_amount'] = COmmonUtils::convertBalance($item['total_win_amount'], false);
  227. $item['res_multiple'] = $item['res_multiple'] / 100;
  228. $item['bet_game_play_type'] = CommonUtils::getGamePlayType($item['bet_game_play_type']);
  229. return $item;
  230. }
  231. }