Zhouzhendong 4 лет назад
Родитель
Сommit
4b9503f1ee

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

@@ -158,10 +158,95 @@ class TestController extends Controller
             dd("方法不存在");
         }
     }
+    function process(Request $request){
+        $token = trim($request->input('token'));
+        $station_id = 'test';
+        $batch_id = 'W211111001514-6';
+
+        $childIndex = null;
+        $arr = explode('-',$batch_id);
+        if (count($arr)==2){
+            $batch_id = $arr[0];
+            $childIndex = (int)$arr[1];
+            $request->offsetSet("batch_id",$batch_id);
+        }
 
+        /** @var Batch|\stdClass $batch */
+        $batch=Batch::query()->where('code',$batch_id)->orderBy('id','desc')->first();
+        $data=[
+            'result'=>'success',
+            'station_id'=>$station_id,
+            'batch_id'=>$batch_id,
+            'orders'=>[]
+        ];
+        if ($childIndex!==null && $batch->split_size){
+            $start = (($childIndex-1)*$batch->split_size)+1;
+            $end = $childIndex*$batch->split_size;
+            $sql = <<<SQL
+SELECT ORDERNO
+FROM (SELECT T.ORDERNO, ROWNUM AS NO
+FROM (SELECT ORDERNO FROM DOC_WAVE_DETAILS WHERE WAVENO = '{$batch_id}' ORDER BY SEQNO) T)
+WHERE NO BETWEEN {$start} AND {$end}
+SQL;
+            dd($sql);
+            $waves = DB::connection("oracle")->select(DB::raw($sql));
+            $codes = array_column($waves,'orderno');
+            $orders = Order::query()->with(["bin","owner","orderCommodities.commodity.barcodes"])->whereIn("code",$codes)->get();
+        }else $orders = $batch->orders()->with(["bin","owner","orderCommodities.commodity.barcodes"])->get();
+
+        $ordersSorted=$orders->sortBy(function(Order $order){
+            return $order->bin->number;
+        });
+        $ordersSorted->each(function(Order $order)use(&$data,$request,$childIndex,$batch){
+            if($order['status']=='取消')return;
+            $orderData=[
+                'order_id'=>$order['code'],
+                'owner'=>$order->owner->code,
+                'status'=>$order['status']=='未处理'?'available':$order['status'],
+                'created_at'=>$order['created_at']->toDateTimeString(),
+                'bin'=>(function()use($order,$childIndex,$batch){
+                    $bin=$order->bin->number??'';
+                    if(!$bin){
+                        $bin=OracleDOCWaveDetails::query()->where('orderno', 'SO201230003574')->get('seqno')->first()['seqno']??'';
+                        LogService::log(__METHOD__,__FUNCTION__,'bin缺失补查:'.$bin.'. order:'.$order->toJson());
+                        return $childIndex!==null ? $bin-(($childIndex-1)*$batch->split_size) : $bin;
+                    }
+                    return $childIndex!==null ? $bin-(($childIndex-1)*$batch->split_size) : $bin;
+                })(),
+                'barcodes'=>[]
+            ];
+            $order->orderCommodities->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request){
+                $commodity=$orderCommodity->commodity;
+                if(!$commodity){
+                    app('LogService')->log(__METHOD__, 'error' . __FUNCTION__, '播种位数据准备出错,找不到订单对应的Commodity id的对象'.$orderCommodity['commodity_id'].',是否表数据在波次生成后丢失?'.json_encode($request->all()));
+                    return;
+                }
+                $barcodeStr=$commodity->barcodes->map(function(CommodityBarcode $barcode){
+                    return $barcode['code'];
+                })->filter(function($code){
+                    return $code&&(!preg_match('/[\x{4e00}-\x{9fa5}]/u',$code));
+                })->join(',');
+                $orderData['barcodes'][]=[
+                    'id'=>$orderCommodity['id']??'',
+                    'barcode_id'=>$barcodeStr??'',
+                    'name'=>$commodity['name']??'',
+                    'sku'=>$commodity['sku']??'',
+                    'amount'=>$orderCommodity['amount']??'',
+                    'location'=>$orderCommodity['location']??'',
+                ];
+            });
+            $data['orders'][]=$orderData;
+        });
+        return $data;
+    }
 
     public function test(Request $request)
     {
+        dd(1);
+
+        dd($this->process($request));
+        $batch = Batch::query()->where("code","W211111001514")->first();
+        dd($batch->orders()->with("bin")->first());
         $path = '';
         $id = 109;
 

+ 9 - 12
app/Http/Controllers/WaveController.php

@@ -179,7 +179,7 @@ class WaveController extends Controller
             }
             $no = rtrim($no,',');
             $sql = <<<SQL
-SELECT WAVENO,COUNT(*) count from DOC_WAVE_DETAILS WHERE WAVENO IN ({$no}) GROUP BY WAVENO
+SELECT WAVENO,MAX(SEQNO) count from DOC_WAVE_DETAILS WHERE WAVENO IN ({$no}) GROUP BY WAVENO
 SQL;
             foreach (DB::connection("oracle")->select(DB::raw($sql)) as $wave){
                 Batch::query()->where("code",$wave->waveno)->update(["split_size" => (int)ceil($wave->count/$splitNumber)]);
@@ -193,10 +193,12 @@ SQL;
         $codes = \request("codes",[]);
         if (!$codes)$this->error("无记录");
         $batches = [];
-        foreach (Batch::query()->select("code","split_size")->withCount("orders")
+        foreach (Batch::query()->select("code","split_size","id")
                      ->whereIn("code",$codes)->whereNotNull("split_size")->get() as $batch){
             if ($batch->orders_count==0)continue;
-            $batches[$batch->code] = (int)ceil($batch->orders_count/$batch->split_size);
+            $bin = OrderBin::query()->selectRaw("MAX(number) max")->whereIn("order_id",Order::query()
+                ->select("id")->where("batch_id",$batch->id))->first();
+            $batches[$batch->code] = (int)ceil($bin->max/$batch->split_size);
         }
         $this->success($batches);
     }
@@ -212,7 +214,7 @@ SQL;
         $batch = null;
         if (!$code || !$batch = Batch::query()->select("id","split_size")->where("code",$code)->first())$this->error("无记录");
         $sql = <<<SQL
-SELECT a.ORDERNO,a.QTY,s.ALTERNATE_SKU1,a.LOCATION FROM ACT_ALLOCATION_DETAILS a
+SELECT a.ORDERNO,a.QTY,s.ALTERNATE_SKU1,a.LOCATION,w.SEQNO FROM ACT_ALLOCATION_DETAILS a
     LEFT JOIN DOC_ORDER_HEADER o ON a.ORDERNO = o.ORDERNO
     LEFT JOIN DOC_WAVE_DETAILS w ON o.ORDERNO = w.ORDERNO
     LEFT JOIN BAS_SKU s ON a.SKU = s.SKU
@@ -221,16 +223,11 @@ SQL;
         $orders = DB::connection("oracle")->select(DB::raw($sql));
         $result = [];
         $currentList = [];
-        $slowPointer = 0;
         $nodeSign = "";
         foreach ($orders as $order){
-            if ($order->orderno!=$nodeSign){
-                if ($slowPointer==$batch->split_size){
-                    $result[] = $currentList;
-                    $currentList = [];
-                    $slowPointer = 0;
-                }
-                $slowPointer++;
+            if ($order->seqno%$batch->split_size==0 && $nodeSign!=$order->orderno){
+                $result[] = $currentList;
+                $currentList = [];
                 $nodeSign = $order->orderno;
             }
             $currentList[] = ["barcode"=>$order->alternate_sku1,"qty"=>$order->qty,"location"=>$order->location];

+ 9 - 12
app/Http/Controllers/api/thirdPart/haochuang/SortingController.php

@@ -95,28 +95,25 @@ class SortingController extends Controller
             $start = (($childIndex-1)*$batch->split_size)+1;
             $end = $childIndex*$batch->split_size;
             $sql = <<<SQL
-SELECT ORDERNO
-FROM (SELECT T.ORDERNO, ROWNUM AS NO
-FROM (SELECT ORDERNO FROM DOC_WAVE_DETAILS WHERE WAVENO = '{$batch_id}' ORDER BY SEQNO) T)
-WHERE NO BETWEEN {$start} AND {$end}
+SELECT ORDERNO FROM DOC_WAVE_DETAILS WHERE WAVENO = '{$batch_id}' AND SEQNO BETWEEN {$start} AND {$end};
 SQL;
             $waves = DB::connection("oracle")->select(DB::raw($sql));
             $codes = array_column($waves,'orderno');
-            $orders = Order::query()->whereIn("code",$codes)->get();
-        }else $orders = $batch->orders()->get();
+            $orders = Order::query()->with(["bin","owner","orderCommodities.commodity.barcodes"])->whereIn("code",$codes)->get();
+        }else $orders = $batch->orders()->with(["bin","owner","orderCommodities.commodity.barcodes"])->get();
 
         $ordersSorted=$orders->sortBy(function(Order $order){
-            return $order->bin()->first()['number'];
+            return $order->bin->number;
         });
         $ordersSorted->each(function(Order $order)use(&$data,$request,$childIndex,$batch){
             if($order['status']=='取消')return;
             $orderData=[
                 'order_id'=>$order['code'],
-                'owner'=>$order->owner()->first()['code'],
+                'owner'=>$order->owner->code,
                 'status'=>$order['status']=='未处理'?'available':$order['status'],
                 'created_at'=>$order['created_at']->toDateTimeString(),
                 'bin'=>(function()use($order,$childIndex,$batch){
-                    $bin=$order->bin()->first()['number']??'';
+                    $bin=$order->bin->number??'';
                     if(!$bin){
                         $bin=OracleDOCWaveDetails::query()->where('orderno', 'SO201230003574')->get('seqno')->first()['seqno']??'';
                         LogService::log(__METHOD__,__FUNCTION__,'bin缺失补查:'.$bin.'. order:'.$order->toJson());
@@ -126,13 +123,13 @@ SQL;
                 })(),
                 'barcodes'=>[]
             ];
-            $order->orderCommodities()->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request){
-                $commodity=$orderCommodity->commodity()->first();
+            $order->orderCommodities->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request){
+                $commodity=$orderCommodity->commodity;
                 if(!$commodity){
                     app('LogService')->log(__METHOD__, 'error' . __FUNCTION__, '播种位数据准备出错,找不到订单对应的Commodity id的对象'.$orderCommodity['commodity_id'].',是否表数据在波次生成后丢失?'.json_encode($request->all()));
                     return;
                 }
-                $barcodeStr=$commodity->barcodes()->get()->map(function(CommodityBarcode $barcode){
+                $barcodeStr=$commodity->barcodes->map(function(CommodityBarcode $barcode){
                     return $barcode['code'];
                 })->filter(function($code){
                     return $code&&(!preg_match('/[\x{4e00}-\x{9fa5}]/u',$code));