diff --git a/beike/Shop/Http/Controllers/CartController.php b/beike/Shop/Http/Controllers/CartController.php index e12674b1..195000ee 100644 --- a/beike/Shop/Http/Controllers/CartController.php +++ b/beike/Shop/Http/Controllers/CartController.php @@ -43,7 +43,7 @@ class CartController extends Controller public function update(Request $request, $cartId): array { $customer = current_customer(); - $quantity = $request->get('quantity'); + $quantity = (int)$request->get('quantity'); CartService::updateQuantity($customer, $cartId, $quantity); return CartService::reloadData(); diff --git a/beike/Shop/Services/CartService.php b/beike/Shop/Services/CartService.php index 27b33de1..f39c8ffc 100644 --- a/beike/Shop/Services/CartService.php +++ b/beike/Shop/Services/CartService.php @@ -48,8 +48,8 @@ class CartService $productId = $sku->product_id; $skuId = $sku->id; - if (empty($sku)) { - throw new Exception("无效的SKU ID"); + if (empty($sku) || $quantity == 0) { + return null; } $cart = Cart::query() ->where('customer_id', $customerId) @@ -96,7 +96,7 @@ class CartService */ public static function updateQuantity($customer, $cartId, $quantity) { - if (empty($cartId)) { + if (empty($cartId) || $quantity == 0) { return; } Cart::query()->where('customer_id', $customer->id)