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.

158 lines
5.4 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 Admin\Controller;
class RechargeSumController extends ThinkController{
public function summation($p=1)
{
if(!empty($_REQUEST['timeStart']) && !empty($_REQUEST['timeEnd'])){
$starttime = strtotime($_REQUEST['timeStart']);
$endtime = strtotime($_REQUEST['timeEnd']);
} elseif(!empty($_REQUEST['timeStart']) && empty($_REQUEST['timeEnd'])) {
$starttime = strtotime($_REQUEST['timeStart']);
$endtime = strtotime(date('Y-m-d'));
} elseif(empty($_REQUEST['timeStart']) && !empty($_REQUEST['timeEnd'])) {
$user = D('User')->field('register_time')->order('id asc')->find();
$starttime = strtotime(date('Y-m-d',$user['register_time']));
$endtime = strtotime($_REQUEST['timeEnd']);
} else {
$user = D('User')->field('register_time')->order('id asc')->find();
$starttime = strtotime(date('Y-m-d',$user['register_time']));
$endtime = strtotime(date('Y-m-d'));
}
$key = 0;
$total = ['current'=>0,'sum'=>0];
for($start = $endtime; $start >= $starttime;$start -= 86400)
{
$startDate = $start;
$endDate = $startDate + 24*60*60-1;
$rmap['register_time'] = $map['register_time'] = array('BETWEEN',array($startDate,$endDate));
$map['play_time'] = array('BETWEEN',array($startDate,$endDate));
$map['pay_time'] = array('BETWEEN',array($startDate,$endDate));
if(!empty($_REQUEST['game_id'])){
$map['game_id'] = $_REQUEST['game_id'];
$rmap['fgame_id'] = $_REQUEST['game_id'];
}
if($_REQUEST['bindcoin']==1) {
$map['pay_way'] = array('egt',0);
}
if(!empty($_REQUEST['promote_id'])){
// switch ($_REQUEST['promote_id']) {
// case 'GUANFANG':
// $map['promote_id'] = 0;
// $rmap['promote_id'] = 0;
// break;
// case 'PROMOTE':
// $map['promote_id'] = array('neq',0);
// $rmap['promote_id'] = array('neq',0);
// break;
// default:
// $map['promote_id'] = $_REQUEST['promote_id'];
// $rmap['promote_id'] = $_REQUEST['promote_id'];
// break;
// }
$promoter_ids = D("Promote")->where("parent_id={$_REQUEST['promote_id']} or grand_id={$_REQUEST['promote_id']} or id={$_REQUEST['promote_id']}")->field('id')->select();
$promoter_ids ? $rmap['promote_id'] = $map['promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))] : null;
}
//当天注册人数
$registerNum = D('User')->where(array_merge($rmap,array('puid'=>0)))->getField("id",true);
//当天活跃人数
$livenNum = D('UserPlay')->where($map)->count("id");
//当天新增付费
if(empty($registerNum)){
$map['user_id'] = array('IN','0');
}else{
$map['user_id'] = array('IN',$registerNum);
}
$map['pay_status'] = 1;
$newAddPay = D('Spend')->where(array_merge($map,array('_string'=>'( small_id = 0 or small_id = user_id)')))->sum('pay_amount');
//当天累计付费
unset($map['user_id']);
$accumulated = D('Spend')->where($map)->sum('pay_amount');
$data[$key]['date'] = date('Y-m-d',$start);
$data[$key]['game_id'] = empty($_REQUEST['game_id'])?"全部":get_game_name($_REQUEST['game_id']);
switch ($_REQUEST['promote_id']) {
case 'GUANFANG':
$data[$key]['promote_id'] = "官方渠道";
break;
case 'PROMOTE':
$data[$key]['promote_id'] = "推广渠道";
break;
case 'ALL':
$data[$key]['promote_id'] = "全部";
break;
default:
$data[$key]['promote_id'] = empty($_REQUEST['promote_id'])?"全部":get_promote_account($_REQUEST['promote_id']);
break;
}
$data[$key]['registerNum'] = count($registerNum);
$data[$key]['livenNum'] = $livenNum;
$data[$key]['newAddPay'] = empty($newAddPay)?0:$newAddPay;
$data[$key]['accumulated'] = empty($accumulated)?0:$accumulated;
$total['sum'] += $data[$key]['accumulated'];
$key++;
}
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$count = count($data);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$pnum = ceil(count($data) / $row); //总页数ceil()函数用于求大于数字的最小整数
//用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度)
$data = array_slice($data, ($p-1)*$row, $row);
foreach($data as $k=>$v) {
$total['current'] += $v['accumulated'];
}
//判断是否执行导出
if(I('export')==1){
$this->exportSum($data);
}
$this->assign('meta_title',"充值汇总");
$this->assign('list_data',$data);
$this->assign('total',$total);
$this->m_title = '充值汇总';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'RechargeSum/summation','status'=>1])->find());
$this->display();
}
public function exportSum($data){
$export = A('Export');
$exptitle = $_REQUEST['xlsname'];
$expCellName = array(
array('date','日期'),
array('promote_id','渠道来源'),
array('game_id','游戏名称'),
array('registerNum','新增人数'),
array('livenNum','活跃人数'),
array('newAddPay',"新增玩家付费"),
array('accumulated','本日累计'),
);
$expTableData = $data;
$export->exportExcel($exptitle,$expCellName,$expTableData);
}
}