getDriver($row['storage'], false); return $driver ? $driver->url($row['url']) : full_url($row['url']); } /** * 新增前 * @throws Throwable */ protected static function onBeforeInsert($model): bool { $repeat = $model->where([ ['sha1', '=', $model->sha1], ['topic', '=', $model->topic], ['storage', '=', $model->storage], ])->find(); if ($repeat) { $driver = self::$upload->getDriver($repeat->storage, false); if ($driver && !$driver->exists($repeat->url)) { $repeat->delete(); return true; } else { $repeat->quote++; $repeat->last_upload_time = time(); $repeat->save(); return false; } } return true; } /** * 新增后 */ protected static function onAfterInsert($model): void { Event::trigger('AttachmentInsert', $model); if (!$model->last_upload_time) { $model->quote = 1; $model->last_upload_time = time(); $model->save(); } } /** * 删除后 */ protected static function onAfterDelete($model): void { Event::trigger('AttachmentDel', $model); $driver = self::$upload->getDriver($model->storage, false); if ($driver && $driver->exists($model->url)) { $driver->delete($model->url); } } public function admin(): BelongsTo { return $this->belongsTo(Admin::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } }