From bf1168d02dc6b62b1bfc8d891238ff0f3896e6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Mon, 29 Apr 2024 23:27:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=EF=BC=8C=E6=96=87=E4=BB=B6=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BC=98=E5=85=88=E4=BA=8E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/library/Upload.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/common/library/Upload.php b/app/common/library/Upload.php index f3409cb1..fe9ce693 100644 --- a/app/common/library/Upload.php +++ b/app/common/library/Upload.php @@ -237,19 +237,21 @@ class Upload 'sha1' => $this->fileInfo['sha1'] ]; - $attachment = new Attachment(); - $attachment->data(array_filter($params)); - $res = $attachment->save(); - if (!$res) { - $attachment = Attachment::where([ - ['sha1', '=', $params['sha1']], - ['topic', '=', $params['topic']], - ['storage', '=', $params['storage']], - ])->find(); + // 附件数据入库 - 不依赖模型新增前事件,确保入库前文件已经移动完成 + $attachment = Attachment::where('sha1', $params['sha1']) + ->where('topic', $params['topic']) + ->where('storage', $params['storage']) + ->find(); + $filePath = Filesystem::fsFit(public_path() . ltrim($params['url'], '/')); + if ($attachment && file_exists($filePath)) { + $attachment->quote++; + $attachment->last_upload_time = time(); } else { $this->move($saveName); + $attachment = new Attachment(); + $attachment->data(array_filter($params)); } - + $attachment->save(); return $attachment->toArray(); }