diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index 828e228d2d8eb97229e1ec4cf9af2fe713935747..40203077074d9fdbdab9efd9640b6a4cdd9a3b5c 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 2149aec71ebe826ec689dda2b745156c7ec534fa..21fe292d2e6a4a6aad68d850ec1e1935a55885ee 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; } });