Просмотр исходного кода

称重对即时账单的补偿逻辑

Zhouzhendong 5 лет назад
Родитель
Сommit
50c6298811

+ 1 - 1
app/Listeners/ResetProcessStatisticStartDateListener.php

@@ -53,7 +53,7 @@ class ResetProcessStatisticStartDateListener
 
     private function comparisonReplace($statistic, $date)
     {
-        if ($statistic->started_at != $date){
+        if ($statistic && $statistic->started_at != $date){
             ProcessStatistic::query()->where("process_id",$statistic->process_id)->update(["started_at"=>$date]);
         }
     }

+ 25 - 14
app/Services/OrderService.php

@@ -1194,23 +1194,34 @@ class OrderService
         if ($order->owner->owner_price_expresses_count < 1)return false; //不存在计费模型 跳出
         foreach ($order->packages as $package)if (!$package->weight)return false; //包裹存在且全部存在数量
 
-        $logisticFee = 0;
+        $logistic_fee = 0;
+        $volume = 0;
+        $weight = 0;
+        if (!$order->logistic || $order->logistic->type != "快递")$logistic_fee = null;
         foreach ($order->packages as $package){
-            if ($logisticFee!==null){
-                $provinceName = mb_substr($order->province,0,2);
-                $province = app(CacheService::class)->getOrExecute("province_".$provinceName,function ()use($provinceName){
-                    return Province::query()->where("name","like",$provinceName."%")->first();
-                },86400);
-                if (!$province)$logisticFee = null;
-
-                $fee = app("OwnerPriceExpressService")->matching($package->weight, $order->owner_id, $order->logistic_id, $province->id);
-                if ($fee<0)$logisticFee = null;
-                else $logisticFee += $fee;
+            $volume += $package->bulk;
+            $weight += $package->weight;
+
+            $provinceName = mb_substr($order->province,0,2);
+            $province = app(CacheService::class)->getOrExecute("province_".$provinceName,function ()use($provinceName){
+                return Province::query()->where("name","like",$provinceName."%")->first();
+            },86400);
+            if (!$province)$logistic_fee = null;
+
+            $fee = app("OwnerPriceExpressService")->matching($package->weight, $order->owner_id, $order->logistic_id, $province->id);
+            OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$feeBill->id)->where("logistic_bill",$package->logistic_number)->update([
+                "volume"=>$package->bulk,
+                "weight"=>$package->weight,
+                "logistic_fee" => $fee>0 ? $fee : null,
+            ]);
+            if ($logistic_fee!==null){
+                if ($fee<0)$logistic_fee = null;
+                else $logistic_fee += $fee;
             }
         }
-        if ($logisticFee===null || $logisticFee<0)
-            LogService::log(__METHOD__,"ERROR-校正即时账单计算物流费错误","订单ID:".$order->id."  费用结果:".$logisticFee);
-        else $feeBill->update(["logistic_fee"=>$logisticFee]);
+        if ($logistic_fee===null || $logistic_fee<0)
+            LogService::log(__METHOD__,"ERROR-校正即时账单计算物流费错误","订单ID:".$order->id."  费用结果:".$logistic_fee);
+        else $feeBill->update(["logistic_fee"=>$logistic_fee,"volume"=>$volume,"weight"=>$weight]);
         return true;
     }