|
@@ -3,6 +3,7 @@
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
use App\Jobs\ProcessDataJob;
|
|
use App\Jobs\ProcessDataJob;
|
|
|
|
+use App\Model\ProductCategory;
|
|
use App\Model\ProductSnInfo;
|
|
use App\Model\ProductSnInfo;
|
|
use App\Model\PurchaseOrder;
|
|
use App\Model\PurchaseOrder;
|
|
use App\Model\Setting;
|
|
use App\Model\Setting;
|
|
@@ -92,32 +93,52 @@ class DataSyncToU8Service extends Service
|
|
return [true, $msg['data'] ?? []];
|
|
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 = [];
|
|
$code = $sn = [];
|
|
foreach ($data['product'] as $value){
|
|
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, '产品编码不能为空'];
|
|
if(empty($value['code'])) return [false, '产品编码不能为空'];
|
|
$code[] = $value['code'];
|
|
$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){
|
|
foreach ($value['product_sn_info'] as $sn_val){
|
|
$sn[] = $sn_val;
|
|
$sn[] = $sn_val;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(empty($sn)) return [true, ''];
|
|
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_list = $msg['data'];
|
|
$sn_map = [];
|
|
$sn_map = [];
|
|
foreach ($sn_list as $value){
|
|
foreach ($sn_list as $value){
|
|
@@ -125,6 +146,7 @@ class DataSyncToU8Service extends Service
|
|
$sn_map[$key] = "";
|
|
$sn_map[$key] = "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //校验用友
|
|
$submit_info = [];
|
|
$submit_info = [];
|
|
foreach ($data['product'] as $value){
|
|
foreach ($data['product'] as $value){
|
|
if(empty($value['product_sn_info'])) continue;
|
|
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, ''];
|
|
return [true, ''];
|
|
}
|
|
}
|
|
@@ -194,13 +202,54 @@ class DataSyncToU8Service extends Service
|
|
$sn = ProductSnInfo::where('del_time',0)
|
|
$sn = ProductSnInfo::where('del_time',0)
|
|
->where('data_id', $data_id)
|
|
->where('data_id', $data_id)
|
|
->where('type', $type)
|
|
->where('type', $type)
|
|
- ->select('product_id','code','sn')
|
|
|
|
|
|
+ ->select('product_id','code','sn','warranty_id')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
|
|
foreach ($sn as $value){
|
|
foreach ($sn as $value){
|
|
- $map[$value['code']][] = $value['sn'];
|
|
|
|
|
|
+ $map[$value['code']][] = [
|
|
|
|
+ 'sn' => $value['sn'],
|
|
|
|
+ 'warranty_id' => $value['warranty_id'],
|
|
|
|
+ ];
|
|
}
|
|
}
|
|
|
|
|
|
return $map;
|
|
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, ''];
|
|
|
|
+ }
|
|
}
|
|
}
|