TrendStatis.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\controller;
  4. use app\BaseController;
  5. use app\model\GameStatisModel;
  6. use app\model\TrendStatisModel;
  7. use app\common\CommonUtils;
  8. use app\model\GameModel;
  9. use think\facade\Request;
  10. class TrendStatis extends BaseController
  11. {
  12. /**
  13. * 在线走势
  14. */
  15. public function Online()
  16. {
  17. $userInfo = $this->request->userInfo;
  18. // 获取查询参数
  19. $page = Request::get('page', 1, 'intval');
  20. $limit = Request::get('limit', 10, 'intval');
  21. // 筛选条件
  22. $filters = [
  23. // 时间筛选
  24. 'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
  25. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  26. 'game_id' => Request::get('game_id', '', 'trim'),
  27. ];
  28. try {
  29. // 获取游戏每日数据
  30. $result = GameStatisModel::getGameDailyList(
  31. $userInfo['merchant_id'],
  32. $page,
  33. $limit,
  34. $filters,
  35. );
  36. // 获取游戏信息信息
  37. $game_ids = array_unique(array_column($result['list'], 'game_id'));
  38. $tempGameList = GameModel::where([['merchant_id', '=', $userInfo['merchant_id']], ['game_id', 'in', $game_ids]])->field(['game_id','title','image'])->select()->toArray();
  39. $gameList = [];
  40. foreach ($tempGameList as $item) {
  41. $game_id = $item['game_id'];
  42. $gameList[$game_id] = $item;
  43. }
  44. // 格式化数据
  45. foreach ($result['list'] as &$item) {
  46. $item['game_profit'] = CommonUtils::convertBalance($item['game_profit'], false);
  47. $item['bet_amount'] = CommonUtils::convertBalance($item['bet_amount'], false);
  48. $item['commission_amount'] = CommonUtils::convertBalance($item['game_profit'] * 0.08, false);
  49. $item['platform_fee'] = CommonUtils::convertBalance($item['bet_amount'] * 0.08, false);
  50. $item['buy_free_bet'] = 0;
  51. $item['game_title'] = $gameList[$item['game_id']]['title'] ?? '';
  52. }
  53. return json_success($result, '获取成功');
  54. } catch (\Exception $e) {
  55. return json_error([], '获取游戏每日数据失败:' . $e->getMessage());
  56. }
  57. }
  58. /**
  59. * 游戏走势
  60. */
  61. public function Game() {
  62. }
  63. /**
  64. * 输赢走势
  65. */
  66. public function Win() {
  67. $userInfo = $this->request->userInfo;
  68. // 获取查询参数
  69. $filters = [
  70. 'date' => Request::get('date', '', 'trim'),
  71. 'game_id' => Request::get('game_id', '', 'trim'),
  72. 'currency' => Request::get('currency', 'USDT', 'trim')
  73. ];
  74. try {
  75. // 获取输赢走势数据
  76. $result = TrendStatisModel::getWinLoseTrend($userInfo['merchant_id'],$filters);
  77. for ($i = 0; $i < 24; $i++) {
  78. $list[] = ['hour' => $i, 'total_win' => 0];
  79. }
  80. if ($result) {
  81. $result = array_column($result, null, 'hour');
  82. foreach ($list as &$item) {
  83. if (isset($result[$item['hour']])) {
  84. $item['total_win'] = (float)$result[$item['hour']]['total_win'];
  85. }
  86. }
  87. }
  88. usort($list, function ($a, $b) {
  89. return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;
  90. });
  91. return json_success($list, '获取成功');
  92. } catch (\Exception $e) {
  93. return json_error([], '获取输赢走势失败:' . $e->getMessage());
  94. }
  95. }
  96. /**
  97. * 返奖倍数走势
  98. */
  99. public function PrizeMultiple() {
  100. $userInfo = $this->request->userInfo;
  101. // 获取查询参数
  102. $filters = [
  103. 'date' => Request::get('date', '', 'trim'),
  104. 'game_id' => Request::get('game_id', '', 'trim'),
  105. ];
  106. try {
  107. // 获取输赢走势数据
  108. $result = TrendStatisModel::getMultipleTrend(
  109. $userInfo['merchant_id'],
  110. $filters
  111. );
  112. for ($i = 0; $i < 24; $i++) {
  113. $list[] = ['hour' => $i, 'total_win' => 0];
  114. }
  115. if ($result) {
  116. $result = array_column($result, null, 'hour');
  117. foreach ($list as &$item) {
  118. if (isset($result[$item['hour']])) {
  119. $item['total_multiple'] = (float)$result[$item['hour']]['total_multiple'];
  120. }
  121. }
  122. }
  123. usort($list, function ($a, $b) {
  124. return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;
  125. });
  126. return json_success($list, '获取成功');
  127. } catch (\Exception $e) {
  128. return json_error([], '获取返奖倍数走势失败:' . $e->getMessage());
  129. }
  130. }
  131. /**
  132. * 商户每日走势
  133. */
  134. public function MerchantDaily() {
  135. $userInfo = $this->request->userInfo;
  136. // 筛选条件
  137. $filters = [
  138. 'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
  139. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  140. 'game_id' => Request::get('game_id', '', 'trim')
  141. ];
  142. try {
  143. // 获取商户每日走势数据
  144. $result = TrendStatisModel::getMerchantDailyTrend(
  145. $userInfo['merchant_id'],
  146. $filters
  147. );
  148. for ($i = strtotime($filters['start_time']); $i <= strtotime($filters['end_time']); $i += 86400) {
  149. $list[] = [
  150. 'date' => intval(date('Ymd', $i)),
  151. 'total_win' => 0,
  152. 'total_bet' => 0,
  153. 'bet_count' => 0,
  154. 'bet_users' => 0,
  155. 'rtp' => 0,
  156. ];
  157. }
  158. if ($result) {
  159. $result = array_column($result, null, 'date');
  160. foreach ($list as &$item) {
  161. if (isset($result[$item['date']])) {
  162. $rowData = $result[$item['date']];
  163. $item['total_win'] = (float)$rowData['total_win'];
  164. $item['total_bet'] = (float)$rowData['total_bet'];
  165. $item['bet_count'] = (int) $rowData['bet_count'];
  166. $item['bet_users'] = (int) $rowData['bet_users'];
  167. $item['rtp'] = calculateRTP($rowData['total_win'], $rowData['total_bet']);
  168. }
  169. }
  170. }
  171. usort($list, function ($a, $b) {
  172. return (int)$a['date'] < (int)$b['date'] ? -1 : 1;
  173. });
  174. return json_success($list, '获取成功');
  175. } catch (\Exception $e) {
  176. return json_error([], '获取商户每日走势失败:' . $e->getMessage());
  177. }
  178. }
  179. }