From 6fc2d308723bc3a3459908fba9a420e558f5f5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Sun, 23 Feb 2025 09:48:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20SystemService::upda?= =?UTF-8?q?te=20=EF=BC=8C=E5=87=8F=E5=B0=91=E6=A3=80=E6=B5=8B=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=9F=A5=E8=AF=A2=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/service/SystemService.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/think-library/src/service/SystemService.php b/plugin/think-library/src/service/SystemService.php index 6cb35a742..4f3d39b91 100644 --- a/plugin/think-library/src/service/SystemService.php +++ b/plugin/think-library/src/service/SystemService.php @@ -189,10 +189,11 @@ class SystemService extends Service public static function update($query, array $data, string $key = 'id', $map = []) { try { - $query = Helper::buildQuery($query)->master()->strict(false)->where($map); + $query = Helper::buildQuery($query)->master()->where($map); if (empty($map[$key])) $query->where([$key => $data[$key] ?? null]); - return (clone $query)->count() > 0 ? (clone $query)->update($data) : (clone $query)->findOrEmpty()->save($data); - } catch (\Exception $exception) { + $model = (clone $query)->findOrEmpty(); + return $model->isExists() ? (clone $query)->strict(false)->update($data) : $model->save($data); + } catch (\Exception|\Throwable $exception) { throw new Exception($exception->getMessage(), $exception->getCode()); } }