|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
|
|
+use App\Feature;
|
|
|
use App\Order;
|
|
use App\Order;
|
|
|
use App\OwnerFeeDetail;
|
|
use App\OwnerFeeDetail;
|
|
|
use App\OwnerFeeDetailLogistic;
|
|
use App\OwnerFeeDetailLogistic;
|
|
@@ -48,7 +49,78 @@ class ResetInstantBill implements ShouldQueue
|
|
|
{
|
|
{
|
|
|
switch ($this->detail->outer_table_name){
|
|
switch ($this->detail->outer_table_name){
|
|
|
case "orders":
|
|
case "orders":
|
|
|
|
|
+ /** @var \stdClass $order */
|
|
|
|
|
+ //检查订单对象
|
|
|
|
|
+ $order = Order::query()->find($this->detail->outer_id);
|
|
|
|
|
+ if (!$order || $order->wms_status != "订单完成")break;
|
|
|
|
|
+ $order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
|
|
|
|
|
+ /** @var OwnerPriceExpressService $service */
|
|
|
|
|
+ $service = app("OwnerPriceExpressService");
|
|
|
|
|
+ $logistic_fee = 0;
|
|
|
|
|
+ $amount = 0;
|
|
|
|
|
+ $volume = 0;
|
|
|
|
|
+ $weight = 0;
|
|
|
|
|
+ $logistic_bill = "";
|
|
|
|
|
+ if (!$order->logistic || $order->logistic->type == "物流")$logistic_fee = null;
|
|
|
|
|
+ $items = [];
|
|
|
|
|
+ foreach ($order->packages as &$package){
|
|
|
|
|
+ $logistic_bill .= $package->logistic_number.",";
|
|
|
|
|
+ $volume += $package->bulk;
|
|
|
|
|
+ $weight += $package->weight;
|
|
|
|
|
+ $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);
|
|
|
|
|
+ if ($province){
|
|
|
|
|
+ $fee = $service->matching($package->weight, $order->owner_id, $order->logistic_id, $province->id);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $logistic_fee = null;
|
|
|
|
|
+ $fee = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ $items[] = [
|
|
|
|
|
+ "amount" => $partAmount,
|
|
|
|
|
+ "logistic_bill" => $package->logistic_number,
|
|
|
|
|
+ "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)$logistic_fee = null;
|
|
|
|
|
+ /** @var OwnerPriceOperationService $service */
|
|
|
|
|
+ $service = app("OwnerPriceOperationService");
|
|
|
|
|
+ $result = $service->matching($order,Feature::MAPPING["order"],$order->owner_id,"出库");
|
|
|
|
|
|
|
|
|
|
+ $detail = $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,
|
|
|
|
|
+ "logistic_id" => $order->logistic_id,
|
|
|
|
|
+ "work_fee" => is_array($result) ? ($result["money"]>0 ? $result["money"] : null) : null,
|
|
|
|
|
+ "owner_price_operation_id" => is_array($result) ? $result["id"] : null,
|
|
|
|
|
+ "logistic_fee" => $logistic_fee,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ if ($detail){
|
|
|
|
|
+ OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$detail->id)->delete();
|
|
|
|
|
+ foreach ($items as &$item)$item["owner_fee_detail_id"] = $detail->id;
|
|
|
|
|
+ if (count($items)>1)OwnerFeeDetailLogistic::query()->insert($items);
|
|
|
|
|
+ app("OrderService")->setOrderQuantity($order->owner_id,$order->logistic_id);
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
case "processes":
|
|
case "processes":
|
|
|
/** @var \stdClass $process */
|
|
/** @var \stdClass $process */
|
|
@@ -83,17 +155,19 @@ class ResetInstantBill implements ShouldQueue
|
|
|
case "stores":
|
|
case "stores":
|
|
|
/** @var \stdClass $store */
|
|
/** @var \stdClass $store */
|
|
|
$store = Store::query()->find($this->detail->outer_id);
|
|
$store = Store::query()->find($this->detail->outer_id);
|
|
|
- $store->loadMissing("storeItems");
|
|
|
|
|
|
|
+ if (!$store || $store->status != "已入库") break;
|
|
|
|
|
+ $store->loadMissing(["storeItems","warehouse"]);
|
|
|
|
|
|
|
|
/** @var OwnerPriceOperationService $service */
|
|
/** @var OwnerPriceOperationService $service */
|
|
|
$service = app("OwnerPriceOperationService");
|
|
$service = app("OwnerPriceOperationService");
|
|
|
-
|
|
|
|
|
- $mapping = ["packages" => "storeItems", "商品名称" => "name", "订单类型" => "stored_method", "订单数"=>"amount"];
|
|
|
|
|
-
|
|
|
|
|
- $result = $service->matching($store, $mapping, $store->owner_id, "入库");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $result = $service->matching($store, Feature::MAPPING["store"], $store->owner_id, "入库");
|
|
|
$this->detail->update([
|
|
$this->detail->update([
|
|
|
|
|
+ "owner_id" => $store->owner_id,
|
|
|
|
|
+ "worked_at" => $store->created_at,
|
|
|
|
|
+ "operation_bill" => $store->asn_code,
|
|
|
|
|
+ "commodity_amount" => array_sum(array_column($store->storeItems->toArray(), "amount")),
|
|
|
"work_fee" => is_array($result) ? ($result["money"]>0 ? $result["money"] : null) : null,
|
|
"work_fee" => is_array($result) ? ($result["money"]>0 ? $result["money"] : null) : null,
|
|
|
|
|
+ "owner_price_operation_id" => is_array($result) ? $result["id"] : null,
|
|
|
]);
|
|
]);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|