public function daochu()
{
//防止跨域,打开缓冲区
header('Access-Control-Allow-Origin:*');
@ini_set("memory_limit", "1024M");
@ini_set("max_execution_time", "40");
ob_end_clean();
ob_start();
$filter = input();
//查出订单表的数据 page(分页的开始位置, 每一页的条数)
$articlesQuery = $this->model->alias('a');
$articlesQuery->join('city u', 'a.province_id = u.id');
$articlesQuery->join('city i', 'a.city_id = i.id');
$field = 'a.*,u.name as p_name,i.name as c_name';
$dataResult = $articlesQuery
->field($field)
->where('a.create_time', '>=', 0)
->where('a.delete_time', 0)
->select()
->toArray();
//拼接数据
$title = $filter['start_time'] . '——' . $filter['end_time'] . "导出列表";
$headtitle = "<tr style='height:50px;'><th style='height:60px;width:300px;font-size:22px;' colspan='14' >线索列表 导出时间:" . date("Y-m-d H:i:s", time()) . "</th></tr>";
$titlename = "<tr>
<th style='width:100px;'>ID</th>
<th style='width:100px;'>省份</th>
<th style='width:100px;'>城市</th>
<th style='width:200px;'>公司名</th>
<th style='width:100px;'>姓名</th>
<th style='width:250px;'>提交时间</th>
</tr>";
$filename = $title . ".xls";
$str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";
//组装表
$str .= "<table border=1 style='text-align:center'>" . $title;
$str .= $titlename;
//获取缓存
$itemData = cache('formSettingOption') ?? [];
//组装表的td 数据
foreach ($dataResult as $key => $vv) {
$str .= "<tr style='text-align:center'>";
$str .= "<td>" . ($vv['id'] ?? '暂无数据') . "</td>";
$str .= "<td>" . ($vv['p_name'] ?? '暂无数据') . "</td>";
$str .= "<td>" . ($vv['c_name'] ?? '暂无数据') . "</td>";
$str .= "<td>" . ($vv['company'] ?? '暂无数据') . "</td>";
$str .= "<td>" . ($vv['name'] ?? '暂无数据') . "</td>";
$str .= "<td>" . date('Y-m-d H:i:s', $vv['create_time'] ?? '暂无数据') . "</td>";
$str .= "</tr>\n";
}
$str .= "</table></body></html>";
//下载
header("Content-Type: application/vnd.ms-excel; name='excel'");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $filename);
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Expires: 0");
exit($str);
}
php 导出大量数据
最新推荐文章于 2024-06-26 08:46:08 发布