瀏覽代碼

Merge branch 'zzd'

zhouzhendong 4 年之前
父節點
當前提交
a3edb06cf3
共有 3 個文件被更改,包括 76 次插入0 次删除
  1. 38 0
      app/Jobs/OrderCreateWaybill.php
  2. 2 0
      app/Services/OrderService.php
  3. 36 0
      app/Services/WaybillService.php

+ 38 - 0
app/Jobs/OrderCreateWaybill.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Order;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+
+class OrderCreateWaybill implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable;
+
+    private $arr;
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(array $arr)
+    {
+        $this->arr = $arr;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        if (!$this->arr)return;
+        $codes = array_column($this->arr,"code");
+        $orders = Order::query()->with("logistic")->where("code",$codes)->get();
+        foreach ($orders as $order) app("WaybillService")->createDbBill($order);
+    }
+}

+ 2 - 0
app/Services/OrderService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 use App\Commodity;
 use App\Feature;
 use App\Jobs\OrderCreateInstantBill;
+use App\Jobs\OrderCreateWaybill;
 use App\Jobs\OrderFreeze;
 use App\Logistic;
 use App\OracleActAllocationDetails;
@@ -712,6 +713,7 @@ class OrderService
                 $arr = $inner_params->toArray();
                 $this->insert($arr,false,false,false);
                 dispatch(new OrderFreeze($arr));
+                dispatch(new OrderCreateWaybill($arr));
             });
         }
         unset($created_params);

+ 36 - 0
app/Services/WaybillService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Order;
 use App\OwnerFeeDetail;
 use App\Services\common\BatchUpdateService;
 use App\Services\common\QueryService;
@@ -277,4 +278,39 @@ class WaybillService
         else OwnerFeeDetail::query()->create($obj);
         return true;
     }
+
+    /**
+     * 生成德邦单据
+     *
+     * @param Order|\stdClass $order
+     *
+     * @return void
+     */
+    public function createDbBill(Order $order)
+    {
+        $order->loadMissing("logistic");
+        if (!$order->logistic || substr($order->logistic->code,0,2) != 'DB')return;
+        if (Waybill::query()->selectRaw("1")->where("wms_bill_number",$order->code)->first())return;
+        $waybill = Waybill::query()->create([
+            'type'=>            "德邦物流",
+            'waybill_number'=>  Uuid::uuid1(),
+            'owner_id'=>        $order->owner_id,
+            'wms_bill_number'=> $order->code,
+            'destination'=>     $order->address,
+            'recipient'=>       $order->consignee_name,
+            'recipient_mobile'=>$order->consignee_phone,
+            'source_bill'=>     $order->client_code,
+            'is_to_pay'=>       strstr($order->logistic->code,'DF')===false ? 0 : 1,
+            'destination_city_id'=>$order->city ? app(RegionService::class)->getCity($receiveInputting['C_City']) : null,
+            'order_id'=>        $order->id,
+        ]);
+        $waybill->update([
+            "waybill_number" => 'BSDB'.date ("ymd").str_pad($waybill->id>99999?$waybill->id%99999:$waybill->id,4,"0",STR_PAD_LEFT),
+        ]);
+        WaybillAuditLog::query()->create([
+            'waybill_id'=>$waybill->id,
+            'audit_stage'=>'创建',
+            'user_id'=>Auth::id() ?? 0,
+        ]);
+    }
 }