|
|
|
<?php
|
|
|
|
namespace Base\Repository;
|
|
|
|
|
|
|
|
class UserRepository {
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function assembleDayRecords($items, $dayList, $valueColumn, $dayColumn = 'day')
|
|
|
|
{
|
|
|
|
$records = [];
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
$dayValue = 0;
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item[$dayColumn] == $day) {
|
|
|
|
$dayValue = $item[$valueColumn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$records[$day] = $dayValue;
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按照时间分组统计登录总数
|
|
|
|
*/
|
|
|
|
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'] ?? [];
|
|
|
|
$dayList = $params['dayList'] ?? [];
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
$map['login_time'] = ['between', [$beginTime, $endTime]];
|
|
|
|
|
|
|
|
if ($gameId > 0) {
|
|
|
|
$map['game_id'] = $gameId;
|
|
|
|
}
|
|
|
|
if ($serverId > 0) {
|
|
|
|
$map['server_id'] = $serverId;
|
|
|
|
}
|
|
|
|
$map['promote_id'] = ['in', $ids];
|
|
|
|
|
|
|
|
$items = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as day, count(DISTINCT user_id) as count')
|
|
|
|
->where($map)
|
|
|
|
->group('day')
|
|
|
|
->select();
|
|
|
|
|
|
|
|
return $this->assembleDayRecords($items, $dayList, 'count');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按照时间分组统计注册总数
|
|
|
|
*/
|
|
|
|
public function getRegisterCountByDay($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'] ?? [];
|
|
|
|
$dayList = $params['dayList'] ?? [];
|
|
|
|
|
|
|
|
$dateform = '%Y-%m-%d';
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
$map['register_time'] = ['between', [$beginTime, $endTime]];
|
|
|
|
|
|
|
|
if ($gameId > 0) {
|
|
|
|
$map['fgame_id'] = $gameId;
|
|
|
|
}
|
|
|
|
|
|
|
|
$map['promote_id'] = ['in', $ids];
|
|
|
|
$map['puid'] = 0;
|
|
|
|
|
|
|
|
$items = M('user', 'tab_')->field('count(*) count, FROM_UNIXTIME(register_time,"'.$dateform.'") as day')
|
|
|
|
->where($map)
|
|
|
|
->group('day')
|
|
|
|
->select();
|
|
|
|
return $this->assembleDayRecords($items, $dayList, 'count');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按照时间分组统计注册编号序列
|
|
|
|
* @param string $newslist 新玩家序列
|
|
|
|
* @param integer $end 结束时间(时间戳)
|
|
|
|
* @param integer $game_id 游戏编号
|
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
|
* @param integer $flag 留存类型
|
|
|
|
* @return array 详细数据
|
|
|
|
* @author 鹿文学
|
|
|
|
*/
|
|
|
|
public function getRatentionRate($newslist,$game_id=0,$promote_id=0,$flag=1) {
|
|
|
|
|
|
|
|
|
|
|
|
$map['lock_status']=1;
|
|
|
|
if($game_id>0) {
|
|
|
|
$map['up.game_id'] = $game_id;
|
|
|
|
}
|
|
|
|
$map['tab_user.promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
|
|
$group = 'up.login_time';
|
|
|
|
|
|
|
|
$fieldname = 'retention_rate'.$flag;
|
|
|
|
|
|
|
|
foreach ($newslist as $value) {
|
|
|
|
$ct1 = strtotime("+$flag day",strtotime($value['time']));
|
|
|
|
$ct2 = strtotime("+1 day",$ct1)-1;
|
|
|
|
|
|
|
|
$map[$group] = array(array('egt',$ct1),array('elt',$ct2));
|
|
|
|
|
|
|
|
$map['user_id']=array('in',$value['id']);
|
|
|
|
$count = count(explode(',',$value['id']));
|
|
|
|
|
|
|
|
|
|
|
|
$d = $this
|
|
|
|
->field('count(distinct up.user_id) as '.$fieldname.' ,FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as play_time')
|
|
|
|
->join('tab_user_login_record up on tab_user.id=up.user_id','right')
|
|
|
|
->where($map)
|
|
|
|
->group('play_time')
|
|
|
|
->select();
|
|
|
|
|
|
|
|
if ($d)
|
|
|
|
$data[]=array(
|
|
|
|
"play_time"=>$value['time'],
|
|
|
|
$fieldname=>($d[0][$fieldname]==0)?0:sprintf("%.2f",($d[0][$fieldname]/$count)*100)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|