orderRule($data); if(!$status) return [$status,$msg]; //操作人 $data['user_name'] = $user['emp_name']; // dd((new U8ServerService())->U8PO_PomainSave($data['id'])); try{ $job = ProcessDataJob::dispatch($data)->onQueue($data['job']); if(! $job) return [false,'任务没有进入队列!']; }catch (\Throwable $e){ return [false,$e->getMessage()]; } return [true,'']; } public function orderRule(&$data){ if(empty($data['type'])) return [false,'type不能为空!']; if(! in_array($data['type'],U8Job::$type)) return [false,'type不能存在!']; if(empty($data['id'])) return [false,'同步数据不能为空!']; $data['job'] = U8Job::$job[$data['type']] ?? ""; if(empty($data['job'])) return [false,'未找到同步任务!']; if($data['type'] == U8Job::one){ //采购同步校验 $bool = PurchaseOrder::whereIn('id',$data['id']) ->where('del_time',0) ->where('supplier',0) ->exists(); if($bool) return [false,'同步的采购单供应商不能为空!']; } return [true, '']; } public function snListAccording($data,$user){ //特殊的门店 $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 = $user['depart_top'][0] ?? []; $current_top_depart_id = $current_top_depart_id['depart_id'] ?? 0; if(in_array($current_top_depart_id, $bt_top_depart_id)){ //总社 直接读取sn码表 $sn_type = 1;//总社 }else{ $sn_type = 2;//分社 //发货单 sn码 } return [true, ['sn_type' => $sn_type]]; } public function getSnFromU8($data, $user){ if(empty($data['sn_type'])) return [false, 'sn码来源依据不能为空']; if(empty($data['code'])) return [false, '产品编码不能为空']; list($status,$return) = $this->getSnList($data, $user); return [$status, $return]; } public function getSnList($data, $user){ $header = ['Content-Type:application/json']; $post = [ 'urlFromT9' => 'getSnList', 'code' => $data['code'], 'sn' => $data['sn'] ?? "", 'sn_type' => $data['sn_type'], 'depart_title' => $this->getMyTopDepart($user,true), '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($msg['code'] != 200) return [false, $msg['msg']]; return [true, $msg['data'] ?? []]; } /** * 校验sn码 施工单 * @param $data * @param false $is_edit 是否补录 * @return array|string */ public function checkSnConstructionRule($data){ //产品字典 $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id')); $data_id = $data['id'] ?? 0; $sn_map = []; if($data_id) $sn_map = $this->getSn($data, ProductSnInfo::type_one); $code = $sn = []; foreach ($data['product'] as $value){ if(empty($value['code'])) return [false, '产品编码不能为空']; $code[] = $value['code']; //校验是否有不需要剔除的sn if($data_id){ $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']] ?? []; if(empty($tmp['warranty_time'])) return [false, "产品编码:" . $value['code'] . "质保时长(月)暂未设置"]; $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, '']; //获取在库的sn码信息 list($status, $msg) = $this->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; $submit_info[] = $key; if(! isset($sn_map[$key])) return [false, "产品编码:" . $value['code'] . "的产品序列码:" . $sn_val . "在用友中不存在"]; } } //校验sn是否被占用 list($status, $msg) = $this->snForCheck($code, $sn, $submit_info, $data); if(! $status) return [false, $msg]; return [true, '']; } //保存sn public function saveSn($data, $type, $time){ $data_id = $data['id'] ?? 0; ProductSnInfo::where('del_time',0) ->where('data_id', $data_id) ->where('type', $type) ->update(['del_time' => $time]); if(! empty($data['product'])){ $insert = []; foreach ($data['product'] as $value){ //没有sn码信息直接返回 if(empty($value['product_sn_info'])) continue; foreach ($value['product_sn_info'] as $sn_val){ $insert[] = [ 'product_id' => $value['product_id'], 'code' => $value['code'], 'sn' => $sn_val, 'crt_time' => $time, 'data_id' => $data_id, 'type' => $type, ]; } } if(! empty($insert)) ProductSnInfo::insert($insert); } } //获取sn详情 public function getSn($data, $type){ $data_id = $data['id'] ?? 0; $map = []; $sn = ProductSnInfo::where('del_time',0) ->where('data_id', $data_id) ->where('type', $type) ->select('product_id','code','sn','warranty_id') ->get()->toArray(); foreach ($sn as $value){ $map[$value['code']][] = [ 'sn' => $value['sn'], 'warranty_id' => $value['warranty_id'], ]; } return $map; } //获取在库的sn码信息通过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码信息通过sn码 客户手动创建质保 public function getSnForWarranty($data){ if(empty($data['sn'])) return [false, "产品序列码不能为空"]; list($status, $msg) = $this->snForWarranty($data); if(! $status) return [false, $msg]; $return = $msg; $product = Product::where('del_time',0) ->where('code', $return['code']) ->select('id','title','code','warranty_time') ->first(); if(empty($product)) return [false, '根据产品序列码查找到的产品编码:' . $return['code'] . '在门店系统中未找到该产品']; $product = $product->toArray(); $product['sn'] = $data['sn']; return [true, $product]; } public function snForWarranty($data){ $header = ['Content-Type:application/json']; $post = [ 'urlFromT9' => 'getSnForWarranty', 'sn' => $data['sn'], ]; $post = json_encode($post); list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnForWarranty", $post, $header); if($msg['code'] != 200) return [false, $msg['msg']]; $return = $msg['data'] ?? []; if(empty($return)) return [false, '产品序列码不存在']; return [true, $return]; } public function hasWarrantyInfo($data){ if(empty($data['customer_contact'])) return [false, "手机号码不能为空"]; $bool = Warranty::where('del_time',0) ->where('customer_contact', $data['customer_contact']) ->exists(); return [true, ['hasWarrantyInfo' => $bool]]; } //校验sn是否被占用 public 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','product_id') ->get()->toArray(); $category_map = Product::whereIn('id',array_unique(array_column($save,'product_id'))) ->pluck('product_category','id') ->toArray(); $data_id = $data['id'] ?? 0; $data_type = $data['data_type'] ?? ProductSnInfo::type_one; 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; $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'] != $data_type) return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$data_type]] . '使用'; } } } return [true, '']; } public function updateByVinNo($data){ if(empty($data['vin_no']) || empty($data['customer_name']) || empty($data['customer_contact'])) return; $vin_no = $data['vin_no']; $customer_name = $data['customer_name']; $customer_contact = $data['customer_contact']; Warranty::where('del_time',0) ->where('vin_no',$vin_no) ->update(["customer_name" => $customer_name, 'customer_contact' => $customer_contact]); } }