From 2ae543ad7e0776879cfe6dae47935dd99d37b7aa Mon Sep 17 00:00:00 2001 From: zhengyongxing Date: Tue, 26 Nov 2019 21:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=AF=BC=E5=87=BA=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ExportController.class.php | 332 +++++++----------- 1 file changed, 126 insertions(+), 206 deletions(-) diff --git a/Application/Admin/Controller/ExportController.class.php b/Application/Admin/Controller/ExportController.class.php index 544cd3208..f2a0baee6 100644 --- a/Application/Admin/Controller/ExportController.class.php +++ b/Application/Admin/Controller/ExportController.class.php @@ -196,7 +196,7 @@ class ExportController extends Controller } break; case 3: - if($_REQUEST['type']==2){ + if($_REQUEST['type']==2){ // $xlsCell = array( // array('id', L('Account_number_ID')), // array('register_type', L('Third_party_source'), "get_registertype", '*'), @@ -213,15 +213,14 @@ class ExportController extends Controller // array('register_ip', L('Register_iP')), // array('lock_status', L('Account_status'), 'get_info_status', '*', '4'), // ); - $field = 'a.id,a.account,a.id as get_registertype,a.promote_account,a.balance,IFNULL(sum(ss.pay_amount),0) as recharge_total, - a.gold_coin,a.alipay,a.id as small_count,a.id as vip_level,a.register_type - ,a.register_ip,a.login_time,a.device_number,a.lock_status,check_status,a.age_status,a.register_way, - a.register_type'; - $xlsCell = [L('Account_number_ID'),"第三方来源","绑定账号",L('Subordinate_channel'), "账户平台币" - , "累计充值", "金币", "绑定支付宝", "小号", "VIP等级", L('Registration_time'), - L('Register_iP'), "最后登录时间","设备号", L('Account_status'),"拉黑状态"]; -// $map['tab_user.register_type']= ['in','3,4,5,6']; - }else{ + $field = 'tab_user.id,tab_user.register_type,tab_user.account,tab_user.promote_account,tab_user.balance + ,IFNULL(sum(ss.pay_amount),0) AS recharge_total,tab_user.gold_coin,tab_user.alipay,tab_user.id as small_count, + tab_user.id as vip_level,register_time,tab_user.login_time,tab_user.register_ip,tab_user.lock_status, + tab_user.age_status,tab_user.register_way'; + $xlsCell = [L('Account_number_ID'),L('Third_party_source'),"玩家账号",L('Subordinate_channel'), "账户平台币" + , "累计充值", "金币", "绑定支付宝", "小号", "VIP等级", L('Registration_time'), "最后登录时间", L('Register_iP'), L('Account_status')]; + $map['tab_user.register_type']= ['in','3,4,5,6']; + }else{ // $xlsCell = array( // array('id', L('Account_number_ID')), // array('account', "玩家账号"), @@ -238,192 +237,111 @@ class ExportController extends Controller // array('register_ip', L('Register_iP')), // array('lock_status', L('Account_status'), 'get_info_status', '*', '4'), // ); - $field = 'a.id,a.account,a.promote_account,a.balance,IFNULL(sum(ss.pay_amount),0) as recharge_total, - a.gold_coin,a.alipay,a.id as small_count,a.id as vip_level,a.register_type,a.register_time - ,a.register_ip,a.login_time,a.device_number,a.lock_status,check_status,a.age_status,a.register_way, - a.register_type'; - $xlsCell = [L('Account_number_ID'),"玩家账号",L('Subordinate_channel'), "账户平台币" - , "累计充值", "金币", "绑定支付宝", "小号", "VIP等级", "注册方式", L('Registration_time'), - L('Register_iP'), "最后登录时间","设备号", L('Account_status'),"拉黑状态"]; - $map['tab_user.register_type']=['in','1,2']; - $map['tab_user.register_type']=['in','0,1,2,7']; - - } - - $hav = ''; + $field = 'tab_user.id,tab_user.account,tab_user.promote_account,tab_user.balance, + IFNULL(sum(ss.pay_amount),0) AS recharge_total,tab_user.gold_coin,tab_user.alipay + ,tab_user.id as small_count,tab_user.id as vip_level,tab_user.register_type,register_time,tab_user.login_time + ,tab_user.register_ip,tab_user.lock_status,tab_user.age_status,tab_user.register_way'; + $xlsCell = [L('Account_number_ID'),"玩家账号",L('Subordinate_channel'), "账户平台币" + , "累计充值", "金币", "绑定支付宝", "小号", "VIP等级", "注册方式", L('Registration_time'), + "最后登录时间", L('Register_iP'), L('Account_status')]; + $map['tab_user.register_type']=['in','1,2']; + $map['tab_user.register_type']=['in','0,1,2,7']; + + } + + if (isset($_REQUEST['user_id'])) { + $map['tab_user.id'] = $_REQUEST['user_id']; + unset($_REQUEST['user_id']); + } + + if (isset($_REQUEST['device_number'])) { + $map['tab_user.device_number'] = $_REQUEST['device_number']; + unset($_REQUEST['device_number']); + } if ($_REQUEST['promote_id'] != '') { - if ($_REQUEST['promote_id'] == 'UC') { - $maps['tab_user.promote_account'] = 'UC用户'; - $hav .= "tab_user.promote_account = 'UC用户' "; - } else if ($_REQUEST['promote_id'] == 0) { - $maps['tab_user.promote_id'] = 0; - $hav .= "tab_user.promote_id = 0"; - } else { + if($_REQUEST['promote_id']=='UC'){ + $map['tab_user.promote_account'] = 'UC用户'; + } else if ($_REQUEST['promote_id']==0) { + $map['tab_user.promote_id'] = 0; + } else{ $promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select(); if ($promoter_ids) { - $maps['tab_user.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))]; - $hav .= "tab_user.promote_id in (" . implode(',', array_column($promoter_ids, 'id')) . ") "; + $map['tab_user.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))]; $spendprom = " AND ss.promote_id IN (" . implode(',', array_column($promoter_ids, 'id')) . ") "; } } } - if (I('type', 1) == 1) { - if (isset($_GET['register_way'])) { + $game_map = ""; + if (isset($_REQUEST['game_name'])) { + $game_map .= " and tab_user_play.game_id in (".implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')).")"; + } + $game_play_map = ''; + if (isset($_REQUEST['server_name'])) { + $game_play_map .= " and tab_user_play_info.server_name = '{$_REQUEST['server_name']}' "; + } + // if (isset($_REQUEST['promote_account'])) { + // $map['promote_id'] = get_promote_id(trim(I('promote_account'))); + // unset($_REQUEST['promote_account']); + // } + if (isset($_REQUEST['register_way'])) { + if($_REQUEST['type']==1) { if ($_GET['register_way'] == 1) { empty($hav) || $hav .= ' AND '; - $hav .= ' tab_user.register_type in (1)'; - $maps['tab_user.register_type'] = 1; - } elseif ($_GET['register_way'] == 7) { + $hav .= ' tab_user.register_type in (0,1)'; + $maps['tab_user.register_type'] = ['in',[0,1]]; + } elseif($_GET['register_way'] == 7){ empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in(7)'; $maps['tab_user.register_type'] = 7; - } else { + }else { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in(2)'; $maps['tab_user.register_type'] = 2; } } else { - empty($hav) || $hav .= ' AND '; - $hav .= ' tab_user.register_type in (1,2,7)'; - $maps['tab_user.register_type'] = ['in', [1, 2, 7]]; - } - } else { - if (isset($_GET['register_type'])) { - empty($hav) || $hav .= ' AND '; - $hav .= ' tab_user.register_type = ' . $_GET['register_type']; - $maps['tab_user.register_type'] = $_GET['register_type']; - - } else { - empty($hav) || $hav .= ' AND '; - $hav .= ' tab_user.register_type in (0,3,4,5,6)'; - $maps['tab_user.register_type'] = ['in', [0, 3, 4, 5, 6]]; - } - } - if (isset($_REQUEST['user_id'])) { - empty($hav) || $hav .= ' AND '; - $hav .= "tab_user.id = '{$_REQUEST['user_id']}'"; - $maps['tab_user.id'] = $_REQUEST['user_id']; - unset($_REQUEST['user_id']); - } - if (isset($_REQUEST['account'])) { - empty($hav) || $hav .= ' AND '; - $hav .= "tab_user.account like '%" . I('account') . "%'"; - $maps['tab_user.account'] = ['like', "%" . I('account') . "%"]; - unset($_REQUEST['account']); - } - if (isset($_REQUEST['device_number'])) { - empty($hav) || $hav .= ' AND '; - $hav .= "tab_user.device_number = '{$_REQUEST['device_number']}'"; - $maps['tab_user.device_number'] = $_REQUEST['device_number']; - unset($_REQUEST['device_number']); - } - if (isset($_REQUEST['age_status'])) { - empty($hav) || $hav .= ' AND '; - $hav .= 'tab_user.age_status =' . I('age_status'); - $maps['tab_user.age_status'] = I('age_status'); - unset($_REQUEST['age_status']); - } - if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { - empty($hav) || $hav .= ' AND '; - $hav .= 'tab_user.register_time BETWEEN ' . strtotime(I('time_start')) . ' AND ' . (strtotime(I('time_end')) + 24 * 60 * 60 - 1); - $maps['tab_user.register_time'] = ['between', [strtotime(I('time_start')), strtotime(I('time_end')) + 86399]]; - unset($_REQUEST['time_start']); - unset($_REQUEST['time_end']); - } elseif (isset($_REQUEST['time_start'])) { - empty($hav) || $hav .= ' AND '; - $hav .= 'tab_user.register_time > ' . strtotime(I('time_start')); - $maps['tab_user.register_time'] = ['GT', strtotime(I('time_start'))]; - unset($_REQUEST['time_start']); - } elseif (isset($_REQUEST['time_end'])) { - empty($hav) || $hav .= ' AND '; - $hav .= 'tab_user.register_time < ' . (strtotime(I('time_end')) + 86399); - $maps['tab_user.register_time'] = ['LT', strtotime(I('time_end')) + 86399]; - unset($_REQUEST['time_end']); - } - if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { - empty($hav) || $hav .= ' AND '; - $hav .= 'tab_user.register_time BETWEEN ' . strtotime(I('start')) . ' AND ' . strtotime(I('end')); - $maps['tab_user.register_time'] = array('between', [strtotime(I('start')), strtotime(I('end'))]); - unset($_REQUEST['start']); - unset($_REQUEST['end']); + $map['register_way'] = I('register_way'); + unset($_REQUEST['register_way']); + } } - if (!empty(I('line_day'))) { - $day = strtotime(date('Y-m-d')) - intval(I('line_day')) * 86400; - empty($hav) || $hav .= ' AND '; - $hav .= $day . '> tab_user.login_time'; - $maps['tab_user.login_time'] = ['lt', $day]; + if (isset($_REQUEST['register_type'])) { + $map['register_type'] = I('register_type'); + unset($_REQUEST['register_type']); } if (isset($_REQUEST['status'])) { - $map['lock_status'] = $_REQUEST['status']; + $map['lock_status'] = I('status'); unset($_REQUEST['status']); } - - - // if (isset($_REQUEST['game_name'])) { - // //$game_map .= " and tab_user_play.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")"; - // } - - $game_map = ""; - -// $game_map .= " and tab_user_play.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")"; - - if (!empty($_REQUEST['game_name']) || !empty($_REQUEST['game_type'])) { - $game_map .= " and tab_user_play.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")"; - } - - $spendprom = " and ss.game_id in (".implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')).")"; - if (isset($_REQUEST['server_name'])) { - $map['server_name'] = ['like', "{$_REQUEST['server_name']}%"]; + if (!empty(I('time_start')) && !empty(I('time_end'))) { + $map['register_time'] = array('BETWEEN', array(strtotime(I('get.time_start')), strtotime(I('time_end')) + 24 * 60 * 60 - 1)); + unset($_REQUEST['time_start']); + unset($_REQUEST['time_end']); } - $game_play_map = ''; - if (isset($_REQUEST['server_name'])) { - $game_play_map .= " and tab_user_play_info.server_name = '{$_REQUEST['server_name']}' "; + empty(I('account')) || $map['account'] = ['like', '%' . I('account') . '%']; + //排序 + if (I('total_status') == 1) { + $order = 'cumulative asc'; + } elseif (I('total_status') == 2) { + $order = 'cumulative desc'; + } else { + $order = 'id desc'; } - if (isset($_REQUEST['viplevel'])) { - $havs = get_vip_level_limit('recharge_total', $_REQUEST['viplevel']); - } - - //排序 - $order = ''; - if (I('key') == 1) { - if (I('balance_status') == 1) { - $order = 'balance,'; - } elseif (I('balance_status') == 2) { - $order = 'balance desc,'; - } - } else { - if (I('recharge_status') == 1) { - $order .= 'recharge_total,'; - } elseif (I('recharge_status') == 2) { - $order .= 'recharge_total desc,'; - } + $havs = get_vip_level_limit('recharge_total',$_REQUEST['viplevel']); } - $order .= 'a.id desc'; - $user = M('user', 'tab_'); - $map['puid'] = array('eq', 0); + $map['puid'] = array('eq',0); $map['is_platform'] = 0; - $usermodel = M('user', 'tab_'); - $sql1 = $usermodel->field('tab_user.*,IFNULL(sum(b.pay_amount),0) as deposit_total') - ->join('left join tab_deposit AS b ON tab_user.id = b.user_id AND b.pay_status = 1') - ->where($map) - ->group('tab_user.id') - ->where($hav) - // ->order($order) - ->select(false); - set_time_limit(0); // $columns = [ // '序号ID', '姓名', '电话', // ]; -// $fileName = '导出.xlsx'; + $fileName = '导出.xlsx'; $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); @@ -437,57 +355,68 @@ class ExportController extends Controller fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum = '100000';//从数据库获取总量,假设是十万 - - - //计数 - $sql = M('user', 'tab_')->field('tab_user.id,IFNULL(sum(ss.pay_amount),0) AS recharge_total') - ->join('left join tab_spend as ss on ss.user_id=tab_user.id AND ss.pay_status = 1'.$spendprom) - ->where($map) - ->group('tab_user.id') - ->where($hav) - ->having($havs)->select(false); - - //替换为新表 if($_REQUEST['promote_id'] && $_REQUEST['promote_id'] > -1){ - $sql = M('user', 'tab_')->field('tab_user.id,IFNULL(sum(ss.pay_amount),0) AS recharge_total') - ->join('left join tab_spend as ss on ss.user_id=tab_user.id AND ss.pay_status = 1'.$spendprom) + $accessNum = M('user', 'tab_') + ->field('IFNULL(sum(ss.pay_amount),0) AS recharge_total,count(tab_user.id) as count') +// ->field($field) + ->join('left join tab_spend as ss on ss.user_id=tab_user.id AND ss.pay_status = 1'.$spendprom) + ->join($game_map ? "tab_user_play on tab_user_play.user_id = tab_user.id $game_map" : false) + ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = tab_user.id $game_play_map" : false) ->where($map) ->group('tab_user.id') - ->where($hav) - ->having($havs)->select(false); - } + ->having($havs) + ->select(false); + $sql = "select count(t.count) as count from ({$accessNum}) as t "; + $accessNum = M('user', 'tab_')->query($sql); + }else{ + $accessNum = M('user', 'tab_') +// ->field('tab_user.id,tab_user.age_status,tab_user.account,tab_user.gold_coin,tab_user.alipay,tab_user.balance,tab_user.promote_account,register_time,tab_user.lock_status,tab_user.register_way,tab_user.register_type,tab_user.register_ip,tab_user.login_time,IFNULL(sum(ss.pay_amount),0) AS recharge_total') + ->field('IFNULL(sum(ss.pay_amount),0) AS recharge_total,count(tab_user.id) as count') + ->join('left join tab_spend as ss on ss.user_id=tab_user.id AND ss.pay_status = 1') + ->join($game_map ? "tab_user_play on tab_user_play.user_id = tab_user.id $game_map" : false) + ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = tab_user.id $game_play_map" : false) + ->where($map) + ->group('tab_user.id') + ->having($havs) + ->select(false); - $jcount = M('User', 'tab_')->field('count(a.id) as count,sum(a.recharge_total) recharge_total')->table('(' . $sql . ') as a')->select(); - $accessNum = $jcount[0]['count'] ?:0 ; + $sql = "select count(t.count) as count from ({$accessNum}) as t "; + $accessNum = M('user', 'tab_')->query($sql); + } + $accessNum = $accessNum[0]['count']; $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); - + $lastId = 0; for($i = 1; $i <= $pages; $i++) { if($_REQUEST['promote_id'] && $_REQUEST['promote_id'] > -1){ - $xlsData = $usermodel->table('(' . $sql1 . ') as a ')->field($field) - ->join('left join tab_spend as ss on ss.user_id=a.id AND ss.pay_status = 1'.$spendprom) - ->join($game_map ? "tab_user_play on tab_user_play.user_id = a.id $game_map" : false) - ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = a.id $game_play_map" : false) + $xlsData = M('user', 'tab_') +// ->field('tab_user.id,tab_user.age_status,tab_user.account,tab_user.gold_coin,tab_user.alipay,tab_user.balance,tab_user.promote_account,register_time,tab_user.lock_status,tab_user.register_way,tab_user.register_type,tab_user.register_ip,tab_user.login_time,IFNULL(sum(ss.pay_amount),0) AS recharge_total') + ->field($field) + ->join('left join tab_spend as ss on ss.user_id=tab_user.id AND ss.pay_status = 1'.$spendprom) + ->join($game_map ? "tab_user_play on tab_user_play.user_id = tab_user.id $game_map" : false) + ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = tab_user.id $game_play_map" : false) + ->where($map) ->limit(($i-1)*$perSize ,$perSize) - ->having($havs) - ->group('a.id') + ->group('tab_user.id') ->order($order) + ->having($havs) ->select(); - // echo $data;die(); }else{ - $xlsData = $usermodel->table('(' . $sql1 . ') as a ')->field($field) - ->join('left join tab_spend as ss on ss.user_id=a.id AND ss.pay_status = 1') - ->join($game_map ? "tab_user_play on tab_user_play.user_id = a.id $game_map" : false) - ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = a.id $game_play_map" : false) + $xlsData = M('user', 'tab_') +// ->field('tab_user.id,tab_user.age_status,tab_user.account,tab_user.gold_coin,tab_user.alipay,tab_user.balance,tab_user.promote_account,register_time,tab_user.lock_status,tab_user.register_way,tab_user.register_type,tab_user.register_ip,tab_user.login_time,IFNULL(sum(ss.pay_amount),0) AS recharge_total') + ->field($field) + ->join('left join tab_spend as ss on ss.user_id=tab_user.id AND ss.pay_status = 1') + ->join($game_map ? "tab_user_play on tab_user_play.user_id = tab_user.id $game_map" : false) + ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = tab_user.id $game_play_map" : false) + ->where($map) ->limit(($i-1)*$perSize ,$perSize) - ->having($havs) - ->group('a.id') + ->group('tab_user.id') ->order($order) + ->having($havs) ->select(); } -// echo $usermodel->_sql();die(); //数据 @@ -505,17 +434,10 @@ class ExportController extends Controller if(empty($v['alipay'])){ $xlsData[$k]['alipay'] = '--'; } - if($_REQUEST['type']==2){ - $xlsData[$k]['register_type'] = get_registertype($v['register_type']); - } - if ($_REQUEST['type']!=2) { - $xlsData[$k]['register_time'] = date('Y-m-d H:i:s',$xlsData[$k]['register_time']); - } + $xlsData[$k]['register_time'] = date('Y-m-d H:i:s',$xlsData[$k]['register_time']); $xlsData[$k]['login_time'] = date('Y-m-d H:i:s',$xlsData[$k]['login_time']); $xlsData[$k]['lock_status'] = $xlsData[$k]['lock_status']==1?'正常':'锁定'; - $xlsData[$k]['check_status'] = $xlsData[$k]['check_status']==1?'正常':'已拉黑'; - $xlsData[$k]['device_number'] = $xlsData[$k]['device_number']."'"; $xlsData[$k]['register_type'] = $v['register_type'] == 2?'手机号':($v['register_type']==7?'邮箱':'账号'); @@ -532,17 +454,15 @@ class ExportController extends Controller } unset($xlsData[$k]['age_status']); unset($xlsData[$k]['register_way']); - mb_convert_variables('GBK', 'UTF-8', $v); - fputcsv($fp, $v); } } -// foreach($xlsData as $value) { -// mb_convert_variables('GBK', 'UTF-8', $value); -// fputcsv($fp, $value); -// $lastId = $value['id']; -// } + foreach($xlsData as $value) { + mb_convert_variables('GBK', 'UTF-8', $value); + fputcsv($fp, $value); + $lastId = $value['id']; + } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush();