客户线索分配

This commit is contained in:
ylyg5690
2025-03-26 09:57:25 +08:00
committed by HESU\HESU
6 changed files with 145 additions and 7 deletions
+67
View File
@@ -5,6 +5,7 @@ namespace app\controller;
use app\model\Channel;
use app\model\Customer;
use app\model\Follow;
use app\service\UserService;
use app\util\Util;
use config\constants\Constants;
use support\Log;
@@ -12,6 +13,13 @@ use support\Request;
class CustomerController
{
/**
* 不需要登录的方法
*/
protected $noNeedLogin = ['collect'];
/**
* 客户分级
* @param Request $request
@@ -347,4 +355,63 @@ class CustomerController
}
}
/**
* 线索分配
* @param Request $request
* @return \support\Response
*/
public function collect(Request $request)
{
Log::info('send follow start',$request->all());
$user_sn = Util::getParam($request, 'user_sn'); //用户sn
$user_email = Util::getParam($request, 'user_email'); //邮箱
$sn = Util::getParam($request, 'order_no'); //客户sn验证客户唯一性
$channel_id = Util::getParam($request, 'channel_id'); //渠道
$country_id = Util::getParam($request, 'country_id'); //国家
$magnitude = Util::getParam($request, 'magnitude'); //商机
$describe = Util::getParam($request, 'describe'); //客户详情
$phone = Util::getParam($request, 'phone'); //用户详情
$email = Util::getParam($request, 'email'); //用户详情
$WhatsApp = Util::getParam($request, 'WhatsApp');
$contacts = Util::getParam($request, 'contacts'); //联系人
if (Util::isEmpty($user_sn)) {
return Util::fail([], '用户sn不能为空');
}
if (Util::isEmpty($user_email)) {
return Util::fail([], '用户邮箱不能为空');
}
if (Util::isEmpty($sn)) {
return Util::fail([], '客户sn不能为空');
}
$user = UserService::updateSn($user_sn, $user_email);
if(!$user){
return Util::fail($user, $user_email.'用户不存在');
}
$res = Customer::firstOrCreate(
['sn' => $sn],
[
'user_id' => $user->id,
'channel_id' => $channel_id,
'country_id' => $country_id,
'magnitude' => $magnitude,
'describe' => $describe,
'phone' => $phone,
'email' => $email,
'WhatsApp' => $WhatsApp,
'contacts' => $contacts,
]
);
if ($res) {
return Util::success($res, trans('success'));
} else {
return Util::fail($res, trans('fail'));
}
}
}
+11 -2
View File
@@ -5,6 +5,7 @@ namespace app\controller;
use app\model\Country;
use app\model\FeishuUser;
use app\model\User;
use app\model\UserSn;
use app\service\MailService;
use app\util\JwtUtil;
use app\util\Util;
@@ -153,12 +154,20 @@ class UserController
'role' => 1,
'password' => $hashedPassword,
'status' => 0,
'avatar' => 'vehicle_album/20250322/175585eeebcf44e8c2a2d50a5e8b5388_67ded58ca1011.jpg',
'sn' => substr(uniqid(), -8)
'avatar' => 'lingke_crm/logo.png'
];
if (Util::isEmpty($id)) {
// 获取编号
$userSnModel = new UserSn();
$sn = $userSnModel->where('user_id', '=', 0)->inRandomOrder()->first();
if (!$sn) {
throw new BusinessException('未找到适用编号');
}
$data['sn'] = $sn['user_sn'];
$res = User::create($data);
UserSn::where(['user_sn'=>$data['sn']])->update(['user_id'=>$res['id']]);
} else {
$res = User::where('id', $id)
->update($data);