GameRecord.php 10 KB

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