Merge branch 'feature/crmadmin0724' into develop

This commit is contained in:
2025-08-05 15:16:17 +08:00
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());
}
+10 -7
View File
@@ -248,15 +248,18 @@ class CustomerService
// 创建Excel写入器
$writer = new Xlsx($spreadsheet);
$writer->save($filepath);
// $writer->save($filepath);
$writer->save('php://output');
$excelContent = ob_get_clean();
return $excelContent;
// 返回文件信息
return [
'filename' => $filename,
'filepath' => $filepath,
'size' => filesize($filepath),
'count' => count($customers)
];
// return [
// 'filename' => $filename,
// 'filepath' => $filepath,
// 'size' => filesize($filepath),
// 'count' => count($customers)
// ];
}
/**