|
@@ -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'] ?? "",
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|