Merge branch 'feature/crmadmin0724' into develop
This commit is contained in:
@@ -13,8 +13,9 @@ class CustomerController extends BaseController
|
|||||||
* 不需要头信息的方法
|
* 不需要头信息的方法
|
||||||
*/
|
*/
|
||||||
protected $noNeedHeader = [];
|
protected $noNeedHeader = [];
|
||||||
|
protected $noNeedHeaderData = ['export'];
|
||||||
|
|
||||||
protected $noNeedLogin = [];
|
protected $noNeedLogin = ['export'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户列表
|
* 客户列表
|
||||||
@@ -43,13 +44,21 @@ class CustomerController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function export(Request $request)
|
public function export(Request $request)
|
||||||
{
|
{
|
||||||
|
set_time_limit(120);
|
||||||
try {
|
try {
|
||||||
$param = $request->all();
|
$param = $request->all();
|
||||||
// $corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
|
// $corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
|
||||||
// $param['corp_abbr'] = $corp->id;
|
// $param['corp_abbr'] = $corp->id;
|
||||||
|
|
||||||
$result = (new CustomerService())->export($param);
|
$excelContent = (new CustomerService())->export($param);
|
||||||
|
// 生成文件名
|
||||||
|
$filename = '客户数据_' . date('Y-m-d_H-i-s') . '.xlsx';
|
||||||
|
return response()
|
||||||
|
->withHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
||||||
|
->withHeader('Content-Disposition', 'attachment; filename="'.$filename.'"')
|
||||||
|
->withBody($excelContent);
|
||||||
|
|
||||||
|
/*$result = (new CustomerService())->export($param);
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
if (!file_exists($result['filepath'])) {
|
if (!file_exists($result['filepath'])) {
|
||||||
return $this->error('导出文件生成失败');
|
return $this->error('导出文件生成失败');
|
||||||
@@ -66,9 +75,9 @@ class CustomerController extends BaseController
|
|||||||
$response->header('Content-Length', $fileSize);
|
$response->header('Content-Length', $fileSize);
|
||||||
$response->header('Cache-Control', 'no-cache, must-revalidate');
|
$response->header('Cache-Control', 'no-cache, must-revalidate');
|
||||||
$response->header('Pragma', 'no-cache');
|
$response->header('Pragma', 'no-cache');
|
||||||
|
|
||||||
return $response;
|
return $response;*/
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,15 +248,18 @@ class CustomerService
|
|||||||
|
|
||||||
// 创建Excel写入器
|
// 创建Excel写入器
|
||||||
$writer = new Xlsx($spreadsheet);
|
$writer = new Xlsx($spreadsheet);
|
||||||
$writer->save($filepath);
|
// $writer->save($filepath);
|
||||||
|
$writer->save('php://output');
|
||||||
|
$excelContent = ob_get_clean();
|
||||||
|
return $excelContent;
|
||||||
|
|
||||||
// 返回文件信息
|
// 返回文件信息
|
||||||
return [
|
// return [
|
||||||
'filename' => $filename,
|
// 'filename' => $filename,
|
||||||
'filepath' => $filepath,
|
// 'filepath' => $filepath,
|
||||||
'size' => filesize($filepath),
|
// 'size' => filesize($filepath),
|
||||||
'count' => count($customers)
|
// 'count' => count($customers)
|
||||||
];
|
// ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user