补链csv导出

master
chenzhi 5 years ago
parent 5359e67860
commit df50ce6352

@ -34,9 +34,10 @@ class MendController extends ThinkController {
/**
* 补链记录
* @param integer $p 分页
* @param booble IS_POST post请求时为下一页ajax请求
* @return void
*/
public function recordList($p=1)
public function recordList($p=1,$export=false)
{
$page = intval($p);
$page = $page ? $page : 1;
@ -52,18 +53,24 @@ class MendController extends ThinkController {
$map['user_account']=array('like','%'.$_REQUEST['account'].'%');
unset($_REQUEST['account']);
}
$data = M("Mend","tab_")
->field("id,user_account,promote_account,promote_account_to,op_account,order_time,create_time,remark")
$data = M("Mend","tab_")
->field("user_account,promote_account,promote_account_to,order_time,create_time,op_account,remark")
->where($map)
->order("create_time desc")
->page($page, $row)
->select();
->order("create_time desc");
if($export){
$data = $data->select();
}else{
$data = $data->page($page, $row)->select();
}
//格式化信息
foreach ($data as $key => $value) {
$data[$key]['create_time'] = date("Y-m-d H:i:s",$value['create_time']);
$data[$key]['order_time'] = date("Y-m-d",$value['order_time']);
}
if($export) db2csv($data,"推广员管理_推广补链_补链记录",["玩家账号","补链前渠道","补链后渠道","切分时间","补链时间","操作人员","备注"]);
if(IS_POST){
$page = set_pagination($_REQUEST['row_count'],$row);
$this->ajaxReturn(array(
@ -83,6 +90,7 @@ class MendController extends ThinkController {
$this->display();
// parent::lists("Mend",$p,$map);
}
public function edit($id = null)
{

@ -85,7 +85,7 @@
</div>
</div>
<div class="page">
<a class="sch-btn" href="{:U('Export/mend_record_list',array_merge(['xlsname'=>'推广员管理_推广补链_补链记录'],I('get.')))}">导出</a>
<a class="sch-btn" href="{:U('Mend/recordList',array_merge(['export'=>1],I('get.')))}">导出</a>
<div id="pagebox">
{$_page|default=''}
</div>

@ -2910,3 +2910,24 @@ function encryption($string) {
return substr($string, 0, $strLen) . $hideChar . substr($string, $orderLen-$strLen);
}
//导出csv
function db2csv(&$data,$title,$header=false){
set_time_limit(0);
$filename = $title .'.csv';
$fp = fopen($filename, 'w'); //生成临时文件
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
if($header) fputcsv($fp, $header);
foreach ($data as $a) {
fputcsv($fp, $a);
}
fclose($fp); //每生成一个文件关闭
//下载
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-Disposition: attachment;filename="' . $title . '.csv"');
header('Cache-Control: max-age=0');
header('Content-Length: ' . filesize($filename));
readfile($filename);
unlink($filename);
die();
}
Loading…
Cancel
Save