// +---------------------------------------------------------------------- namespace Home\Model; use Think\Model; /** * 分类模型 */ class UserModel extends Model{ protected $_validate = array( ); protected $_auto = array( ); /** * 构造函数 * @param string $name 模型名称 * @param string $tablePrefix 表前缀 * @param mixed $connection 数据库连接信息 */ public function __construct($name = '', $tablePrefix = '', $connection = '') { /* 设置默认的表前缀 */ $this->tablePrefix ='tab_'; /* 执行构造方法 */ parent::__construct($name, $tablePrefix, $connection); } /** * 按照时间分组统计注册总数 * @param integer $start 开始时间(时间戳) * @param integer $end 结束时间(时间戳) * @param integer $game_id 游戏编号 * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) * @return array 详细数据 * @author 鹿文学 */ public function register_count_by_time($start,$end,$game_id=0,$promote_id=0,$group='time') { $map['lock_status']=1; $map['register_time'] = array('between',array($start,$end)); $map['fgame_id'] = $game_id>0?$game_id:array('egt',0); $map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id); $data = $this->field("FROM_UNIXTIME(register_time,'%Y-%m-%d') as $group,count(id) as register_num") ->where($map)->group($group)->select(); return $data; } /** * 按照时间分组统计登录总数 * @param integer $start 开始时间(时间戳) * @param integer $end 结束时间(时间戳) * @param integer $game_id 游戏编号 * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) * @return array 详细数据 * @author 鹿文学 */ public function login_count_by_time($start,$end,$game_id=0,$promote_id=0,$group='time') { $tmap['lock_status']=$map['lock_status']=1; $tmap['register_time']=$map['up.login_time'] = array('between',array($start,$end)); if($game_id>0) { $tmap['fgame_id']=$map['up.game_id'] = $game_id; } $tmap['promote_id']=$map['tab_user.promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id); /* $data = $this->field("FROM_UNIXTIME(up.login_time,'%Y-%m-%d') as $group,count(distinct up.user_id) as login_num") ->join('tab_user_login_record up on up.user_id=tab_user.id','right') ->where($map)->group($group)->select(); */ $union = $this->field('FROM_UNIXTIME(register_time,"%Y-%m-%d") as '.$group.',GROUP_CONCAT(DISTINCT id) as user_id') ->where($tmap)->group($group)->select(false); $sql = $this->field('FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as '.$group.',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($group)->select(false); $lists = $this->table('('.$sql.') as a')->field('a.'.$group.',GROUP_CONCAT(a.user_id) as user_id')->group('a.'.$group)->select(); foreach($lists as $k => $v) { $login = array_unique(explode(',',$v['user_id'])); $data[$k] = array( $group => $v[$group], 'login_num' => count($login), ); } return $data; } /** * 按照时间分组统计注册编号序列 * @param integer $start 开始时间(时间戳) * @param integer $end 结束时间(时间戳) * @param integer $game_id 游戏编号 * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) * @param integer $lock_status 用户状态(1正常,0锁定) * @return array 详细数据 * @author 鹿文学 */ public function register_list_by_time($start,$end,$game_id,$promote_id,$group='time',$lock_status=1) { $dateform = '%Y-%m-%d'; $map['fgame_id'] = $game_id>0?$game_id:array('egt',0); $map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id); $map['register_time'] = array('between',array($start,$end)); $map['puid'] = 0; if(is_numeric($lock_status) && ($lock_status==1 or $lock_status==0)) { $map['lock_status']=$lock_status; } $data = $this ->field('group_concat(id) as id,FROM_UNIXTIME(register_time,"'.$dateform.'") as '.$group) ->where($map)->group($group)->select(); return $data; } /** * 按照时间分组统计注册编号序列 * @param string $newslist 新玩家序列 * @param integer $end 结束时间(时间戳) * @param integer $game_id 游戏编号 * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) * @param integer $flag 留存类型 * @return array 详细数据 * @author 鹿文学 */ public function ratention_rate($newslist,$game_id=0,$promote_id=0,$flag=1) { $map['lock_status']=1; if($game_id>0) { $map['up.game_id'] = $game_id; } /*$map['up.game_id'] = $game_id>0?$game_id:array('egt',0);*/ /*$map['up.promote_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; } }