From a4bbe1c4d8b6fd0784b8000a8c17ec280f59e2c3 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 22 Aug 2023 18:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=E3=80=81=E6=9C=AA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=92=8C=E7=99=BB=E5=BD=95=E5=90=8E=E7=9A=84=E8=BF=90?= =?UTF-8?q?=E8=B4=B9=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TotalServices/ShippingService.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index ccbc1d91..1df9e861 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -14,6 +14,7 @@ namespace Beike\Shop\Services\TotalServices; use Beike\Libraries\Weight; use Beike\Models\Logistics; +use Beike\Models\Product; use Beike\Shop\Services\CheckoutService; use Illuminate\Support\Str; @@ -46,16 +47,20 @@ class ShippingService{ $logisticsInfo = self::getLogistics($logisticsId,$checkout->cart); if($logisticsInfo) { // 商品信息处理 获取同一个商品的数量 - $products = $checkout->selectedProducts->toArray() ?? []; + $products = $totalService->getCartProducts(); + // $products = $checkout->selectedProducts->toArray() ?? []; $productsList = collect($products)->groupBy('product_id')->map(function($group){ $firstInfo = $group->first(); + $productWeightInfo = Product::query() + ->select(['id','weight','weight_class']) + ->find($firstInfo['product_id']); + if($productWeightInfo) $productWeightInfo = $productWeightInfo->toArray(); // 重量转换 - 物流重量单位为 千克;商品重量需要进行转换 - $weight = $firstInfo['product']['weight'] ?? 0; + $weight = $productWeightInfo['weight'] ?? 0; $sumQuantity = $group->sum('quantity'); $sumWeight = (float)sprintf("%.2f",($weight * $sumQuantity)); - $weightClass = $firstInfo['product']['weight_class']; + $weightClass = $productWeightInfo['weight_class']; $sumWeight = Weight::convert($sumWeight,$weightClass);// 总重量 单位:克 - return [ 'product_id' => $firstInfo['product_id'], 'sum_quantity' => $sumQuantity, @@ -92,11 +97,12 @@ class ShippingService{ private static function getLogistics($logisticsId,$cart){ if($logisticsId <= 0){ // 获取当前收货地址国家ID - $address = $cart->guest_shipping_address ?? $cart->guest_payment_address; + $cartArr = $cart->toArray(); + $address = $cart->guest_shipping_address ?? $cart->guest_payment_address ?? $cartArr['payment_address'] ?? $cartArr['shipping_address']; if(!$address) return []; $countryId = $address['country_id']; // 获取全部物流 返回第一个物流信息ID - $logisticsList = Logistics::getAll($countryId,['type','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee']); + $logisticsList = Logistics::getAll($countryId,['id','type','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee']); return $logisticsList[0] ?? []; }else{