refactor: 修改各模块导出
This commit is contained in:
@@ -115,13 +115,14 @@ if (!function_exists('xlsx_writer')) {
|
|||||||
flush();
|
flush();
|
||||||
ob_flush();
|
ob_flush();
|
||||||
if ($filename == '') $filename = date('YmdHis');
|
if ($filename == '') $filename = date('YmdHis');
|
||||||
|
$filename = urlencode($filename);
|
||||||
// 文件写入缓冲区
|
// 文件写入缓冲区
|
||||||
\PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx')->save($output);
|
\PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx')->save($output);
|
||||||
// 从缓冲区获取导出文件,并通过Response返回(解决thinkphp框架的Response无法获取设置的header问题)
|
// 从缓冲区获取导出文件,并通过Response返回(解决thinkphp框架的Response无法获取设置的header问题)
|
||||||
$file_data = ob_get_clean();
|
$file_data = ob_get_clean();
|
||||||
$response = \think\Response::create($file_data)->header([
|
$response = \think\Response::create($file_data)->header([
|
||||||
'Access-Control-Expose-Headers' => 'Content-Disposition',
|
'Access-Control-Expose-Headers' => 'Content-Disposition',
|
||||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; Charset=UTF-8',
|
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8',
|
||||||
'Content-Disposition' => 'attachment;filename=' . $filename . '.xlsx',
|
'Content-Disposition' => 'attachment;filename=' . $filename . '.xlsx',
|
||||||
'Cache-Control' => 'max-age=0'
|
'Cache-Control' => 'max-age=0'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class Agent
|
|||||||
$agents = $this->getAgentExportData();
|
$agents = $this->getAgentExportData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($agents, $schema);
|
return xlsx_writer($agents, $schema, '代理商申请列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
// 获取要导出的代理商数据
|
// 获取要导出的代理商数据
|
||||||
private function getAgentExportData()
|
private function getAgentExportData()
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ class Article
|
|||||||
$data = $this->getExportArticleData();
|
$data = $this->getExportArticleData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($data, $schema);
|
return xlsx_writer($data, $schema, '文章列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取文章导出数据
|
// 获取文章导出数据
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class ArticleLeaveMessage
|
|||||||
$data = $this->getExportMessageData();
|
$data = $this->getExportMessageData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($data, $schema);
|
return xlsx_writer($data, $schema, '文章评论列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
private function getExportMessageData()
|
private function getExportMessageData()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class BannerItem
|
|||||||
$banner_items = $this->getBannerExportData();
|
$banner_items = $this->getBannerExportData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($banner_items, $schema);
|
return xlsx_writer($banner_items, $schema, 'banner列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
// 获取导出数据
|
// 获取导出数据
|
||||||
private function getBannerExportData()
|
private function getBannerExportData()
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class BulkPurchaseInquiry
|
|||||||
$data = $this->getExportData();
|
$data = $this->getExportData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($data, $schema);
|
return xlsx_writer($data, $schema, '批量购买询盘列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
// 获取要导出的采购询盘数据
|
// 获取要导出的采购询盘数据
|
||||||
private function getExportData()
|
private function getExportData()
|
||||||
|
|||||||
@@ -40,19 +40,19 @@ class LeaveMessage
|
|||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
$schema = [
|
$schema = [
|
||||||
|
'created_at' => '提交时间',
|
||||||
'id' => 'ID',
|
'id' => 'ID',
|
||||||
'name' => '姓名',
|
'name' => '姓名',
|
||||||
'email' => '邮箱',
|
'email' => '邮箱',
|
||||||
'ip' => 'IP',
|
'ip' => 'IP',
|
||||||
'content' => '留言内容',
|
'content' => '留言内容'
|
||||||
'created_at' => '提交时间'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// 获取留言导出数据
|
// 获取留言导出数据
|
||||||
$msgs = $this->getLeaveMessageExportData();
|
$msgs = $this->getLeaveMessageExportData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($msgs, $schema);
|
return xlsx_writer($msgs, $schema, '联系我们列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
// 获取留言导出数据
|
// 获取留言导出数据
|
||||||
private function getLeaveMessageExportData()
|
private function getLeaveMessageExportData()
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ class Menu
|
|||||||
$data = $this->getExportMenuData();
|
$data = $this->getExportMenuData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($data, $schema, '', 'php://output', 'file');
|
return xlsx_writer($data, $schema, '菜单列表' . date('YmdHis'), 'php://output', 'file');
|
||||||
}
|
}
|
||||||
private function getExportMenuData()
|
private function getExportMenuData()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ class Product
|
|||||||
$data = $this->getExportProductData();
|
$data = $this->getExportProductData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($data, $schema);
|
return xlsx_writer($data, $schema, '产品列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
// 获取产品导出数据
|
// 获取产品导出数据
|
||||||
private function getExportProductData()
|
private function getExportProductData()
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class ProductPurchaseLink
|
|||||||
$data = $this->getExportLinkData();
|
$data = $this->getExportLinkData();
|
||||||
|
|
||||||
/// 导出
|
/// 导出
|
||||||
return xlsx_writer($data, $schema);
|
return xlsx_writer($data, $schema, '产品购买链接' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
private function getExportLinkData()
|
private function getExportLinkData()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class Video
|
|||||||
$data = $this->getExportVideoData();
|
$data = $this->getExportVideoData();
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
return xlsx_writer($data, $schema);
|
return xlsx_writer($data, $schema, '视频列表' . date('YmdHis'));
|
||||||
}
|
}
|
||||||
private function getExportVideoData()
|
private function getExportVideoData()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user