From 93d99abc9763c39d0c13da71dc32d484c48d09fe Mon Sep 17 00:00:00 2001 From: lq Date: Tue, 13 May 2025 16:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=8B=E8=BD=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/CodeGenerationController.php | 12 +++++++ app/Service/core/CodeGenerationService.php | 33 +++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/core/CodeGenerationController.php b/app/Http/Controllers/core/CodeGenerationController.php index ceedfe91..10adc427 100644 --- a/app/Http/Controllers/core/CodeGenerationController.php +++ b/app/Http/Controllers/core/CodeGenerationController.php @@ -46,4 +46,16 @@ class CodeGenerationController extends BaseController return $this->service->download($id); } + public function downloadInfo() + { +// $id = request()->post('id'); + $id = request()->get('id'); + if (!$id) { + return jerr('参数错误!'); + } + return jok( + $this->service->downloadInfo($id) + ); + } + } diff --git a/app/Service/core/CodeGenerationService.php b/app/Service/core/CodeGenerationService.php index 3bb0764e..58e500fa 100644 --- a/app/Service/core/CodeGenerationService.php +++ b/app/Service/core/CodeGenerationService.php @@ -77,6 +77,12 @@ class CodeGenerationService return self::$_instance[$name]; } + /** + * 下载文件 + * @param $id + * @return BinaryFileResponse + * @throws Exception + */ public function download($id) { $model = CodeGenerationModel::find($id); @@ -88,7 +94,23 @@ class CodeGenerationService } /** - * 创建临时文件夹,复制模板文件,压缩并返回文件流 + * 下载文件信息 + * @param $id + * @return mixed + * @throws Exception + */ + public function downloadInfo($id) + { + $model = CodeGenerationModel::find($id); + if (!$model) { + $this->utils->errorThrow('文件不存在'); + } + // 返回下载 $path 文件流 + return $model; + } + + /** + * 创建临时文件夹,复制模板文件,压缩并文件信息 */ public function downloadUrl() { @@ -118,7 +140,10 @@ class CodeGenerationService 'created_at' => time(), 'updated_at' => time(), ]); - return $insertModel->id; + return [ + 'id' => $insertModel->id, + 'file_name' => $insertModel->file_name + ]; } catch (\Exception $e) { return response()->json([ 'error' => '生成模板文件失败', @@ -127,6 +152,10 @@ class CodeGenerationService } } + /** + * 初始化参数 + * @return void + */ private function init() { // 生成uuid