cqp 3 mesiacov pred
rodič
commit
f521aa02b9

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

@@ -99,6 +99,19 @@ class ConstructionController extends BaseController
         }
     }
 
+    public function detailSn(Request $request)
+    {
+        $service = new ConstructionService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->detailSn($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function constructionGet(Request $request)
     {
         $service = new ConstructionService();
@@ -189,6 +202,19 @@ class ConstructionController extends BaseController
         }
     }
 
+    public function snListAccording(Request $request)
+    {
+        $service = new ConstructionService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->snListAccording($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function show(Request $request){
         $construction = [
           "id" => 45,

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

@@ -71,6 +71,19 @@ class TSpaceController extends BaseController
         }
     }
 
+    public function needSnFix(Request $request)
+    {
+        $service = new TSpaceService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->needSnFix($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function warrantyAdd(Request $request)
     {
         $service = new TSpaceService();

+ 7 - 3
app/Model/Construction.php

@@ -34,15 +34,19 @@ class Construction extends UseScopeBaseModel
     const STATE_DIFF_TWO = -100;//已预约施工
     const STATE_TWO = 2;//已审核
     const STATE_THREE = 3;//待确认
-    const STATE_FOUR = 4;//已完结
+    const STATE_FOUR = 4;//待验车
+    const STATE_FIVE = 5;//待交车
+    const STATE_SIX = 6;//已交车
     public static $name = [
         self::State_minus_one => '驳回',
         self::STATE_ZERO => '未审核',
         self::STATE_ONE => '待审核',
         self::STATE_DIFF_TWO => '已预约施工',
         self::STATE_TWO => '施工中',
-        self::STATE_THREE => '待完结审核',
-        self::STATE_FOUR => '已完结',
+        self::STATE_THREE => '待确认',
+        self::STATE_FOUR => '待验车',
+        self::STATE_FIVE => '待交车',
+        self::STATE_SIX => '已交车',
     ];
 
     public static $pq_name = [

+ 2 - 0
app/Model/RoleMenuButton.php

@@ -21,4 +21,6 @@ class RoleMenuButton extends Model
     const special_eight = -8;
     const special_nine = -9;
     const special_ten = -10;
+    const special_eve = -11;
+    const special_twl = -12;
 }

+ 199 - 14
app/Service/ConstructionService.php

@@ -29,6 +29,7 @@ use App\Model\SalesOrderInfo;
 use App\Model\SalesOrderProductInfo;
 use App\Model\ScheduleInfo;
 use App\Model\SeeRange;
+use App\Model\Setting;
 use App\Model\Storehouse;
 use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
@@ -44,7 +45,7 @@ use Barryvdh\DomPDF\PDF;
 class ConstructionService extends Service
 {
     //补录sn码信息
-    public function constructionEditSn($data,$user){
+    public function constructionEditSn($data,$user){return [false, '补录功能暂时关闭'];
         list($status,$msg) = $this->constructionEditSnRule($data, $user);
         if(!$status) return [$status, $msg];
 
@@ -52,7 +53,7 @@ class ConstructionService extends Service
             DB::beginTransaction();
 
             //sn码
-            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, time());
+//            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, time());
 
             DB::commit();
         }catch (\Exception $exception){
@@ -72,8 +73,8 @@ class ConstructionService extends Service
         if(empty($data['product'])) return [false, '产品不能为空'];
 
         //校验sn码
-        list($status, $msg) = (new DataSyncToU8Service())->checkSnConstructionRule($data);
-        if(! $status) return [false, $msg];
+//        list($status, $msg) = (new DataSyncToU8Service())->checkSnConstructionRule($data);
+//        if(! $status) return [false, $msg];
 
         return [true, ''];
     }
@@ -262,7 +263,7 @@ class ConstructionService extends Service
             }
 
             //sn码
-            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, $time);
+//            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, $time);
 
             DB::commit();
         }catch (\Exception $exception){
@@ -403,7 +404,7 @@ class ConstructionService extends Service
             (new CheckService())->orderInventoryInsert(['order_number' => $data['order_number'], 'is_check_stock' => $data['is_check_stock']]);
 
             //sn码
-            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, $time);
+//            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, $time);
 
             DB::commit();
         }catch (\Exception $exception){
@@ -440,7 +441,7 @@ class ConstructionService extends Service
         $construction = $construction->toArray();
         if($construction['state'] > Construction::STATE_ZERO) return [false,'请确认施工单状态,操作失败'];
 
-        $product_save = $this->getSaveDetail($data['id']);
+//        $product_save = $this->getSaveDetail($data['id']);
         try {
             DB::beginTransaction();
 
@@ -660,6 +661,43 @@ class ConstructionService extends Service
         return [true, $construction];
     }
 
+    public function detailSn($data,$user){
+        if(empty($data['id'])) return [false,'请选择数据!'];
+
+        $p_info = ConstructionProductInfo::where('del_time',0)
+            ->where('construction_id',$data['id'])
+            ->get()->toArray();
+        $basic_price = BasicType::whereIn('id',array_unique(array_column($p_info,'basic_type_id')))->pluck('title','id')->toArray();
+        $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
+
+        $return = [];
+        $service = new DataSyncToU8Service();
+        foreach ($p_info as $value){
+            $tmp = $map[$value['product_id']] ?? [];
+            if(empty($tmp['warranty_time'])) continue;
+            $bool = $service->forCheck($tmp['product_category']);
+            if($bool){//车窗膜不需要
+                $value['product_type_for_sn'] = 1;
+            }else{
+                $bool = $service->forCheck2($tmp['product_category']);
+                if($bool){
+                    $value['product_type_for_sn'] = $value['product_type_for_sn'] = 1;
+                }else{
+                    $value['product_type_for_sn'] = $value['product_type_for_sn'] = 2;
+                }
+            }
+            $value['title'] = $tmp['title'] ?? "";
+            $value['code'] = $tmp['code'] ?? "";
+            $value['size'] = $tmp['size'] ?? "";
+            $value['unit'] = $tmp['unit'] ?? "";
+            $value['bar_code'] = $tmp['bar_code'] ?? "";
+            $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
+            $return[] = $value;
+        }
+
+        return [true, $return];
+    }
+
     public function constructionCommon($data,$user,$field = []){
         if(empty($field)){
             $field = ['title','id','model_type','order_number','customer_id','customer_contact_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction','service_price','storehouse_id','start_time','end_time','pq_state','day_start_stamp','day_end_stamp','vin_no'];
@@ -874,9 +912,11 @@ class ConstructionService extends Service
             $product_id[] = $value['product_id'];
         }
 
-        //校验sn码
-        list($status, $msg) = (new DataSyncToU8Service())->checkSnConstructionRule($data);
-        if(! $status) return [false, $msg];
+//        //校验sn码
+//        if($is_add){
+//            list($status, $msg) = (new DataSyncToU8Service())->checkSnConstructionRule($data);
+//            if(! $status) return [false, $msg];
+//        }
 
         //剩余能施工
         $id = $data['id'] ?? 0;
@@ -1703,7 +1743,7 @@ class ConstructionService extends Service
 
         $send_data = [];
         if($data['type'] == 1){
-            if($order['state'] != Construction::STATE_TWO) return [false, '请确认施工单单据状态,操作完结失败'];
+            if($order['state'] != Construction::STATE_TWO) return [false, '请确认施工单单据状态,操作失败'];
             $state = Construction::STATE_THREE;
 
             //提醒分配人
@@ -1735,8 +1775,8 @@ class ConstructionService extends Service
                     ];
                 }
             }
-        }else{
-            if($order['state'] != Construction::STATE_THREE) return [false, '请确认施工单单据状态,操作待确认失败'];
+        }elseif($data['type'] == 2){
+            if($order['state'] != Construction::STATE_THREE) return [false, '请确认施工单单据状态,操作失败'];
             $state = Construction::STATE_FOUR;
 
             //提醒创建人
@@ -1750,7 +1790,52 @@ class ConstructionService extends Service
                 'tmp_data' => [
                     $order['order_number'],
                     "施工单",
-                    '已完结',
+                    '待验车',
+                    $emp_tmp,
+                    date('Y-m-d H:i:s'),
+                ],
+            ];
+        }elseif($data['type'] == 3){
+            if($order['state'] != Construction::STATE_FOUR) return [false, '请确认施工单单据状态,操作失败'];
+            $state = Construction::STATE_FIVE;
+
+            //提醒创建人
+            $emp_tmp = Employee::where('id', $order['crt_id'])->value('emp_name');
+            $send_data[] = [
+                'employee_id' => $order['crt_id'],
+                'type' => 2,
+                'state' => 0,
+                'menu_id' => 34,
+                'order_number' => $order['order_number'],
+                'tmp_data' => [
+                    $order['order_number'],
+                    "施工单",
+                    '待交车',
+                    $emp_tmp,
+                    date('Y-m-d H:i:s'),
+                ],
+            ];
+        }else{
+            list($status, $msg) = $this->checkWarranty($order, $data);
+            if(! $status) return [false, $msg];
+
+            list($status, $msg) = (new TSpaceService())->warrantyAddNew($msg, $data, $user);
+            if(! $status) return [false, $msg];
+
+            $state = Construction::STATE_SIX;
+
+            //提醒创建人
+            $emp_tmp = Employee::where('id', $order['crt_id'])->value('emp_name');
+            $send_data[] = [
+                'employee_id' => $order['crt_id'],
+                'type' => 2,
+                'state' => 0,
+                'menu_id' => 34,
+                'order_number' => $order['order_number'],
+                'tmp_data' => [
+                    $order['order_number'],
+                    "施工单",
+                    '已交车',
                     $emp_tmp,
                     date('Y-m-d H:i:s'),
                 ],
@@ -1764,4 +1849,104 @@ class ConstructionService extends Service
 
         return [true, ''];
     }
+
+    public function snListAccording($data,$user){
+        if(empty($data['id'])) return [false, 'ID不能为空'];
+        $sn_type = (new DataSyncToU8Service())->snListAccordingForOrder($data['id']);
+
+        return [true, ['sn_type' => $sn_type]];
+    }
+
+    public function checkWarranty($order, &$data){
+        if($order['state'] != Construction::STATE_FIVE) return [false, '施工单未处在待交车状态,操作失败'];
+        if(empty($order['vin_no'])) return [false, '车架号不能为空'];
+        $bool = $this->isValidVin($order['vin_no']);
+        if(! $bool) return [false, '车架号错误,请查看原施工单车架号,编辑输入完整车架号'];
+        if(empty($order['customer_id'])) return [false, '客户信息不存在'];
+        $customer = Customer::where('del_time', 0)->where('id',$order['customer_id'])->first();
+        if(empty($customer)) return [false, '客户不存在或已被删除'];
+        $customer = $customer->toArray();
+        $info = CustomerInfo::where('del_time',0)
+            ->where('type',CustomerInfo::type_one)
+            ->where('customer_id', $customer['id'])
+            ->where('contact_info', "<>", "")
+            ->select('contact_info')
+            ->first();
+        if(empty($info)) return [false, "客户的联系方式不能为空"];
+        $info = $info->toArray();
+        $customer_info = $info['contact_info'];
+        $order['customer_info'] = $customer_info;
+        $order['customer_title'] = $customer['title'];
+        if(empty($data['product'])) return [false, '产品不能为空'];
+        list($status, $msg) = $this->checkSnConstructionRule($data);
+        if(! $status) return [false, $msg];
+
+        return [true, $order];
+    }
+
+    /**
+     * 校验sn码 施工单
+     * @param $data
+     * @param false $is_edit 是否补录
+     * @return array|string
+     */
+    public function checkSnConstructionRule(&$data){
+        //产品字典
+        $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id'));
+
+        $code = $sn = [];
+        $service = new DataSyncToU8Service();
+        foreach ($data['product'] as $key => $value){
+            if(empty($value['code'])) return [false, '产品编码不能为空'];
+            $code[] = $value['code'];
+            //没有sn码信息直接跳过
+            if(empty($value['product_sn_info'])) continue;
+            //产品
+            $tmp = $map[$value['product_id']] ?? [];
+            if(empty($tmp['warranty_time'])) return [false, "产品编码:" . $value['code'] . "质保时长(月)暂未设置"];
+            $bool = $service->forCheck($tmp['product_category']);
+
+            $n = 0;
+            foreach ($value['product_sn_info'] as $k_s => $sn_val){
+                if(empty($sn_val['auto_id'])) return [false, 'AutoID不能为空'];
+                if(empty($sn_val['sn'])) return [false, '产品SN不能为空'];
+                $value['product_sn_info'][$k_s]['for_update'] = $bool ? 0 : 1;
+                $n ++;
+                $sn[] = $sn_val['sn'];
+            }
+            $data['product'][$key]['product_sn_info'] = $value['product_sn_info'];
+            //非车窗膜需校验sn码
+            if(! $bool && $n > $value['number']) return [false, "产品编码:" . $value['code'] . "选择的sn码数量不能超过产品数量"];
+        }
+        if(empty($sn)) return [true, ''];
+
+        //获取在库的sn码信息
+        list($status, $msg) = $service->getSnForMap($code, $sn);
+        if(! $status) return [false, $msg];
+
+        //sn码map
+        $sn_list = $msg['data'];
+        $sn_map = [];
+        foreach ($sn_list as $value){
+            $key = $value['code'] . $value['sn'];
+            $sn_map[$key] = "";
+        }
+
+        //校验用友
+        $submit_info = [];
+        foreach ($data['product'] as $value){
+            if(empty($value['product_sn_info'])) continue;
+            foreach ($value['product_sn_info'] as $sn_val){
+                $key = $value['code'] . $sn_val['sn'];
+                $submit_info[] = $key;
+                if(! isset($sn_map[$key])) return [false, "产品编码:" . $value['code'] . "的产品序列码:" . $sn_val['sn'] . "在用友中不存在"];
+            }
+        }
+
+        //校验sn是否被占用
+        list($status, $msg) = $service->snForCheck($code, $sn, $submit_info, $data);
+        if(! $status) return [false, $msg];
+
+        return [true, ''];
+    }
 }

+ 80 - 7
app/Service/DataSyncToU8Service.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Jobs\ProcessDataJob;
+use App\Model\Construction;
 use App\Model\Product;
 use App\Model\ProductCategory;
 use App\Model\ProductSnInfo;
@@ -70,6 +71,26 @@ class DataSyncToU8Service extends Service
         return [true, ['sn_type' => $sn_type]];
     }
 
+    public function snListAccordingForOrder($data_id){
+        //特殊的门店
+        $setting = Setting::where('setting_name','bt_top_depart_id')->first();
+        $bt_top_depart_id = $setting['setting_value'] ?? [];
+        $bt_top_depart_id = json_decode($bt_top_depart_id,true);
+
+        //当前门店
+        $current_top_depart_id = Construction::where('id', $data_id)->value('top_depart_id');
+
+        if(in_array($current_top_depart_id, $bt_top_depart_id)){
+            //总社 直接读取sn码表
+            $sn_type = 1;//总社
+        }else{
+            $sn_type = 2;//分社
+            //发货单 sn码
+        }
+
+        return $sn_type;
+    }
+
     public function getSnFromU8($data, $user){
         if(empty($data['sn_type'])) return [false, 'sn码来源依据不能为空'];
         if(empty($data['code'])) return [false, '产品编码不能为空'];
@@ -79,17 +100,21 @@ class DataSyncToU8Service extends Service
 
     public function getSnList($data, $user){
         $header = ['Content-Type:application/json'];
+        $construction_id = $data['construction_id'] ?? 0;
         $post = [
             'urlFromT9' => 'getSnList',
             'code' => $data['code'],
             'sn' => $data['sn'] ?? "",
             'sn_type' => $data['sn_type'],
             'depart_title' => $this->getMyTopDepart($user,true),
+            'construction_id' => $construction_id,
             'page_size' => $data['page_size'] ?? 10,
             'page_index' => $data['page_index'] ?? 1,
         ];
         $post = json_encode($post);
         list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnList", $post, $header);
+        if(! $status) return [false, "用友数据获取失败"];
+
         if($msg['code'] != 200) return [false, $msg['msg']];
 
         return [true, $msg['data'] ?? []];
@@ -101,7 +126,7 @@ class DataSyncToU8Service extends Service
      * @param false $is_edit 是否补录
      * @return array|string
      */
-    public function checkSnConstructionRule($data){
+    public function checkSnConstructionRule(&$data){
         //产品字典
         $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id'));
 
@@ -126,9 +151,9 @@ class DataSyncToU8Service extends Service
             if(empty($value['product_sn_info'])) continue;
             $tmp = $map[$value['product_id']] ?? [];
             if(empty($tmp['warranty_time'])) return [false, "产品编码:" . $value['code'] . "质保时长(月)暂未设置"];
-            $category = json_decode($tmp['product_category'],true);
+            $bool = $this->forCheck($tmp['product_category']);
             //非车窗膜需校验sn码
-            if(! in_array(ProductCategory::Special_for_sn, $category)){
+            if(! $bool){
                 if(count($value['product_sn_info']) > $value['number']) return [false, "产品编码:" . $value['code'] . "选择的sn码数量不能超过产品数量"];
             }
 
@@ -137,6 +162,14 @@ class DataSyncToU8Service extends Service
             }
         }
         if(empty($sn)) return [true, ''];
+        if(empty($data['sn_for_u8'])) return [false, "校验用友数据信息不能为空"];
+        foreach ($data['sn_for_u8'] as $key => $value){
+            if(empty($value['auto_id'])) return [false, 'AutoID不能为空'];
+            if(empty($value['product_id'])) return [false, '产品ID不能为空'];
+            $tmp = $map[$value['product_id']] ?? [];
+            $bool = $this->forCheck($tmp['product_category']);
+            if($bool) unset($data['sn_for_u8'][$key]);
+        }
 
         //获取在库的sn码信息
         list($status, $msg) = $this->getSnForMap($code, $sn);
@@ -168,6 +201,18 @@ class DataSyncToU8Service extends Service
         return [true, ''];
     }
 
+    public function forCheck($product_category){
+        $category = json_decode($product_category,true);
+        if(in_array(ProductCategory::Special_for_sn, $category)) return true;
+        return false;
+    }
+
+    public function forCheck2($product_category){
+        $category = json_decode($product_category,true);
+        if(in_array(ProductCategory::Special_for_roll, $category)) return true;
+        return false;
+    }
+
     //保存sn
     public function saveSn($data, $type, $time){
         $data_id = $data['id'] ?? 0;
@@ -177,6 +222,8 @@ class DataSyncToU8Service extends Service
             ->where('type', $type)
             ->update(['del_time' => $time]);
 
+        $sn_type = $this->snListAccordingForOrder($data_id);
+        $update = [];
         if(! empty($data['product'])){
             $insert = [];
             foreach ($data['product'] as $value){
@@ -186,14 +233,18 @@ class DataSyncToU8Service extends Service
                     $insert[] = [
                         'product_id' => $value['product_id'],
                         'code' => $value['code'],
-                        'sn' => $sn_val,
+                        'sn' => $sn_val['sn'],
+                        'auto_id' => $sn_val['auto_id'],
                         'crt_time' => $time,
                         'data_id' => $data_id,
                         'type' => $type,
+                        'sn_type' => $sn_type,
                     ];
+                    if(! empty($sn_val['for_update'])) $update[] = $sn_val['auto_id'];
                 }
             }
 
+            if(! empty($update)) $this->updateSnInfo($sn_type, $update,$data_id);
             if(! empty($insert)) ProductSnInfo::insert($insert);
         }
     }
@@ -220,7 +271,7 @@ class DataSyncToU8Service extends Service
     }
 
     //获取在库的sn码信息通过sn码和产品编码
-    private function getSnForMap($code, $sn){
+    public function getSnForMap($code, $sn){
         $header = ['Content-Type:application/json'];
         $post = [
             'urlFromT9' => 'getSnMap',
@@ -229,6 +280,8 @@ class DataSyncToU8Service extends Service
         ];
         $post = json_encode($post);
         list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnforMap", $post, $header);
+        if(! $status) return [false, "用友数据获取失败"];
+
         if($msg['code'] != 200) return [false, $msg['msg']];
 
         return [true, $msg];
@@ -248,10 +301,29 @@ class DataSyncToU8Service extends Service
         if(empty($product)) return [false, '根据产品序列码查找到的产品编码:' . $return['code'] . '在门店系统中未找到该产品'];
         $product = $product->toArray();
         $product['sn'] = $data['sn'];
+        $product['auto_id'] = $return['auto_id'] ?? 0;
 
         return [true, $product];
     }
 
+    //更新sn信息
+    public function updateSnInfo($sn_type, $sn_for_u8,$data_id){
+        $header = ['Content-Type:application/json'];
+        $post = [
+            'urlFromT9' => 'saveSnUseData',
+            'sn_type' => $sn_type,
+            'sn_for_u8' => $sn_for_u8,
+            'data_id' => $data_id,
+        ];
+        $post = json_encode($post);
+        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/saveSnUseData", $post, $header);
+        if(! $status) return [false, "用友数据获取失败"];
+
+        if($msg['code'] != 200) return [false, $msg['msg']];
+
+        return [true, ''];
+    }
+
     public function snForWarranty($data){
         $header = ['Content-Type:application/json'];
         $post = [
@@ -260,6 +332,7 @@ class DataSyncToU8Service extends Service
         ];
         $post = json_encode($post);
         list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnForWarranty", $post, $header);
+        if(! $status) return [false, "用友数据获取失败"];
         if($msg['code'] != 200) return [false, $msg['msg']];
         $return = $msg['data'] ?? [];
         if(empty($return)) return [false, '产品序列码不存在'];
@@ -293,8 +366,8 @@ class DataSyncToU8Service extends Service
         foreach ($save as $value){
             //车窗膜不管sn使用次数
             $category = $category_map[$value['product_id']] ?? "";
-            $category = json_decode($category,true);
-            if(in_array(ProductCategory::Special_for_sn, $category)) continue;
+            $bool = $this->forCheck($category);
+            if($bool) continue;
 
             $key = $value['code'] . $value['sn'];
             if(in_array($key, $submit_info)) {

+ 3 - 2
app/Service/SalesOrderService.php

@@ -2543,10 +2543,11 @@ class SalesOrderService extends Service
         }
 
         $return = [];
+        $service = new DataSyncToU8Service();
         foreach ($product as $key => $value){
-            $category = json_decode($value['product_category'],true);
+            $bool = $service->forCheck($value['product_category']);
             //车窗膜不管数量算一个
-            if(in_array(ProductCategory::Special_for_sn, $category)) $value['number'] = 1;
+            if($bool) $value['number'] = 1;
 
             $sn_tmp = $product_map1[$value['product_id']] ?? 0;
             $return_tmp = $product_map2[$value['product_id']] ?? 0;

+ 28 - 3
app/Service/ScheduleService.php

@@ -648,7 +648,7 @@ class ScheduleService extends Service
         //可见范围
         $employee = (new RangeService())->RangeConstructionEmpDetail($order_id);
         //激活按钮
-        $warranty_button_map = $this->getWarrantyInfo($construction, $product);
+//        $warranty_button_map = $this->getWarrantyInfo($construction, $product);
         foreach ($construction as $value){
             $str = "";
             if(! empty($value['start_time']) && ! empty($value['end_time'])) $str = date('Y-m-d H:i',$value['start_time']) . '-' . date("Y-m-d H:i",$value['end_time']);
@@ -662,8 +662,11 @@ class ScheduleService extends Service
                 //待确认 分配/调配
                 $button = $this->fillFpButton($special_button,$special_button_map, $emp_tmp, 1);
             }elseif($value['state'] == Construction::STATE_FOUR){
-                $t = $warranty_button_map[$value['id']] ?? "";
-                $button = $this->fillWjButton($special_button,$special_button_map,$t);
+//                $t = $warranty_button_map[$value['id']] ?? "";
+//                $button = $this->fillWjButton($special_button,$special_button_map,$t);
+                $button = $this->fillFpButton2($special_button,$special_button_map);
+            }elseif ($value['state'] == Construction::STATE_FIVE){
+                $button = $this->fillFpButton2($special_button,$special_button_map,1);
             }
             $button = array_filter($button);
 
@@ -725,6 +728,28 @@ class ScheduleService extends Service
         return $button;
     }
 
+    public function fillFpButton2($special_button,$special_button_map, $type = 0){
+        $button = [];
+        if(! $type){
+            $button_tmp = $special_button_map[RoleMenuButton::special_eve] ?? [];
+            if(in_array(RoleMenuButton::special_eve,$special_button)){
+                $button_tmp['is_button'] = 1;
+            }else{
+                $button_tmp['is_button'] = 0;
+            }
+        }else{
+            $button_tmp = $special_button_map[RoleMenuButton::special_twl] ?? [];
+            if(in_array(RoleMenuButton::special_twl,$special_button)){
+                $button_tmp['is_button'] = 1;
+            }else{
+                $button_tmp['is_button'] = 0;
+            }
+        }
+        $button[] = $button_tmp;
+
+        return $button;
+    }
+
     public function fillWjButton($special_button,$special_button_map,$t){
         $button = [];
         $button_tmp = $special_button_map[RoleMenuButton::special_ten] ?? [];

+ 1 - 1
app/Service/Service.php

@@ -621,7 +621,7 @@ class Service
         return $days;
     }
 
-    public function post_helper($url, $data, $header = [], $timeout = 20){
+    public function post_helper($url, $data, $header = [], $timeout = 30){
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);

+ 220 - 4
app/Service/TSpaceService.php

@@ -214,11 +214,11 @@ class TSpaceService extends Service
                 $product_map2[$key] = $value['number'];
             }
         }
-
+        $service = new DataSyncToU8Service();
         foreach ($product as $value){
-            $category = json_decode($value['product_category'],true);
+            $bool = $service->forCheck($value['product_category']);
             //车窗膜不管数量算一个
-            if(in_array(ProductCategory::Special_for_sn, $category)) $value['number'] = 1;
+            if($bool) $value['number'] = 1;
 
             //合同质保产品
             $p1 = $product_map1[$value['product_id']] ?? 0;
@@ -242,6 +242,70 @@ class TSpaceService extends Service
         return $return;
     }
 
+    public function needSnFix($data, $user){
+        if(empty($data['id'])) return [false, '施工单id不能为空'];
+        //产品
+        $p_info = ConstructionProductInfo::where('del_time',0)
+            ->where('construction_id',$data['id'])
+            ->get()->toArray();
+        $basic_price = BasicType::whereIn('id',array_unique(array_column($p_info,'basic_type_id')))->pluck('title','id')->toArray();
+        $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
+
+        $product = [];
+        //sn码信息
+        $sn_map = (new DataSyncToU8Service())->getSn($data, ProductSnInfo::type_one);
+        $service = new DataSyncToU8Service();
+        $needSnFix = false;
+        foreach ($p_info as $value){
+            $tmp = $map[$value['product_id']] ?? [];
+            $value['title'] = $tmp['title'] ?? "";
+            $value['code'] = $tmp['code'] ?? "";
+            $value['size'] = $tmp['size'] ?? "";
+            $value['unit'] = $tmp['unit'] ?? "";
+            $value['bar_code'] = $tmp['bar_code'] ?? "";
+            $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
+            $s_t = $sn_map[$value['code']] ?? [];
+            $sn = array_column($s_t,'sn');
+            $value['product_sn_info'] = $sn;
+            $bool = $service->forCheck($tmp['product_category']);
+            $count = count($sn);
+            if($bool){
+                //如果车窗膜已经有sn码 则跳过
+                if($count > 0) {
+                    $product_type_for_sn = 0;
+                }else{
+                    if(! $needSnFix) $needSnFix = true;
+                    $product_type_for_sn = 1;
+                }
+            }else{
+                $bool = $service->forCheck2($tmp['product_category']);
+                if($bool){
+                    //如果除车窗膜外已经有sn码 则跳过
+                    if($count > 0) {
+                        $product_type_for_sn = 0;
+                    }else{
+                        if(! $needSnFix) $needSnFix = true;
+                        $product_type_for_sn = 1;
+                    }
+                }else{
+                    //其它产品数量达到 则跳过
+                    if($count >= $p_info['number']) {
+                        $product_type_for_sn = 0;
+                    }else{
+                        if(! $needSnFix) $needSnFix = true;
+                        $product_type_for_sn = 2;
+                    }
+                }
+            }
+            $value['product_type_for_sn'] = $product_type_for_sn;
+            $product[] = $value;
+        }
+
+        if(empty($needSnFix)) return [true, ['needSnFix' => $needSnFix, 'product' => $product]];
+
+        return [true, ['needSnFix' => $needSnFix, 'product' => $product]];
+    }
+
     public function warrantyAdd($data, $user){
         list($status, $msg) = $this->warrantyAddRule($data,$user);
         if(! $status) return [false, $msg];
@@ -494,6 +558,8 @@ class TSpaceService extends Service
             'crt_time' => $time,
             'crt_id' => 0,
             'is_active' => Warranty::type_one,
+            'sn_type' => 1,
+            'auto_id' => $data['auto_id'] ?? 0,
         ];
         $sn_update = [
             'data_id' => 0,
@@ -565,6 +631,12 @@ class TSpaceService extends Service
                     ];
                     ProductSnInfo::insert($sn_update);
                 }
+            }elseif($order['type'] == ProductSnInfo::type_one){
+                $update = [
+                    'construction_site_title' => $data['construction_site_title'] ?? '',
+                    'is_active' => Warranty::type_one
+                ];
+                Warranty::where('id',$data['id'])->update($update);
             }
 
             (new DataSyncToU8Service())->updateByVinNo($data);
@@ -610,7 +682,7 @@ class TSpaceService extends Service
     //后台列表
     public function warrantyList($data,$user){
         $model = Warranty::where('del_time',0)
-            ->select('id','data_id','data_title','code','type','product_id','title','sn','customer_name','customer_contact','vin_no','warranty_time','construction_site_title','start_time','crt_id','is_active','active_id')
+            ->select('id','data_id','data_title','code','type','product_id','title','sn','customer_name','customer_contact','vin_no','warranty_time','construction_site_title','start_time','crt_id','is_active','active_id','sy_code')
             ->orderBy('id','desc');
 
         if(! empty($data['type'])) $model->where('type', $data['type']);
@@ -626,6 +698,7 @@ class TSpaceService extends Service
         if(isset($data['is_active'])) $model->where('is_active', $data['is_active']);
         if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
         if(! empty($data['id'])) $model->where('id', $data['id']);
+        if(! empty($data['sy_code'])) $model->where('sy_code', 'LIKE', '%'.$data['sy_code'].'%');
 
         $list = $this->limit($model,'', $data);
         $list = $this->fillWarrantyList($list);
@@ -876,4 +949,147 @@ class TSpaceService extends Service
 
         return [true, ''];
     }
+
+    public function warrantyAddNew($order, $data, $user){
+        try {
+            DB::beginTransaction();
+
+            $data['id'] = $order['id'];
+            $time = time();
+            //保存sn关联关系
+            (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, $time);
+            $product_sn = ProductSnInfo::from('product_sn_info as a')
+                ->leftJoin('product as b','b.id','a.product_id')
+                ->select('a.*','b.title','b.warranty_time')
+                ->where('a.del_time',0)
+                ->where('a.data_id',$data['id'])
+                ->where('a.type', ProductSnInfo::type_one)
+                ->where('a.warranty_id', 0)
+                ->get()->toArray();
+            $construction_site = BasicType::where('id',$order['install_position'])->value('title') ?? "";
+
+            //生成质保单数据 需要更新的sn码信息
+            if(! empty($product_sn)){
+                $warranty = $sn_update = [];
+                foreach ($product_sn as $value){
+                    $warranty[] = [
+                        'data_id' => $order['id'],
+                        'data_title' => $order['order_number'],
+                        'type' => ProductSnInfo::type_one,
+                        'product_id' => $value['product_id'],
+                        'code' => $value['code'],
+                        'title' => $value['title'],
+                        'sn' => $value['sn'],
+                        'customer_id' => $order['customer_id'],
+                        'customer_name' => $order['customer_title'],
+                        'customer_contact' => $order['customer_info'],
+                        'vin_no' => $order['vin_no'],
+                        'warranty_time' => $value['warranty_time'],
+                        'construction_site_title' => $construction_site,
+                        'start_time' => $order['end_time'],
+                        'crt_time' => $time,
+                        'crt_id' => $user['id'],
+                        'sn_type' => $value['sn_type'],
+                        'sy_code' => ""
+                    ];
+                    $sn_update[] = $value['sn'];
+                }
+                if(! empty($warranty)) Warranty::insert($warranty);
+                if(! empty($sn_update)){
+                    $warranty_list = Warranty::where('del_time',0)
+                        ->whereIn("sn",$sn_update)
+                        ->select('id','sn')
+                        ->get()->toArray();
+                    foreach ($warranty_list as $value){
+                        ProductSnInfo::where('del_time',0)
+                            ->where('sn', $value['sn'])
+                            ->update(['warranty_id' => $value['id']]);
+                    }
+                }
+            }
+
+            //生成溯源码质保卡
+            $insert2 = $this->getInsert($data,$order,$construction_site,$time,$user);
+            if(! empty($insert2)) Warranty::insert($insert2);
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function getInsert($data,$order,$construction_site,$time,$user){
+        $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id'));
+        $service = new DataSyncToU8Service();
+        $insert2 = [];
+        foreach ($data['product'] as $value){
+            $tmp = $map[$value['product_id']] ?? [];
+            $bool = $service->forCheck($tmp['product_category']);
+            $value['warranty_time'] = $tmp['warranty_time'];
+            //没有sn码信息直接返回
+            if(empty($value['product_sn_info'])) {
+                if($bool){
+                    $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
+                }else{
+                    $bool = $service->forCheck2($tmp['product_category']);
+                    if($bool){
+                        $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
+                    }else{
+                        for ($i = 0; $i < intval($value['number']); $i++){
+                            $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
+                        }
+                    }
+                }
+            }else{
+                $num = count(array_column($value['product_sn_info'],'sn'));
+                if($bool){
+                    if($num < 1){
+                        $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
+                    }
+                }else{
+                    $bool = $service->forCheck2($tmp['product_category']);
+                    if($bool){
+                        if($num < 1){
+                            $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
+                        }
+                    }else{
+                        $n = bcsub($value['number'], $num,2);
+                        if(intval($n) > 0){
+                            for ($i = 0; $i < intval($value['number']); $i++){
+                                $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return $insert2;
+    }
+
+    public function fillInsert(&$insert2, $order, $value, $construction_site,$time,$user){
+        $insert2[] = [
+            'data_id' => $order['id'],
+            'data_title' => $order['order_number'],
+            'type' => ProductSnInfo::type_one,
+            'product_id' => $value['product_id'],
+            'code' => $value['code'],
+            'title' => $value['title'],
+            'sn' => "",
+            'customer_id' => $order['customer_id'],
+            'customer_name' => $order['customer_title'],
+            'customer_contact' => $order['customer_info'],
+            'vin_no' => $order['vin_no'],
+            'warranty_time' => $value['warranty_time'],
+            'construction_site_title' => $construction_site,
+            'start_time' => $order['end_time'],
+            'crt_time' => $time,
+            'crt_id' => $user['id'],
+//            'sn_type' => $value['sn_type'] ?? 0,
+            'sy_code' => $value['sy_code'] ?? "",
+        ];
+    }
 }

+ 18 - 4
config/specialButton.php

@@ -72,11 +72,25 @@ return [
         "func" => "special_show_customer_from",
         "menu_id" => 16,
     ],
+//    [
+//        "id" => \App\Model\RoleMenuButton::special_ten,
+//        "title" => "生成质保",
+//        "sort" => -10,
+//        "func" => "special_warranty_activation",
+//        "menu_id" => 34,
+//    ],
+    [
+        "id" => \App\Model\RoleMenuButton::special_eve,
+        "title" => "待验车",
+        "sort" => -11,
+        "func" => "special_sure_car",
+        "menu_id" => 34,
+    ],
     [
-        "id" => \App\Model\RoleMenuButton::special_ten,
-        "title" => "生成质保",
-        "sort" => -10,
-        "func" => "special_warranty_activation",
+        "id" => \App\Model\RoleMenuButton::special_twl,
+        "title" => "待交车",
+        "sort" => -12,
+        "func" => "special_wait_submit_car",
         "menu_id" => 34,
     ],
 ];

+ 19 - 0
config/wdt.php

@@ -0,0 +1,19 @@
+<?php
+//旺店通参数
+
+return [
+    //测试
+    0 => [
+      'sid' => 'apidevnew2',
+      'appKey' => 'tjdys03-test',
+      'appSecret' => '6f330a187',
+      'order_query' => 'https://sandbox.wangdian.cn/openapi2/trade_query.php', //订单查询管理
+    ],
+    //正式
+    1 => [
+        'sid' => '',
+        'appKey' => '',
+        'appSecret' => '',
+        'order_query' => 'https://api.wangdian.cn/openapi2/trade_query.php', //订单查询管理
+    ],
+];

+ 1 - 0
routes/api.php

@@ -385,6 +385,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //生成质保信息
     $route->any('warrantyGetProduct', 'Api\TSpaceController@warrantyGetProduct'); //合同获取能生成质保的产品
+    $route->any('needSnFix', 'Api\TSpaceController@needSnFix'); //是否补录的判断
     $route->any('warrantyAdd', 'Api\TSpaceController@warrantyAdd'); //生成质保
     $route->any('warrantyList', 'Api\TSpaceController@warrantyList'); //质保列表
     $route->any('warrantyEditAndActivation', 'Api\TSpaceController@warrantyEditAndActivation'); //后台人工编辑或激活质保

+ 2 - 0
routes/wx.php

@@ -147,4 +147,6 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('constructionEditSn', 'Api\ConstructionController@constructionEditSn');
     //生成质保
     $route->any('warrantyAdd', 'Api\TSpaceController@warrantyAdd'); //生成质保
+    $route->any('snListAccordingFromConstruction', 'Api\ConstructionController@snListAccording'); //是否补录的判断
+    $route->any('detailSnConstruction', 'Api\ConstructionController@detailSn'); //施工单产品
 });