客户线索分配

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);
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\model;
use support\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class UserSn extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_sn';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
+7 -4
View File
@@ -19,15 +19,18 @@ class MailService
{
// SMTP 配置
$this->mailer->isSMTP();
$this->mailer->Host = 'smtp.gmail.com';
// $this->mailer->Host = 'smtp.qq.com';
// $this->mailer->Host = 'smtp.gmail.com';
$this->mailer->Host = 'smtp.feishu.cn';
$this->mailer->SMTPAuth = true;
// $this->mailer->Username = 'xinyouhe25@gmail.com'; // 替换为你的 Gmail
// $this->mailer->Password = 'zhjkkaplncykzymo'; // 替换为应用专用密码
$this->mailer->Username = 'linyang0618@gmail.com'; // 替换为你的 Gmail
$this->mailer->Password = 'mrjefuahbwbpqakb'; // 替换为应用专用密码
// $this->mailer->Username = 'linyang0618@gmail.com'; // 替换为你的 Gmail
// $this->mailer->Password = 'mrjefuahbwbpqakb'; // 替换为应用专用密码
$this->mailer->Username = 'app@hnxinyouhe.com'; // 替换为你的 Gmail
$this->mailer->Password = 'akyIUFJ6ihGGjI5h'; // 替换为应用专用密码
// $this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // 使用 TLS
$this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // SSL 加密
// $this->mailer->Port = 587;
+1 -1
View File
@@ -17,7 +17,7 @@ class OssService
{
$this->accessKeyId = 'LTAI5tAGiH7bkVkmrniXnfkA';
$this->accessKeySecret = 'nqklJBft6t3S0A4ZvxF4ci9ni91kmm';
$this->bucket = 'vehicle-album';
$this->bucket = 'lingke_crm';
$this->endpoint = 'https://oss-cn-beijing.aliyuncs.com';
$this->ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace app\service;
use app\model\User;
use app\model\UserSn;
class UserService
{
/**
* 更新用户sn
* @param $sn
* @param $email
*/
public static function updateSn($sn, $email)
{
$user = User::first()
->where('email',$email)
->first();
return $user;
if(!$user){
return false;
}
if($user->sn != $sn){
UserSn::where(['sn' => $user->sn])->update(['user_id' => 0]);
UserSn::where(['sn' => $sn])->update(['user_id' => $user->id]);
$user->sn = $sn;
$user->save();
}
return $user;
}
}