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'); - } }