|
|
@@ -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(){
|