Zhouzhendong 4 лет назад
Родитель
Сommit
e3dbcfccac
1 измененных файлов с 55 добавлено и 0 удалено
  1. 55 0
      app/Http/Controllers/TestController.php

+ 55 - 0
app/Http/Controllers/TestController.php

@@ -649,6 +649,61 @@ sql;
         ValueStore::query()->where('name','last_order_sync_task_end_at')->update(['value' => '2021-10-12 06:23:38']);
     }
 
+    public function test3()
+    {
+        foreach (Batch::query()->where("updated_at",">=","2021-11-22 09:00:00")->get() as $batch){
+            try {
+                $this->assignBatch($batch->code);
+            }catch (\Exception $e){
+                continue;
+            }
+        }
+    }
+
+    public function assignBatch($code)
+    {
+        $batches = Batch::query()->where("code",$code)->get();
+        if (!$batches->count()){
+            $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
+            if (!$wave){
+                dd("FLUX无波次");
+            }
+            $owner = app("OwnerService")->codeGetOwner($wave->customerid);
+            $obj = [
+                "wms_status" => $this->wms_status($wave),
+                "wms_type"=>$wave->descr,
+                "created_at"=>date("Y-m-d H:i:s"),
+                "wms_created_at"=>$wave->addtime,
+                "updated_at"=>$wave->edittime,
+                "owner_id"=>$owner->id,
+            ];
+            $wave = Batch::query()->where("code",$code)->first();
+            if (!$wave){
+                $obj["code"] = $code;
+                $wave = Batch::query()->create($obj);
+            }else{
+                Batch::query()->where("code",$code)->update($obj);
+            }
+            $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
+            Order::query()->whereIn("code",$ordernos)->update([
+                "batch_id"=>$wave->id
+            ]);
+            Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
+                if (!$order->bin){
+                    $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
+                    if ($bin){
+                        OrderBin::query()->create([
+                            'order_id' => $order->id,
+                            'number' => $bin->seqno,
+                        ]);
+                    }
+                }
+            });
+            $batches = Batch::query()->where("code",$code)->get();
+        }
+        app("BatchService")->assignTasks($batches);
+    }
+
 
     public function syncOrder()
     {