cqp hace 3 días
padre
commit
5d16b90e2a

+ 13 - 0
app/Http/Controllers/Api/ConstructionController.php

@@ -47,6 +47,19 @@ class ConstructionController extends BaseController
         }
     }
 
+    public function constructionEditSn(Request $request)
+    {
+        $service = new ConstructionService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->constructionEditSn($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function constructionDel(Request $request)
     {
         $service = new ConstructionService();

+ 2 - 0
app/Model/ProductCategory.php

@@ -12,4 +12,6 @@ class ProductCategory extends UseScopeBaseModel
         0 => "否",
         1 => "是",
     ];
+    const Special_for_roll = 112; //有模有样
+    const Special_for_sn = 133; //车窗膜
 }

+ 83 - 34
app/Service/DataSyncToU8Service.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Jobs\ProcessDataJob;
+use App\Model\ProductCategory;
 use App\Model\ProductSnInfo;
 use App\Model\PurchaseOrder;
 use App\Model\Setting;
@@ -92,32 +93,52 @@ class DataSyncToU8Service extends Service
         return [true, $msg['data'] ?? []];
     }
 
-    //校验sn码 施工单
-    public function checkSnConstructionRule($data){
+    /**
+     * 校验sn码 施工单
+     * @param $data
+     * @param false $is_edit 是否补录
+     * @return array|string
+     */
+    public function checkSnConstructionRule($data, $is_edit = false){
+        //产品字典
+        $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id'));
+
+        $sn_map = [];
+        if($is_edit) $sn_map = $this->getSn($data, ProductSnInfo::type_one);
+
         $code = $sn = [];
         foreach ($data['product'] as $value){
-            //没有sn码信息直接返回
-            if(empty($value['product_sn_info'])) continue;
-            if(count($value['product_sn_info']) > $value['number']) return [false, "产品编码:" . $value['code'] . "选择的sn码数量不能超过产品数量"];
             if(empty($value['code'])) return [false, '产品编码不能为空'];
             $code[] = $value['code'];
+
+            //补录校验
+            if($is_edit){
+                $sn_tmp = $sn_map[$value['code']] ?? [];
+                foreach ($sn_tmp as $val){
+                    if(! empty($val['warranty_id']) && ! in_array($val['sn'], $value['product_sn_info'])) return [false,  "产品编码:" . $value['code'] . "选择的sn码". $val['sn'] . "已生成质保,不允许删除"];
+                }
+            }
+
+            //没有sn码信息直接跳过
+            if(empty($value['product_sn_info'])) continue;
+            $tmp = $map[$value['product_id']] ?? [];
+            $category = json_decode($tmp['product_category'],true);
+            //非车窗膜需校验sn码
+            if(! in_array(ProductCategory::Special_for_sn, $category)){
+                if(count($value['product_sn_info']) > $value['number']) return [false, "产品编码:" . $value['code'] . "选择的sn码数量不能超过产品数量"];
+            }
+
             foreach ($value['product_sn_info'] as $sn_val){
                 $sn[] = $sn_val;
             }
         }
         if(empty($sn)) return [true, ''];
 
-        $header = ['Content-Type:application/json'];
-        $post = [
-            'urlFromT9' => 'getSnMap',
-            'code' => $code,
-            'sn' => $sn,
-        ];
-        $post = json_encode($post);
-        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnforMap", $post, $header);
-        if($msg['code'] != 200) return [false, $msg['msg']];
+        //获取在库的sn码信息
+        list($status, $msg) = $this->getSnForMap($code, $sn);
+        if(! $status) return [false, $msg];
 
-        //sn码
+        //sn码map
         $sn_list = $msg['data'];
         $sn_map = [];
         foreach ($sn_list as $value){
@@ -125,6 +146,7 @@ class DataSyncToU8Service extends Service
             $sn_map[$key] = "";
         }
 
+        //校验用友
         $submit_info = [];
         foreach ($data['product'] as $value){
             if(empty($value['product_sn_info'])) continue;
@@ -135,23 +157,9 @@ class DataSyncToU8Service extends Service
             }
         }
 
-        $save = ProductSnInfo::where('del_time',0)
-            ->whereIn("code", $code)
-            ->whereIn('sn', $sn)
-            ->select('code','sn','data_id','type')
-            ->get()->toArray();
-
-        $construction_id = $data['id'] ?? 0;
-        foreach ($save as $value){
-            $key = $value['code'] . $value['sn'];
-            if(in_array($key, $submit_info)) {
-                if(! $construction_id){
-                    return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$value['type']]] . '使用';
-                }else{
-                    if($value['data_id'] != $construction_id || $value['type'] != ProductSnInfo::type_one) return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$value['type']]] . '使用';
-                }
-            }
-        }
+        //校验sn是否被占用
+        list($status, $msg) = $this->snForCheck($code, $sn, $submit_info, $data);
+        if(! $status) return [false, $msg];
 
         return [true, ''];
     }
@@ -194,13 +202,54 @@ class DataSyncToU8Service extends Service
         $sn = ProductSnInfo::where('del_time',0)
             ->where('data_id', $data_id)
             ->where('type', $type)
-            ->select('product_id','code','sn')
+            ->select('product_id','code','sn','warranty_id')
             ->get()->toArray();
 
         foreach ($sn as $value){
-            $map[$value['code']][] = $value['sn'];
+            $map[$value['code']][] = [
+                'sn' => $value['sn'],
+                'warranty_id' => $value['warranty_id'],
+            ];
         }
 
         return $map;
     }
+
+    //获取在库的sn码信息
+    private function getSnForMap($code, $sn){
+        $header = ['Content-Type:application/json'];
+        $post = [
+            'urlFromT9' => 'getSnMap',
+            'code' => $code,
+            'sn' => $sn,
+        ];
+        $post = json_encode($post);
+        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnforMap", $post, $header);
+        if($msg['code'] != 200) return [false, $msg['msg']];
+
+        return [true, $msg];
+    }
+
+    //校验sn是否被占用
+    private function snForCheck($code = [], $sn = [], $submit_info = [], $data){
+        $save = ProductSnInfo::where('del_time',0)
+            ->whereIn("code", $code)
+            ->whereIn('sn', $sn)
+            ->select('code','sn','data_id','type')
+            ->get()->toArray();
+
+        $data_id = $data['id'] ?? 0;
+        foreach ($save as $value){
+            $key = $value['code'] . $value['sn'];
+            if(in_array($key, $submit_info)) {
+                if(! $data_id){
+                    return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$value['type']]] . '使用';
+                }else{
+                    if($value['data_id'] != $data_id || $value['type'] != ProductSnInfo::type_one) return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$value['type']]] . '使用';
+                }
+            }
+        }
+
+        return [true, ''];
+    }
 }

+ 2 - 2
app/Service/ProductService.php

@@ -1313,7 +1313,7 @@ class ProductService extends Service
         foreach ($data['data'] as $key => $value){
             $arr = json_decode($value['product_category'], true);
             $arr = array_flip($arr);
-            if (isset($arr[112])) {
+            if (isset($arr[ProductCategory::Special_for_roll])) {
                 $data['data'][$key]['is_roll'] = true;
                 $is_roll = true;
             }else{
@@ -1394,7 +1394,7 @@ class ProductService extends Service
             $product[$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
             $arr = json_decode($value['product_category'], true);
             $arr = array_flip($arr);
-            if (isset($arr[112])) {
+            if (isset($arr[ProductCategory::Special_for_roll])) {
                 $product[$key]['is_roll'] = true;
             }else{
                 $product[$key]['is_roll'] = false;

+ 4 - 0
routes/api.php

@@ -235,6 +235,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('constructionPdf', 'Api\ConstructionController@constructionPdf');
     $route->any('constructionOperation', 'Api\ConstructionController@constructionOperation');
     $route->any('constructionEditOther', 'Api\ConstructionController@constructionEditOther');
+    $route->any('constructionEditSn', 'Api\ConstructionController@constructionEditSn');
 
     //交车单
     $route->any('deliveryNoteList', 'Api\ConstructionController@deliveryNoteList');
@@ -375,6 +376,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('tSpaceEdit', 'Api\TSpaceController@edit')->middleware('OssFileDeal');
     $route->any('tSpaceDetail', 'Api\TSpaceController@detail');
 
+    //生成质保信息
+    $route->any('warrantyAdd', 'Api\TSpaceController@warrantyAdd');
+
     //获取下载模板
     $route->any('getTableTitleXls','Api\ImportController@getTableTitleXls');
     //导入