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

更改物流费计算规则,修复以往错误数据

Zhouzhendong 5 лет назад
Родитель
Сommit
484109a191

+ 46 - 6
app/Http/Controllers/TestController.php

@@ -156,14 +156,54 @@ class TestController extends Controller
     {
         ini_set('max_execution_time',2500);
         ini_set('memory_limit','1526M');
-        $orders = Order::query()->where("updated_at",">=","2021-02-27 00:00:00")->where("wms_status","订单完成")->get();
-        $orders->each(function ($order){
-            dump($order->id);
-            dispatch(new OrderCreateInstantBill($order));
-        });
+        OwnerFeeDetail::query()->where("logistic_fee",">",0)
+            ->whereNotNull("logistic_fee")
+            ->where("type","发货")->get()->each(function ($detail){
+                if (!$this->exe($detail)){
+                    dump($detail->id);
+                };
+            });
+    }
+    public function exe(OwnerFeeDetail $feeBill){
+        $order = Order::query()->where("id",$feeBill->outer_id);
+        $order->loadMissing("packages","owner");//加载包裹
+        if (!$order->packages || !$order->owner)return false;
+        $order->owner->loadCount("ownerPriceExpresses");
+        if ($order->owner->owner_price_expresses_count < 1)return false; //不存在计费模型 跳出
+        foreach ($order->packages as $package)if (!$package->weight)return false; //包裹存在且全部存在数量
+
+        $logistic_fee = 0;
+        $volume = 0;
+        $weight = 0;
+        if (!$order->logistic || $order->logistic->type != "快递")$logistic_fee = null;
+        foreach ($order->packages as $package){
+            $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 ($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;
     }
     public function tt1(){
-        $order = Order::query()->find(2300619);
+        $order = Order::query()->find(2301382);
         app("OrderService")->createInstantBill($order);
     }
     public function zzd(){

+ 2 - 3
app/Services/OwnerPriceExpressService.php

@@ -144,9 +144,8 @@ class OwnerPriceExpressService
             })->first();
         });
         if (!$model || !$model->details)return -1;
-        if ($weight < $model->initial_weight)$weight = $model->initial_weight;
-        $initialMoney = $model->initial_weight*$model->details[0]->initial_weight_price;
+        if ($weight <= $model->initial_weight)return $model->details[0]->initial_weight_price;
         $weight -= $model->initial_weight;
-        return (ceil($weight/$model->additional_weight)*$model->details[0]->additional_weight_price)+$initialMoney;
+        return (ceil($weight/$model->additional_weight)*$model->details[0]->additional_weight_price)+$model->details[0]->initial_weight_price;
     }
 }

+ 45 - 0
database/migrations/2021_03_01_150232_create_delivery_appointments_table.php

@@ -0,0 +1,45 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateDeliveryAppointmentsTable extends Migration
+{
+    public $authorities = [
+        "入库管理-盘收一体-客户预约",
+    ];
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('delivery_appointments', function (Blueprint $table) {
+            $table->id();
+            $table->timestamps();
+        });
+        foreach ($this->authorities as $authority){
+            \App\Authority::query()->firstOrCreate([
+                "name"=>$authority
+            ],[
+                "name"=>$authority,
+                "alias_name"=>$authority
+            ]);
+        }
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('delivery_appointments');
+        foreach ($this->authorities as $authority){
+            \App\Authority::query()->where("name",$authority)->delete();
+        }
+    }
+}