From ceb76964cf3aced510d35f0fd728126cf312bae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Fri, 21 Feb 2025 08:26:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/service/SystemService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/think-library/src/service/SystemService.php b/plugin/think-library/src/service/SystemService.php index 095860aea..3f4dcc0f0 100644 --- a/plugin/think-library/src/service/SystemService.php +++ b/plugin/think-library/src/service/SystemService.php @@ -186,12 +186,12 @@ class SystemService extends Service * @return boolean|integer 失败返回 false, 成功返回主键值或 true * @throws \think\admin\Exception */ - public static function batchUpdate($query, array &$data, string $key = 'id', $map = []) + public static function batchUpdate($query, array $data, string $key = 'id', $map = []) { try { - $query = Helper::buildQuery($query)->master()->strict(false); + $query = Helper::buildQuery($query)->master()->strict(false)->where($map); if (empty($map[$key])) $query->where([$key => $data[$key] ?? null]); - return $query->where($map)->update($data); + return (clone $query)->count() > 0 ? (clone $query)->update($data) : (clone $query)->save($data); } catch (\Exception $exception) { throw new Exception($exception->getMessage(), $exception->getCode()); }