diff --git a/beike/Shop/Services/CartService.php b/beike/Shop/Services/CartService.php index 7645b4ed..77fca0c3 100644 --- a/beike/Shop/Services/CartService.php +++ b/beike/Shop/Services/CartService.php @@ -18,6 +18,8 @@ use Exception; class CartService { + private static $cartList = null; + /** * 获取购物车商品列表 * @@ -27,6 +29,10 @@ class CartService */ public static function list($customer, bool $selected = false): array { + if (self::$cartList !== null) { + return self::$cartList; + } + $cartBuilder = CartRepo::allCartProductsBuilder($customer->id ?? 0); if ($selected) { $cartBuilder->where('selected', true); @@ -52,7 +58,7 @@ class CartService $cartList = CartDetail::collection($cartItems)->jsonSerialize(); - return hook_filter('service.cart.list', $cartList); + return self::$cartList = hook_filter('service.cart.list', $cartList); } /**