cqp 9 月之前
父节点
当前提交
77a6150e37

+ 4 - 4
app/Http/Controllers/Api/ScreenController.php

@@ -809,9 +809,9 @@ class ScreenController extends BaseController
                 "device_name" => $k,
                 "is_close" => $is_close,
                 "is_close_title" => $is_close_title,
-                "current_order"=> [],
-                "last_counting"=> [],
-                "now_counting"=> [],
+                "current_order"=> (object)[],
+                "last_counting"=> (object)[],
+                "now_counting"=> (object)[],
                 "pending_order"=> [],
                 "average"=> 0,
             ];
@@ -861,7 +861,7 @@ class ScreenController extends BaseController
 
         $dispatch = DispatchSub::where('del_time',0)
             ->whereIn('id', array_column($apply,'data_id'))
-            ->select('dispatch_no','order_product_id','out_order_no')
+            ->select('dispatch_no','order_product_id','out_order_no','dispatch_quantity')
             ->get()->toArray();
         $equipment_map = [];
         $emp_sub = DispatchEmpSub::where('del_time',0)

+ 2 - 2
app/Service/Box/BoxHookService.php

@@ -87,12 +87,12 @@ class BoxHookService extends Service
     public function boxDetailInsert($data){
         $order_no = $data['order_no'];
         $out_order_no = $data['out_order_no'];
-        $box_detail = new BoxDetail(['channel'=>$order_no]);
+        $top_order_no = $data['top_order_no'];
+        $box_detail = new BoxDetail(['channel'=>$top_order_no]);
 
         if(!isset($data['detail'])||empty($data['detail'])) return [true,''];
 
         $insert = $data['detail'];
-        $top_order_no = $data['top_order_no'];
         list($status,$insert) = $this->dealBoxDetail($insert,$order_no,$out_order_no,$top_order_no);
         if(!$status) return [false,$insert];
         $box_detail->insert($insert);

+ 74 - 12
app/Service/Box/BoxService.php

@@ -1170,14 +1170,8 @@ class BoxService extends Service
         if(empty($orders_product_id_map)) return [true,''];
         $production_list = array_keys($orders_product_id_map);
 
-        //组织派工数据
-        $dispatch = DispatchSub::where('del_time',0)
-            ->whereIn('order_product_id', $production_list)
-            ->get()->toArray();
+        $dispatch = $this->getDispatch($production_list, $orders_product_id_map);
         if(empty($dispatch)) return [true,''];
-        foreach ($dispatch as $key => $value){
-            $dispatch[$key]['out_number'] = $orders_product_id_map[$value['order_product_id']] ?? 0;
-        }
 
         try {
             DB::beginTransaction();
@@ -1216,6 +1210,61 @@ class BoxService extends Service
         return [true, ''];
     }
 
+    public function getDispatch($order_product_id,$map){
+        $order = OrdersProduct::where('del_time',0)
+            ->where('id', $order_product_id)
+            ->select('id', 'process_id')
+            ->get()->toArray();
+        $order_map = [];
+        foreach ($order as $value){
+            $order_map[$value['id']] = explode(',', $value['process_id']);
+        }
+
+        //组织派工数据
+        $dispatch = DispatchSub::where('del_time',0)
+            ->whereIn('order_product_id', $order_product_id)
+            ->where('finished_num','>',0)
+            ->get()->toArray();
+        if(empty($dispatch)) return [];
+        $dispatch_map = [];
+        foreach ($dispatch as $value){
+            $key = $value['order_product_id'] . '|' .  $value['crt_time']; //同一次下的派工单
+            $dispatch_map[$key][] = $value;
+        }
+
+        $result = []; $tmp = [];
+        foreach ($dispatch_map as $key => $value){
+            foreach ($value as $v){
+                $process = $order_map[$v['order_product_id']] ?? [];
+                $num = $map[$v['order_product_id']];
+
+                if(in_array($v['process_id'], $process)){
+                    $str = $v['order_product_id'] . $v['process_id'];
+                    $tmp_v = $tmp[$str] ?? 0;
+                    $num = bcsub($num, $tmp_v,3);
+                    if($num <= 0) continue;
+
+                    if($v['finished_num'] >= $num){
+                        $v['out_number'] = $num;
+                        $result[] = $v;
+                    }else{
+                        $v['out_number'] = $v['finished_num'];
+                        $result[] = $v;
+                    }
+
+                    if(isset($tmp[$str])){
+                        $num = bcadd($tmp[$str], $v['out_number'],3);
+                        $tmp[$str] = $num;
+                    }else{
+                        $tmp[$str] = $v['out_number'];
+                    }
+                }
+            }
+        }unset($tmp);
+
+        return $result;
+    }
+
     public function boxAdd($data)
     {
         list($status,$msg) = $this->boxAddRule($data);
@@ -1414,10 +1463,8 @@ class BoxService extends Service
             ->orderBy('id','desc');
 
         if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
-        if(! empty($data['out_order_no']) || ! empty($data['shipment_order_no'])) {
-            $id = $this->searchDetail($data);
-            $model->whereIn('order_no', $id);
-        }
+        if(! empty($data['shipment_order_no'])) $model->where('shipment_order_no', 'LIKE', '%'.$data['shipment_order_no'].'%');
+        if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
         if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
         if(isset($data['status'])) $model->where('status',$data['status']);
 
@@ -1490,7 +1537,22 @@ class BoxService extends Service
 
     public function searchDetail($data){
         $out_order_no = $data['out_order_no'] ?? '';
-        $shipment_order_no = $data['shipment_order_no'] ?? '';
+        $box = Box::where('del_time',0)
+            ->where('out_order_no', 'LIKE', '%'. $out_order_no .'%')
+            ->select('top_order_no')
+            ->get()->toArray();
+        if(empty($box)) return [];
+
+        $order_no = [];
+        foreach ($box as $value){
+            $model = new BoxDetail(['channel'=> $value['top_order_no']]);
+            $result = $model->where('del_time',0)
+                ->where('order_no',$box['order_no'])
+                ->select('order_no')
+                ->get()->toArray();
+            $detail_list = array_merge($order_no, array_column($result, 'order_no'));
+
+        }
         $result = BoxDetail::where('del_time',0)
             ->when(! empty($out_order_no), function ($query) use ($out_order_no) {
                 return $query->where('out_order_no', 'LIKE', '%'. $out_order_no .'%');

+ 4 - 12
app/Service/DeleteOrderService.php

@@ -17,6 +17,7 @@ use App\Model\OrdersProductMain;
 use App\Model\OrdersProductProcess;
 use App\Model\Process;
 use App\Model\SaleOrdersProduct;
+use App\Service\Box\BoxService;
 use Illuminate\Support\Facades\DB;
 
 class DeleteOrderService extends Service
@@ -338,18 +339,9 @@ class DeleteOrderService extends Service
                 if($value['status'] > Box::status_zero) return [false, '包装单已审核,删除失败'];
                 $order_no[] = $value['order_no'];
             }
-            $time = time();
-
-            Box::whereIn('id',$id)->update([
-                'del_time' => $time
-            ]);
-
-            foreach ($box as $value){
-                $model = new BoxDetail(['channel'=> $value['top_order_no']]);
-                $model->where('del_time',0)
-                    ->where('order_no',$value['order_no'])
-                    ->update(['del_time' => $time]);
-            }
+            $service = new BoxService();
+            list($status, $msg) = $service->delBoxDetail(['order_nos' => $order_no]);
+            if(! $status) return [false, $msg];
 
             DB::commit();
         }catch (\Throwable $e){