From 4e78370f142ed44cb7e5d7b0dac1ffe779d5046c Mon Sep 17 00:00:00 2001 From: zhengyongxing Date: Tue, 26 Nov 2019 22:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=91=98=E5=85=85=E5=80=BC?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ExportController.class.php | 154 ++++++++++-------- 1 file changed, 87 insertions(+), 67 deletions(-) diff --git a/Application/Admin/Controller/ExportController.class.php b/Application/Admin/Controller/ExportController.class.php index 74766a830..9a441082d 100644 --- a/Application/Admin/Controller/ExportController.class.php +++ b/Application/Admin/Controller/ExportController.class.php @@ -2099,7 +2099,18 @@ class ExportController extends Controller if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); + } elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) { + $map['create_time'] = ['between', array(strtotime($_REQUEST['timestart']), time())]; + $pay_time = " between " . strtotime($_REQUEST['timestart']) . " and " . time() . " "; + unset($_REQUEST['timestart']); + } elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) { + $map['create_time'] = ['elt', strtotime($_REQUEST['timeend']) + 86399]; + $pay_time = " between 0 and " . (strtotime($_REQUEST['timeend']) + 86399) . " "; + unset($_REQUEST['timeend']); + } else { + $pay_time = " between 0 and " . time(); } + if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); @@ -2109,82 +2120,82 @@ class ExportController extends Controller // unset($_REQUEST['promote_id']); // } $map1['pay_status'] = $map['pay_status']=1; - $map1['pay_way'] = $map['pay_way'] = array('gt', 0); +// $map1['pay_way'] = $map['pay_way'] = array('gt', 0); $today=total(1); $week=total(2); $mounth=total(3); - $map1['pay_way'] = $map['pay_way'] = array('gt',0); - $bindrecharge_data = M('bind_recharge','tab_') - ->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time, sum(real_amount) as count, - sum(IF(create_time '.$today.',real_amount,0)) as today, - sum(IF(create_time '.$week.',real_amount,0)) as week, - sum(IF(create_time '.$mounth.',real_amount,0)) as mounth') - ->where($map1) - ->group('promote_id') - ->select(false); - - $deposit_data = M('deposit','tab_') - ->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time, sum(pay_amount) as count, - sum(IF(create_time '.$today.',pay_amount,0)) as today, - sum(IF(create_time '.$week.',pay_amount,0)) as week, - sum(IF(create_time '.$mounth.',pay_amount,0)) as mounth') - ->where($map1) - ->group('promote_id') - ->select(false); - if(isset($_REQUEST['game_name'])){ - $map['game_name'] = $_REQUEST['game_name']; - if(isset($_REQUEST['server_id'])){ - $map['server_name'] = $_REQUEST['server_id']; - unset($_REQUEST['server_id']); - } - $data=$spend - ->field('max(id) as id,promote_account,promote_id,pay_time as ordertime,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count, - sum(IF(pay_time '.$today.',pay_amount,0)) as today, - sum(IF(pay_time '.$week.',pay_amount,0)) as week, - sum(IF(pay_time '.$mounth.',pay_amount,0)) as mounth') - ->where($map) - ->group('promote_id') - ->select(false); - }else{ - $data=$spend - ->field('max(id) as id,promote_account,promote_id,pay_time as ordertime,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count, - sum(IF(pay_time '.$today.',pay_amount,0)) as today, - sum(IF(pay_time '.$week.',pay_amount,0)) as week, - sum(IF(pay_time '.$mounth.',pay_amount,0)) as mounth') - ->where($map) - ->union(' ('.$bindrecharge_data.') ') - ->union(' ('.$deposit_data.') ') - ->group('promote_id') - ->select(false); - } - $promote_map = "tp1.`chain` = '/'"; + unset( $map['create_time']); + + //获取所有会长 + $promote_map = "`chain` = '/'"; if (isset($_REQUEST['promote_id'])) { - $promote_map = "tp1.`id` = {$_REQUEST['promote_id']}"; - unset($_REQUEST['promote_id']); + $promote_map = "`chain` = '%/{$_REQUEST['promote_id']}/%' OR id = {$_REQUEST['promote_id']}"; } - $data = $spend->field('t.pid as promote_id,t.promote_account,sum(a.count) AS count,sum(a.today) AS today,sum(a. WEEK) AS WEEK,sum(a.mounth) AS mounth') - ->join("INNER JOIN (SELECT tp2.*, tp1.id AS pid, tp1.account as promote_account FROM tab_promote tp1 LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') where $promote_map ) AS t ON promote_id = t.id") - ->where($condition)->table('(' . $data . ') as a')->group('t.pid')->order('count desc,a.ordertime')->select(); - $count=count($data); - foreach ($data as $key => $value) { - static $i=0; - $i++; - $data[$key]['rand']=$i; - if($data[$key]['promote_id']=='0'){ - unset($data[$key]); + + $promote = M("promote","tab_")->field("id,account")->page($page,$row)->where($promote_map)->select(); + $pcount = M("promote","tab_")->field("count(*) acount")->where($promote_map)->find()['acount']; + + // var_dump( $promote); + $data =array(); + for ($i=0; $i < count($promote); $i++) { + # code... + $proid = M("promote","tab_")->field("id")->where("`chain` like '%/{$promote[$i]['id']}/%'")->select(); + $str = ''; + for($k=0; $kfield(' + floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as count, + floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today, + floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week, + floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth') + ->where($map) + ->where("pay_time".$pay_time) + ->find(); + $dbdata['promote_account'] = $promote[$i]['account']; + $dbdata['promote_id'] = $promote[$i]['id']; + } else { + $dbdata = $spend + ->field(' + floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as count, + floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today, + floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week, + floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth') + ->where($map) + ->where("pay_time".$pay_time) + ->find(); + $dbdata['promote_account'] = $promote[$i]['account']; + $dbdata['promote_id'] = $promote[$i]['id']; } + $data[] = $dbdata; } - $total=A('Platform')->data_total($data); - if($_REQUEST['data_order']!=''){ - $data_order=reset(explode(',',$_REQUEST['data_order'])); - $data_order_type=end(explode(',',$_REQUEST['data_order'])); + $count = count($data); + foreach ($data as $key => $value) { + $value['count'] ?: 0; + $value['today'] ?: 0; + $value['week'] ?: 0; + $value['mounth'] ?: 0; + static $i = 0; + $i++; + $data[$key]['rand'] = $i; + $data[$key]['count'] = $value['count'] / 100; + $data[$key]['today'] = $value['today'] / 100; + $data[$key]['week'] = $value['week'] / 100; + $data[$key]['mounth'] = $value['mounth'] / 100; } - $data=my_sort($data,$data_order_type,(int)$data_order); - $size=$row;//每页显示的记录数 - $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 - //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) - $data = array_slice($data, ($arraypage-1)*$size, $size); + $total = $this->data_total($data); + $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'推广员充值统计'; $xlsCell = array( array('promote_id', "推广员账号"), @@ -2210,6 +2221,15 @@ class ExportController extends Controller $this->exportExcel($xlsName, $xlsCell, $xlsData); } + public function data_total($data) + { + $total['sum_count'] = array_sum(array_column($data, 'count')); + $total['sum_today'] = array_sum(array_column($data, 'today')); + $total['sum_week'] = array_sum(array_column($data, 'week')); + $total['sum_mounth'] = array_sum(array_column($data, 'mounth')); + return $total; + } + public function userretention_export($p = 0) { $request=$_REQUEST;