From 0f0ba924ce37d3206c5483aaabc7f41e786885c9 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 8 Feb 2023 18:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=80=BB=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Shop/Services/TotalService.php | 12 ++++++++++++ .../Shop/Services/TotalServices/SubtotalService.php | 10 +--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/beike/Shop/Services/TotalService.php b/beike/Shop/Services/TotalService.php index 3e21ee7c..c03236aa 100644 --- a/beike/Shop/Services/TotalService.php +++ b/beike/Shop/Services/TotalService.php @@ -102,4 +102,16 @@ class TotalService return $this->totals; } + + /** + * 获取当前购物车商品总额 + * + * @return mixed + */ + public function getSubTotal(): mixed + { + $carts = $this->cartProducts; + + return collect($carts)->sum('subtotal'); + } } diff --git a/beike/Shop/Services/TotalServices/SubtotalService.php b/beike/Shop/Services/TotalServices/SubtotalService.php index 4354b789..1e7f72e0 100644 --- a/beike/Shop/Services/TotalServices/SubtotalService.php +++ b/beike/Shop/Services/TotalServices/SubtotalService.php @@ -13,7 +13,6 @@ namespace Beike\Shop\Services\TotalServices; use Beike\Shop\Services\CheckoutService; -use Beike\Shop\Services\TotalService; class SubtotalService { @@ -24,7 +23,7 @@ class SubtotalService public static function getTotal(CheckoutService $checkout) { $totalService = $checkout->totalService; - $amount = self::getAmount($totalService); + $amount = $totalService->getSubTotal(); $totalData = [ 'code' => 'sub_total', 'title' => trans('shop/carts.product_total'), @@ -37,11 +36,4 @@ class SubtotalService return $totalData; } - - public static function getAmount(TotalService $totalService) - { - $carts = $totalService->cartProducts; - - return collect($carts)->sum('subtotal'); - } }