cqpCow 1 年間 前
コミット
30125a285c
1 ファイル変更30 行追加0 行削除
  1. 30 0
      app/Service/CustomerService.php

+ 30 - 0
app/Service/CustomerService.php

@@ -563,6 +563,20 @@ class CustomerService extends Service
                 ->where('title',$data['title'])
 //                ->where('model_type',$data['model_type'])
                 ->exists();
+            if(! empty($data['customer_contact'])) {
+                $search = [];
+                foreach ($data['customer_contact'] as $value){
+                    $search[] = $value['info'];
+                }
+                $boolean = CustomerInfo::from('customer_info as a')
+                    ->join('customer as b','b.id','a.customer_id')
+                    ->where('a.del_time',0)
+                    ->where('b.del_time',0)
+                    ->where('b.top_depart_id',$data['top_depart_id'])
+                    ->whereIn('a.contact_info', $search)
+                    ->exists();
+                if($boolean) return [false,'客户联系内容已存在'];
+            }
         }else{
             if(empty($data['id'])) return [false,'ID不能为空'];
             $bool = Customer::where('del_time',0)
@@ -571,6 +585,22 @@ class CustomerService extends Service
                 ->where('title',$data['title'])
 //                ->where('model_type',$data['model_type'])
                 ->exists();
+
+            if(! empty($data['customer_contact'])) {
+                $search = [];
+                foreach ($data['customer_contact'] as $value){
+                    $search[] = $value['info'];
+                }
+                $boolean = CustomerInfo::from('customer_info as a')
+                    ->join('customer as b','b.id','a.customer_id')
+                    ->where('b.id','<>',$data['id'])
+                    ->where('a.del_time',0)
+                    ->where('b.del_time',0)
+                    ->where('b.top_depart_id',$data['top_depart_id'])
+                    ->whereIn('a.contact_info', $search)
+                    ->exists();
+                if($boolean) return [false,'客户联系内容已存在'];
+            }
         }
         if($bool) return [false,'客户名称不能重复'];