From d733793c931ab553238f6429d5e32b0006224a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=A0=E8=BE=BE=E6=B5=AA?= Date: Fri, 22 Mar 2019 17:55:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9Attachment=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=8F=92=E5=85=A5=E4=BA=8B=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E7=94=B1=E5=88=A4=E6=96=ADurl=E6=94=B9=E4=B8=BA=E5=88=A4?= =?UTF-8?q?=E6=96=ADsha1=E5=80=BC=EF=BC=8C=E9=81=BF=E5=85=8D=E7=94=B1?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9B=AE=E5=BD=95=E4=B8=8D=E5=90=8C=E9=80=A0?= =?UTF-8?q?=E6=88=90=E7=9A=84=E7=9B=B8=E5=90=8C=E6=96=87=E4=BB=B6=E5=A4=9A?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E3=80=82=202.=20=E4=BF=AE=E6=94=B9ajax?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=94=E5=9B=9E=E6=96=87=E4=BB=B6id?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E6=BB=A1=E8=B6=B3=E9=9C=80=E8=A6=81=E5=A4=96?= =?UTF-8?q?=E9=94=AE=E7=9A=84=E5=89=8D=E7=AB=AF=E9=9C=80=E6=B1=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Ajax.php | 8 +++++++- application/common/model/Attachment.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index 828e228d2..402030770 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -124,9 +124,15 @@ class Ajax extends Backend $attachment = model("attachment"); $attachment->data(array_filter($params)); $attachment->save(); + + $lastId = empty($attachment['id']) + ? $attachment->where('sha1', '=', $params['sha1'])->value('id') + : $attachment['id']; + \think\Hook::listen("upload_after", $attachment); $this->success(__('Upload successful'), null, [ - 'url' => $uploadDir . $splInfo->getSaveName() + 'url' => $uploadDir . $splInfo->getSaveName(), + 'id' => $lastId ]); } else { // 上传失败获取错误信息 diff --git a/application/common/model/Attachment.php b/application/common/model/Attachment.php index 2149aec71..21fe292d2 100644 --- a/application/common/model/Attachment.php +++ b/application/common/model/Attachment.php @@ -25,7 +25,7 @@ class Attachment extends Model { // 如果已经上传该资源,则不再记录 self::beforeInsert(function ($model) { - if (self::where('url', '=', $model['url'])->find()) { + if (self::where('sha1', '=', $model['sha1'])->find()) { return false; } }); -- Gitee