TrendStatis.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. $list = TrendStatisModel::getWinLoseTrend(
  77. $userInfo['merchant_id'],
  78. $filters
  79. );
  80. if ($list) {
  81. foreach ($list as &$item) {
  82. $item['hour'] = (int) $item['hour'];
  83. $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
  84. }
  85. }
  86. usort($list, function ($a, $b) {
  87. return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;
  88. });
  89. return json_success($list, '获取成功');
  90. } catch (\Exception $e) {
  91. return json_error([], '获取输赢走势失败:' . $e->getMessage());
  92. }
  93. }
  94. /**
  95. * 返奖倍数走势
  96. */
  97. public function PrizeMultiple() {
  98. $userInfo = $this->request->userInfo;
  99. // 获取查询参数
  100. $filters = [
  101. 'date' => Request::get('date', '', 'trim'),
  102. 'game_id' => Request::get('game_id', '', 'trim'),
  103. ];
  104. try {
  105. // 获取输赢走势数据
  106. $list = TrendStatisModel::getMultipleTrend(
  107. $userInfo['merchant_id'],
  108. $filters
  109. );
  110. if ($list) {
  111. foreach ($list as &$item) {
  112. $item['hour'] = (int) $item['hour'];
  113. $item['total_multiple'] = (int) $item['total_multiple'];
  114. }
  115. }
  116. usort($list, function ($a, $b) {
  117. return (int)$a['hour'] < (int)$b['hour'] ? -1 : 1;
  118. });
  119. return json_success($list, '获取成功');
  120. } catch (\Exception $e) {
  121. return json_error([], '获取返奖倍数走势失败:' . $e->getMessage());
  122. }
  123. }
  124. /**
  125. * 商户每日走势
  126. */
  127. public function MerchantDaily() {
  128. $userInfo = $this->request->userInfo;
  129. // 筛选条件
  130. $filters = [
  131. 'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
  132. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  133. 'game_id' => Request::get('game_id', '', 'trim')
  134. ];
  135. try {
  136. // 获取商户每日走势数据
  137. $list = TrendStatisModel::getMerchantDailyTrend(
  138. $userInfo['merchant_id'],
  139. $filters
  140. );
  141. if ($list) {
  142. foreach ($list as &$item) {
  143. $item['date'] = (int) $item['date'];
  144. $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
  145. $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
  146. $item['bet_count'] = (int) $item['bet_count'];
  147. $item['bet_users'] = (int) $item['bet_users'];
  148. $item['rtp'] = round($item['total_win'] / $item['total_bet'], 2) * 100;
  149. }
  150. }
  151. usort($list, function ($a, $b) {
  152. return (int)$a['date'] < (int)$b['date'] ? -1 : 1;
  153. });
  154. return json_success($list, '获取成功');
  155. } catch (\Exception $e) {
  156. return json_error([], '获取商户每日走势失败:' . $e->getMessage());
  157. }
  158. }
  159. }