master
parent
0dc0063092
commit
ab4dc74784
@ -0,0 +1,55 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue