master
ELF 5 years ago
parent ab4dc74784
commit d3412cc3ce

4
.gitignore vendored

@ -3,4 +3,6 @@ Runtime/
Uploads/
Application/Common/Conf/env.php
Application/Common/Conf/pay_config.php
.idea/
Application/Sdk/OrderNo/
.idea/
Uploads/

@ -8,7 +8,10 @@ class SpendRepository {
}
public function getPayGameByDay($params) {
/**
* 付费游戏数
*/
public function getPayGameCountByDay($params) {
$beginTime = $params['begin_time'] ?? 0;
$endTime = $params['end_time'] ?? 0;
$gameId = $params['game_id'] ?? 0;
@ -23,10 +26,183 @@ class SpendRepository {
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,game_id as pay_num';
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time, game_id';
$subTable = M('spend', 'tab_')->field($field)->where($map)->group('pay_time')->select(false);
$data = M()->field('a.pay_time,count(DISTINCT a.pay_num) as pay_num')->table('(' . $subTable . ') as a')->group('a.pay_time')->select();
// var_dump(M()->getLastSql());die();
$data = M()->field('a.pay_time, count(DISTINCT a.game_id) as pay_num')->table('(' . $subTable . ') as a')->group('a.pay_time')->select();
return $data;
}
public function getPayAmountByDay($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'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map['pay_status'] = 1;
$map['pay_time'] = ['between', [$beginTime, $endTime]];
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,sum(pay_amount) as money_amount';
$data = M('spend', 'tab_')->field($field)->where($map)->group('FROM_UNIXTIME(pay_time,"%Y-%m-%d")')->select();
return $data;
}
public function getPayUserCountByDay($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'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map['pay_status'] = 1;
$map['pay_time'] = ['between', [$beginTime, $endTime]];
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,user_id as pay_num';
$subTable = M('spend', 'tab_')->field($field)->where($map)->group('pay_time')->buildSql();
return M('spend', 'tab_')->field('a.pay_time,count(distinct a.pay_num) as pay_num')->table('(' . $subTable . ') as a')->group('a.pay_time')->select();
}
/**
* 按照时间分组统计新增付费用户数
*/
public function getNewPayUserCountByDay($params) {
$dayList = $params['dayList'] ?? [];
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map = [];
$map['pay_status']=1;
if ($gameId > 0) {
$map['game_id'] = $gameId;
}
if ($serverId > 0) {
$map['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$oldMap = $map;
$records = [];
foreach ($dayList as $day) {
$time = strtotime($day);
$oldMap['pay_time'] = ['lt', $time];
$map['pay_time'] = ['between', $time, ($time + 24 * 3600 -1)];
$oldQuery = M('spend', 'tab_')->field('user_id')->where($oldMap)->group('user_id')->buildSql();
$map['user_id'] = ['exp', ' not in (' . $oldQuery . ')'];
$result = M('spend', 'tab_')->field('count(distinct user_id) count')->where($map)->find();
$records[$day] = $result['count'];
}
return $records;
}
/**
* 按照时间分组统计新增付费用户数
*/
public function getNewPayAmountByDay($params) {
$dayList = $params['dayList'] ?? [];
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map = [];
$map['pay_status']=1;
if ($gameId > 0) {
$map['game_id'] = $gameId;
}
if ($serverId > 0) {
$map['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$oldMap = $map;
$records = [];
foreach ($dayList as $day) {
$time = strtotime($day);
$oldMap['pay_time'] = ['lt', $time];
$map['pay_time'] = ['between', $time, ($time + 24 * 3600 -1)];
$oldQuery = M('spend', 'tab_')->field('user_id')->where($oldMap)->group('user_id')->buildSql();
$map['user_id'] = ['exp', ' not in (' . $oldQuery . ')'];
$result = M('spend', 'tab_')->field('sum(pay_amount) amount')->where($map)->find();
$records[$day] = $result['amount'];
}
return $records;
}
/**
* 按照时间分组统计付费玩家付费数(新付费用户指用户第一次付费)
* @param array $daylist 时间序列
* @param integer $game_id 游戏编号
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
* @param integer $flag 类别1新玩家2老玩家
* @return array 详细数据
* @author 鹿文学
*/
public function pay_sum_by_time_class_game($daylist,$game_id=0,$promote_id=0,$flag=1,$bangbi=true) {
$map['pay_status']=1;
$oldmap['game_id'] = $map['game_id'] = $game_id>0?$game_id:array('gt',0);
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
if ($flag == 1) {$str='user_id not in ';$map['_string']='(small_id=0 or small_id=user_id)';} else {$str = 'user_id in';}
foreach ($daylist as $value) {
$time = strtotime($value);
$oldmap['pay_time'] = array('lt',$time);
$old_sdk_id=$this->field('user_id')
->where($oldmap)->group('user_id')
->buildSql();
$map['pay_time'] = array(array('egt',$time),array('elt',strtotime("+1 day",$time)-1));
$map['_string'] = $map['_string']?($map['_string'].' and '.$str.$old_sdk_id):($str.$old_sdk_id);
$sql=$this
->field('user_id,pay_amount,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time')
->where($map)
->buildSql();
$d = $this->query('select sum(a.pay_amount) as pay_sum, a.pay_time as pay_time from '.$sql.' as a group by pay_time');
if ($d)
$data[]=$d[0];
}
return $data;
}
/**
* 统计给定时间前的付费玩家总数
* @param integer $start 开始时间(时间戳)
* @param integer $game_id 游戏编号
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
* @return integer 结果
* @author 鹿文学
*/
public function payUsersStatisticsAgo($start,$game_id,$promote_id,$bangbi=true) {
$map['pay_status']=1;
$map['pay_time'] = array('lt',$start);
$map['game_id'] = $game_id>0?$game_id:array('gt',0);
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
$data = $this->field('count(DISTINCT user_id) as user_id')->where($map)->select();
return $data[0]['user_id']?$data[0]['user_id']:0;
}
}

@ -18,37 +18,98 @@ class UserRepository {
$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]];
$map = [];
$map['login_time'] = ['between', [$beginTime, $endTime]];
if ($gameId > 0) {
$tmap['fgame_id'] = $map['up.game_id'] = $gameId;
$map['game_id'] = $gameId;
}
if ($serverId > 0) {
$tmap['fgame_id'] = $map['up.game_id'] = $serverId;
$map['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$records = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as time, count(DISTINCT user_id) as count')
->where($map)
->group('time')
->select();
return $records;
}
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'] ?? [];
$dateform = '%Y-%m-%d';
$map = [];
$map['register_time'] = ['between', [$beginTime, $endTime]];
if ($gameId > 0) {
$map['fgame_id'] = $gameId;
}
$tmap['promote_id'] = $map['tab_user.promote_id'] = ['in', $ids];
$map['promote_id'] = ['in', $ids];
$map['puid'] = 0;
$records = M('user', 'tab_')->field('group_concat(id) as id,FROM_UNIXTIME(register_time,"'.$dateform.'") as time')
->where($map)
->group('time')
->select();
return $records;
}
/**
* 按照时间分组统计注册编号序列
* @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;
$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);
$map[$group] = array(array('egt',$ct1),array('elt',$ct2));
$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);
$map['user_id']=array('in',$value['id']);
$count = count(explode(',',$value['id']));
$lists = M()->table('('.$sql.') as a')->field('a.time,GROUP_CONCAT(a.user_id) as user_id')->group('a.time')->select();
$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();
$data = [];
foreach($lists as $k => $v) {
$login = array_unique(explode(',', $v['user_id']));
$data[$k] = [
'time' => $v['time'],
'login_num' => count($login),
];
if ($d)
$data[]=array(
"play_time"=>$value['time'],
$fieldname=>($d[0][$fieldname]==0)?0:sprintf("%.2f",($d[0][$fieldname]/$count)*100)
);
}
return $data;
}

@ -6,6 +6,8 @@ use OT\DataDictionary;
use User\Api\PromoteApi;
use Base\Repository\PromoteRepository;
use Base\Repository\SpendRepository;
use Base\Repository\UserRepository;
/**
* 前台首页控制器
* 主要获取首页聚合数据
@ -661,8 +663,11 @@ class QueryController extends BaseController
$params['begin_time'] = $beginTime;
$params['end_time'] = $endTime;
$userRepository = new UserRepository();
$spendRepository = new SpendRepository();
$spendRepository->getPayGameByDay($params);
$payGameCountList = $spendRepository->getPayGameCountByDay($params);
$loginCountList = $userRepository->getLoginCountByDay($params);
var_dump($loginCountList);
A('User', 'Event')->arpu_analysis();
}
@ -733,7 +738,7 @@ class QueryController extends BaseController
}
$spend2 = D('Spend');
$data = M('Game', 'tab_')->field('id as game_id, game_name')->order('id desc')->select();
$data = M('Apply', 'tab_')->field('game_id, game_name')->order('game_id desc')->select();
foreach ($data as $key => $value) {
$game_id = $value['game_id'];
$map_list['game_id'] = $game_id;

Loading…
Cancel
Save