TrendStatisModel.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model;
  4. use think\Model;
  5. use think\facade\Db;
  6. /**
  7. * 走势数据统计
  8. */
  9. class TrendStatisModel extends Model
  10. {
  11. protected $name = 'game_bet_game';
  12. // 连接到fortue_tiger数据库
  13. protected $connection = 'fortue_tiger';
  14. /**
  15. * 获取输赢走势数据
  16. */
  17. public static function getWinLoseTrend($appId, $filters = [])
  18. {
  19. $wheres = [];
  20. $wheres[] = ['action_type', '=', 1];
  21. $wheres[] = ['app_id', '=', $appId];
  22. // 时间筛选
  23. $startTime = !empty($filters['date']) ? strtotime($filters['date']) : strtotime(date('Ymd'));
  24. $endTime = $startTime + 86400;
  25. $wheres[] = ['create_time', '>=', $startTime];
  26. $wheres[] = ['create_time', '<=', $endTime];
  27. // 游戏ID筛选
  28. if (!empty($filters['game_id'])) {
  29. $filters['game_id'] = explode(',', $filters['game_id']);
  30. $wheres[] = ['game_id', 'IN', $filters['game_id']];
  31. }
  32. // 货币类型筛选
  33. if (!empty($filters['currency'])) {
  34. // 这里可能需要关联其他表来获取货币类型,暂时忽略
  35. }
  36. $query = self::where($wheres);
  37. // 获取列表数据
  38. $data = $query->field([
  39. "from_unixtime(create_time, '%k') AS hour",
  40. 'SUM(total_win_amount) as total_win',
  41. ])
  42. ->group('hour')
  43. ->select()
  44. ->toArray();
  45. return $data;
  46. }
  47. /**
  48. * 获取返奖倍数走势数据(RTP走势)
  49. */
  50. public static function getMultipleTrend($appId, $filters = [])
  51. {
  52. $wheres = [];
  53. $wheres[] = ['action_type', '=', 1];
  54. $wheres[] = ['app_id', '=', $appId];
  55. // 时间筛选
  56. $startTime = !empty($filters['date']) ? strtotime($filters['date']) : strtotime(date('Ymd'));
  57. $endTime = $startTime + 86400;
  58. $wheres[] = ['create_time', '>=', $startTime];
  59. $wheres[] = ['create_time', '<=', $endTime];
  60. // 游戏ID筛选
  61. if (!empty($filters['game_id'])) {
  62. $filters['game_id'] = explode(',', $filters['game_id']);
  63. $wheres[] = ['game_id', 'IN', $filters['game_id']];
  64. }
  65. $query = self::where($wheres);
  66. // 获取列表数据
  67. $data = $query->field([
  68. "from_unixtime(create_time, '%k') AS hour",
  69. 'SUM(res_multiple) as total_multiple',
  70. ])
  71. ->group('hour')
  72. ->select()
  73. ->toArray();
  74. return $data;
  75. }
  76. /**
  77. * 获取商户每日走势数据
  78. */
  79. public static function getMerchantDailyTrend($appId, $filters = [])
  80. {
  81. $wheres = [];
  82. $wheres[] = ['action_type', '=', 1];
  83. $wheres[] = ['app_id', '=', $appId];
  84. // 时间筛选
  85. if (!empty($filters['start_time'])) {
  86. $startTime = strtotime($filters['start_time']);
  87. $wheres[] = ['create_time', '>=', $startTime];
  88. }
  89. if (!empty($filters['end_time'])) {
  90. $endTime = strtotime($filters['end_time']);
  91. $wheres[] = ['create_time', '<=', $endTime];
  92. }
  93. // 游戏ID筛选
  94. if (!empty($filters['game_id'])) {
  95. $wheres[] = ['game_id', 'IN', $filters['game_id']];
  96. }
  97. $query = self::where($wheres);
  98. // 获取列表数据
  99. $data = $query->field([
  100. "from_unixtime(create_time, '%Y%m%d') AS date",
  101. 'SUM(total_win_amount) as total_win',
  102. 'SUM(bet) as total_bet',
  103. 'COUNT(*) as bet_count', // 注单数
  104. 'COUNT(DISTINCT uname) as bet_users', // 投注用户数
  105. ])
  106. ->group('date')
  107. ->select()
  108. ->toArray();
  109. return $data;
  110. }
  111. }