21,886
社区成员
发帖
与我相关
我的任务
分享
set_time_limit(0);
header ( "Content-type:application/vnd.ms-excel" );
header ( "Content-Disposition:filename=" . iconv ( "UTF-8", "GB18030", "会员列表" ) . ".csv" );
// 打开PHP文件句柄,php://output 表示直接输出到浏览器
$fp = fopen('php://output', 'a');
// 设置表格头标题
$head_title = array('id', '账号', '用户名称', '状态', '最后登录时间', '注册时间');
// 将中文标题转换编码,否则乱码
foreach ($head_title as $i => $v) {
$head_title[$i] = iconv('utf-8', 'GB18030', $v);
}
// 将标题名称通过fputcsv写到文件句柄
fputcsv($fp, $head_title);
// 统计导出的总数
$total_export_count = $user->count();
// limit
$pre_count = 10000;
for ($i=1;$i<=ceil($total_export_count/$pre_count);$i++){
$export_data = $user->where($where)->order('create_time DESC')->limit(strval(($i-1)*$pre_count), $pre_count)->select();
foreach ( $export_data as $v ) {
$rows = array();
$rows[] = iconv('utf-8', 'GB18030', $v['id'] . "\t");
$rows[] = iconv('utf-8', 'GB18030', $v['mobile'] . "\t");
$rows[] = iconv('utf-8', 'GB18030', $v['username'] . "\t");
$rows[] = iconv('utf-8', 'GB18030', $v['sum_alleat_reel'] . "\t");
$rows[] = iconv('utf-8', 'GB18030', $v['alleat_reel'] . "\t");
$rows[] = iconv('utf-8', 'GB18030', $v['give_alleat_reel'] . "\t");
if($v['status'] == 1){
$rows[] = iconv('utf-8', 'GB18030', '正常' . "\t");
} else {
$rows[] = iconv('utf-8', 'GB18030', '黑名单' . "\t");
}
$rows[] = date('Y-m-d H:i:s',$v["last_login_time"] . "\t\n");
$rows[] = date('Y-m-d H:i:s',$v["create_time"] . "\t\n");
fputcsv($fp, $rows);
}
// 将已经写到csv中的数据存储变量销毁,释放内存占用
unset($export_data);
ob_flush();
flush();
}
exit ();