chenqp 1 éve
szülő
commit
d201fcc2f4
1 módosított fájl, 67 hozzáadás és 5 törlés
  1. 67 5
      app/Service/Box/BoxService.php

+ 67 - 5
app/Service/Box/BoxService.php

@@ -248,7 +248,7 @@ class BoxService extends Service
 
         //组织派工数据
         $dispatch = DispatchSub::where('del_time',0)
-            ->where('order_product_id', array_column($production_list,'id'))
+            ->whereIn('order_product_id', array_column($production_list,'id'))
             ->get()->toArray();
         if(empty($dispatch)) return [true,''];
         $dispatch_map = [];
@@ -853,6 +853,8 @@ class BoxService extends Service
         try {
             DB::beginTransaction();
 
+            //更新销售订单 生产订单数据
+            $orders_product_id_map = [];
             foreach ($order_nos as $v){
                 $list = self::$box_hook->delBox($v);
                 if(empty($list)) continue;
@@ -861,13 +863,23 @@ class BoxService extends Service
                         'box_num' => DB::raw('box_num - '.$vv['num'])
                     ]);
 
-                    if($vv['box_type'] == 1){
-                        OrdersProduct::where('id',$vv['orders_product_id'])->update([
-                            'box_num' => DB::raw('box_num - '.$vv['num'])
-                        ]);
+                    OrdersProduct::where('id',$vv['orders_product_id'])->update([
+                        'box_num' => DB::raw('box_num - '.$vv['num'])
+                    ]);
+
+                    if(isset($orders_product_id_map[$vv['orders_product_id']])){
+                        $num = bcadd($orders_product_id_map[$vv['orders_product_id']], $vv['num'],3);
+                        $orders_product_id_map[$vv['orders_product_id']] = $num;
+                    }else{
+                        $orders_product_id_map[$vv['orders_product_id']] = $vv['num'];
                     }
                 }
             }
+
+            //更新完工数据 和 底表数据
+            list($status,$msg) = $this->updateFinishDel($orders_product_id_map);
+            if(! $status) return [false, $msg];
+
             DB::commit();
         }catch (\Throwable $exception){
             DB::rollBack();
@@ -877,6 +889,56 @@ class BoxService extends Service
         return [true, ''];
     }
 
+    public function updateFinishDel($orders_product_id_map){
+        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();
+        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();
+
+            //根据派工数据回写
+            foreach ($dispatch as $value){
+                $finished_num = bcsub($value['finished_num'], $value['out_number'],3);
+
+                DispatchSub::where('id',$value['id'])->update([
+                    'finished_num' => $finished_num
+                ]);
+
+                $quantity = $value['out_number'] * 1000;
+                //工序表
+                $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
+                $process_model->where('order_product_id',$value['order_product_id'])
+                    ->where('process_id',$value['process_id'])
+                    ->where('dispatch_no',$value['dispatch_no'])
+                    ->where('status', 2)
+                    ->take($quantity)
+                    ->update([
+                        'finished_time' => 0,
+                        'status' => 1,
+                        'finished_id' => 0,
+                        'team_id' => 0,
+                        'equipment_id' => 0,
+                    ]);
+            }
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getLine().':'.$exception->getMessage() . ':' . $exception->getFile()];
+        }
+
+        return [true, ''];
+    }
+
     public function boxAdd($data)
     {
         list($status,$msg) = $this->boxAddRule($data);