cqp 1 сар өмнө
parent
commit
10c39cd218
1 өөрчлөгдсөн 292 нэмэгдсэн , 239 устгасан
  1. 292 239
      app/Service/ApplyOrderService.php

+ 292 - 239
app/Service/ApplyOrderService.php

@@ -3115,39 +3115,45 @@ class ApplyOrderService extends Service
         }elseif ($for_type == 9){
             $dispatch = DispatchSub::where('id',$id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_one)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_one)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 10){
             $dispatch = DispatchSub::where('id',$id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_two)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_two)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 11){
             $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
             $box_id = [];
@@ -3194,25 +3200,28 @@ class ApplyOrderService extends Service
         }elseif ($for_type == 13){
             $dispatch = DispatchSub::where('id',$id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $s_id = ScrappCount::where('del_time', 0)
-                ->whereIn('dispatch_sub_id', $dispatch_id)
-                ->pluck('id')
-                ->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $s_id)
-                ->where('type', ApplyOrder::type_five)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $s_id = ScrappCount::where('del_time', 0)
+                    ->whereIn('dispatch_sub_id', $dispatch_id)
+                    ->pluck('id')
+                    ->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $s_id)
+                    ->where('type', ApplyOrder::type_five)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 14){
             $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
             $box_id = [];
@@ -3334,21 +3343,24 @@ class ApplyOrderService extends Service
             $dispatch_id = $dispatch_id[0] ?? 0;
             $dispatch = DispatchSub::where('id',$dispatch_id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_one)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_one)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 10){
             $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
                 ->where('del_time',0)
@@ -3357,23 +3369,26 @@ class ApplyOrderService extends Service
             $dispatch_id = $dispatch_id[0] ?? 0;
             $dispatch = DispatchSub::where('id',$dispatch_id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_two)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $return = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
-            $t = $return[0] ?? [];
-            if(! empty($t)) $result[] = $t;
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_two)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $return = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+                $t = $return[0] ?? [];
+                if(! empty($t)) $result[] = $t;
+            }
         }elseif ($for_type == 11){
             $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
                 ->where('del_time',0)
@@ -3549,41 +3564,47 @@ class ApplyOrderService extends Service
         }elseif ($for_type == 9){
             $dispatch = DispatchSub::where('id',$id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_one)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_one)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 10){
             $dispatch = DispatchSub::where('id',$id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_two)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $return = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
-            $t = $return[0] ?? [];
-            if(! empty($t)) $result[] = $t;
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_two)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $return = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+                $t = $return[0] ?? [];
+                if(! empty($t)) $result[] = $t;
+            }
         }elseif ($for_type == 11){
             $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
             $box_id = [];
@@ -3777,48 +3798,62 @@ class ApplyOrderService extends Service
             $dispatch_id = BoxWithDispatch::where('del_time',0)
                 ->where('box_id', $id)
                 ->select('dispatch_id')
-                ->first()->toArray();
-            $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
-                ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_one)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch_id)){
+                $dispatch_id = $dispatch_id->toArray();
+                $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
+                    ->select('order_product_id','crt_time','product_no','technology_name')
+                    ->first();
+                if(! empty($dispatch)){
+                    $dispatch = $dispatch->toArray();
+                    $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                        ->where('crt_time',$dispatch['crt_time'])
+                        ->where('product_no',$dispatch['product_no'])
+                        ->where('technology_name',$dispatch['technology_name'])
+                        ->pluck('id')->toArray();
+                    $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                        ->whereIn('data_id', $dispatch_id)
+                        ->where('type', ApplyOrder::type_one)
+                        ->pluck('apply_order_id')
+                        ->toArray();
+                    $result = ApplyOrder::where('del_time', 0)
+                        ->whereIn('id', $apply_order_id)
+                        ->select('id','order_number as order_no')
+                        ->get()->toArray();
+                }
+            }
+
         }elseif ($for_type == 10){
             $dispatch_id = BoxWithDispatch::where('del_time',0)
                 ->where('box_id', $id)
                 ->select('dispatch_id')
-                ->first()->toArray();
-            $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
-                ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_two)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $return = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
-            $t = $return[0] ?? [];
-            if(! empty($t)) $result[] = $t;
+                ->first();
+            if(! empty($dispatch_id)){
+                $dispatch_id = $dispatch_id->toArray();
+                $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
+                    ->select('order_product_id','crt_time','product_no','technology_name')
+                    ->first();
+                if(! empty($dispatch)){
+                    $dispatch = $dispatch->toArray();
+                    $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                        ->where('crt_time',$dispatch['crt_time'])
+                        ->where('product_no',$dispatch['product_no'])
+                        ->where('technology_name',$dispatch['technology_name'])
+                        ->pluck('id')->toArray();
+                    $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                        ->whereIn('data_id', $dispatch_id)
+                        ->where('type', ApplyOrder::type_two)
+                        ->pluck('apply_order_id')
+                        ->toArray();
+                    $return = ApplyOrder::where('del_time', 0)
+                        ->whereIn('id', $apply_order_id)
+                        ->select('id','order_number as order_no')
+                        ->get()->toArray();
+                    $t = $return[0] ?? [];
+                    if(! empty($t)) $result[] = $t;
+                }
+            }
+
         }elseif ($for_type == 11){
             $dispatch_id = BoxWithDispatch::where('del_time',0)
                 ->where('box_id', $id)
@@ -3879,28 +3914,34 @@ class ApplyOrderService extends Service
             $dispatch_id = BoxWithDispatch::where('del_time',0)
                 ->where('box_id', $id)
                 ->select('dispatch_id')
-                ->first()->toArray();
-            $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
-                ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $s_id = ScrappCount::where('del_time', 0)
-                ->whereIn('dispatch_sub_id', $dispatch_id)
-                ->pluck('id')
-                ->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $s_id)
-                ->where('type', ApplyOrder::type_five)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch_id)){
+                $dispatch_id = $dispatch_id->toArray();
+                $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
+                    ->select('order_product_id','crt_time','product_no','technology_name')
+                    ->first();
+                if(! empty($dispatch)){
+                    $dispatch = $dispatch->toArray();
+                    $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                        ->where('crt_time',$dispatch['crt_time'])
+                        ->where('product_no',$dispatch['product_no'])
+                        ->where('technology_name',$dispatch['technology_name'])
+                        ->pluck('id')->toArray();
+                    $s_id = ScrappCount::where('del_time', 0)
+                        ->whereIn('dispatch_sub_id', $dispatch_id)
+                        ->pluck('id')
+                        ->toArray();
+                    $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                        ->whereIn('data_id', $s_id)
+                        ->where('type', ApplyOrder::type_five)
+                        ->pluck('apply_order_id')
+                        ->toArray();
+                    $result = ApplyOrder::where('del_time', 0)
+                        ->whereIn('id', $apply_order_id)
+                        ->select('id','order_number as order_no')
+                        ->get()->toArray();
+                }
+            }
         }elseif ($for_type == 14){
             $dispatch_id = BoxWithDispatch::where('del_time',0)
                 ->where('box_id', $id)
@@ -4016,22 +4057,25 @@ class ApplyOrderService extends Service
             $dispatch_id = $dispatch_id[0] ?? 0;
             $dispatch = DispatchSub::where('id',$dispatch_id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_one)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_one)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 10){
             $dispatch_id = ScrappCount::where('del_time',0)
                 ->where('id', $id)
@@ -4040,23 +4084,26 @@ class ApplyOrderService extends Service
             $dispatch_id = $dispatch_id[0] ?? 0;
             $dispatch = DispatchSub::where('id',$dispatch_id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_two)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $return = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
-            $t = $return[0] ?? [];
-            if(! empty($t)) $result[] = $t;
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_two)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $return = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+                $t = $return[0] ?? [];
+                if(! empty($t)) $result[] = $t;
+            }
         }elseif ($for_type == 11){
             $dispatch_id = ScrappCount::where('del_time',0)
                 ->where('id', $id)
@@ -4244,22 +4291,25 @@ class ApplyOrderService extends Service
             $dispatch_id = $dispatch_id[0] ?? 0;
             $dispatch = DispatchSub::where('id',$dispatch_id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_one)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $result = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_one)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $result = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+            }
         }elseif ($for_type == 10){
             $dispatch_id = ScrappCount::where('del_time',0)
                 ->where('id', $id)
@@ -4268,23 +4318,26 @@ class ApplyOrderService extends Service
             $dispatch_id = $dispatch_id[0] ?? 0;
             $dispatch = DispatchSub::where('id',$dispatch_id)
                 ->select('order_product_id','crt_time','product_no','technology_name')
-                ->first()->toArray();
-            $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
-                ->where('crt_time',$dispatch['crt_time'])
-                ->where('product_no',$dispatch['product_no'])
-                ->where('technology_name',$dispatch['technology_name'])
-                ->pluck('id')->toArray();
-            $apply_order_id = ApplyOrderDetail::where('del_time', 0)
-                ->whereIn('data_id', $dispatch_id)
-                ->where('type', ApplyOrder::type_two)
-                ->pluck('apply_order_id')
-                ->toArray();
-            $return = ApplyOrder::where('del_time', 0)
-                ->whereIn('id', $apply_order_id)
-                ->select('id','order_number as order_no')
-                ->get()->toArray();
-            $t = $return[0] ?? [];
-            if(! empty($t)) $result[] = $t;
+                ->first();
+            if(! empty($dispatch)){
+                $dispatch = $dispatch->toArray();
+                $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
+                    ->where('crt_time',$dispatch['crt_time'])
+                    ->where('product_no',$dispatch['product_no'])
+                    ->where('technology_name',$dispatch['technology_name'])
+                    ->pluck('id')->toArray();
+                $apply_order_id = ApplyOrderDetail::where('del_time', 0)
+                    ->whereIn('data_id', $dispatch_id)
+                    ->where('type', ApplyOrder::type_two)
+                    ->pluck('apply_order_id')
+                    ->toArray();
+                $return = ApplyOrder::where('del_time', 0)
+                    ->whereIn('id', $apply_order_id)
+                    ->select('id','order_number as order_no')
+                    ->get()->toArray();
+                $t = $return[0] ?? [];
+                if(! empty($t)) $result[] = $t;
+            }
         }elseif ($for_type == 11){
             $dispatch_id = ScrappCount::where('del_time',0)
                 ->where('id', $id)