master
chenzhi 5 years ago
parent c602946088
commit d3ccc3bb5b

@ -1734,40 +1734,40 @@ function getOffspringByPromoteId($promote_id = null) {
* @return void * @return void
*/ */
function data2csv(&$data,$title,$fields){ function data2csv(&$data,$title,$fields){
set_time_limit(0);  set_time_limit(0);
ini_set('memory_limit', '-1'); //设置内存不受限制     ini_set('memory_limit', '-1'); //设置内存不受限制
$filename = $title .'.csv';     $csvFileName = $title.'.csv';
$fp = fopen($filename, 'w'); //生成临时文件     //设置好告诉浏览器要下载excel文件的headers
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码     header('Content-Description: File Transfer');
$field = array_keys($fields);     header('Content-Type: application/vnd.ms-excel;charset=utf-8');
//生成首行     header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
$header = array_values($fields);     header('Expires: 0');
fputcsv($fp, $header);     header('Cache-Control: must-revalidate');
    header('Pragma: public');
$index = 0;     $fp = fopen('php://output', 'a');//打开output流
foreach ($data as $row) {     fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
$a = [];     $field = array_keys($fields);
foreach($field as $k=>$v){     //生成首行
// $a[$v] = $row[$v] . "\t";//防止格式错误     $header = array_values($fields);
$a[$v] = $row[$v];     fputcsv($fp, $header);
}
if ($index == 10000) { //每次写入1000条数据清除内存     $index = 0;
$index = 0;     foreach ($data as $row) {
ob_flush();//清除内存         $a = [];
flush();         foreach($field as $k=>$v){
}             // $a[$v] = $row[$v] . "\t";//防止格式错误
$index++;             $a[$v] = $row[$v];
fputcsv($fp, $a);         }
}         if ($index == 10000) { //每次写入1000条数据清除内存
ob_flush();             $index = 0;
fclose($fp); //每生成一个文件关闭             ob_flush();//清除内存
//下载             flush();
header('Content-Type: application/vnd.ms-excel;charset=utf-8');         }
header('Content-Disposition: attachment;filename="' . $title . '.csv"');         $index++;
header('Cache-Control: max-age=0');         fputcsv($fp, $a);
header('Content-Length: ' . filesize($filename));     }
@readfile($filename);     ob_flush();
unlink($filename);     fclose($fp);  //每生成一个文件关闭
die();     die();
} }
?> ?>

@ -137,8 +137,11 @@ class MemberController extends ThinkController
->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total") ->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total")
->where($map) ->where($map)
->group("tab_user.id") ->group("tab_user.id")
->page($page, $row) // ->page($page, $row)
->order($order); ->order($order);
if(!isset($_REQUEST['export'])){
$data ->page($page, $row);
}
if($havs){ if($havs){
$data->having($havs); $data->having($havs);
} }
@ -158,6 +161,55 @@ class MemberController extends ThinkController
$data->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left"); $data->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left");
} }
$data = $data->select(); $data = $data->select();
if(isset($_REQUEST['export'])){
$isadmin = is_administrator();
//获取等级
$tool = M('tool',"tab_")->field('config,status')->where(['name'=>'viplevel'])->find();
$viplevel = false;
if(!empty($tool) && $tool['status']==1){
$viplevel = json_decode($tool['config'],true);
$len = count($viplevel);
if(empty($viplevel)) {$viplevel = false;}
}
foreach ($data as $k => &$v) {
$v['register_type'] = get_registertype($v['register_type']);
if(!$isadmin){
$v['account'] = encryptStr($v['account']);
$v['promote_account'] = encryptStr($v['promote_account']);
$v['device_number'] = encryptStr($v['device_number']);
}
empty($v['alipay']) && $v['alipay']="--";
empty($v['small_count']) && $v['small_count']="--";
$v['gold_coin']?:'0.00';
if($viplevel){
$vl=0;
$money = intval($v['recharge_total']*10000);
foreach($viplevel as $k=>$value) {
$i = intval(str_replace('vip','',$k));
if($money<intval($value*10000)) {$vl = $i-1;break;}
if($i == $len) {$vl = $i;}
}
$v['vip_level'] = $vl;
}else{
$v['vip_level'] = 0;
}
$v['register_time'] = date('Y-m-d H:i:s',$v['register_time']);
$v['login_time'] = date('Y-m-d H:i:s',$v['login_time']);
$v['lock_status'] = get_info_status($v['lock_status'],4);
$v['check_status'] = $v['check_status']==1 ? "正常" :"拉黑";
// $data[$k] = $v;
}
$field = array(
"id"=>"账号ID","account"=>"玩家账号","promote_account"=>"所属推广员","balance"=>"账户平台币","recharge_total"=>"累计充值","gold_coin"=>"金币",
"alipay"=>"绑定支付宝","small_count"=>"小号","vip_level"=>"VIP等级","register_type"=>"注册方式","register_time"=>"注册时间","register_ip"=>"注册IP","login_time"=>"最后登录时间",
"device_number"=>"设备号","lock_status"=>"账号状态","check_status"=>"拉黑状态"
);
data2csv($data,"玩家_玩家列表",$field);
}
if($havs){ if($havs){
//判断是否需要vip等级分类 //判断是否需要vip等级分类

@ -354,7 +354,9 @@
</div> </div>
<div class="page"> <div class="page">
<if condition="$is_admin eq true "> <if condition="$is_admin eq true ">
<a class="sch-btn" href="{:U('Export/expUser',array_merge(['id'=>3,'xlsname'=>'玩家_玩家列表_'.(I('get.type')==2?'第三方玩家':'本站玩家')],I('get.')))}">导出</a> <a class="sch-btn"
href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a>
<!-- <a class="sch-btn" href="{:U('Export/expUser',array_merge(['id'=>3,'xlsname'=>'玩家_玩家列表_'.(I('get.type')==2?'第三方玩家':'本站玩家')],I('get.')))}">导出</a> -->
</if> </if>
{$_page|default=''} {$_page|default=''}
</div> </div>

Loading…
Cancel
Save