| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- namespace App\Jobs;
- use App\Feature;
- use App\Order;
- use App\OwnerFeeDetail;
- use App\OwnerFeeDetailLogistic;
- use App\OwnerFeeExpress;
- use App\OwnerFeeLogistic;
- use App\Process;
- use App\RejectedBill;
- use App\Services\OwnerPriceDirectLogisticService;
- use App\Services\OwnerPriceLogisticService;
- use App\Services\OwnerPriceOperationService;
- use App\Store;
- use App\StoreRejected;
- use App\Waybill;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- /**
- * @Deprecated 即时账单重置
- */
- class ResetInstantBill implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable;
- /** @var \stdClass $detail */
- private $detail;
- /**
- * Create a new job instance.
- *
- * @param OwnerFeeDetail $detail
- *
- * @return void
- */
- public function __construct(OwnerFeeDetail $detail)
- {
- $this->detail = $detail;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- switch ($this->detail->outer_table_name){
- case "orders":
- $order = Order::query()->find($this->detail->outer_id);
- if (!$order)break;
- //加载所需数据
- $order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
- //获取运输费
- $month = substr($this->detail->worked_at,0,7);
- $logisticInfo = app("OrderService")->getLogisticFeeInfo($order,$month);
- //获取作业费
- /** @var OwnerPriceOperationService $service */
- $service = app("OwnerPriceOperationService");
- $GLOBALS["FEE_INFO"] = [];
- list($id,$money,$workTaxFee) = $service->matching($month, $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" => $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" => $logisticInfo["logisticTaxFee"],
- ]);
- 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 ($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;
- 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,$provinceId, $cityId);
- if (isset($GLOBALS["FEE_INFO"])) OwnerFeeLogistic::query()->create($GLOBALS["FEE_INFO"]);
- }else{
- /** @var OwnerPriceDirectLogisticService $service */
- $service = app("OwnerPriceDirectLogisticService");
- list($fee,$taxFee) = $service->matching($waybill->mileage,$owner_id,$waybill->carType_id);
- }
- $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)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,substr($this->detail->worked_at,0,7));
- $this->detail->update([
- "commodity_amount" => $amount,
- "work_fee" => $money,
- "owner_price_operation_id" => $id,
- "work_tax_fee" => $taxFee,
- ]);
- if ($money>0)app("StoreService")->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":
- /** @var \stdClass $rejectedBill */
- $number = array_column(StoreRejected::query()->where("logistic_number_return",$rejectedBill->logistic_number_return)->get()->toArray(),"store_id");
- $stores = Store::query()->with("storeItems")->whereIn("id",$number)->get();
- /** @var OwnerPriceOperationService $service */
- $service = app("OwnerPriceOperationService");
- foreach ($stores as $store){
- $GLOBALS["FEE_INFO"] = [];
- list($id,$money,$taxFee) = $service->matching($store, Feature::MAPPING["store"], $store->owner_id, "入库",0);
- app("StoreService")->clearFeeInfo($store->asn_code);
- $this->detail->update([
- "work_fee" => $money,
- "owner_price_operation_id" => $id,
- "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"=>'',
- ]);
- }
- if ($stores->count())return;
- $rejectedBill = RejectedBill::query()->find($this->detail->outer_id);
- $rejectedBill->loadMissing("items");
- $GLOBALS["FEE_INFO"] = [];
- list($id,$money,$taxFee) = $service->matching($rejectedBill, Feature::MAPPING["rejected_bill"], $rejectedBill->id_owner, "入库",0);
- $this->detail->update([
- "commodity_amount" => $rejectedBill->goods_amount,
- "work_fee" => $money,
- "owner_price_operation_id" => $id,
- "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" => null,
- "commodity_id" => 0,
- "total_fee" =>0,
- "tax_rate" =>0,
- "fee_description"=>'',
- ]);
- }
- }
- }
|