客户线索重复检查
This commit is contained in:
@@ -7,10 +7,12 @@ use app\model\Corp;
|
|||||||
use app\model\Customer;
|
use app\model\Customer;
|
||||||
use app\model\CustomerHis;
|
use app\model\CustomerHis;
|
||||||
use app\model\Follow;
|
use app\model\Follow;
|
||||||
|
use app\model\InquiryLog;
|
||||||
use app\model\User;
|
use app\model\User;
|
||||||
use app\service\UserService;
|
use app\service\UserService;
|
||||||
use app\util\Util;
|
use app\util\Util;
|
||||||
use config\constants\Constants;
|
use config\constants\Constants;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
@@ -330,6 +332,7 @@ class CustomerController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$user = User::where(['id' => $request->user['id']])->first();
|
$user = User::where(['id' => $request->user['id']])->first();
|
||||||
|
$whatsApp = Util::getParam($request, 'WhatsApp', '');
|
||||||
$data = [
|
$data = [
|
||||||
'user_id' => $request->user['id'],
|
'user_id' => $request->user['id'],
|
||||||
'corp_id' => $user->corp_id,
|
'corp_id' => $user->corp_id,
|
||||||
@@ -340,7 +343,7 @@ class CustomerController
|
|||||||
'magnitude' => Util::getParam($request, 'magnitude', 0),
|
'magnitude' => Util::getParam($request, 'magnitude', 0),
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'phone' => $phone,
|
'phone' => $phone,
|
||||||
'WhatsApp' => Util::getParam($request, 'WhatsApp', ''),
|
'WhatsApp' => $whatsApp,
|
||||||
'contacts' => $contacts,
|
'contacts' => $contacts,
|
||||||
'describe' => Util::getParam($request, 'describe'),
|
'describe' => Util::getParam($request, 'describe'),
|
||||||
'lat' => Util::getParam($request, 'lat', 0),
|
'lat' => Util::getParam($request, 'lat', 0),
|
||||||
@@ -350,6 +353,16 @@ class CustomerController
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (Util::isEmpty($id)) {
|
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);
|
$res = Customer::create($data);
|
||||||
} else {
|
} else {
|
||||||
unset($data['grade']);
|
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
|
* @param Request $request
|
||||||
@@ -399,6 +432,7 @@ class CustomerController
|
|||||||
'user_his' => 0,
|
'user_his' => 0,
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
]);
|
]);
|
||||||
|
self::inquiryUpdate($customer,$request->user['id']);
|
||||||
|
|
||||||
if ($res) {
|
if ($res) {
|
||||||
return Util::success($res, trans('success'));
|
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
|
* @param Request $request
|
||||||
@@ -440,6 +504,7 @@ class CustomerController
|
|||||||
'user_his' => $item->user_id,
|
'user_his' => $item->user_id,
|
||||||
'user_id' => $user['id'],
|
'user_id' => $user['id'],
|
||||||
]);
|
]);
|
||||||
|
self::inquiryUpdate($customer,$user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
|||||||
@@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user