GameStatis.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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'] = $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_date' => Request::get('start_date', date('Y-m-d'), 'trim'),
  82. 'end_date' => Request::get('end_date', 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. // 游戏信息
  113. $item['game_title'] = $gameInfo['title'] ?? '未知游戏';
  114. $item['game_platform'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  115. $item['rtp'] = $gameInfo['rtp'] ?? '';
  116. // 计算游戏RTP
  117. $item['game_rtp'] = $item['total_bet'] > 0 ? bcdiv($item['total_score'], $item['total_bet'], 4) * 100 : 0;
  118. // 格式化数据
  119. $item['game_id'] = (int) $item['game_id'];
  120. $item['buy_game_amount'] = (int) $item['buy_game_amount'];
  121. $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
  122. $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
  123. $item['total_score'] = CommonUtils::convertBalance($item['total_score'], false);
  124. // 计算历史游戏RTP
  125. if (isset($result['history'][$game_id])) {
  126. $history = $result['history'][$game_id];
  127. $item['history_rtp'] = (float) bcdiv($history['total_score'], $history['total_bet'], 4) * 100;
  128. } else {
  129. $item['history_rtp'] = 0;
  130. }
  131. }
  132. }
  133. // 计算汇总数据
  134. $summary = [
  135. 'total_bet' => CommonUtils::convertBalance($result['summary']['total_bet'], false),
  136. 'total_bet_count' => $result['summary']['total_bet_count'],
  137. 'total_win' => CommonUtils::convertBalance($result['summary']['total_win'], false),
  138. 'total_user_count' => $result['summary']['total_user_count'],
  139. ];
  140. return json_success([
  141. 'list' => $result['list'],
  142. 'total' => $result['total'],
  143. 'page' => $page,
  144. 'limit' => $limit,
  145. 'summary' => $summary
  146. ], '获取成功');
  147. } catch (\Exception $e) {
  148. return json_error([], '获取游戏汇总数据失败:' . $e->getMessage());
  149. }
  150. }
  151. /**
  152. * 档位押注数据
  153. */
  154. public function BetLevel()
  155. {
  156. $userInfo = $this->request->userInfo;
  157. // 获取查询参数
  158. $page = Request::get('page', 1, 'intval');
  159. $limit = Request::get('limit', 10, 'intval');
  160. // 筛选条件
  161. $filters = [
  162. 'start_date' => Request::get('start_date', date('Y-m-d'), 'trim'),
  163. 'end_date' => Request::get('end_date', date('Y-m-d'), 'trim'),
  164. 'game_id' => Request::get('game_id', '', 'trim'),
  165. ];
  166. try {
  167. // 获取档位押注数据
  168. $result = GameStatisModel::getBetLevelData(
  169. $userInfo['merchant_id'],
  170. $page,
  171. $limit,
  172. $filters
  173. );
  174. // 获取游戏信息
  175. if (!empty($result['list'])) {
  176. $game_ids = array_unique(array_column($result['list'], 'game_id'));
  177. $tempGameList = GameModel::where([
  178. ['merchant_id', '=', $userInfo['merchant_id']],
  179. ['game_id', 'in', $game_ids]
  180. ])
  181. ->field(['game_id','title', 'game_platform'])
  182. ->select()
  183. ->toArray();
  184. $gameList = [];
  185. foreach ($tempGameList as $game) {
  186. $game_id = $game['game_id'];
  187. $gameList[$game_id] = $game;
  188. }
  189. // 格式化数据
  190. foreach ($result['list'] as &$item) {
  191. $game_id = $item['game_id'];
  192. $gameInfo = $gameList[$game_id] ?? [];
  193. // 游戏信息
  194. $item['game_title'] = $gameInfo['title'] ?? '未知游戏';
  195. $item['game_platform'] = CommonUtils::getGameTypeConfig($gameInfo['game_platform']);
  196. // 游戏RTP
  197. $item['game_rtp'] = bcmul(bcdiv($item['total_score'], $item['total_bet'], 4), "100", 2);
  198. $item['bet'] = CommonUtils::convertBalance($item['bet'], false);
  199. $item['total_bet_rate'] = bcmul(bcdiv($item['total_bet'], $result['total_stats']['total_bet_all'], 4), "100", 2);
  200. $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
  201. $item['bet_count_rate'] = bcmul(bcdiv((string)$item['bet_count'], (string)$result['total_stats']['total_count_all'], 4), "100", 2);
  202. $item['bet_count'] = ($item['bet_count']);
  203. // 游戏输赢
  204. $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
  205. // 游戏返奖
  206. $item['total_score'] = CommonUtils::convertBalance($item['total_score'], false);
  207. }
  208. }
  209. return json_success([
  210. 'list' => $result['list'],
  211. 'total' => $result['total'],
  212. 'page' => $page,
  213. 'limit' => $limit
  214. ], '获取成功');
  215. } catch (\Exception $e) {
  216. return json_error([], '获取档位押注数据失败:' . $e->getMessage());
  217. }
  218. }
  219. }