输出文件流

This commit is contained in:
2025-08-05 15:16:05 +08:00
parent 46c6a950e0
commit 1c040943ed
2 changed files with 26 additions and 14 deletions
+16 -7
View File
@@ -13,8 +13,9 @@ class CustomerController extends BaseController
* 不需要头信息的方法
*/
protected $noNeedHeader = [];
protected $noNeedHeaderData = ['export'];
protected $noNeedLogin = [];
protected $noNeedLogin = ['export'];
/**
* 客户列表
@@ -43,13 +44,21 @@ class CustomerController extends BaseController
*/
public function export(Request $request)
{
set_time_limit(120);
try {
$param = $request->all();
// $corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
// $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'])) {
return $this->error('导出文件生成失败');
@@ -66,9 +75,9 @@ class CustomerController extends BaseController
$response->header('Content-Length', $fileSize);
$response->header('Cache-Control', 'no-cache, must-revalidate');
$response->header('Pragma', 'no-cache');
return $response;
return $response;*/
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}