Merge branch 'feature/distinct'
# Conflicts: # app/queue/redis/InquiryToCrmNew.php
This commit is contained in:
@@ -18,12 +18,13 @@ trait ResponseTrait
|
||||
*/
|
||||
public function success(
|
||||
$data = [],
|
||||
string $message = '请求成功',
|
||||
int $code = 200,
|
||||
string $message = '请求成功',
|
||||
string $status = 'success',
|
||||
int $code = 200,
|
||||
int $httpStatus = 200,
|
||||
array $header = ['Content-Type' => 'application/json']
|
||||
): Response {
|
||||
return $this->result('success', $code, $httpStatus, $message, $data, $header);
|
||||
return $this->result($status, $code, $httpStatus, $message, $data, $header);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class CustomerController extends BaseController
|
||||
try {
|
||||
$param = $request->all();
|
||||
$corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
|
||||
$param['corp_abbr'] = $corp->id;
|
||||
$param['corp_id'] = $corp->id;
|
||||
// $param['corp_abbr'] = $request->basic_data['corp_abbr'];
|
||||
$result = (new CustomerService())->list($param);
|
||||
|
||||
@@ -49,7 +49,7 @@ class CustomerController extends BaseController
|
||||
try {
|
||||
$param = $request->all();
|
||||
// $corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
|
||||
// $param['corp_abbr'] = $corp->id;
|
||||
// $param['corp_id'] = $corp->id;
|
||||
|
||||
$result = (new CustomerService())->export($param);
|
||||
$excelContent = file_get_contents($result['filepath']);
|
||||
|
||||
@@ -339,6 +339,7 @@ class CustomerService
|
||||
|
||||
$query= Customer::whereIn('id',explode(',',$customerId));
|
||||
$customer = $query->get();
|
||||
$user = User::where(['id' => $userId])->first();
|
||||
|
||||
foreach ($customer as $item) {
|
||||
//记录客户关系变化
|
||||
@@ -357,6 +358,7 @@ class CustomerService
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $userId,
|
||||
'corp_id' => $user->corp_id,
|
||||
'obtain' => time(),
|
||||
];
|
||||
$res = $query->update($data);
|
||||
|
||||
@@ -41,7 +41,7 @@ class InquiryToCrm implements Consumer
|
||||
// 同步客户数据
|
||||
$crmCustomer = new CrmCustomer();
|
||||
$crmCustomer->sn = $info->order_no;
|
||||
$crmCustomer->corp_abbr = $corpId;
|
||||
$crmCustomer->corp_id = $corpId;
|
||||
$crmCustomer->user_id = $recipient;
|
||||
$crmCustomer->type = 1;
|
||||
$crmCustomer->channel_id = $info->channel;
|
||||
@@ -54,6 +54,9 @@ class InquiryToCrm implements Consumer
|
||||
$crmCustomer->desc_collect = $info->content;
|
||||
$crmCustomer->enter_user_id = $info->enter_user_id;
|
||||
$crmCustomer->obtain = time();
|
||||
if(empty($recipient)){
|
||||
$crmCustomer->deleted_at = time();
|
||||
}
|
||||
// 修改同步CRM状态
|
||||
$info->sync_crm = 1;
|
||||
// 保存
|
||||
|
||||
@@ -105,7 +105,7 @@ class InquiryToCrmNew implements Consumer
|
||||
}
|
||||
|
||||
$udata = [
|
||||
'corp_abbr' => $uInfo['corpId'],
|
||||
'corp_id' => $uInfo['corpId'],
|
||||
'user_id' => $info->recipient,
|
||||
'channel_id' => $info->channel,
|
||||
'country_id' => $info->country,
|
||||
@@ -122,7 +122,7 @@ class InquiryToCrmNew implements Consumer
|
||||
} else {
|
||||
$crmCustomer = new CrmCustomer();
|
||||
$crmCustomer->sn = $info->order_no;
|
||||
$crmCustomer->corp_abbr = $uInfo['corpId'];
|
||||
$crmCustomer->corp_id = $uInfo['corpId'];
|
||||
$crmCustomer->user_id = $uInfo['recipient'];
|
||||
$crmCustomer->type = 1;
|
||||
$crmCustomer->channel_id = $info->channel;
|
||||
@@ -135,6 +135,9 @@ class InquiryToCrmNew implements Consumer
|
||||
$crmCustomer->desc_collect = $info->content;
|
||||
$crmCustomer->enter_user_id = $info->enter_user_id;
|
||||
$crmCustomer->obtain = time();
|
||||
if(empty($uInfo['recipient'])){
|
||||
$crmCustomer->deleted_at = time();
|
||||
}
|
||||
// 修改同步CRM状态
|
||||
$info->sync_crm = 1;
|
||||
// 保存
|
||||
|
||||
@@ -38,7 +38,7 @@ class InquiryToCrmUpdate implements Consumer
|
||||
$crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first();
|
||||
if ($crmCustomerInfo) {
|
||||
$udata = [
|
||||
'corp_abbr' => $corpId,
|
||||
'corp_id' => $corpId,
|
||||
'user_id' => $info->recipient,
|
||||
'channel_id' => $info->channel,
|
||||
'country_id' => $info->country,
|
||||
@@ -54,7 +54,7 @@ class InquiryToCrmUpdate implements Consumer
|
||||
// 同步客户数据
|
||||
$crmCustomer = new CrmCustomer();
|
||||
$crmCustomer->sn = $info->order_no;
|
||||
$crmCustomer->corp_abbr = $corpId;
|
||||
$crmCustomer->corp_id = $corpId;
|
||||
$crmCustomer->user_id = $info->recipient;
|
||||
$crmCustomer->type = 1;
|
||||
$crmCustomer->channel_id = $info->channel;
|
||||
@@ -66,6 +66,9 @@ class InquiryToCrmUpdate implements Consumer
|
||||
$crmCustomer->contacts = $info->contacts;
|
||||
$crmCustomer->desc_collect = $info->content;
|
||||
$crmCustomer->enter_user_id = $info->enter_user_id;
|
||||
if(empty($info->recipient)){
|
||||
$crmCustomer->deleted_at = time();
|
||||
}
|
||||
// 修改同步CRM状态
|
||||
$info->sync_crm = 1;
|
||||
// 保存
|
||||
|
||||
@@ -234,6 +234,7 @@ Route::group('/crm', function () {
|
||||
Route::any('/customer/getCountry', [app\crm\controller\CustomerController::class, 'getCountry']);
|
||||
Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']);
|
||||
Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']);
|
||||
Route::any('/customer/distinctNotice', [app\crm\controller\CustomerController::class, 'distinctNotice']);
|
||||
|
||||
Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']);
|
||||
Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);
|
||||
|
||||
Reference in New Issue
Block a user