瀏覽代碼

Merge branch 'zzd' of ssh://was.baoshi56.com:10022/var/git/bswas

LD 5 年之前
父節點
當前提交
7004708f30

+ 1 - 2
app/Http/Controllers/TestController.php

@@ -169,8 +169,7 @@ class TestController extends Controller
 
     public function test()
     {
-        $service = new OrderService();
-        dd($service->createInstantBill(Order::query()->find(2617624)));
+        throw new Exception();
         return view("test");
     }
 

+ 2 - 0
app/Jobs/OrderCreateInstantBill.php

@@ -32,6 +32,7 @@ class OrderCreateInstantBill implements ShouldQueue
      *
      * @param OrderService $service
      * @return void
+     * @throws
      */
     public function handle(OrderService $service)
     {
@@ -40,6 +41,7 @@ class OrderCreateInstantBill implements ShouldQueue
                 LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson());
         }catch (\Exception $e){
             LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson()." | ".$e->getMessage());
+            throw new \Exception($e->getMessage());
         }
     }
 }

+ 2 - 0
app/Jobs/ProcessCreateInstantBill.php

@@ -32,6 +32,7 @@ class ProcessCreateInstantBill implements ShouldQueue
      *
      * @param ProcessService $service
      * @return void
+     * @throws
      */
     public function handle(ProcessService $service)
     {
@@ -39,6 +40,7 @@ class ProcessCreateInstantBill implements ShouldQueue
             $service->createInstantBill($this->process);
         }catch (\Exception $e){
             LogService::log(__METHOD__,"ERROR-入库生成即时账单",$this->process->toJson()." | ".$e->getMessage());
+            throw new \Exception($e->getMessage());
         }
     }
 }

+ 2 - 0
app/Jobs/RejectedBillCreateInstantBill.php

@@ -31,6 +31,7 @@ class RejectedBillCreateInstantBill implements ShouldQueue
      * Execute the job.
      *
      * @return void
+     * @throws
      */
     public function handle()
     {
@@ -38,6 +39,7 @@ class RejectedBillCreateInstantBill implements ShouldQueue
             app("RejectedBillService")->buildInstantBill($this->rejected);
         }catch(\Exception $exception){
             LogService::log(__CLASS__,"退货单建立即时账单",$exception->getMessage()." | ".json_encode($this->rejected));
+            throw new \Exception($e->getMessage());
         }
     }
 }

+ 30 - 41
app/Jobs/ResetInstantBill.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs;
 
+use App\Feature;
 use App\Order;
 use App\OwnerFeeDetail;
 use App\OwnerFeeDetailLogistic;
@@ -49,40 +50,28 @@ class ResetInstantBill implements ShouldQueue
         switch ($this->detail->outer_table_name){
             case "orders":
                 /** @var \stdClass $order */
+                //检查订单对象
                 $order = Order::query()->find($this->detail->outer_id);
-                $key = date("Y-m")."_".$order->owner_id;
-                if (Cache::has($key))Cache::increment($key);
-                else Cache::put($key,1,2678400);
-
+                if (!$order || $order->wms_status != "订单完成")break;
                 $order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
-
                 /** @var OwnerPriceExpressService $service */
                 $service = app("OwnerPriceExpressService");
                 $logistic_fee = 0;
-                $commodities = [];
                 $amount = 0;
                 $volume = 0;
                 $weight = 0;
                 $logistic_bill = "";
-
-                if (!$order->logistic || $order->logistic->type != "快递")$logistic_fee = null;
-
+                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){
-                        $commodity["commodity_name"] = $commodity->commodity ? $commodity->commodity->name : '';
-                        $commodity["sku"] = $commodity->commodity ? $commodity->commodity->sku : '';
+                    foreach($package->commodities as $commodity){
                         $partAmount += $commodity->amount;
                     }
                     $amount += $partAmount;
-                    $commodities = array_merge($commodities,$package->commodities->toArray());
-
                     $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();
@@ -93,7 +82,6 @@ class ResetInstantBill implements ShouldQueue
                         $logistic_fee = null;
                         $fee = null;
                     }
-
                     $items[] = [
                         "amount" => $partAmount,
                         "logistic_bill" => $package->logistic_number,
@@ -107,32 +95,31 @@ class ResetInstantBill implements ShouldQueue
                     }
                 }
                 if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
-
-                $object = ["commodities"=>$commodities,
-                    "logistic_name"=>($order->logistic ? $order->logistic->name : ''),
-                    "shop_name"=>($order->shop ? $order->shop->name : ''),
-                    "order_type"=>$order->order_type,
-                    "batch_type" => $order->batch ? $order->batch->wms_type : '',
-                    "owner_id"=>$order->owner_id];
-                $mapping = ["packages"=>"commodities","商品名称"=>"commodity_name",
-                    "承运商"=>"logistic_name","店铺类型"=>"shop_name","订单类型"=>"order_type",
-                    "波次类型"=>"batch_type"];
-
                 /** @var OwnerPriceOperationService $service */
                 $service = app("OwnerPriceOperationService");
-                $result = $service->matching($object,$mapping,$order->owner_id,"出库");
-
+                $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){
-                    foreach ($items as $item){
-                        OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$detail->id)
-                            ->where("logistic_bill",$item["logistic_bill"])
-                            ->update($item);
-                    }
+                    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;
             case "processes":
@@ -168,17 +155,19 @@ class ResetInstantBill implements ShouldQueue
             case "stores":
                 /** @var \stdClass $store */
                 $store = Store::query()->find($this->detail->outer_id);
-                $store->loadMissing("storeItems");
+                if (!$store || $store->status != "已入库") break;
+                $store->loadMissing(["storeItems","warehouse"]);
 
                 /** @var OwnerPriceOperationService $service */
                 $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([
+                    "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,
+                    "owner_price_operation_id" => is_array($result) ? $result["id"] : null,
                 ]);
                 break;
         }

+ 2 - 0
app/Jobs/StoreCreateInstantBill.php

@@ -33,6 +33,7 @@ class StoreCreateInstantBill implements ShouldQueue
      *
      * @param StoreService $service
      * @return void
+     * @throws
      */
     public function handle(StoreService $service)
     {
@@ -40,6 +41,7 @@ class StoreCreateInstantBill implements ShouldQueue
             $service->createInstantBill($this->store);
         }catch (\Exception $e){
             LogService::log(__METHOD__,"ERROR-入库生成即时账单",$this->store->toJson()." | ".$e->getMessage());
+            throw new \Exception($e->getMessage());
         }
     }
 }

+ 2 - 0
app/Jobs/WaybillCreateInstantBill.php

@@ -33,6 +33,7 @@ class WaybillCreateInstantBill implements ShouldQueue
      *
      * @param WaybillService $service
      * @return void
+     * @throws
      */
     public function handle(WaybillService $service)
     {
@@ -40,6 +41,7 @@ class WaybillCreateInstantBill implements ShouldQueue
             $service->createInstantBill($this->waybill);
         }catch (\Exception $e){
             LogService::log(__METHOD__,"ERROR-运输计算运费失败",$this->waybill->toJson()." | ".$e->getMessage());
+            throw new \Exception($e->getMessage());
         }
     }
 }

+ 2 - 3
app/Services/OrderService.php

@@ -1067,7 +1067,7 @@ sql
         if ($isToB)$type = "|B|";
         else $type = "|C|";
         if (!Cache::has($date.$type.$owner))$this->orderQuantityCompensationLogic($owner);
-        return Cache::get($date.$type.$owner);
+        return Cache::get($date.$type.$owner)+1;//+1是算本单
     }
 
     /**
@@ -1083,8 +1083,6 @@ sql
         if (!$order || $order->wms_status != "订单完成")return true;
         if (OwnerFeeDetail::query()->where("outer_table_name","orders")->where("outer_id",$order->id)->first())return true;
 
-        $this->setOrderQuantity($order->owner_id,$order->logistic_id);
-
         $order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
 
         /** @var OwnerPriceExpressService $service */
@@ -1161,6 +1159,7 @@ sql
        if ($detail){
             foreach ($items as &$item)$item["owner_fee_detail_id"] = $detail->id;
             if (count($items)>1)OwnerFeeDetailLogistic::query()->insert($items);
+            $this->setOrderQuantity($order->owner_id,$order->logistic_id);
             return true;
        }
        return false;

+ 6 - 2
app/Services/OwnerPriceOperationService.php

@@ -316,8 +316,12 @@ class OwnerPriceOperationService
         $units = app("UnitService")->getUnitMapping(["件","箱"]); //获取单位映射集
         $rules = $this->getOwnerPriceOperation($ownerId,$type,$typeMark);//货主下的全部规则
         if (!$rules)return -2;  //规则不存在跳出
-        if ($type == '出库') $total = app("OrderService")->getOrderQuantity($ownerId);//获取该货主本月C端单量
-        else $total = app("StoreService")->getStoreAmount($ownerId);//获取该货主本月入库件数
+        if ($type == '出库')$total = app("OrderService")->getOrderQuantity($ownerId);//获取该货主本月C端单量
+        else {
+            $total = 0;
+            if ($matchObject->storeItems)foreach ($matchObject->storeItems as $item)$total += $item->amount;
+            $total += app("StoreService")->getStoreAmount($ownerId);//获取该货主本月入库件数
+        }
         foreach ($rules as $rule){
             if (!$rule->items)continue; //不存在子规则跳出
 

+ 6 - 4
app/Services/StoreService.php

@@ -325,9 +325,6 @@ class StoreService
         if (OwnerFeeDetail::query()->where("outer_table_name","stores")->where("outer_id",$store->id)->first())return false;
         $store->loadMissing(["storeItems","warehouse"]);
 
-        $amount = 0;
-        if ($store->storeItems)foreach ($store->storeItems as $item)$amount += $item->amount;
-        $this->setStoreAmount($store->owner_id,$amount);
         /** @var OwnerPriceOperationService $service */
         $service = app("OwnerPriceOperationService");
 
@@ -344,7 +341,12 @@ class StoreService
             "created_at" => date('Y-m-d H:i:s'),
             "outer_id" => $store->id,
             "outer_table_name" => "stores",
-        ])) return true;
+        ])){
+            $amount = 0;
+            if ($store->storeItems)foreach ($store->storeItems as $item)$amount += $item->amount;
+            $this->setStoreAmount($store->owner_id,$amount);
+            return true;
+        }
         return false;
     }
     public function createStoreRejected($asnHerders){