You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB
PHTML

5 years ago
<?php
namespace Base\Repository;
class UserRepository {
public function __construct()
{
}
/**
* 按照时间分组统计登录总数
*/
public function getLoginCountByDay($params) {
$beginTime = $params['begin_time'] ?? 0;
$endTime = $params['end_time'] ?? 0;
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$tmap = $map = [];
$tmap['lock_status'] = $map['lock_status'] = 1;
$tmap['register_time'] = $map['up.login_time'] = ['between', [$beginTime, $endTime]];
if ($gameId > 0) {
$tmap['fgame_id'] = $map['up.game_id'] = $gameId;
}
if ($serverId > 0) {
$tmap['fgame_id'] = $map['up.game_id'] = $serverId;
}
$tmap['promote_id'] = $map['tab_user.promote_id'] = ['in', $ids];
$union = M('user', 'tab_')->field('FROM_UNIXTIME(register_time,"%Y-%m-%d") as time,GROUP_CONCAT(DISTINCT id) as user_id')
->where($tmap)->group('time')->select(false);
$sql = M('user', 'tab_')->field('FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as time,GROUP_CONCAT(DISTINCT up.user_id) as user_id')
->join('tab_user_login_record up on up.user_id=tab_user.id','inner')
->union($union)
->where($map)->group('time')->select(false);
$lists = M()->table('('.$sql.') as a')->field('a.time,GROUP_CONCAT(a.user_id) as user_id')->group('a.time')->select();
$data = [];
foreach($lists as $k => $v) {
$login = array_unique(explode(',', $v['user_id']));
$data[$k] = [
'time' => $v['time'],
'login_num' => count($login),
];
}
return $data;
}
}