Merge branch 'feature/distinct'
# Conflicts: # app/queue/redis/InquiryToCrmNew.php
This commit is contained in:
@@ -163,7 +163,7 @@ class CustomerController extends BaseController
|
||||
$perPage = $request->input('size', 10);
|
||||
$where = [
|
||||
['user_id', '=', $userId],
|
||||
// ['corp_abbr', '=', $request->basic_data['corp_abbr']],
|
||||
//['corp_abbr', '=', $request->basic_data['corp_abbr']],
|
||||
['follow_next', '<>', 0],
|
||||
];
|
||||
|
||||
@@ -306,7 +306,8 @@ class CustomerController extends BaseController
|
||||
$contacts = Util::getParam($request, 'contacts');
|
||||
$email = Util::getParam($request, 'email');
|
||||
$phone = Util::getParam($request, 'phone');
|
||||
if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) {
|
||||
$whatsApp = Util::getParam($request, 'WhatsApp', '');
|
||||
if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone) && Util::isEmpty($whatsApp)) {
|
||||
return $this->error(trans('contacts_not_null'));
|
||||
}
|
||||
|
||||
@@ -314,7 +315,7 @@ class CustomerController extends BaseController
|
||||
$corpId = $corpInfo->id;
|
||||
$data = [
|
||||
'user_id' => $request->user->uid,
|
||||
'corp_abbr' => $corpId,
|
||||
'corp_id' => $corpId,
|
||||
'grade' => Util::getParam($request, 'grade', 0),
|
||||
'channel_id' => $channel_id,
|
||||
'country_id' => $country_id,
|
||||
@@ -322,7 +323,7 @@ class CustomerController extends BaseController
|
||||
'magnitude' => Util::getParam($request, 'magnitude', 0),
|
||||
'email' => $email,
|
||||
'phone' => $phone,
|
||||
'WhatsApp' => Util::getParam($request, 'WhatsApp', ''),
|
||||
'WhatsApp' => $whatsApp,
|
||||
'contacts' => $contacts,
|
||||
'describe' => Util::getParam($request, 'describe'),
|
||||
'lat' => Util::getParam($request, 'lat', 0),
|
||||
@@ -335,6 +336,15 @@ class CustomerController extends BaseController
|
||||
|
||||
if (Util::isEmpty($id)) {
|
||||
$data['enter_user_id'] = $request->user->uid;
|
||||
$distinct = [
|
||||
'email' => $email,
|
||||
'phone' => $phone,
|
||||
'whatsApp' => $whatsApp,
|
||||
];
|
||||
$dis = (new CustomerService())->distinct($distinct,$corpId);
|
||||
if($dis){
|
||||
return $this->success($dis,'客户线索重复,已经业务跟进','distinct');
|
||||
}
|
||||
$res = Customer::create($data);
|
||||
} else {
|
||||
unset($data['grade']);
|
||||
@@ -351,6 +361,25 @@ class CustomerController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复通知
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function distinctNotice(Request $request){
|
||||
$customer_id = Util::getParam($request, 'customer_id');
|
||||
if (Util::isEmpty($customer_id)) {
|
||||
return $this->error('客户id不能为空');
|
||||
}
|
||||
$res = (new CustomerService())->distinctNotice($customer_id);
|
||||
|
||||
if ($res) {
|
||||
return $this->success($res, '成功');
|
||||
} else {
|
||||
return $this->error(trans('fail'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -506,12 +535,14 @@ class CustomerController extends BaseController
|
||||
{
|
||||
$customerId = Util::getParam($request, 'customer_id');
|
||||
$userId = $request->user->uid;
|
||||
$user = User::where(['id' => $userId])->first();
|
||||
if (Util::isEmpty($customerId)) {
|
||||
return $this->error(trans('customer_id').trans('not_null'));
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $request->user->uid,
|
||||
'obtain' => time(),
|
||||
'corp_id' => $user->corp_id,
|
||||
];
|
||||
|
||||
try {
|
||||
@@ -592,6 +623,7 @@ class CustomerController extends BaseController
|
||||
$data = [
|
||||
'user_id' => $user->id,
|
||||
'obtain' => time(),
|
||||
'corp_id' => $user->corp_id,
|
||||
];
|
||||
$res = $query->update($data);
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ class FollowController extends BaseController
|
||||
$corpId = $corpInfo->id;
|
||||
$data = [
|
||||
'user_id' => $request->user->uid,
|
||||
'corp_abbr' => $corpId,
|
||||
'corp_id' => $corpId,
|
||||
'customer_id' => $customer_id,
|
||||
'type' => $type,
|
||||
'picture' => $picture,
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -319,4 +320,65 @@ class CustomerService
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询客户关系是否重复
|
||||
*/
|
||||
public function distinct($params,$corpId){
|
||||
|
||||
$customer = Customer::where('corp_id',$corpId)
|
||||
->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){
|
||||
// return false;
|
||||
// }
|
||||
return $customer;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户重复通知
|
||||
* @param $params
|
||||
* @param $corpId
|
||||
* @return Customer|false|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object
|
||||
*/
|
||||
public function distinctNotice($customer_id){
|
||||
|
||||
$customer = Customer::where('id', $customer_id)
|
||||
->first();
|
||||
if (!empty($customer)) {
|
||||
$contacts = $customer->contacts??$customer['phone'];
|
||||
$contacts = $contacts??$customer['whatsApp'];
|
||||
$contacts = $contacts??$customer['email'];
|
||||
$data = [
|
||||
'sender_id' => 0, //发送人ID 0默认系统
|
||||
'sender_type' => 'system', //发送者类型 user admin system
|
||||
'title' => '客户跟进提醒 - ' . $contacts, //标题
|
||||
'content' => $contacts . ' 产生了新的询单,请及时跟进', //内容
|
||||
'scene' => 1, //场景 0系统公共 1系统通知
|
||||
'recipient' => [$customer->user_id], //接收人 空为全部
|
||||
'push_method' => 0 //推送方式0系统推送1手动推送
|
||||
];
|
||||
|
||||
// 异步推送
|
||||
\Webman\RedisQueue\Redis::send('notice', $data);
|
||||
return $customer;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user