From 15302b3c2882d0be40fa48c9a6d43e15889bd594 Mon Sep 17 00:00:00 2001 From: TL Date: Thu, 5 Jan 2023 14:59:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E5=AE=A2=E7=BB=93=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Shop/Services/CartService.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/beike/Shop/Services/CartService.php b/beike/Shop/Services/CartService.php index c9c737c0..7867e920 100644 --- a/beike/Shop/Services/CartService.php +++ b/beike/Shop/Services/CartService.php @@ -93,12 +93,16 @@ class CartService */ public static function select($customer, $cartIds) { - CartProduct::query()->where('customer_id', $customer->id)->update(['selected' => 0]); + if ($customer) { + $builder = CartProduct::query()->where('customer_id', $customer->id); + } else { + $builder = CartProduct::query()->where('session_id', session()->getId()); + } + $builder->update(['selected' => 0]); if (empty($cartIds)) { return; } - CartProduct::query()->where('customer_id', $customer->id) - ->whereIn('id', $cartIds) + $builder->whereIn('id', $cartIds) ->update(['selected' => 1]); } @@ -111,8 +115,12 @@ class CartService if (empty($cartId) || $quantity == 0) { return; } - CartProduct::query()->where('customer_id', $customer->id) - ->where('id', $cartId) + if ($customer) { + $builder = CartProduct::query()->where('customer_id', $customer->id); + } else { + $builder = CartProduct::query()->where('session_id', session()->getId()); + } + $builder->where('id', $cartId) ->update(['quantity' => $quantity, 'selected' => 1]); }