GameStatis.php 10 KB

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