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.

1514 lines
58 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Home\Event;
use Think\Controller;
/**
* 后台事件控制器
* @author 王贺
*/
class UserEvent extends BaseEvent {
public function lists($model=null){
}
public function join_list($model,$p){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
$map = $model['map'];
if(isset($_REQUEST['time-start']) && isset($_REQUEST['time-end']) && !empty($_REQUEST['time-start']) && !empty($_REQUEST['time-end'])){
$map[$model['time_fields']] = array('BETWEEN',array(strtotime($_REQUEST['time-start']),strtotime($_REQUEST['time-end'])));
unset($_REQUEST['time-start']);unset($_REQUEST['time-end']);
}
if(isset($_REQUEST['account']) && !empty($_REQUEST['account'])){
$map['account'] = array('like','%'.$_REQUEST['account'].'%');
unset($_REQUEST['account']);
}
if(isset($_REQUEST['game_appid']) && !empty($_REQUEST['game_appid'])){
$map['game_appid'] = $_REQUEST['game_appid'];
unset($_REQUEST['game_appid']);
}
$row = empty($model['list_row']) ? 10 : $model['list_row'];
//读取模型数据列表
$name = $model['m_name'];
$data = M($name,'tab_user_')
/* 查询指定字段,不指定则查询所有字段 */
->field('tab_user_play.id,user_id,account,game_appid,promote_id,register_time,register_ip')
->join("tab_user on tab_user_play.user_id = tab_user.id")
// 查询条件
->where($map)
/* 默认通过id逆序排列 */
->order($order)
/* 数据分页 */
->page($page, $row)
/* 执行查询 */
->select();
/* 查询记录总数 */
$count = M($name,'tab_user_')->join("tab_user on tab_user_play.user_id = tab_user.id")->where($map)->count();
//分页
if($count > $row){
$page = new \Think\Page($count, $row);
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
}
$this->assign('model', $model);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function bill_list($model,$p){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
$map = $model['map'];
$row = empty($model['list_row']) ? 10 : $model['list_row'];
//读取模型数据列表
$name = $model['m_name'];
$data = M($name,'tab_')
/* 查询指定字段,不指定则查询所有字段 */
// 查询条件
->where($map)
/* 默认通过id逆序排列 */
->order($order)
/* 数据分页 */
->page($page, $row)
/* 执行查询 */
->select();
/* 查询记录总数 */
$count = M($name,'tab_')->where($map)->count();
if($count > $row){
$page = new \Think\Page($count, $row);
foreach($map as $key=>$val) {
$page->parameter[$key] = urlencode($val);
}
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
}
$this->assign('model', $model);
$this->assign('count',$count);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function shou_list($model,$p){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
$order = $model['order']?:'id';
$map = $model['map'];
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
//读取模型数据列表
$name = $model['m_name'];
$data = M($name,'tab_')
->field($model['fields'])
/* 查询指定字段,不指定则查询所有字段 */
// 查询条件
->where($map)
->group($model['group'])
/* 默认通过id逆序排列 */
->order($order)
/* 数据分页 */
->page($page, $row)
/* 执行查询 */
->select();
/* 查询记录总数 */
/*$count = M($name,'tab_')->where($map)->count();*/
$result = M($name,'tab_')->field($model['group'])->where($map)->group($model['group'])->select();
$count = count($result);
if($name=="son_settlement"){
/*$sum_money=M($name,'tab_')->where(array("promote_id"=>get_pid()))->sum("floor(jie_money*100)/100");*/
$sum_money = 0;
foreach ($data as $key => $value) {
$sum_money=$sum_money+$value['jie_money'];
if($value['ti_status']==1){
$kk[]=$data[$key];
}
}
$y_money=0;
foreach ($kk as $k=> $v) {
$y_money=$y_money+$v['jie_money'];
}
$w_money=$sum_money-$y_money;
}else{
//随搜索条件变化
static $sum_money=0;
foreach ($data as $key => $value) {
$sum_money=$sum_money+$value['sum_money'];
if($value['ti_status']==1){
$kk[]=$data[$key];
}
}
$y_money=0;
foreach ($kk as $k=> $v) {
$y_money=$y_money+$v['sum_money'];
}
$w_money=$sum_money-$y_money;
}
//分页
$parameter = $map;
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
//$list = $data;
//$list['结算汇总'] = ['sum_money'=>$sum_money==""?'0.00':$sum_money];
//$list['未提现汇总']=['sum_money'=>$w_money==""?'0.00':$w_money];
//$list['成功提现汇总']=['sum_money'=>$y_money==""?'0.00':$y_money];
//file_put_contents(dirname(__FILE__) . '/../Controller/earning'.PID.'.txt',json_encode($list));
$this->assign('model', $model);
$this->assign('count',$count);
$this->assign('sum_money',$sum_money==""?'0.00':$sum_money);
$this->assign('w_money',$w_money==""?'0.00':$w_money);
$this->assign('y_money',$y_money==""?'0.00':$y_money);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function earning_data($p=1){
$pro_map['id']=get_pid();
$pro=M("promote","tab_")->where($pro_map)->find();
if($pro['parent_id']==0){
$map['promote_id']=get_pid();
if(isset($_REQUEST['settlement_number'])&&!empty($_REQUEST['settlement_number'])){
$map['settlement_number']=$_REQUEST['settlement_number'];
}
if(!empty($_REQUEST['timestart'])&&!empty($_REQUEST['timeend'])){
$map['bill_start_time'] = array('egt',strtotime($_REQUEST['timestart']));
$map['bill_end_time'] = array('elt',strtotime($_REQUEST['timeend'])+24*3600-1);
}
$model=array(
'm_name'=>'TotalSettlement',
'map' =>$map,
'fields'=>true,
'order' => 'create_time desc ',
'template_list'=>'my_earning',
'title' =>'我的结算',
);
}else{
$model=array(
'm_name'=>'son_settlement',
'map' =>$map,
'template_list'=>'my_earning',
'title' =>'我的结算',
);
}
return $this->shou_list_data($model,$p);
}
public function shou_list_data($model,$p){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
$map = $model['map'];
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
//读取模型数据列表
$name = $model['m_name'];
$data = M($name,'tab_')
->field($model['fields'])
/* 查询指定字段,不指定则查询所有字段 */
// 查询条件
->where($map)
->group($model['group'])
/* 默认通过id逆序排列 */
->order($order)
/* 数据分页 */
->page($page, $row)
/* 执行查询 */
->select();
/* 查询记录总数 */
$count = M($name,'tab_')->where($map)->count();
if($name=="son_settlement"){
$sum_money=M($name,'tab_')->where(array("promote_id"=>get_pid()))->sum("jie_money");
}else{
//随搜索条件变化
static $sum_money=0;
foreach ($data as $key => $value) {
$sum_money=$sum_money+$value['sum_money'];
if($value['ti_status']==1){
$kk[]=$data[$key];
}
}
foreach ($kk as $k=> $v) {
$y_money=$y_money+$v['sum_money'];
}
$w_money=$sum_money-$y_money;
}
//分页
$parameter = $map;
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
$list = $data;
$list['结算汇总'] = ['sum_money'=>$sum_money==""?'0.00':$sum_money];
$list['未提现汇总']=['sum_money'=>$w_money==""?'0.00':$w_money];
$list['成功提现汇总']=['sum_money'=>$y_money==""?'0.00':$y_money];
//file_put_contents(dirname(__FILE__) . '/../Controller/earning'.PID.'.txt',json_encode($list));
return $list;
}
public function earning_detail_data(){
$map['id'] = $_REQUEST['id'];
$data = M('TotalSettlement','tab_')->where($map)->find();
$mapSett['promote_id'] = $data['promote_id'];
$mapSett['starttime'] = $data['starttime'];
$mapSett['endtime'] = $data['endtime'];
$mapSett['create_time'] = $data['create_time'];
$listData = M('settlement','tab_')->where($mapSett)->select();
$totalData = M('settlement','tab_')->where($mapSett)->sum('sum_money');
$this->assign('total',$totalData);
$listData['汇总'] = ['sum_money'=>$totalData];
return $listData;
}
public function check_bill($model = null,$p,$extend=array()){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
$map0 = empty($extend[0])?array():$extend[0];
// var_dump($extend);exit;
$map1 = empty($extend[1])?array():$extend[1];
$row = empty($model['list_row']) ? 10 : $model['list_row'];
//读取模型数据列表
$name = $model['m_name'];
$data= M($name,'tab_')
/* 查询指定字段,不指定则查询所有字段 */
->field($fields)
->join($model['join'])
// 查询条件
->where($map1)
/* 默认通过id逆序排列 */
->order($order)
->group($model['group'])
/* 数据分页 */
->page($page,$row)
/* 执行查询 */
->select();
$data1 = M($name,'tab_')//spend表与apply表连获得数据没有注册人数
/* 查询指定字段,不指定则查询所有字段 */
->field($fields)
->join($model['join'])
// 查询条件
->where($map1)
/* 默认通过id逆序排列 */
->order($order)
->group($model['group'])
/* 数据分页 */
/* 执行查询 */
->select(false);
$data2 =M("user",'tab_')//$data1 sql语句 与user表连
->field('tab_user.id,tab_user.promote_id,tab_user.fgame_id as game_id,tab_user.fgame_name as game_name,tab_user.promote_account')
->join('INNER JOIN'.$data1."as p on p.game_id = tab_user.fgame_id and p.promote_id = tab_user.promote_id")
->where($map0)
->select(false);
$data3=M()//获得注册人数
->field("COUNT(q.id) as total_number,q.promote_id,q.fgame_id")
->join($data2.'as q')
->group("q.promote_id,q.fgame_id")
->query("select %FIELD% from %JOIN% %GROUP%",true);
if(!empty($data)&&!empty($data3)){
foreach ($data3 as $key => $value) {//如果游戏、推广员 同时符合,把注册人数插入data
foreach ($data as $k => $v) {
if($v['promote_id']==$value['promote_id']&&$v['game_id']==$value['fgame_id']){
$data[$k]['total_number']=$value['total_number'];
}
}
}
}
/* 查询记录总数 */
$count = M($name,'tab_')
/* 查询指定字段,不指定则查询所有字段 */
->field($fields)
->join($model['join'])
// 查询条件
->where($map1)
/* 默认通过id逆序排列 */
->order($order)
->group($model['group'])
/* 执行查询 */
->select();
$count=(count($count));
//分页
if($count > $row){
$page = new \Think\Page($count, $row);
//分页跳转的时候保证查询条件
foreach($_POST as $key=>$val) {
$page->parameter[$key] = $val;
}
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
}
$this->assign('model', $model);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
// 子渠道结算确认
public function check_bill_($model = null,$p,$extend=array()){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
// 关键字搜索
$map0 = empty($extend[0])?array():$extend[0];
$map1 = empty($extend[1])?array():$extend[1];
$user = M("User","tab_");
$spend = M("Spend","tab_");
//读取模型数据列表
$data = array();
$row = 10 ;
$map1['sub_status'] = $map0['sub_status'] = 0;
$map0['fgame_id'] = array('neq',0);
$map1['pay_status']=1;
$map1['is_check']=array('in',array(1,3));
$map0['is_check']=array('in',array(1,3));
$offset = ($page-1)*$row;
$sql0 = $user->table("__USER__ as u ")
->field('u.id,u.promote_id,p.account as promote_account,fgame_id,fgame_name,p.parent_id')
->join('__PROMOTE__ as p on(p.id=u.promote_id)','left')
->where($map0)
->order("u.id")
->group("u.id")
->select(false);
$sql0 = "select a.promote_id,a.promote_account,a.fgame_id as game_id,a.fgame_name as game_name,count(a.id) as total_number from ("
.$sql0
." ) as a left join tab_apply as ap on(a.parent_id=ap.promote_id and ap.game_id=fgame_id) "
." group by fgame_id,a.promote_id order by a.promote_account ";
$data0 = $user->query($sql0." limit $offset,$row");
$count0 = count($user->query($sql0));
$sql1 = $spend->table("__SPEND__ as s")
->field("s.id,s.promote_id,p.account as promote_account,p.parent_id,s.game_id,s.game_name,s.pay_amount ")
->join('__PROMOTE__ as p on(p.id=s.promote_id)','left')
->where($map1)
->group("id")
->select(false);
$sql1 = "select a.promote_id,a.promote_account,a.game_id,a.game_name,sum(a.pay_amount) as total_amount from ( "
.$sql1
." ) as a left join tab_apply as ap on(a.parent_id=ap.promote_id and ap.game_id=a.game_id) "
." group by a.game_id,a.promote_id order by a.promote_account ";
$data1 = $spend->query($sql1." limit $offset,$row");
$count1 = count($spend->query($sql1));
if (!empty($data1) && !empty($data0)) {
foreach ($data1 as $j => $u) {
foreach ($data0 as $k => $v) {
if (($u['promote_id'] == $v['promote_id']) && ($u['game_id'] == $v['game_id'])) {
$data[] = array_merge($u,$v);unset($data1[$j]);unset($data0[$k]);
}
}
}
$data = array_merge($data,$data0,$data1);
} elseif (!empty($data0)) {$data = $data0;}
elseif (!empty($data1)) {$data = $data1;}
$count = $count0>$count1?$count0:$count1;
//分页
if($count > $row){
$page = new \Think\Page($count, $row);
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
}
foreach ($data as $keyy => $valuee) {
if($valuee['game_id']>0){
$ggdata=M('Game','tab_')->where(array('id'=>$valuee['game_id']))->find();
$data[$keyy]['ratio']=$ggdata['ratio']==''?100.00:$ggdata['ratio'];
$data[$keyy]['money']=$ggdata['money']==''?20.00:$ggdata['money'];
}else{
$data[$keyy]['ratio']=0.00;
$data[$keyy]['money']=0.00;
}
}
$this->assign('model', $model);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
/**
* 子渠道结算
* @author 鹿文学
*/
public function check_child_bill($model = null,$p,$extend=array()){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
// 关键字搜索
$map0 = empty($extend[0])?array():$extend[0];
$map1 = empty($extend[1])?array():$extend[1];
$user = M("User","tab_");
$spend = M("Spend","tab_");
//读取模型数据列表
$data = array();
$row = 10 ;
$parentid = $model['currentid'];
$map1['s.'.SETTLEMENT_GRADE] = $map0['u.'.SETTLEMENT_GRADE] = 0;
$map0['fgame_id'] = array('neq',0);
$map1['pay_status']=1;
$map1['is_check']=array('in',array(1,3));
$map0['is_check']=array('in',array(1,3));
$map0['puid']=0;
$offset = ($page-1)*$row;
$sql0 = $user->table("__USER__ as u ")
->field('u.id,u.promote_id as tpromote_id,fgame_id,fgame_name,p.parent_id,if(p.parent_id = '.$parentid.',p.parent_id,p.id) as promote_id,if(p.parent_id = '.$parentid.',p.parent_name,p.account) as promote_account')
->join('__PROMOTE__ as p on(p.id=u.promote_id)','left')
->where($map0)
->order("u.id")
->group("u.id")
->select(false);
$sql0 = "select a.promote_id,a.promote_account,a.fgame_id as game_id,a.fgame_name as game_name,count(a.id) as total_number,GROUP_CONCAT(DISTINCT a.tpromote_id) as tupromote_id from ("
.$sql0
." ) as a left join tab_apply as ap on(a.parent_id=ap.promote_id and ap.game_id=fgame_id) "
." group by fgame_id,a.promote_id order by a.promote_account ";
$data0 = $user->query($sql0." limit $offset,$row");
$count0 = count($user->query($sql0));
$sql1 = $spend->table("__SPEND__ as s")
->field("s.id,s.promote_id as tpromote_id,p.parent_id,s.game_id,s.game_name,s.pay_amount,if(p.parent_id = ".$parentid.",p.parent_id,p.id) as promote_id,if(p.parent_id = ".$parentid.",p.parent_name,p.account) as promote_account ")
->join('__PROMOTE__ as p on(p.id=s.promote_id)','left')
->where($map1)
->group("id")
->select(false);
$sql1 = "select a.promote_id,a.promote_account,a.game_id,a.game_name,sum(a.pay_amount) as total_amount,GROUP_CONCAT(DISTINCT a.tpromote_id) as tspromote_id from ( "
.$sql1
." ) as a left join tab_apply as ap on(a.parent_id=ap.promote_id and ap.game_id=a.game_id) "
." group by a.game_id,a.promote_id order by a.promote_account ";
$data1 = $spend->query($sql1." limit $offset,$row");
$count1 = count($spend->query($sql1));
if (!empty($data1) && !empty($data0)) {
foreach ($data1 as $j => $u) {
foreach ($data0 as $k => $v) {
if (($u['promote_id'] == $v['promote_id']) && ($u['game_id'] == $v['game_id'])) {
$data[] = array_merge($u,$v);unset($data1[$j]);unset($data0[$k]);
}
}
}
$data = array_merge($data,$data0,$data1);
} elseif (!empty($data0)) {$data = $data0;}
elseif (!empty($data1)) {$data = $data1;}
$count = $count0>$count1?$count0:$count1;
//分页
if($count > $row){
$page = new \Think\Page($count, $row);
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
}
foreach ($data as $keyy => $valuee) {
if($valuee['game_id']>0){
if(PRO_GRADE == 1 || PRO_GRADE == 2) {
$applyresult = M('apply','tab_')->field('promote_ratio,promote_money')->where(['game_id'=>$valuee['game_id'],'promote_id'=>$parentid])->find();
if(!empty($applyresult) && !empty($applyresult['promote_ratio']) && !empty($applyresult['promote_money']) && ($applyresult['promote_ratio']*1>=0 && $applyresult['promote_money']*1>=0 )) {
$data[$keyy]['ratio']=$applyresult['promote_ratio']==''?0.00:$applyresult['promote_ratio'];
$data[$keyy]['money']=$applyresult['promote_money']==''?0.00:$applyresult['promote_money'];
} else {
$ggdata=M('Game','tab_')->where(array('id'=>$valuee['game_id']))->find();
$data[$keyy]['ratio']=(!empty($applyresult['promote_ratio']) && $applyresult['promote_ratio']*1>=0)?$applyresult['promote_ratio']:($ggdata['ratio']==''?100.00:$ggdata['ratio']);
$data[$keyy]['money']=(!empty($applyresult['promote_money']) && $applyresult['promote_money']*1>=0)?$applyresult['promote_money']:($ggdata['money']==''?20.00:$ggdata['money']);
}
} else {
$data[$keyy]['ratio']=0.00;
$data[$keyy]['money']=0.00;
}
}else{
$data[$keyy]['ratio']=0.00;
$data[$keyy]['money']=0.00;
}
if($valuee['tspromote_id'] && $valuee['tupromote_id']) {
$data[$keyy]['tpromote_id'] = implode(',',array_unique(array_merge(explode(',',$valuee['tspromote_id']),explode(',',$valuee['tupromote_id']))));
/* unset($data[$keyy]['tspromote_id']);
unset($data[$keyy]['tupromote_id']); */
} elseif($valuee['tspromote_id']) {
$data[$keyy]['tpromote_id'] = $valuee['tspromote_id'];/* unset($data[$keyy]['tspromote_id']); */
} elseif($valuee['tupromote_id']) {
$data[$keyy]['tpromote_id'] = $valuee['tupromote_id'];/* unset($data[$keyy]['tupromote_id']); */
}
}
$this->assign('model', $model);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function money_list($model = null,$p,$extend=array()) {
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
//解析列表规则
$fields = $model['fields'];
// 关键字搜索
$map = empty($extend)?array():$extend;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
//读取模型数据列表
$name = $model['m_name'];
$new_model = M($name,"tab_");
$data = $new_model
->field(empty($model['fields'])?true:$model['fields'])
->where($map)
->group($model['group'])
->order($model['order'])
->page($page, $row)
->select();
/*$count = $new_model->where($map)->group($model['group'])->count();*/
$result = $new_model->field($model['group'])->where($map)->group($model['group'])->select();
$count = count($result);
$total = 0;
foreach ($data as $v) {
$total += $v['jie_money'];
}
//分页
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->assign('model', $model);
$this->assign('list_data', $data);
$this->assign('total',$total);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function son_list($model,$p){
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$spen_map = $model['spen_map'];
$user_map = $model['user_map'];
$row = empty($model['list_row']) ? 10 : $model['list_row'];
$apply=M("apply","tab_")
->field("promote_id,game_id,game_name,pattern")
->group("promote_id,game_id")
->select();
$spend=M("spend","tab_")
->field("promote_id,promote_account,game_id,game_name,sum(pay_amount)")
->group("promote_id,game_id")
->where($spen_map)
// ->page($page, $row)
->select();
$user_count=M("user as a ","tab_")
->field("fgame_id,fgame_name,promote_id,promote_account,count(*) as count")
->group("promote_id,fgame_id")
->where($user_map)
->select();
foreach ($apply as $key => $value) {
foreach ($spend as $k => $v) {
if($v['promote_id']==$value['promote_id']&&$v['game_id']==$value['game_id']){
$spend[$k]['pattern']=$value['pattern'];
}
foreach ($user_count as $s => $d) {
if($v['game_id']==$d['fgame_id']&&$v['promote_id']==$d['promote_id']){
$spend[$k]['count']=$d['count'];
}
}
}
}
$count=count($spend);
//分页
if($count > $row){
$page = new \Think\Page($count, $row);
$list=array_slice($spend,$page->firstRow,$page->listRows);
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page',$page->show());
}
$this->assign('model', $model);
$this->assign('list_data', $list);
$this->assign('p', $p);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
public function arpu_analysis() {
$promote = M('promote', 'tab_')->where(['id' => session('promote_auth.pid')])->find();
$map = [
'_logic' => 'or',
'id' => $promote['id'],
'parent_id' => $promote['id'],
'grand_id' => $promote['id'],
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
if (IS_POST && $_POST['time_start'] && $_POST['time_end']) {
$request = $_REQUEST;
$game_id = $request['game_id'];
$promote_id = $request['promote_id'];
$this->assign('promote_arpu', $promote_id);
$start = strtotime($request['time_start']);
$end = strtotime($request['time_end'])+24*60*60-1;
if ($start>$end) {
$start = $end;
$_REQUEST['time_start'] = $request['time_end'];
$_REQUEST['time_end'] = $request['time_start'];
$end = strtotime($request['time_start']);
}
} else {
$game_id = empty($request['game_id'])?0:$request['game_id'];
$promote_id = empty($request['promote_id'])?0:$request['promote_id'];
$start = mktime(0,0,0,date('m'),date('d')-6,date('Y'));
$_REQUEST['time_start'] = date('Y-m-d',$start);
$end = time();
$_REQUEST['time_end'] = date('Y-m-d');
}
//包含绑币 和 排除绑币
if (I('bind_coin') == 1){
$bangbi = true;
}else{
$bangbi = false;
}
if ($end - $start <= 7776000 ) {
if ($promote_id <1) {
$pid = D('Promote')->get_child_promote(PID,'id');
if (empty($pid[0])) {
$promote_id = PID;
} else {
$id = implode(',',array_column($pid,'id'));
$promote_id = PID.','.$id;
}
} else {
if(PID == $promote_id) {
} else {
$pro_id1 = get_prmoote_chlid_account($promote_id);
$pro_arr = array_column($pro_id1,'id');
$pro_arr[] = $promote_id;
$promote_id=implode(',',$pro_arr);
}
}
$datelist = get_date_list($start,$end);
$user = D('User');
$spend = D('Spend');
/*付费游戏数*/
$paygame = $spend->pay_game_by_time($start,$end,$game_id,$promote_id,$bangbi);
$newslist = $user->register_list_by_time($start,$end,$game_id,$promote_id,'time','');
/* 活跃玩家 */
$activelist = $user->login_count_by_time($start,$end,$game_id,$promote_id);
/* 充值金额 */
$incomelist = $spend -> money_amount_by_time($start,$end,$game_id,$promote_id,$bangbi);
/* 付费玩家 */
$paylist = $spend->pay_count_by_time($start,$end,$game_id,$promote_id,$bangbi);
/* 新付费玩家 */
$newspay = $spend->pay_count_by_time_class_game($datelist,$game_id,$promote_id,1,$bangbi);
/*新付费金额*/
$newspaysum = $spend->pay_sum_by_time_class_game($datelist,$game_id,$promote_id,1,$bangbi);
/* 开始时间前的付费玩家 */
$totalPayPlayer = $spend->payUsersStatisticsAgo($start,$game_id,$promote_id,$bangbi);
/* 留存 */
$ratention1 = $user->ratention_rate($newslist,$game_id,$promote_id);
/* 数据整理 */
foreach($datelist as $dv) {
$newPayUsers[$dv]=$activeUsers[$dv]=$newUsers[$dv]=$payUsers[$dv]=$usersIncome[$dv]=$ratentionRate1[$dv]=0;
$data[$dv]['newPayUsers']=$data[$dv]['activeUsers']=$data[$dv]['newUsers']=$data[$dv]['payUsers']=$data[$dv]['usersIncome']=0;
$data[$dv]['totalPayUsers']=intval($totalPayPlayer);
$data[$dv]['ratentionRate1']='--';
$data[$dv]['usersPayRate'] = '--';
$data[$dv]['usersArpu']=0;
$data[$dv]['usersArppu']=0;
$data[$dv]['payGame'] = 0;
}
foreach($datelist as $dv) {
/**
* 付费游戏数
*/
foreach ($paygame as $pgal) {
if($dv == $pgal['pay_time']) {
$paygame[$dv]=intval($pgal['pay_num']);
$data[$dv]['payGame']=intval($pgal['pay_num']);break;
}
}
/* 新增玩家 */
foreach ($newslist as $nlv) {
if ($dv == $nlv['time']) {
$data[$dv]['newUsers']=count(explode(',',$nlv['id']));break;
}
}
/* 活跃玩家 */
foreach ($activelist as $alv) {
if ($dv == $alv['time']) {
$activeUsers[$dv]=intval($alv['login_num']);
$data[$dv]['activeUsers']=intval($alv['login_num']);break;
}
}
/* 充值金额 */
foreach ($incomelist as $ilv) {
if($ilv['pay_time']==$dv) {
$usersIncome[$dv] = round($ilv['money_amount'],2);
$data[$dv]['usersIncome'] = round($ilv['money_amount'],2);
break;
}
}
/* 付费玩家 */
foreach ($paylist as $plv) {
if ($plv['pay_time']==$dv) {
$payUsers[$dv]=intval($plv['pay_num']);
$data[$dv]['payUsers']=intval($plv['pay_num']);break;
}
}
/* 1日留存 */
foreach ($ratention1 as $r1) {
if ($r1['play_time'] == $dv) {
$rate = str_replace('.00','',$r1['retention_rate1']);
$data[$dv]['ratentionRate1']=$rate.'%';break;
}
}
/* 新付费玩家 */
foreach ($newspay as $npv) {
if ($npv['pay_time'] == $dv) {
$totalPayPlayer = $totalPayPlayer+intval($npv['pay_num']);
$data[$dv]['newPayUsers']=intval($npv['pay_num']);
$data[$dv]['totalPayUsers']=intval($totalPayPlayer);
break;
} else {
$data[$dv]['totalPayUsers']=intval($totalPayPlayer);
}
}
/*新付费金额*/
foreach ($newspaysum as $nspv) {
if ($nspv['pay_time'] == $dv) {
$data[$dv]['newPaySum']=round($nspv['pay_sum'],2);
break;
}
}
}
foreach ($activeUsers as $k1=>$ap) {
/* 付费率=付费玩家/活跃玩家 */
foreach ($payUsers as $k2 => $pp) {
if ($k1 === $k2 && $ap>0 && $pp>0) {
$payrate = sprintf("%.2f",$pp/$ap*100);
$data[$k1]['usersPayRate']=str_replace('.00','',$payrate).'%';
break;
} elseif ($k1 === $k2) {
}
}
/* ARPU=当日总充值数/活跃玩家数 */
foreach ($usersIncome as $k2 => $ns) {
if ($k1 === $k2 && $ap>0 && $ns>0) {
$data[$k1]['usersArpu']=$ns/$ap;//str_replace('.00','',$ui);
break;
} elseif ($k1 === $k2) {
}
}
}
foreach ($usersIncome as $k1 => $ns) {
/* ARPPU=当日总充值/付费玩家数 */
foreach ($payUsers as $k2 => $pp) {
if ($k1 === $k2 && $pp>0 && $ns>0) {
$data[$k1]['usersArppu']=$ns/$pp;//sprintf("%d",$ns/$pp);
break;
} elseif ($k1 === $k2) {
}
}
}
} else {
$this->assign('timeout',1);
}
//file_put_contents(dirname(__FILE__) . '/../Controller/arpu'.PID.'.txt',json_encode($data));
$this->assign('list_data',$data);
$this->display();
}
public function arpu_analysis_data() {
if ($_REQUEST['time_start'] && $_REQUEST['time_end']) {
$request = $_REQUEST;
$game_id = $request['game_id'];
$promote_id = $request['promote_id'];
$start = strtotime($request['time_start']);
$end = strtotime($request['time_end'])+24*60*60-1;
if ($start>$end) {
$start = $end;
$_REQUEST['time_start'] = $request['time_end'];
$_REQUEST['time_end'] = $request['time_start'];
$end = strtotime($request['time_start']);
}
} else {
$game_id = empty($request['game_id'])?0:$request['game_id'];
$promote_id = empty($request['promote_id'])?0:$request['promote_id'];
$start = mktime(0,0,0,date('m'),date('d')-6,date('Y'));
$_REQUEST['time_start'] = date('Y-m-d',$start);
$end = time();
$_REQUEST['time_end'] = date('Y-m-d');
}
//包含绑币 和 排除绑币
if (I('bind_coin') == 1){
$bangbi = true;
}else{
$bangbi = false;
}
if ($end-$start<=7776000 ) {
if ($promote_id <1) {
$pid = D('Promote')->get_child_promote(PID,'id');
if (empty($pid[0])) {
$promote_id = PID;
} else {
$id = implode(',',array_column($pid,'id'));
$promote_id = PID.','.$id;
}
} else {
$pro_id1=get_prmoote_chlid_account($promote_id);
$pro_arr = array_column($pro_id1,'id');
$pro_arr[] = $promote_id;
$promote_id=implode(',',$pro_arr);
}
$datelist = get_date_list($start,$end);
$user = D('User');
$spend = D('Spend');
/*付费游戏数*/
$paygame = $spend->pay_game_by_time($start,$end,$game_id,$promote_id,$bangbi);
$newslist = $user->register_list_by_time($start,$end,$game_id,$promote_id,'time','');
/* 活跃玩家 */
$activelist = $user->login_count_by_time($start,$end,$game_id,$promote_id);
/* 充值金额 */
$incomelist = $spend -> money_amount_by_time($start,$end,$game_id,$promote_id,$bangbi);
/* 付费玩家 */
$paylist = $spend->pay_count_by_time($start,$end,$game_id,$promote_id,$bangbi);
/* 新付费玩家 */
$newspay = $spend->pay_count_by_time_class_game($datelist,$game_id,$promote_id,1,$bangbi);
/*新付费金额*/
$newspaysum = $spend->pay_sum_by_time_class_game($datelist,$game_id,$promote_id,1,$bangbi);
/* 开始时间前的付费玩家 */
$totalPayPlayer = $spend->payUsersStatisticsAgo($start,$game_id,$promote_id,$bangbi);
/* 留存 */
$ratention1 = $user->ratention_rate($newslist,$game_id,$promote_id);
/* 数据整理 */
foreach($datelist as $dv) {
$newPayUsers[$dv]=$activeUsers[$dv]=$newUsers[$dv]=$payUsers[$dv]=$usersIncome[$dv]=$ratentionRate1[$dv]=0;
$data[$dv]['newPayUsers']=$data[$dv]['activeUsers']=$data[$dv]['newUsers']=$data[$dv]['payUsers']=$data[$dv]['usersIncome']=0;
$data[$dv]['totalPayUsers']=intval($totalPayPlayer);
$data[$dv]['ratentionRate1']='--';
$data[$dv]['usersPayRate'] = '--';
$data[$dv]['usersArpu']=0;
$data[$dv]['usersArppu']=0;
$data[$dv]['payGame'] = 0;
}
foreach($datelist as $dv) {
/**
* 付费游戏数
*/
foreach ($paygame as $pgal) {
if($dv == $pgal['pay_time']) {
$paygame[$dv]=intval($pgal['pay_num']);
$data[$dv]['payGame']=intval($pgal['pay_num']);break;
}
}
/* 新增玩家 */
foreach ($newslist as $nlv) {
if ($dv == $nlv['time']) {
$data[$dv]['newUsers']=count(explode(',',$nlv['id']));break;
}
}
/* 活跃玩家 */
foreach ($activelist as $alv) {
if ($dv == $alv['time']) {
$activeUsers[$dv]=intval($alv['login_num']);
$data[$dv]['activeUsers']=intval($alv['login_num']);break;
}
}
/* 充值金额 */
foreach ($incomelist as $ilv) {
if($ilv['pay_time']==$dv) {
$usersIncome[$dv] = round($ilv['money_amount'],2);
$data[$dv]['usersIncome'] = round($ilv['money_amount'],2);
break;
}
}
/* 付费玩家 */
foreach ($paylist as $plv) {
if ($plv['pay_time']==$dv) {
$payUsers[$dv]=intval($plv['pay_num']);
$data[$dv]['payUsers']=intval($plv['pay_num']);break;
}
}
/* 1日留存 */
foreach ($ratention1 as $r1) {
if ($r1['play_time'] == $dv) {
$rate = str_replace('.00','',$r1['retention_rate1']);
$data[$dv]['ratentionRate1']=$rate.'%';break;
}
}
/* 新付费玩家 */
foreach ($newspay as $npv) {
if ($npv['pay_time'] == $dv) {
$totalPayPlayer = $totalPayPlayer+intval($npv['pay_num']);
$data[$dv]['newPayUsers']=intval($npv['pay_num']);
$data[$dv]['totalPayUsers']=intval($totalPayPlayer);
break;
} else {
$data[$dv]['totalPayUsers']=intval($totalPayPlayer);
}
}
/*新付费金额*/
foreach ($newspaysum as $nspv) {
if ($nspv['pay_time'] == $dv) {
$data[$dv]['newPaySum']=round($nspv['pay_sum'],2);
break;
}
}
}
foreach ($activeUsers as $k1=>$ap) {
/* 付费率=付费玩家/活跃玩家 */
foreach ($payUsers as $k2 => $pp) {
if ($k1 === $k2 && $ap>0 && $pp>0) {
$payrate = sprintf("%.2f",$pp/$ap*100);
$data[$k1]['usersPayRate']=str_replace('.00','',$payrate).'%';
break;
} elseif ($k1 === $k2) {
}
}
/* ARPU=当日总充值数/活跃玩家数 */
foreach ($usersIncome as $k2 => $ns) {
if ($k1 === $k2 && $ap>0 && $ns>0) {
$data[$k1]['usersArpu']=$ns/$ap;//str_replace('.00','',$ui);
break;
} elseif ($k1 === $k2) {
}
}
}
foreach ($usersIncome as $k1 => $ns) {
/* ARPPU=当日总充值/付费玩家数 */
foreach ($payUsers as $k2 => $pp) {
if ($k1 === $k2 && $pp>0 && $ns>0) {
$data[$k1]['usersArppu']=$ns/$pp;//sprintf("%d",$ns/$pp);
break;
} elseif ($k1 === $k2) {
}
}
}
} else {
$this->assign('timeout',1);
}
//file_put_contents(dirname(__FILE__) . '/../Controller/arpu'.PID.'.txt',json_encode($data));
return $data;
}
public function arpu_analysis_detail_data($p=0){
$time = $_REQUEST['time'];
$promote_id = $_REQUEST['promote_id'];
$join = "left join tab_user u on u.fgame_id = tab_game.id";
if($time==''){
$this->error('参数错误,缺少时间');
}else{
$map['register_time']=array('between',array(strtotime($time),strtotime($time)+24*60*60-1));
}
if($promote_id>0) {
if(PID == $promote_id) {
$pro_arr[] = PID;
} else {
$pro_id1=get_prmoote_chlid_account2($promote_id);
$pro_arr = array_column($pro_id1,'id');
$pro_arr[] = $promote_id;
}
$map['promote_id']=array('in',$pro_arr);
$map_list['promote_id']=array('in',$pro_arr);
$promote_id = implode(',',$pro_arr);
$join .= " AND u.promote_id in ({$promote_id})";
} else {
$pid = D('Promote')->get_child_promote(PID,'id');
if (empty($pid[0])) {
$pro_arr[] = PID;
} else {
$pro_arr = array_column($pid,'id');
$pro_arr[] = PID;
}
$map['promote_id']=array('in',$pro_arr);
$map_list['promote_id']=array('in',$pro_arr);
$promote_id = implode(',',$pro_arr);
$join .= " AND u.promote_id in ({$promote_id})";
}
$spend2 = D('Spend');
$data=M('Game','tab_')->field('id as game_id, game_name')->order('id desc')->select();
foreach ($data as $key => $value) {
$game_id = $value['game_id'];
$map_list['game_id']=$game_id;
$user=M('User','tab_');
$spend=M('spend','tab_');
//新增人数
$rdata=$user
->field('count(id) as register_num')
->where(array('fgame_id'=>$game_id))
->where(array_merge($map,['puid'=>0]))
->find();
$data[$key]['register_num']=$rdata['register_num'];
//活跃玩家
//$data[$key]['act_user'] = $this->count_act_user($time,$game_id,$promote_id);
$activedata = D('User')->login_count_by_time(strtotime($time),strtotime($time)+86399,$game_id,$promote_id);
$data[$key]['act_user'] = $activedata[0]['login_num']?$activedata[0]['login_num']:0;
//1日留存
$mapl=$map_list;
$mapl["FROM_UNIXTIME(register_time,'%Y-%m-%d')"] = $time;
$mapl['tab_user.promote_id']=$mapl['promote_id'];$mapl['tab_user.puid'] = 0;
unset($mapl['promote_id']);
$login_time = date('Y-m-d', strtotime("+1 day",strtotime($time)));
$num = $user
->field('count(DISTINCT tab_user.id) as num')
->join("right join tab_user_login_record as ur on ur.user_id = tab_user.id and FROM_UNIXTIME(ur.login_time,'%Y-%m-%d') = '{$login_time}'")
->where($mapl)
->find();
$data[$key]['keep_num'] = round($num['num']/$data[$key]['register_num'],4)*100;
//充值
$mapl = $map_list;
empty($game_name ) || $mapl['game_name'] = array('like','%'.$game_name.'%');
$mapl['pay_status'] = 1;
$mapl["FROM_UNIXTIME(pay_time,'%Y-%m-%d')"] = $time;
if (I('bangbi') == 1){
$mapl['pay_way'] = array('neq','-10');$bangbi = true;
}else{
$mapl['pay_way'] = array('neq',-1);$bangbi = false;
}
$spend = $spend->field("IFNULL(sum(pay_amount),0) as money,IFNULL(count(distinct user_id),0) as people")->where($mapl)->find();
$data[$key]['spend'] = $spend['money'];
//付费玩家数
$data[$key]['spend_people'] = $spend['people'];
//新付费玩家
$newsdata = $spend2->pay_count_by_time_class([$time],$game_id,$promote_id,1,$bangbi);
$data[$key]['spend_news'] = $newsdata[0]['pay_num']?$newsdata[0]['pay_num']:0;
//付费率
$data[$key]['spend_rate'] = round($data[$key]['spend_people']/$data[$key]['act_user'],4)*100;
//ARPU
$data[$key]['ARPU'] = round($data[$key]['spend']/$data[$key]['act_user'],2);
//ARPPU
$data[$key]['ARPPU'] = round($data[$key]['spend']/$data[$key]['spend_people'],2);
if($data[$key]['register_num']==0&&$data[$key]['act_user']==0&&$data[$key]['keep_num']==0&&$data[$key]['spend']==0&&$data[$key]['spend_people']==0){
unset($data[$key]);
}
}
return $data;
}
public function retention_analysis() {
if (IS_POST && $_POST['time-start'] && $_POST['time-end']) {
$request=$_REQUEST;
$game_id = $request['game_id'];
$promote_id = $request['promote_id'];
$start = strtotime($request['time-start']);
$end = strtotime($request['time-end'])+24*60*60-1;
if ($start>$end) {
$start = $end;
$_REQUEST['time-start'] = $request['time-end'];
$_REQUEST['time-end'] = $request['time-start'];
$end = strtotime($request['time-start']);
}
} else {
$game_id = 0;
$promote_id = 0;
$start = mktime(0,0,0,date('m'),date('d')-9,date('Y'));
$_REQUEST['time-start'] = date('Y-m-d',$start);
$end = time();
$_REQUEST['time-end'] = date('Y-m-d');
}
if ($promote_id <1) {
$pid = D('Promote')->get_child_promote(PID,'id');
if (empty($pid[0])) {
$promote_id = PID;
} else {
$id = implode(',',array_column($pid,'id'));
$promote_id = PID.','.$id;
}
} else {
if ($promote_id != PID) {
$pro_id1=get_prmoote_chlid_account($promote_id);
$pro_arr = array_column($pro_id1,'id');
$pro_arr[] = $promote_id;
$promote_id=implode(',',$pro_arr);
}
}
$datelist = get_date_list($start,$end);
$user = D('User');
$newslist = $user->register_list_by_time($start,$end,$game_id,$promote_id,'time','');
$ratention1 = $user->ratention_rate($newslist,$game_id,$promote_id);
$ratention2 = $user->ratention_rate($newslist,$game_id,$promote_id,2);
$ratention3 = $user->ratention_rate($newslist,$game_id,$promote_id,3);
$ratention4 = $user->ratention_rate($newslist,$game_id,$promote_id,4);
$ratention5 = $user->ratention_rate($newslist,$game_id,$promote_id,5);
$ratention6 = $user->ratention_rate($newslist,$game_id,$promote_id,6);
$ratention7 = $user->ratention_rate($newslist,$game_id,$promote_id,7);
$ratention15 = $user->ratention_rate($newslist,$game_id,$promote_id,15);
$ratention30 = $user->ratention_rate($newslist,$game_id,$promote_id,30);
foreach($datelist as $dv) {
$data[$dv]['newUsers']=0;
$data[$dv]['ratentionRate1']=$data[$dv]['ratentionRate2']=$data[$dv]['ratentionRate3']=$data[$dv]['ratentionRate4']=$data[$dv]['ratentionRate5']=$data[$dv]['ratentionRate6']=$data[$dv]['ratentionRate7']=$data[$dv]['ratentionRate15']=$data[$dv]['ratentionRate30']='--';
/* 新增玩家 */
foreach ($newslist as $nlv) {
if ($dv == $nlv['time']) {
$data[$dv]['newUsers']=count(explode(',',$nlv['id']));break;
}
}
/* 1日留存 */
foreach ($ratention1 as $r1) {
if ($r1['play_time'] == $dv) {
$rate1 = str_replace('.00','',$r1['retention_rate1']);
$data[$dv]['ratentionRate1']=$rate1.'%';break;
}
}
foreach ($ratention2 as $r2) {
if ($r2['play_time'] == $dv) {
$rate2 = str_replace('.00','',$r2['retention_rate2']);
$data[$dv]['ratentionRate2']=$rate2.'%';break;
}
}
foreach ($ratention3 as $r3) {
if ($r3['play_time'] == $dv) {
$rate3 = str_replace('.00','',$r3['retention_rate3']);
$data[$dv]['ratentionRate3']=$rate3.'%';break;
}
}
foreach ($ratention4 as $r4) {
if ($r4['play_time'] == $dv) {
$rate4 = str_replace('.00','',$r4['retention_rate4']);
$data[$dv]['ratentionRate4']=$rate4.'%';break;
}
}
foreach ($ratention5 as $r5) {
if ($r5['play_time'] == $dv) {
$rate5 = str_replace('.00','',$r5['retention_rate5']);
$data[$dv]['ratentionRate5']=$rate5.'%';break;
}
}
foreach ($ratention6 as $r6) {
if ($r6['play_time'] == $dv) {
$rate6 = str_replace('.00','',$r6['retention_rate6']);
$data[$dv]['ratentionRate6']=$rate6.'%';break;
}
}
foreach ($ratention7 as $r7) {
if ($r7['play_time'] == $dv) {
$rate7 = str_replace('.00','',$r7['retention_rate7']);
$data[$dv]['ratentionRate7']=$rate7.'%';break;
}
}
foreach ($ratention15 as $r15) {
if ($r15['play_time'] == $dv) {
$rate15 = str_replace('.00','',$r15['retention_rate15']);
$data[$dv]['ratentionRate15']=$rate15.'%';break;
}
}
foreach ($ratention30 as $r30) {
if ($r30['play_time'] == $dv) {
$rate30 = str_replace('.00','',$r30['retention_rate30']);
$data[$dv]['ratentionRate30']=$rate30.'%';break;
}
}
}
//file_put_contents(dirname(__FILE__) . '/../Controller/retention'.PID.'.txt',json_encode($data));
$this->assign('list_data',$data);
$this->display();
}
public function retention_analysis_data() {
if ($_REQUEST['time-start'] && $_REQUEST['time-end']) {
$request=$_REQUEST;
$game_id = $request['game_id'];
$promote_id = $request['promote_id'];
$start = strtotime($request['time-start']);
$end = strtotime($request['time-end'])+24*60*60-1;
if ($start>$end) {
$start = $end;
$_REQUEST['time-start'] = $request['time-end'];
$_REQUEST['time-end'] = $request['time-start'];
$end = strtotime($request['time-start']);
}
} else {
$game_id = 0;
$promote_id = 0;
$start = mktime(0,0,0,date('m'),date('d')-9,date('Y'));
$_REQUEST['time-start'] = date('Y-m-d',$start);
$end = time();
$_REQUEST['time-end'] = date('Y-m-d');
}
if ($promote_id <1) {
$pid = D('Promote')->get_child_promote(PID,'id');
if (empty($pid[0])) {
$promote_id = PID;
} else {
$id = implode(',',array_column($pid,'id'));
$promote_id = PID.','.$id;
}
} else {
$pro_id1=get_prmoote_chlid_account($promote_id);
$pro_arr = array_column($pro_id1,'id');
$pro_arr[] = $promote_id;
$promote_id=implode(',',$pro_arr);
}
$datelist = get_date_list($start,$end);
$user = D('User');
$newslist = $user->register_list_by_time($start,$end,$game_id,$promote_id,'time','');
$ratention1 = $user->ratention_rate($newslist,$game_id,$promote_id);
$ratention2 = $user->ratention_rate($newslist,$game_id,$promote_id,2);
$ratention3 = $user->ratention_rate($newslist,$game_id,$promote_id,3);
$ratention4 = $user->ratention_rate($newslist,$game_id,$promote_id,4);
$ratention5 = $user->ratention_rate($newslist,$game_id,$promote_id,5);
$ratention6 = $user->ratention_rate($newslist,$game_id,$promote_id,6);
$ratention7 = $user->ratention_rate($newslist,$game_id,$promote_id,7);
$ratention15 = $user->ratention_rate($newslist,$game_id,$promote_id,15);
$ratention30 = $user->ratention_rate($newslist,$game_id,$promote_id,30);
foreach($datelist as $dv) {
$data[$dv]['newUsers']=0;
$data[$dv]['ratentionRate1']=$data[$dv]['ratentionRate2']=$data[$dv]['ratentionRate3']=$data[$dv]['ratentionRate4']=$data[$dv]['ratentionRate5']=$data[$dv]['ratentionRate6']=$data[$dv]['ratentionRate7']=$data[$dv]['ratentionRate15']=$data[$dv]['ratentionRate30']='--';
/* 新增玩家 */
foreach ($newslist as $nlv) {
if ($dv == $nlv['time']) {
$data[$dv]['newUsers']=count(explode(',',$nlv['id']));break;
}
}
/* 1日留存 */
foreach ($ratention1 as $r1) {
if ($r1['play_time'] == $dv) {
$rate1 = str_replace('.00','',$r1['retention_rate1']);
$data[$dv]['ratentionRate1']=$rate1.'%';break;
}
}
foreach ($ratention2 as $r2) {
if ($r2['play_time'] == $dv) {
$rate2 = str_replace('.00','',$r2['retention_rate2']);
$data[$dv]['ratentionRate2']=$rate2.'%';break;
}
}
foreach ($ratention3 as $r3) {
if ($r3['play_time'] == $dv) {
$rate3 = str_replace('.00','',$r3['retention_rate3']);
$data[$dv]['ratentionRate3']=$rate3.'%';break;
}
}
foreach ($ratention4 as $r4) {
if ($r4['play_time'] == $dv) {
$rate4 = str_replace('.00','',$r4['retention_rate4']);
$data[$dv]['ratentionRate4']=$rate4.'%';break;
}
}
foreach ($ratention5 as $r5) {
if ($r5['play_time'] == $dv) {
$rate5 = str_replace('.00','',$r5['retention_rate5']);
$data[$dv]['ratentionRate5']=$rate5.'%';break;
}
}
foreach ($ratention6 as $r6) {
if ($r6['play_time'] == $dv) {
$rate6 = str_replace('.00','',$r6['retention_rate6']);
$data[$dv]['ratentionRate6']=$rate6.'%';break;
}
}
foreach ($ratention7 as $r7) {
if ($r7['play_time'] == $dv) {
$rate7 = str_replace('.00','',$r7['retention_rate7']);
$data[$dv]['ratentionRate7']=$rate7.'%';break;
}
}
foreach ($ratention15 as $r15) {
if ($r15['play_time'] == $dv) {
$rate15 = str_replace('.00','',$r15['retention_rate15']);
$data[$dv]['ratentionRate15']=$rate15.'%';break;
}
}
foreach ($ratention30 as $r30) {
if ($r30['play_time'] == $dv) {
$rate30 = str_replace('.00','',$r30['retention_rate30']);
$data[$dv]['ratentionRate30']=$rate30.'%';break;
}
}
}
///file_put_contents(dirname(__FILE__) . '/../Controller/retention'.PID.'.txt',json_encode($data));
return $data;
}
}