|
|
@@ -6,6 +6,7 @@ use App\Feature;
|
|
|
use App\Order;
|
|
|
use App\OwnerFeeDetail;
|
|
|
use App\OwnerFeeDetailLogistic;
|
|
|
+use App\OwnerFeeExpress;
|
|
|
use App\Process;
|
|
|
use App\Province;
|
|
|
use App\RejectedBill;
|
|
|
@@ -49,176 +50,157 @@ class ResetInstantBill implements ShouldQueue
|
|
|
*/
|
|
|
public function handle()
|
|
|
{
|
|
|
- /*switch ($this->detail->outer_table_name){
|
|
|
+ switch ($this->detail->outer_table_name){
|
|
|
case "orders":
|
|
|
- //检查订单对象
|
|
|
$order = Order::query()->find($this->detail->outer_id);
|
|
|
- if (!$order || $order->wms_status != "订单完成")break;
|
|
|
+ if (!$order)break;
|
|
|
+ //加载所需数据
|
|
|
$order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
|
|
|
- $service = app("OwnerPriceExpressService");
|
|
|
- $logistic_fee = 0;
|
|
|
- $amount = 0;
|
|
|
- $volume = 0;
|
|
|
- $weight = 0;
|
|
|
- $logistic_bill = "";
|
|
|
-
|
|
|
- if (!$order->logistic || $order->logistic->type == "物流")$logistic_fee = null;
|
|
|
-
|
|
|
- $items = [];
|
|
|
- $isBunched = $order->logistic && $order->logistic->is_bunched=='Y';
|
|
|
- $weightExceptionMark = false;
|
|
|
- $provinceId = null;
|
|
|
- $logisticTaxFee = 0;
|
|
|
- foreach ($order->packages as &$package){
|
|
|
- $tax = 0;
|
|
|
-
|
|
|
- $logistic_bill .= $package->logistic_number.",";
|
|
|
- $volume += $package->bulk;
|
|
|
- $weight += $package->weight;
|
|
|
- if (!$weightExceptionMark && (!$package->weight || $package->weight<0))$weightExceptionMark = true;
|
|
|
- $partAmount = 0;
|
|
|
- foreach($package->commodities as $commodity){
|
|
|
- $partAmount += $commodity->amount;
|
|
|
- }
|
|
|
- $amount += $partAmount;
|
|
|
-
|
|
|
- $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);
|
|
|
- $fee = null;
|
|
|
- if ($province){
|
|
|
- if (!$provinceId)$provinceId = $province->id;
|
|
|
- else if ($provinceId!=$province->id)$weightExceptionMark = true;
|
|
|
- if (!$isBunched)list($fee,$tax) = $service->matching($package->weight, $order->owner_id, $order->logistic_id, $province->id);
|
|
|
- }else $logistic_fee = null;
|
|
|
-
|
|
|
- $items[] = [
|
|
|
- "amount" => $partAmount,
|
|
|
- "logistic_bill" => $package->logistic_number,
|
|
|
- "volume"=>$package->bulk,
|
|
|
- "weight"=>$package->weight,
|
|
|
- "logistic_fee" => $fee,
|
|
|
- "tax_fee" => $tax,
|
|
|
- ];
|
|
|
- if ($logistic_fee!==null){
|
|
|
- if (!$fee || $fee<0)$logistic_fee = null;
|
|
|
- else $logistic_fee += $fee;
|
|
|
- }
|
|
|
- $logisticTaxFee += $tax;
|
|
|
- }
|
|
|
- if ($isBunched && !$weightExceptionMark && $weight>0 && $provinceId)list($logistic_fee,$logisticTaxFee) = $service->matching($weight, $order->owner_id, $order->logistic_id, $provinceId);
|
|
|
- if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
|
|
|
-
|
|
|
+ //获取运输费
|
|
|
+ $logisticInfo = app("OrderService")->getLogisticFeeInfo($order);
|
|
|
+ //获取作业费
|
|
|
+ /** @var OwnerPriceOperationService $service */
|
|
|
$service = app("OwnerPriceOperationService");
|
|
|
- list($id,$money,$workTaxFee) = $service->matching($order,Feature::MAPPING["order"],$order->owner_id,"出库");
|
|
|
-
|
|
|
- $this->detail->update([
|
|
|
- "owner_id" => $order->owner_id,
|
|
|
- "worked_at" => $order->wms_edittime ?? $order->updated_at,
|
|
|
- "shop_id" => $order->shop_id,
|
|
|
- "operation_bill" => $order->code,
|
|
|
- "consignee_name" => $order->consignee_name,
|
|
|
- "consignee_phone" => $order->consignee_phone,
|
|
|
- "commodity_amount" => $amount,
|
|
|
- "logistic_bill" => rtrim($logistic_bill,","),
|
|
|
- "volume" => $volume,
|
|
|
- "weight" => $weight,
|
|
|
+ $GLOBALS["FEE_INFO"] = [];
|
|
|
+ list($id,$money,$workTaxFee) = $service->matching($order,Feature::MAPPING["order"],$order->owner_id);
|
|
|
+ //数据组装
|
|
|
+ OwnerFeeDetail::query()->where("id",$this->detail->id)->update([
|
|
|
+ "commodity_amount" => $logisticInfo["amount"],
|
|
|
+ "logistic_bill" => $logisticInfo["logisticBill"],
|
|
|
+ "volume" => $logisticInfo["volume"],
|
|
|
+ "weight" => $logisticInfo["weight"],
|
|
|
"logistic_id" => $order->logistic_id,
|
|
|
"work_fee" => $money,
|
|
|
"owner_price_operation_id" => $id,
|
|
|
- "logistic_fee" => $logistic_fee,
|
|
|
+ "logistic_fee" => $logisticInfo["logisticFee"],
|
|
|
+ "created_at" => date('Y-m-d H:i:s'),
|
|
|
+ "outer_id" => $order->id,
|
|
|
+ "outer_table_name" => "orders",
|
|
|
"work_tax_fee" => $workTaxFee,
|
|
|
- "logistic_tax_fee" => $logistic_fee ? $logisticTaxFee : null,
|
|
|
+ "logistic_tax_fee" => $logisticInfo["logisticTaxFee"],
|
|
|
]);
|
|
|
+ //向指定表插入标记 TODO
|
|
|
+ //if ($logisticInfo["logisticFee"] && $logisticInfo["fee_info"])OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
|
|
|
+ /*if ($money>0)app("StoreService")->constructFeeInfo([
|
|
|
+ "worked_at" => $order->wms_edittime ?: $order->updated_at,
|
|
|
+ "owner_id" => $order->owner_id,
|
|
|
+ "model_id" => $id,
|
|
|
+ "source_number"=> $order->client_code,
|
|
|
+ "doc_number" => $order->code,
|
|
|
+ "commodity_id" => 0,
|
|
|
+ "total_fee" =>0,
|
|
|
+ "tax_rate" =>0,
|
|
|
+ "fee_description"=>'',
|
|
|
+ ]);*/
|
|
|
+ //后续处理
|
|
|
OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$this->detail->id)->delete();
|
|
|
- foreach ($items as &$item)$item["owner_fee_detail_id"] = $this->detail->id;
|
|
|
- if (count($items)>1)OwnerFeeDetailLogistic::query()->insert($items);
|
|
|
- app("OrderService")->setOrderQuantity($order->owner_id,$order->logistic_id);
|
|
|
+ foreach ($logisticInfo["items"] as &$item)$item["owner_fee_detail_id"] = $this->detail->id;
|
|
|
+ if (count($logisticInfo["items"])>1)OwnerFeeDetailLogistic::query()->insert($logisticInfo["items"]);
|
|
|
break;
|
|
|
case "processes":
|
|
|
-
|
|
|
$process = Process::query()->with("processStatistic")->find($this->detail->outer_id);
|
|
|
$this->detail->update([
|
|
|
"work_fee" => $process->processStatistic ? $process->processStatistic->revenue : null,
|
|
|
]);
|
|
|
break;
|
|
|
case "waybills":
|
|
|
-
|
|
|
+ /** @var \stdClass $waybill */
|
|
|
$waybill = Waybill::query()->find($this->detail->outer_id);
|
|
|
+ if (!$waybill)break;
|
|
|
$waybill->loadMissing(["destinationCity","order.owner"]);
|
|
|
if (!$waybill->destinationCity && !$waybill->order)break;
|
|
|
-
|
|
|
$owner_id = $waybill->order->owner_id ?? $waybill->owner_id;
|
|
|
- $detail = OwnerFeeDetail::query()->where("type","发货")
|
|
|
- ->where("owner_id",$owner_id)->whereIn("operation_bill",[$waybill->wms_bill_number,$waybill->waybill_number])->first();
|
|
|
-
|
|
|
- if ($detail && $detail->logistic_fee !== null)break;
|
|
|
-
|
|
|
if ($waybill->type == "专线"){
|
|
|
-
|
|
|
+ $provinceId = $waybill->order ? app("ProvinceService")->getProvince($waybill->order->province) : $waybill->destinationCity->province_id;
|
|
|
+ $cityId = $waybill->destination_city_id;
|
|
|
+ $consigneeName = $waybill->order ? $waybill->order->consignee_name : $waybill->recipient;
|
|
|
+ $consigneePhone = $waybill->order ? $waybill->order->consignee_phone : $waybill->recipient_mobile;
|
|
|
+ $GLOBALS["FEE_INFO"] = [
|
|
|
+ "province_id" => $provinceId,
|
|
|
+ "owner_id" => $waybill->owner_id,
|
|
|
+ "city_id" => $cityId,
|
|
|
+ "logistic_id" => $waybill->logistic_id,
|
|
|
+ "order_number" => $waybill->wms_bill_number,
|
|
|
+ "recipient_name"=>$consigneeName,
|
|
|
+ "recipient_phone"=>$consigneePhone,
|
|
|
+ "quantity"=>$waybill->carrier_weight_other,
|
|
|
+ "unit_id"=>$waybill->carrier_weight_unit_id_other,
|
|
|
+ "remark"=>$waybill->ordering_remark,
|
|
|
+ "created_at"=>$waybill->updated_at,
|
|
|
+ ];
|
|
|
+ /** @var OwnerPriceLogisticService $service */
|
|
|
$service = app("OwnerPriceLogisticService");
|
|
|
list($fee,$taxFee) = $service->matching($waybill->carrier_weight_other,$owner_id,$waybill->logistic_id,
|
|
|
- $waybill->carrier_weight_unit_id_other,$waybill->order ? app("RegionService")->getProvince($waybill->order->province) : $waybill->destinationCity->province_id,
|
|
|
- $waybill->destination_city_id);
|
|
|
+ $waybill->carrier_weight_unit_id_other,$provinceId, $cityId);
|
|
|
+ //$this->buildWaybillFeeInfo(); TODO
|
|
|
}else{
|
|
|
-
|
|
|
+ /** @var OwnerPriceDirectLogisticService $service */
|
|
|
$service = app("OwnerPriceDirectLogisticService");
|
|
|
list($fee,$taxFee) = $service->matching($waybill->mileage,$owner_id,$waybill->carType_id);
|
|
|
}
|
|
|
- $this->detail->update([
|
|
|
+ $obj = [
|
|
|
"logistic_fee" => $fee,
|
|
|
"logistic_tax_fee" => $taxFee,
|
|
|
- ]);
|
|
|
+ ];
|
|
|
+ app("OwnerFeeDetailService")->updateFind($this->detail,$obj);
|
|
|
break;
|
|
|
case "stores":
|
|
|
-
|
|
|
+ /** @var \stdClass $store */
|
|
|
$store = Store::query()->find($this->detail->outer_id);
|
|
|
- if (!$store || $store->status != "已入库") break;
|
|
|
+ if (!$store)break;
|
|
|
$store->loadMissing(["storeItems.commodity","warehouse"]);
|
|
|
-
|
|
|
-
|
|
|
+ /** @var OwnerPriceOperationService $service */
|
|
|
$service = app("OwnerPriceOperationService");
|
|
|
+ $GLOBALS["FEE_INFO"] = [];
|
|
|
list($id,$money,$taxFee) = $service->matching($store, Feature::MAPPING["store"], $store->owner_id, "入库");
|
|
|
+ $amount = 0;
|
|
|
+ if ($store->storeItems)foreach ($store->storeItems as $item)$amount += $item->amount;
|
|
|
+ if (($this->detail->commodity_amount - $amount)!==0)app("StoreService")->setStoreAmount($store->owner_id,$this->detail->commodity_amount - $amount);
|
|
|
$this->detail->update([
|
|
|
- "owner_id" => $store->owner_id,
|
|
|
- "worked_at" => $store->updated_at,
|
|
|
- "operation_bill" => $store->asn_code,
|
|
|
- "commodity_amount" => array_sum(array_column($store->storeItems->toArray(), "amount")),
|
|
|
+ "commodity_amount" => $amount,
|
|
|
"work_fee" => $money,
|
|
|
"owner_price_operation_id" => $id,
|
|
|
- "work_tax_fee" => $taxFee
|
|
|
+ "work_tax_fee" => $taxFee,
|
|
|
]);
|
|
|
+ /* if ($money>0)$this->constructFeeInfo([
|
|
|
+ "worked_at" => $store->updated_at,
|
|
|
+ "owner_id" => $store->owner_id,
|
|
|
+ "model_id" => $id,
|
|
|
+ "source_number"=> null,
|
|
|
+ "doc_number" => $store->asn_code,
|
|
|
+ "commodity_id" => 0,
|
|
|
+ "total_fee" =>0,
|
|
|
+ "tax_rate" =>0,
|
|
|
+ "fee_description"=>'',
|
|
|
+ ]);*/
|
|
|
break;
|
|
|
case "rejected_bills":
|
|
|
- $rejectedBill = RejectedBill::query()->find($this->detail->outer_id);
|
|
|
-
|
|
|
+ /** @var \stdClass $rejectedBill */
|
|
|
$number = array_column(StoreRejected::query()->where("logistic_number_return",$rejectedBill->logistic_number_return)->get()->toArray(),"store_id");
|
|
|
|
|
|
foreach (Store::query()->with("storeItems")->whereIn("id",$number)->get() as $store){
|
|
|
-
|
|
|
+ /** @var OwnerPriceOperationService $service */
|
|
|
$service = app("OwnerPriceOperationService");
|
|
|
+ $GLOBALS["FEE_INFO"] = [];
|
|
|
list($id,$money,$taxFee) = $service->matching($store, Feature::MAPPING["store"], $store->owner_id, "入库",0);
|
|
|
- $bill = OwnerFeeDetail::query()->where("outer_id",$store->id)->where("outer_table_name","stores")->first();
|
|
|
- if ($bill) $bill->update([
|
|
|
- "work_fee" => $money,
|
|
|
- "owner_price_operation_id" => $id,
|
|
|
- "outer_id" => $rejectedBill->id,
|
|
|
- "outer_table_name" => "rejected_bills",
|
|
|
- ]); else app("OwnerFeeDetailService")->create([
|
|
|
- "owner_id" => $store->owner_id,
|
|
|
- "worked_at" => $store->created_at,
|
|
|
- "type" => "收货",
|
|
|
- "operation_bill" => $store->asn_code,
|
|
|
- "commodity_amount" => array_sum(array_column($store->storeItems->toArray(), "amount")),
|
|
|
+ app("StoreService")->clearFeeInfo($store->asn_code);
|
|
|
+ $this->detail->update([
|
|
|
"work_fee" => $money,
|
|
|
"owner_price_operation_id" => $id,
|
|
|
- "created_at" => date('Y-m-d H:i:s'),
|
|
|
- "outer_id" => $rejectedBill->id,
|
|
|
- "outer_table_name" => "rejected_bills",
|
|
|
"work_tax_fee" => $taxFee,
|
|
|
]);
|
|
|
+ app("StoreService")->constructFeeInfo([
|
|
|
+ "worked_at" => $rejectedBill->updated_at,
|
|
|
+ "owner_id" => $rejectedBill->id_owner,
|
|
|
+ "model_id" => $id,
|
|
|
+ "source_number"=> null,
|
|
|
+ "doc_number" => $store->asn_code,
|
|
|
+ "commodity_id" => 0,
|
|
|
+ "total_fee" =>0,
|
|
|
+ "tax_rate" =>0,
|
|
|
+ "fee_description"=>'',
|
|
|
+ ]);
|
|
|
}
|
|
|
- }*/
|
|
|
+ }
|
|
|
}
|
|
|
}
|