GameStatis.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\controller;
  4. use app\BaseController;
  5. use app\model\GameBetGameModel;
  6. use app\model\GameBetOrderModel;
  7. use app\model\GameStatisModel;
  8. use app\common\CommonUtils;
  9. use app\model\GameModel;
  10. use think\facade\Request;
  11. class GameStatis extends BaseController
  12. {
  13. /**
  14. * 获取游戏每日数据列表
  15. */
  16. public function Daily()
  17. {
  18. $userInfo = $this->request->userInfo;
  19. // 获取查询参数
  20. $page = Request::get('page', 1, 'intval');
  21. $limit = Request::get('limit', 10, 'intval');
  22. // 筛选条件
  23. $filters = [
  24. // 时间筛选
  25. 'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
  26. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  27. 'game_id' => Request::get('game_id', '', 'trim'),
  28. ];
  29. try {
  30. // 获取游戏每日数据
  31. $result = GameStatisModel::getGameDailyList(
  32. $userInfo['merchant_id'],
  33. $page,
  34. $limit,
  35. $filters,
  36. );
  37. // 获取游戏信息信息
  38. $game_ids = array_unique(array_column($result['list'], 'game_id'));
  39. $tempGameList = GameModel::where([['merchant_id', '=', $userInfo['merchant_id']], ['game_id', 'in', $game_ids]])
  40. ->field(['game_id','title','image', 'game_platform'])
  41. ->select()
  42. ->toArray();
  43. $gameList = [];
  44. foreach ($tempGameList as $game) {
  45. $game_id = $game['game_id'];
  46. $gameList[$game_id] = $game;
  47. }
  48. // 格式化数据
  49. foreach ($result['list'] as &$item) {
  50. $game_id = $item['game_id'];
  51. $gameInfo = $gameList[$game_id] ?? [];
  52. if (!empty($gameInfo))
  53. {
  54. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  55. }
  56. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  57. $item['game_title'] = $gameInfo['title'] ?? '';
  58. $item['game_type_text'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  59. $item['game_profit'] = CommonUtils::convertBalance($item['game_profit'], false);
  60. $item['bet_amount'] = CommonUtils::convertBalance($item['bet_amount'], false);
  61. $item['commission_amount'] = CommonUtils::convertBalance($item['game_profit'] * 0.08, false);
  62. $item['platform_fee'] = CommonUtils::convertBalance($item['bet_amount'] * 0.08, false);
  63. $item['buy_free_bet'] = intval($item['buy_free_bet_count'] ?? 0);
  64. }
  65. return json_success($result, '获取成功');
  66. } catch (\Exception $e) {
  67. return json_error([], '获取游戏每日数据失败:' . $e->getMessage());
  68. }
  69. }
  70. /**
  71. * 游戏输赢汇总
  72. */
  73. public function Summary()
  74. {
  75. $userInfo = $this->request->userInfo;
  76. // 获取查询参数
  77. $page = Request::get('page', 1, 'intval');
  78. $limit = Request::get('limit', 10, 'intval');
  79. // 筛选条件
  80. $filters = [
  81. 'start_time' => Request::get('start_time', date('Y-m-d'), 'trim'),
  82. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  83. 'game_id' => Request::get('game_id', '', 'trim'),
  84. ];
  85. try {
  86. // 获取游戏汇总数据
  87. $result = GameStatisModel::getGameSummary(
  88. $userInfo['merchant_id'],
  89. $page,
  90. $limit,
  91. $filters
  92. );
  93. // 获取游戏信息
  94. if (!empty($result['list'])) {
  95. $game_ids = array_unique(array_column($result['list'], 'game_id'));
  96. $tempGameList = GameModel::where([
  97. ['merchant_id', '=', $userInfo['merchant_id']],
  98. ['game_id', 'in', $game_ids]
  99. ])
  100. ->field(['game_id','title','image', 'game_platform', 'rtp'])
  101. ->select()
  102. ->toArray();
  103. $gameList = [];
  104. foreach ($tempGameList as $game) {
  105. $game_id = $game['game_id'];
  106. $gameList[$game_id] = $game;
  107. }
  108. // 格式化数据
  109. foreach ($result['list'] as &$item) {
  110. $game_id = $item['game_id'];
  111. $gameInfo = $gameList[$game_id] ?? [];
  112. if (!empty($gameInfo))
  113. {
  114. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  115. }
  116. // 游戏信息
  117. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  118. $item['game_title'] = $gameInfo['title'] ?? '未知游戏';
  119. $item['game_platform'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  120. $item['rtp'] = $gameInfo['rtp'] ?? '';
  121. // 计算游戏RTP
  122. $item['game_rtp'] = calculateRTP($item['total_score'], $item['total_bet']);
  123. // 格式化数据
  124. $item['game_id'] = (int) $item['game_id'];
  125. $item['buy_game_amount'] = (int) $item['buy_game_amount'];
  126. $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
  127. $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
  128. $item['total_score'] = CommonUtils::convertBalance($item['total_score'], false);
  129. // 计算历史游戏RTP
  130. if (isset($result['history'][$game_id])) {
  131. $history = $result['history'][$game_id];
  132. $item['history_rtp'] = calculateRTP($history['total_score'], $history['total_bet']);
  133. } else {
  134. $item['history_rtp'] = 0;
  135. }
  136. }
  137. }
  138. // 计算汇总数据
  139. $summary = [
  140. 'total_bet' => CommonUtils::convertBalance($result['summary']['total_bet'], false),
  141. 'total_bet_count' => $result['summary']['total_bet_count'],
  142. 'total_win' => CommonUtils::convertBalance($result['summary']['total_win'], false),
  143. 'total_user_count' => $result['summary']['total_user_count'],
  144. ];
  145. return json_success([
  146. 'list' => $result['list'],
  147. 'total' => $result['total'],
  148. 'page' => $page,
  149. 'limit' => $limit,
  150. 'summary' => $summary
  151. ], '获取成功');
  152. } catch (\Exception $e) {
  153. echo $e->getTraceAsString();
  154. return json_error([], '获取游戏汇总数据失败:' . $e->getMessage());
  155. }
  156. }
  157. /**
  158. * 档位押注数据
  159. */
  160. public function BetLevel()
  161. {
  162. $userInfo = $this->request->userInfo;
  163. // 获取查询参数
  164. $page = Request::get('page', 1, 'intval');
  165. $limit = Request::get('limit', 10, 'intval');
  166. // 筛选条件
  167. $filters = [
  168. 'start_time' => Request::get('start_time', date('Y-m-d'), 'trim'),
  169. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  170. 'game_id' => Request::get('game_id', '', 'trim'),
  171. ];
  172. try {
  173. // 获取档位押注数据
  174. $result = GameStatisModel::getBetLevelData(
  175. $userInfo['merchant_id'],
  176. $page,
  177. $limit,
  178. $filters
  179. );
  180. // 获取游戏信息
  181. if (!empty($result['list'])) {
  182. $game_ids = array_unique(array_column($result['list'], 'game_id'));
  183. $tempGameList = GameModel::where([
  184. ['merchant_id', '=', $userInfo['merchant_id']],
  185. ['game_id', 'in', $game_ids]
  186. ])
  187. ->field(['game_id','title','image', 'game_platform'])
  188. ->select()
  189. ->toArray();
  190. $gameList = [];
  191. foreach ($tempGameList as $game) {
  192. $game_id = $game['game_id'];
  193. $gameList[$game_id] = $game;
  194. }
  195. // 格式化数据
  196. foreach ($result['list'] as &$item) {
  197. $game_id = $item['game_id'];
  198. $gameInfo = $gameList[$game_id] ?? [];
  199. if (!empty($gameInfo))
  200. {
  201. $gameImages = CommonUtils::getGameDefaultImage($gameInfo);
  202. }
  203. // 游戏信息
  204. $item['game_image_url'] = $gameImages['image_url'] ?? '';
  205. $item['game_title'] = $gameInfo['title'] ?? '未知游戏';
  206. $item['game_platform'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  207. // 游戏RTP
  208. $item['game_rtp'] = calculateRTP($item['total_score'], $item['total_bet']);
  209. $item['bet'] = CommonUtils::convertBalance($item['bet'], false);
  210. $item['total_bet_rate'] = bcmul(bcdiv($item['total_bet'], $result['total_stats']['total_bet_all'], 4), "100", 2);
  211. $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
  212. $item['bet_count_rate'] = bcmul(bcdiv((string)$item['bet_count'], (string)$result['total_stats']['total_count_all'], 4), "100", 2);
  213. $item['bet_count'] = ($item['bet_count']);
  214. // 游戏输赢
  215. $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
  216. // 游戏返奖
  217. $item['total_score'] = CommonUtils::convertBalance($item['total_score'], false);
  218. }
  219. }
  220. return json_success([
  221. 'list' => $result['list'],
  222. 'total' => $result['total'],
  223. 'page' => $page,
  224. 'limit' => $limit
  225. ], '获取成功');
  226. } catch (\Exception $e) {
  227. return json_error([], '获取档位押注数据失败:' . $e->getMessage());
  228. }
  229. }
  230. }