cqpCow 1 year ago
parent
commit
c2bd3ce093
2 changed files with 43 additions and 33 deletions
  1. 11 7
      app/Service/Box/BoxHookService.php
  2. 32 26
      app/Service/Box/BoxService.php

+ 11 - 7
app/Service/Box/BoxHookService.php

@@ -108,6 +108,7 @@ class BoxHookService extends Service
                 'order_no' => $order_no,
                 'out_order_no' => $out_order_no,
                 'top_id' => $v['top_id'],
+                'orders_product_id' => $v['orders_product_id'] ?? 0,
                 'code' => '',
                 'title' => '',
                 'num' => $v['num'],
@@ -172,15 +173,18 @@ class BoxHookService extends Service
     public function delBox($order_no){
         $box = Box::where('del_time',0)->where('order_no',$order_no)->first();
         if(empty($box)) return [];
-        $boxDetail = new BoxDetail(['channel'=>$box->top_order_no]);
-//        $list = [];
-        $list = $boxDetail->where('order_no',$order_no)->where('del_time',0)->select('id','top_id','num','ext_1','ext_2','ext_3','ext_4','ext_5','out_order_no','box_type')->get()->toArray();
-
-        $boxDetail->where('order_no',$order_no)->where('del_time',0)->update([
-            'del_time' => time()
-        ]);
+        $boxDetail = new BoxDetail(['channel' => $box->top_order_no]);
+        $list = $boxDetail->where('order_no', $order_no)
+            ->where('del_time',0)
+            ->select('id','top_id','orders_product_id','num','ext_1','ext_2','ext_3','ext_4','ext_5','out_order_no','box_type')
+            ->get()->toArray();
+
+        $boxDetail->where('order_no',$order_no)
+            ->where('del_time',0)
+            ->update(['del_time' => time()]);
         $box->del_time = time();
         $box->save();
+
         return $list;
     }
 

+ 32 - 26
app/Service/Box/BoxService.php

@@ -75,6 +75,8 @@ class BoxService extends Service
             if(!$lock_status) return [false,'操作过于频繁'];
             $product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
             $sale_product_list = SaleOrdersProduct::wherein('id', $sale_ids)->get()->toArray();
+
+            //生产订单包装----------------
             $box_insert = [];
             foreach ($product_list as $v) {
                 $num_list = $key_list[$v['id']];
@@ -95,9 +97,10 @@ class BoxService extends Service
                     $box_insert[] = [
                         'out_order_no' => $out_order_no,
                         'top_id' => $top_id,
-                        'ext_1' => $ext_1,
+                        'orders_product_id' => $v['id'],
+                        'ext_1' => $ext_1,//产品编号
                         'ext_2' => $ext_2,
-                        'ext_3' => $ext_3,
+                        'ext_3' => $ext_3,//颜色
                         'ext_4' => $ext_4,
                         'ext_5' => $ext_5,
                         'num' => $vv,
@@ -107,7 +110,7 @@ class BoxService extends Service
                         'shipment_order_no' => $transport_no,
                     ];
                 }
-
+                //修改销售订单  生产订单 包装数量
                 SaleOrdersProduct::where('id',$v['sale_orders_product_id'])->update([
                     'box_num' => DB::raw('box_num + '.$total),
                 ]);
@@ -115,6 +118,8 @@ class BoxService extends Service
                     'box_num' => DB::raw('box_num + '.$total),
                 ]);
             }
+
+            //销售订单包装----------------
             foreach ($sale_product_list as $v) {
                 $box_type = 0;
                 if($v['id'] < 0)  {
@@ -140,6 +145,7 @@ class BoxService extends Service
                     $box_insert[] = [
                         'out_order_no' => $out_order_no,
                         'top_id' => $top_id,
+                        'orders_product_id' => 0,
                         'ext_1' => $ext_1,
                         'ext_2' => $ext_2,
                         'ext_3' => $ext_3,
@@ -153,6 +159,7 @@ class BoxService extends Service
                     ];
                 }
 
+                //修改销售订单  包装数量
                 SaleOrdersProduct::where('id',$v['id'])->update([
                     'box_num' => DB::raw('box_num + '.$total),
                 ]);
@@ -168,12 +175,11 @@ class BoxService extends Service
             $insert['order_no'] = $box_no;
             $insert['shipment_order_no'] = $transport_no;
             list($status,$msg) = self::$box_hook->boxInsert($insert);
-            if(!$status) {
+            if(! $status) {
                 $this->delLock($key);
                 DB::rollBack();
                 return [false,$msg];
-            }
-            $this->delLock($key);
+            }$this->delLock($key);
 
             //用友 ------产成品入库
             $package_data = $msg->toArray();
@@ -181,7 +187,6 @@ class BoxService extends Service
                 $service = new FinishedOrderService();
                 list($status,$msg) = $service->U8Rdrecord10Save($package_data,$user);
                 if(! $status) {
-                    (new FyySqlServerService())->recordErrorTable($msg,$user,$package_data,$time,1);
                     DB::rollBack();
                     return [false, $msg];
                 }
@@ -196,7 +201,7 @@ class BoxService extends Service
     }
 
     /**
-     * 根据发货单包装
+     * 根据发货单包装(恒诚塑业不需要)
      * @param $data
      * @return array
      */
@@ -321,7 +326,7 @@ class BoxService extends Service
     }
 
     public function boxProductList($data){
-        if(!isset($data['id'])) return [false,'id not found'];
+        if(empty($data['id'])) return [false,'请选择数据!'];
         $sale_order_ids = $data['id'];
         $model = SaleOrdersProduct::where('del_time',0)->wherein('id',$sale_order_ids)
             ->select('id','out_order_no','order_no','customer_no','customer_name','product_no','product_title','product_size','crt_time as production_time','id as sale_orders_product_id','finished_num as dispatch_complete_quantity','box_num','technology_name','wood_name','crt_time','order_quantity','technology_material','technology_name','wood_name','process_mark')
@@ -528,30 +533,31 @@ class BoxService extends Service
     }
 
     public function delBoxDetail($data){
+        if(empty($data['order_nos'])) return [false, '请选择包装单!'];
         $order_nos = $data['order_nos'];
-        foreach ($order_nos as $v){
-            $list = self::$box_hook->delBox($v);
-            foreach ($list as $vv){
-                SaleOrdersProduct::where('id',$vv['top_id'])->update([
-                    'box_num' => DB::raw('box_num - '.$vv['num'])
-                ]);
-                if($vv['box_type'] == 1){
-                    //   $ext_1 = $v['product_no'];//产品编号
-                    //                $ext_2 = $v['technology_material']; //工艺材质
-                    //                $ext_3 = $v['technology_name'];//工艺名称
-                    //                $ext_4 = $v['wood_name'];//木皮
-                    //                $ext_5 = $v['process_mark'];//工艺备注
-                    // toDO 有问题
-                    OrdersProduct::where('product_no',$vv['ext_1'])->where('technology_material',$vv['ext_2'])->where('technology_name',$vv['ext_3'])->where('wood_name',$vv['ext_4'])->where('process_mark',$vv['ext_5'])->where('sale_orders_product_id',$vv['top_id'])
-                        ->update([
+        try {
+            DB::beginTransaction();
+
+            foreach ($order_nos as $v){
+                $list = self::$box_hook->delBox($v);
+                foreach ($list as $vv){
+                    SaleOrdersProduct::where('id',$vv['top_id'])->update([
+                        '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'])
                         ]);
-
+                    }
                 }
             }
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
         }
 
-        return [true,'删除成功'];
+        return [true, ''];
     }
 
     public function boxAdd($data)