diff --git a/Application/Admin/Controller/ExportController.class.php b/Application/Admin/Controller/ExportController.class.php index 7c4372ca8..a099ad1bd 100644 --- a/Application/Admin/Controller/ExportController.class.php +++ b/Application/Admin/Controller/ExportController.class.php @@ -102,15 +102,21 @@ class ExportController extends Controller break; case 2: $xlsName = $xlsName?$xlsName:"渠道注册"; +// $xlsCell = array( +// array('account', "玩家账号"), +// array('fgame_name', "注册游戏"), +// array('promote_account', L('Subordinate_channel')), +// array('register_time', L('Registration_time'), 'time_format', '*'), +// array('register_ip', L('Register_iP')), +// array('parent_id', "上级推广员"), +// array('ba_id', '商务专员'), +// ); + $xlsCell = array( - array('account', "玩家账号"), - array('fgame_name', "注册游戏"), - array('promote_account', L('Subordinate_channel')), - array('register_time', L('Registration_time'), 'time_format', '*'), - array('register_ip', L('Register_iP')), - array('parent_id', "上级推广员"), - array('ba_id', '商务专员', 'get_business_affairs_account', '*'), + "玩家账号", "注册游戏", L('Subordinate_channel'), L('Registration_time'), L('Register_iP'), + "上级推广员", '商务专员', ); + if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); @@ -121,16 +127,41 @@ class ExportController extends Controller } $map['tab_user.promote_id'] = array("neq", 0); if (isset($_REQUEST['promote_name'])) { - if ($_REQUEST['promote_name'] == L('All')) { + if ($_REQUEST['promote_name']=='全部') { unset($_REQUEST['promote_name']); - } else if ($_REQUEST['promote_name'] == "官方渠道") { - $map['tab_user.promote_id'] = array("elt", 0); + } elseif ($_REQUEST['promote_name']=='自然注册') { + $map['tab_user.promote_id']=array("elt",0); unset($_REQUEST['promote_name']); } else { - $map['tab_user.promote_id'] = get_promote_id($_REQUEST['promote_name']); + $promoteid = get_promote_id($_REQUEST['promote_name']); + $map['tab_user.promote_id']=array('eq',get_promote_id($_REQUEST['promote_name'])); unset($_REQUEST['promote_name']); + + if (isset($_REQUEST['parent_id'])) { + $parent_id = get_promote_id($_REQUEST['parent_id']); + if ($promoteid == $parent_id) { + $map['tab_user.promote_id'] = $promoteid; + } else { + $parent_id = get_promote_id($_REQUEST['parent_id']); + } + } else { + $map['tab_user.promote_id'] = $promoteid; + } + } + } else { + if (isset($_REQUEST['parent_id'])) { + $parent_id = get_promote_id($_REQUEST['parent_id']); + $pro = M('promote', 'tab_')->field('id,account')->where("chain like '%/{$parent_id}/%'")->select(); + $pro_ids = array_column($pro, 'id'); + $pro_ids[] = get_promote_id($_REQUEST['parent_id']); + if (!empty($pro_ids)) { + $map['tab_user.promote_id'] = ['in',$pro_ids]; + } else { + $map['tab_user.promote_id'] = array('eq',-1); + } } } + if (isset($_REQUEST['is_check']) && $_REQUEST['is_check'] != L('All')) { $map['is_check'] = check_status($_REQUEST['is_check']); unset($_REQUEST['is_check']); @@ -172,7 +203,8 @@ class ExportController extends Controller 'promote_account', 'tab_user.parent_name', 'is_check', - 'tab_promote.ba_id' + 'tab_promote.ba_id', + "REPLACE(substring_index(tab_promote.chain, '/', 2),'/','') as top_promote" ), 'key' => array('tab_user.account', 'tab_game.fgame_name'), 'map' => $map, @@ -180,8 +212,21 @@ class ExportController extends Controller 'title' => "渠道注册", 'template_list' => 'ch_reg_list', ); + + $csvFileName = $xlsName.'.csv'; + //设置好告诉浏览器要下载excel文件的headers + header('Content-Description: File Transfer'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + $fp = fopen('php://output', 'a');//打开output流 + mb_convert_variables('GBK', 'UTF-8', $xlsCell); + fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 + $name = $model['m_name']; - $xlsData = M($name, "tab_") + $xlsData = M($name, "tab_",'union_table') ->field($model['fields']) ->join($model['join']) ->join($model['joins']) @@ -189,10 +234,65 @@ class ExportController extends Controller ->where($model['map']) ->order($model['order']) ->group($model['group']) - ->select(); - foreach ($xlsData as $key => &$value) { - $xlsData[$key]['parent_id'] = get_top_promote($value['promote_id'], $value['parent_id']); + ->select(false); + + $accessNum = M()->table("({$xlsData}) as a") + ->field("a.id,count(a.account) as count") + ->join("left join tab_promote ON a.top_promote = tab_promote.id") + ->join("left join tab_business_affairs ON tab_business_affairs.id=a.ba_id") + ->order("id desc") + ->find(); + $accessNum =$accessNum['count']; + + $perSize = 2000;//每次查询的条数 + $pages = ceil($accessNum / $perSize); + $lastId = 0; + + // $xlsCell = array( +// array('account', "玩家账号"), +// array('fgame_name', "注册游戏"), +// array('promote_account', L('Subordinate_channel')), +// array('register_time', L('Registration_time'), 'time_format', '*'), +// array('register_ip', L('Register_iP')), +// array('parent_id', "上级推广员"), +// array('ba_id', '商务专员'), +// ); + + + for($i = 1; $i <= $pages; $i++) { + $xlsData = M($name, "tab_",'union_table') + ->field($model['fields']) + ->join($model['join']) + ->join($model['joins']) + ->join($model['joinss']) + ->where($model['map']) + ->limit(($i-1)*$perSize ,$perSize) + ->order($model['order']) + ->group($model['group']) + ->select(false); + $xlsData = M()->table("({$xlsData}) as a") + ->field("a.account,a.fgame_name,a.promote_account,a.register_time,a.register_ip,tab_promote.account as parent_id,tab_business_affairs.account as ba_id") + ->join("left join tab_promote ON a.top_promote = tab_promote.id") + ->join("left join tab_business_affairs ON tab_business_affairs.id=a.ba_id") + ->order("a.id desc") + ->select(); + + foreach($xlsData as $value) { + if (!$value['ba_id']) { + $value['ba_id'] = "暂无"; + } + $value['register_time'] = date("Y-m-d H:i:s",$value['register_time']); + mb_convert_variables('GBK', 'UTF-8', $value); + fputcsv($fp, $value); + $lastId = $value['id']; + } + unset($xlsData);//释放变量的内存 + //刷新输出缓冲到浏览器 + ob_flush(); + flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } + fclose($fp); + exit(); break; case 3: if($_REQUEST['type']==2){ @@ -925,8 +1025,8 @@ class ExportController extends Controller $xlsCell = array( - "订单号", "充值时间", "玩家账号", "游戏名称", L('Subordinate_channel'), "充值ip", "游戏区服", - "角色名称", "订单金额", "实付金额", "充值方式", L('Order_status'), "游戏通知状态", "消费"."{$total}" + "支付订单号","CP订单号", "充值时间", "玩家账号", "游戏名称", L('Subordinate_channel'), "充值ip","区服ID", "游戏区服", + "角色ID","角色名称", "订单金额", "实付金额", "充值方式", L('Order_status'), "游戏通知状态", "消费"."{$total}" ); $csvFileName = $xlsName.'.csv'; @@ -942,7 +1042,7 @@ class ExportController extends Controller fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum = D('Spend') - ->field('pay_order_number,pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,cost,pay_amount,pay_way,pay_status,pay_game_status') + ->field('pay_order_number,pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_id,game_player_name,cost,pay_amount,pay_way,pay_status,pay_game_status') ->where($map) ->join($tab_promote_join) ->order('pay_time DESC') @@ -954,7 +1054,7 @@ class ExportController extends Controller // var_dump($count);die(); for($i = 1; $i <= $pages; $i++) { $xlsData = D('Spend') - ->field('pay_order_number,pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,cost,pay_amount,pay_way,pay_status,pay_game_status') + ->field('pay_order_number,extend,pay_time,user_account,game_name,promote_account,spend_ip,server_id,server_name,game_player_id,game_player_name,cost,pay_amount,pay_way,pay_status,pay_game_status') ->where($map) ->limit(($i-1)*$perSize ,$perSize) ->join($tab_promote_join) @@ -1180,20 +1280,23 @@ class ExportController extends Controller break; case 11: $xlsName = $xlsName?$xlsName:"礼包领取"; +// $xlsCell = array( +// array('user_account', "玩家账号"), +// array('game_name', "游戏名称"), +// array('gift_name', '礼包名称'), +// array('novice', '礼包卡号'), +// array('gift_id', '运营平台', 'get_operation_platform', '*', 'giftbag'), +// array('create_time', '领取时间', 'time_format', '*'), +// ); $xlsCell = array( - array('user_account', "玩家账号"), - array('game_name', "游戏名称"), - array('gift_name', '礼包名称'), - array('novice', '礼包卡号'), - array('gift_id', '运营平台', 'get_operation_platform', '*', 'giftbag'), - array('create_time', '领取时间', 'time_format', '*'), + "玩家账号", "游戏名称", '礼包名称', '礼包卡号', '运营平台', '领取时间', ); if (isset($_REQUEST['game_name'])) { - $extend['game_name'] = trim($_REQUEST['game_name']); + $extend['tab_gift_record.game_name'] = trim($_REQUEST['game_name']); unset($_REQUEST['game_name']); } if (isset($_REQUEST['user_account'])) { - $extend['user_account'] = trim($_REQUEST['user_account']); + $extend['tab_gift_record.user_account'] = trim($_REQUEST['user_account']); unset($_REQUEST['user_account']); } if (isset($_REQUEST['sdk_version'])) { @@ -1203,14 +1306,69 @@ class ExportController extends Controller $map['sdk_version'] = $_REQUEST['sdk_version']; $game_ids = M('game', 'tab_')->field('id')->where($map)->select(); $game_ids = array_column($game_ids, 'id'); - $extend['sdk_version'] = ['in', $game_ids]; + $extend['tab_gift_record.sdk_version'] = ['in', $game_ids]; unset($_REQUEST['sdk_version']); } } - $xlsData = M('gift_record', 'tab_') + + $csvFileName = $xlsName.'.csv'; + //设置好告诉浏览器要下载excel文件的headers + header('Content-Description: File Transfer'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + $fp = fopen('php://output', 'a');//打开output流 + mb_convert_variables('GBK', 'UTF-8', $xlsCell); + fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 + + + + + $accessNum = M('gift_record', 'tab_') + ->field("user_account,game_name,gift_name,novice,gift_id,FROM_UNIXTIME(create_time) as create_time") ->where($extend) ->order("id DESC") - ->select(); + ->count(); + + $perSize = 5000;//每次查询的条数 + $pages = ceil($accessNum / $perSize); + +// var_dump($count);die(); + for($i = 1; $i <= $pages; $i++) { + + $xlsData = M('gift_record', 'tab_') + ->field("tab_gift_record.user_account,tab_gift_record.game_name,tab_gift_record.gift_name,tab_gift_record.novice,giftbag_version,FROM_UNIXTIME(tab_gift_record.create_time) as create_time") + ->join("left join tab_giftbag on tab_gift_record.gift_id = tab_giftbag.id") + ->where($extend) + ->limit(($i-1)*$perSize ,$perSize) + ->order("tab_gift_record.id DESC") + ->select(); + + foreach($xlsData as $value) { + if($value['giftbag_version']==0){ + $value['giftbag_version']= '双平台'; + }elseif($value['giftbag_version']==1){ + $value['giftbag_version']= "安卓"; + }elseif($value['giftbag_version']==2){ + $value['giftbag_version']= "苹果"; + } else { + $value['giftbag_version']= ""; + } +// $value['gift_id'] = get_operation_platform($value['gift_id'],'giftbag'); + mb_convert_variables('GBK', 'UTF-8', $value); + fputcsv($fp, $value); + } + unset($xlsData);//释放变量的内存 + //刷新输出缓冲到浏览器 + ob_flush(); + flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 + } + fclose($fp); + exit(); + + break; case 12: get_info_status(); @@ -4956,11 +5114,12 @@ if ($key == 'model'){ } $map['id']=array('in',$zid); } - $map['level'] = I('promote_level'); + if (I("promote_level")) { + $map['level'] = I("promote_level"); + } if(I('oa_associated',-1) != -1) { $map['oa_associated'] = I('oa_associated'); } - }