客户线索重复检查

This commit is contained in:
2025-08-29 18:49:42 +08:00
parent 1500e39bb0
commit 69ae53f545
2 changed files with 140 additions and 1 deletions
+66 -1
View File
@@ -7,10 +7,12 @@ use app\model\Corp;
use app\model\Customer;
use app\model\CustomerHis;
use app\model\Follow;
use app\model\InquiryLog;
use app\model\User;
use app\service\UserService;
use app\util\Util;
use config\constants\Constants;
use Illuminate\Database\Eloquent\Builder;
use support\Log;
use support\Request;
@@ -330,6 +332,7 @@ class CustomerController
}
$user = User::where(['id' => $request->user['id']])->first();
$whatsApp = Util::getParam($request, 'WhatsApp', '');
$data = [
'user_id' => $request->user['id'],
'corp_id' => $user->corp_id,
@@ -340,7 +343,7 @@ class CustomerController
'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),
@@ -350,6 +353,16 @@ class CustomerController
];
if (Util::isEmpty($id)) {
$data['enter_user_id'] = $request->user->uid;
$distinct = [
'email' => $email,
'phone' => $phone,
'whatsapp' => $whatsApp,
];
$dis = $this->distinct($distinct, $user->corp_id);
if($dis){
return Util::fail([], '客户线索重复,已经有人在跟进');
}
$res = Customer::create($data);
} else {
unset($data['grade']);
@@ -366,6 +379,26 @@ class CustomerController
}
}
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']);
return $query;
}))
->first();
if (!empty($customer)) {
return true;
}
return false;
}
/**
* 领取公海客户
* @param Request $request
@@ -399,6 +432,7 @@ class CustomerController
'user_his' => 0,
'user_id' => $userId,
]);
self::inquiryUpdate($customer,$request->user['id']);
if ($res) {
return Util::success($res, trans('success'));
@@ -408,6 +442,36 @@ class CustomerController
}
/**
* 询单修改
*/
public static function inquiryUpdate($customer,$userId = null)
{
if(empty($customer->sn) || $customer->type!=1){
return false;
}
$inquiryLog = InquiryLog::where('order_no', $customer->sn)->first();
if(empty($inquiryLog)){
return false;
}
$userId = $userId??$customer->user_id;
if ($userId == 0){
$inquiryLog->recipient = 0;
$inquiryLog->t_time = time();
$inquiryLog->status = 1;
$inquiryLog->r_time = time();
$inquiryLog->save();
}else {
$inquiryLog->recipient = $customer->user_id;
$inquiryLog->t_time = time();
$inquiryLog->save();
}
return true;
}
/**
* 批量转让
* @param Request $request
@@ -440,6 +504,7 @@ class CustomerController
'user_his' => $item->user_id,
'user_id' => $user['id'],
]);
self::inquiryUpdate($customer,$user->id);
}
$data = [
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace app\model;
use support\Model;
class InquiryLog extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'inquiry_log';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = [
'id', 'order_no', 'enter_user_id', 'recipient',
'quality', 'channel', 'email', 'tel', 'whatsapp',
'country', 'contacts', 'content', 'status',
'r_time', 't_time', 'created_at', 'updated_at'
];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
public function enter()
{
return $this->hasOne(User::class, 'id', 'enter_user_id');
}
// public function recipientInfo()
// {
// return $this->hasOne(User::class, 'id', 'recipient')->where('status', 1);
// }
public function recipientInfo()
{
return $this->hasOne(User::class, 'id', 'recipient');
}
public function countryInfo()
{
return $this->hasOne(Country::class, 'id', 'country');
}
}