diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 104eae5..5f3638a 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -307,7 +307,7 @@ class CustomerController extends BaseController $email = Util::getParam($request, 'email'); $phone = Util::getParam($request, 'phone'); $whatsApp = Util::getParam($request, 'WhatsApp', ''); - if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) { + if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone) && Util::isEmpty($whatsApp)) { return $this->error(trans('contacts_not_null')); } diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index fc1215c..ee4b695 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -15,6 +15,7 @@ use app\crm\model\CustomerHis; use app\crm\model\Follow; use app\crm\utils\Util; use config\constants\Constants; +use Illuminate\Database\Eloquent\Builder; use support\Request; /** @@ -320,13 +321,26 @@ class CustomerService return $customer; } + /** + * 查询客户关系是否重复 + */ public function distinct($params,$corpId){ $customer = Customer::where('corp_id',$corpId) - ->Orwhere('email', '=', $params['email']) - ->Orwhere('phone', '=', $params['phone']) - ->Orwhere('whatsApp', '=', $params['whatsApp']) + ->where((function (Builder $query) use ($params) { + if(!empty($params['email'])) + $query->Orwhere('email', '=', $params['email']); + if(!empty($params['phone'])) + $query->Orwhere('phone', '=', $params['phone']); + if(!empty($params['whatsApp'])) + $query->Orwhere('whatsApp', '=', $params['whatsApp']); +// $query->where('email', '=', $params['email']) +// ->Orwhere('phone', '=', $params['phone']) +// ->Orwhere('whatsApp', '=', $params['whatsApp']); + return $query; + })) ->first(); + if (!empty($customer)) { //客户重复,消息通知 // if($corpId != $customer->corp_id){