Overview.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\MerchantStatisModel;
  5. use app\common\CommonUtils;
  6. use app\model\GameBetGameModel;
  7. use app\model\MerchantsUserModel;
  8. use app\model\PlayerLoginLogModel;
  9. use think\facade\Request;
  10. class Overview extends BaseController
  11. {
  12. /**
  13. * 仪表盘 - 获取概览统计数据
  14. */
  15. public function Dashboard()
  16. {
  17. $userInfo = $this->getUserInfo();
  18. try {
  19. // 获取昨、今日时间范围
  20. $today = date('Y-m-d');
  21. $filtter = [
  22. 'start_time' => date('Y-m-d', strtotime('yesterday')),
  23. 'end_time' => date('Y-m-d', strtotime('tomorrow')),
  24. ];
  25. $merchantId = $userInfo['merchant_id'];
  26. // 获取昨、今日游戏相关统计
  27. $dailySummary = GameBetGameModel::getGameDailySummary($merchantId, $filtter);
  28. // 获取玩家统计数据
  29. $playerSummary = MerchantsUserModel::getPlayerStatistics($merchantId, $filtter);
  30. $tempPlayerData = [];
  31. if ($playerSummary) {
  32. foreach ($playerSummary as $key => $row) {
  33. foreach ($row as $date => $item) {
  34. $date = $date == $today ? 'today' : 'yesterday';
  35. $tempPlayerData[$key][$date] = $item;
  36. }
  37. }
  38. }
  39. if ($dailySummary) {
  40. foreach ($dailySummary as $row) {
  41. $date = $row['date'] == $today ? 'today' : 'yesterday';
  42. $row['commission'] = (float)bcmul($row['game_profit'], $GLOBALS['CommissionRate'], 2);
  43. $row['bet_amount'] = (float)$row['bet_amount'];
  44. $row['game_profit'] = (float)$row['game_profit'];
  45. $row['register_users'] = CommonUtils::convertToInt($tempPlayerData['register'][$date]['count'] ?? 0);
  46. $row['login_users'] = CommonUtils::convertToInt($tempPlayerData['login'][$date]['count'] ?? 0);
  47. $row['online_users'] = CommonUtils::convertToInt($tempPlayerData['login'][$date]['count'] ?? 0);
  48. $row['buy_free_bet_count'] = CommonUtils::convertToInt($row['buy_free_bet_count']);
  49. $dashboardData[$date] = $row;
  50. }
  51. }
  52. // 在线人数、登录数据
  53. $dashboardData['online_data'] = PlayerLoginLogModel::getLoginHourCount($merchantId, $filtter);;
  54. $dashboardData['login_data'] = $dashboardData['online_data'];
  55. return json_success($dashboardData, '获取成功');
  56. } catch (\Exception $e) {
  57. return json_error([], '获取仪表盘数据失败' . $e->getMessage());
  58. }
  59. }
  60. /**
  61. * 结算报表 - 按日期查询投注数据
  62. */
  63. public function SettlementReport()
  64. {
  65. $userInfo = $this->request->userInfo;
  66. // 获取查询参数
  67. $page = Request::get('page', 1, 'intval');
  68. $limit = Request::get('limit', 10, 'intval');
  69. // 筛选条件
  70. $filters = [
  71. // 时间筛选
  72. 'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
  73. 'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
  74. ];
  75. try {
  76. // 获取商户每日数据
  77. $result = MerchantStatisModel::getMerchantDailyList(
  78. $userInfo['merchant_id'],
  79. $page,
  80. $limit,
  81. $filters,
  82. );
  83. // 格式化数据
  84. foreach ($result['list'] as &$item) {
  85. $item['game_profit'] = (float)$item['game_profit'];
  86. $item['game_profit_usdt'] = $item['game_profit'];
  87. $item['bet_amount'] = (float)$item['bet_amount'];
  88. $item['bet_amount_usdt'] = (int)$item['bet_amount'];
  89. $item['platform_fee'] = (float)bcmul($item['bet_amount'], $GLOBALS['CommissionRate'], 2);
  90. $item['platform_fee_usdt'] = $item['platform_fee'];
  91. $item['buy_free_bet_count'] = (int)$item['buy_free_bet_count'];
  92. $item['total_winning_score'] = (float)$item['total_winning_score'];
  93. $item['region'] = '';
  94. }
  95. return json_success($result, '获取成功');
  96. } catch (\Exception $e) {
  97. return json_error([], '获取商户每日数据失败:' . $e->getMessage());
  98. }
  99. }
  100. /**
  101. * 导出结算报表
  102. */
  103. public function exportSettlement() {
  104. ;
  105. }
  106. }