推广补链导出修改

master
zhengyongxing 5 years ago
parent 65fd27fe36
commit fbead8c3a1

@ -5414,57 +5414,122 @@ if ($key == 'model'){
$model = M('user','tab_'); $model = M('user','tab_');
$xlsCell = array( // $xlsCell = array(
array('account','玩家账号'), // array('account','玩家账号'),
array('register_time','注册时间'), // array('register_time','注册时间'),
array('login_time','最后登录时间'), // array('login_time','最后登录时间'),
array('register_type','注册来源'), // array('register_type','注册来源'),
array('register_ip','注册IP'), // array('register_ip','注册IP'),
array('login_time','上次登录'), // array('login_time','上次登录'),
array('top_promote','所属推广员'), // array('top_promote','所属推广员'),
); // );
$xlsCell = array(
'玩家账号','注册时间','最后登录时间','注册来源','注册IP','上次登录','所属推广员',
);
if(isset($_REQUEST['account'])){ if(isset($_REQUEST['account'])){
if ($_REQUEST['account']=='全部') { if ($_REQUEST['account']=='全部') {
unset($_REQUEST['account']); unset($_REQUEST['account']);
} }
$map['account']=array('like','%'.$_REQUEST['account'].'%'); $map['tab_user.account']=array('like','%'.$_REQUEST['account'].'%');
unset($_REQUEST['account']); unset($_REQUEST['account']);
} }
$page = intval($_REQUEST['p']); $csvFileName = $xlsName.'.csv';
//设置好告诉浏览器要下载excel文件的headers
$page = $page?$page:1; header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
$row = $_REQUEST['row']?$_REQUEST['row']:10; header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
$data=$model header('Pragma: public');
->where($map) $fp = fopen('php://output', 'a');//打开output流
->order('id desc') mb_convert_variables('GBK', 'UTF-8', $xlsCell);
->select(); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
$xlsData = []; $accessNum=$model
->join("left join tab_promote on tab_promote.id=tab_user.promote_id")
if(is_array($data)){ ->field("tab_user.id,tab_user.account,tab_user.register_time,tab_user.login_time,tab_user.register_type
,tab_user.register_ip,
foreach($data as $k => $v) { tab_promote.parent_name as parent_name,
tab_promote.account as promote_account")
$v['register_time'] = date('Y-m-d H:i:s',$v['register_time']); ->where($map)
$v['login_time'] = $v['login_time']>0?date('Y-m-d H:i:s',$v['login_time']):'暂无登录'; ->order('tab_user.id desc')
->count();
$v['register_type'] = get_registertype($v['register_type']);
$perSize = 5000;//每次查询的条数
$pages = ceil($accessNum / $perSize);
$lastId = 0;
for($i = 1; $i <= $pages; $i++) {
// REPLACE(substring_index(tab_promote.chain, '/', 2),'/','')
$xlsData=$model
->join("left join tab_promote on tab_promote.id=tab_user.promote_id")
->field("tab_user.id,tab_user.account,tab_user.register_time,tab_user.login_time,tab_user.register_type
,tab_user.register_ip,tab_user.login_time as last_login_time,
tab_promote.parent_name as parent_name,
tab_promote.account as promote_account,tab_user.id as top_promote")
->where($map)
->limit(($i-1)*$perSize ,$perSize)
->order('tab_user.id desc')
->select();
$promote = get_parent_promoteto($v['promote_id']); foreach($xlsData as $key => $value) {
unset($value['id']);
$value['register_time'] = date('Y-m-d H:i:s',$value['register_time']);
$value['login_time'] = $value['login_time']>0?date('Y-m-d H:i:s',$value['login_time']):'暂无登录';
$value['last_login_time'] = $value['last_login_time']>0?date('Y-m-d H:i:s',$value['last_login_time']):'暂无登录';
$value['register_type'] = get_registertype($value['register_type']);
$value['top_promote'] = $value['parent_name']?$value['promote_account'].'['.$value['parent_name'].']':$value['promote_account'];
if (!$value['promote_account']) {
$value['top_promote'] = "官方渠道";
}
if($value['parent_name'] == "官方渠道") {
$value['top_promote'] = $value['promote_account'];
}
unset($value['promote_account']);
unset($value['parent_name']);
mb_convert_variables('GBK', 'UTF-8', $value);
fputcsv($fp, $value);
$v['top_promote'] = $promote?($v['promote_account'] . get_parent_promoteto($v['promote_id'])):get_promote_name($v['promote_id']); }
unset($xlsData);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
fclose($fp);
exit();
$xlsData[] = $v; // $data = M()->table("({$data}) as a")
// ->field("a.account,a.register_time,a.login_time,a.register_type,a.register_ip,a.top_promote,a.promote_account")
// ->join("left join tab_promote on a.top_promote=tab_promote.id")
// ->order("a.id desc")
// ->select(false);
} // var_dump($data);die();
// $xlsData = [];
} // if(is_array($data)){
//
// foreach($data as $k => $v) {
//
// $v['register_time'] = date('Y-m-d H:i:s',$v['register_time']);
// $v['login_time'] = $v['login_time']>0?date('Y-m-d H:i:s',$v['login_time']):'暂无登录';
//
// $v['register_type'] = get_registertype($v['register_type']);
//
// $promote = get_parent_promoteto($v['promote_id']);
//
// $v['top_promote'] = $promote?($v['promote_account'] . get_parent_promoteto($v['promote_id'])):get_promote_name($v['promote_id']);
//
// $xlsData[] = $v;
//
// }
//
//
// }
$this->exportExcel($xlsName, $xlsCell, $xlsData); $this->exportExcel($xlsName, $xlsCell, $xlsData);

Loading…
Cancel
Save