From 6af1a100e00d3c9f5ff8c5d36daefc7988494d6b Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Thu, 21 Sep 2023 18:32:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E8=AE=A1=E6=8A=9B=E6=AF=94=E8=AE=A1=E7=AE=97=E4=BD=93=E7=A7=AF?= =?UTF-8?q?=E9=87=8D=E3=80=82=E5=9C=A8=E4=BD=93=E7=A7=AF=E9=87=8D=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E9=87=8F=E9=87=8D=E4=B8=AD=E5=8F=96=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E7=9A=84=E5=80=BC=E8=AE=A1=E7=AE=97=E8=BF=90=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Models/Logistics.php | 10 +++++++--- .../Services/TotalServices/ShippingService.php | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/beike/Models/Logistics.php b/beike/Models/Logistics.php index ce8fca91..f14d721f 100644 --- a/beike/Models/Logistics.php +++ b/beike/Models/Logistics.php @@ -65,14 +65,18 @@ class Logistics extends Base{ }else{ // 循环判断:只要有一个商品不符合条件 则当前物流不可用; foreach($productsList as $productItem){ - $surplusWeight = $productItem['sum_weight'] - $firstWeight;// 总重量 - 减首重 = 剩余重量 + // 计算体积重 并且取数值大的作为重量计算 + $volumeWeight = $productItem['volume_weight'] / $logisticsItem['throwing_ratio']; + $sumWeight = $productItem['sum_weight'] > $volumeWeight ? $productItem['sum_weight'] : $volumeWeight; + // 总重量 - 减首重 = 剩余重量 + $surplusWeight = $sumWeight - $firstWeight; // 判断:如果剩余重量小于等于0 则符合条件;否则计算续重区间 if($surplusWeight <= 0){ continue; }else{ $eligibleCount = collect($weights) - ->where('min','<=',$surplusWeight) - ->where('max','>',$surplusWeight) + ->where('min','<=',$sumWeight)//$surplusWeight + ->where('max','>',$sumWeight)//$surplusWeight ->count(); if($eligibleCount <= 0) { $logisticsItem = []; diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 714dcbb9..90a5bf77 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -56,19 +56,25 @@ class ShippingService{ self::$productsList = collect($products)->groupBy('product_id')->map(function($group){ $firstInfo = $group->first(); $productWeightInfo = Product::query() - ->select(['id','weight','weight_class']) + ->select(['id','weight','weight_class','length','width','height']) ->find($firstInfo['product_id']); if($productWeightInfo) $productWeightInfo = $productWeightInfo->toArray(); // 重量转换 - 物流重量单位为 千克;商品重量需要进行转换 $weight = $productWeightInfo['weight'] ?? 0; $sumQuantity = $group->sum('quantity'); - $sumWeight = (float)sprintf("%.2f",($weight * $sumQuantity)); + // 判断:如果是按批卖 则数量需要除以每批的数量 在计算总重量。按件卖则直接计算 + $weightQuantity = $firstInfo['sales_method'] == 'batches' ? ($sumQuantity / $firstInfo['piece_to_batch']) : $sumQuantity;// 多少件/多少批 根据销售方式获取 + $sumWeight = (float)sprintf("%.2f",($weight * $weightQuantity)); $weightClass = $productWeightInfo['weight_class']; $sumWeight = Weight::convert($sumWeight,$weightClass);// 总重量 单位:克 + // 获取 体积重 (长cm*宽cm*高cm)*数量/抛比=体积重 + $volumeWeight = ($productWeightInfo['length'] * $productWeightInfo['width'] * $productWeightInfo['height']) * $weightQuantity;// 还需要除以计抛比 + return [ 'product_id' => $firstInfo['product_id'], 'sum_quantity' => $sumQuantity, 'sum_weight' => $sumWeight, + 'volume_weight' => $volumeWeight, 'weight' => $weight, 'weight_class' => $weightClass, ]; @@ -103,7 +109,7 @@ class ShippingService{ * @return array|mixed|mixed[] */ private static function getLogistics($logisticsId,$cart){ - $logisticsField = ['id','type', 'name','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee']; + $logisticsField = ['id','type', 'name','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee','throwing_ratio']; // 判断:客服端是否切换国家 如果存在切换的国家id 则使用切换的国家id;不存在则继续执行 $countryId = (int)request()->input('products_country_id'); if($countryId > 0) { @@ -190,10 +196,13 @@ class ShippingService{ $continuationWeightFee = (float)$logisticsInfo['continuation_weight_fee'];// 续重运费 // 循环处理商品 foreach(self::$productsList as $productInfo){ + // 计算体积重 并且取数值大的作为重量计算 + $volumeWeight = $productInfo['volume_weight'] / $logisticsInfo['throwing_ratio']; + $sumWeight = $productInfo['sum_weight'] > $volumeWeight ? $productInfo['sum_weight'] : $volumeWeight; // 首重运费 $amount += (float)sprintf("%.2f",$firstWeightFee); // 判断:如果总重量超过首重 则计算续重运费 - $surplus = (int)$productInfo['sum_weight'] - $firstWeight; + $surplus = (float)$sumWeight - $firstWeight; if($surplus > 0) $amount += (float)sprintf("%.2f",($surplus / $addWeight) * $continuationWeightFee); }