From 967c4f04d995fd7442714f2011fe43005fd2a2f6 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 17 Feb 2022 18:34:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=85=E5=AE=B9=E4=B8=BA=E7=A9=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/FileController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index edc34082..75752f32 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -293,9 +293,19 @@ class FileController extends AbstractController 'userid' => $userid, 'created_id' => $user->userid, ]); - $file->save(); + $data = AbstractModel::transaction(function() use ($file) { + $content = FileContent::select(['content', 'text', 'size'])->whereFid($file->cid)->orderByDesc('id')->first(); + $file->size = $content?->size ?: 0; + $file->save(); + if ($content) { + $content = $content->toArray(); + $content['fid'] = $file->id; + $content['userid'] = $file->userid; + FileContent::createInstance($content)->save(); + } + return File::find($file->id); + }); // - $data = File::find($file->id); $data->pushMsg('add', $data); return Base::retSuccess('倍刢成功', $data); } @@ -531,6 +541,7 @@ class FileController extends AbstractController $content->save(); // $file->size = $content->size; + $file->updated_at = Carbon::now(); $file->save(); $file->pushMsg('update', $file); }