| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- declare (strict_types = 1);
- namespace app\model;
- use think\Model;
- use think\facade\Db;
- /**
- * 游戏数据统计
- */
- class GameStatisModel extends Model
- {
- protected $name = 'game_bet_game';
- // 连接到fortue_tiger数据库
- protected $connection = 'fortue_tiger';
-
- /**
- * 获取游戏每日数据列表
- */
- public static function getGameDailyList($merchantId, $page = 1, $limit = 20, $filters = [])
- {
- $where = [
- ['app_id', '=', $merchantId]
- ];
-
- // 时间筛选
- if (!empty($filters['start_time'])) {
- $startTime = strtotime($filters['start_time']);
- $where[] = ['create_time', '>=', $startTime];
- }
-
- if (!empty($filters['end_time'])) {
- $endTime = strtotime($filters['end_time']);
- $where[] = ['create_time', '<=', $endTime];
- }
- if (!empty($filters['game_id'])) {
- $gameId = is_array($filters['game_id']) ? $filters['game_id'] : explode(',', $filters['game_id']);
- $where[] = ['game_id', 'in', $gameId];
- }
- // 使用子查询获取每个用户的统计数据
- $subQuery = self::field([
- "FROM_UNIXTIME(create_time, '%Y-%m-%d') as date", // 日期
- 'game_id', //游戏id
- 'AVG(rtp) AS rtp', // 平均RTP
- 'COUNT(DISTINCT uname) as bet_users', // 投注用户数
- 'COUNT(id) as bet_count', // 注单数
- 'SUM(bet) as bet_amount', // 注单金额(下注分数)
- 'SUM(total_win_amount) as game_profit', // 游戏输赢(金额变化)
- ])
- ->where($where)
- ->group('date, game_id')
- ->buildSql();
-
- // 获取总数
- $total = self::table($subQuery . ' t')->count();
-
- // 获取排行榜数据
- $list = self::table($subQuery . ' t')
- ->order('date', 'desc')
- ->page($page, $limit)
- ->select()
- ->toArray();
- // 获取登录用户、注册用户
- $merchantsUserStatic = MerchantsUserModel::getPlayerStatistics($merchantId, $filters);
-
- foreach ($list as &$row)
- {
- $row['login_users'] = $merchantsUserStatic[$row['date']]['login_users'] ?? 0;
- $row['register_users'] = $merchantsUserStatic[$row['date']]['register_users'] ?? 0;
- }
-
- return [
- 'list' => $list,
- 'total' => $total,
- 'page' => $page,
- 'limit' => $limit
- ];
- }
- }
|