| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- declare (strict_types = 1);
- namespace app\model;
- use think\Model;
- /**
- * 玩家登录日志模型
- */
- class PlayerLoginLogModel extends Model
- {
- // 设置数据库连接
- protected $connection = 'fortue_tiger';
- // 设置表名
- protected $name = 'player_login_log';
- // 设置主键
- protected $pk = 'id';
- // 设置自动时间戳
- protected $autoWriteTimestamp = 'int';
- // 设置字段类型
- protected $type = [
- 'merchant_id' => 'int',
- 'player_id' => 'int',
- 'game_id' => 'int',
- 'game_platform' => 'string',
- 'login_ip' => 'string',
- 'login_time' => 'int',
- 'login_status' => 'int',
- ];
- /**
- * 获取玩家登录次数
- */
- public static function getLoginCount($merchant_id, $player_ids, $filter = []) {
- // 支持单个或多个player_id
- $player_ids = is_array($player_ids) ? $player_ids : [$player_ids];
-
- $query = self::where('merchant_id', $merchant_id)
- ->whereIn('player_id', $player_ids);
-
- // 处理可选过滤条件
- if (!empty($filter['game_id'])) {
- $query->where('game_id', $filter['game_id']);
- }
-
- if (!empty($filter['game_platform'])) {
- $query->where('game_platform', $filter['game_platform']);
- }
-
- if (!empty($filter['login_status'])) {
- $query->where('login_status', $filter['login_status']);
- }
-
- if (!empty($filter['start_time'])) {
- $query->where('login_time', '>=', $filter['start_time']);
- }
-
- if (!empty($filter['end_time'])) {
- $query->where('login_time', '<=', $filter['end_time']);
- }
-
- if (!empty($filter['login_ip'])) {
- $query->where('login_ip', $filter['login_ip']);
- }
-
- // 按player_id分组统计
- $result = $query->field('player_id, COUNT(*) as count')
- ->group('player_id')
- ->select()
- ->toArray();
- return array_column($result, null, 'player_id');
- }
- }
|