diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 2ce3c6c..ac48287 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -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')); + } + } + } \ No newline at end of file diff --git a/app/controller/UserController.php b/app/controller/UserController.php index e8f423e..a1fb4ff 100644 --- a/app/controller/UserController.php +++ b/app/controller/UserController.php @@ -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); diff --git a/app/model/UserSn.php b/app/model/UserSn.php new file mode 100644 index 0000000..dd7c55e --- /dev/null +++ b/app/model/UserSn.php @@ -0,0 +1,27 @@ +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; diff --git a/app/service/OssService.php b/app/service/OssService.php index 5e73783..2096240 100644 --- a/app/service/OssService.php +++ b/app/service/OssService.php @@ -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); } diff --git a/app/service/UserService.php b/app/service/UserService.php new file mode 100644 index 0000000..b934a91 --- /dev/null +++ b/app/service/UserService.php @@ -0,0 +1,32 @@ +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; + } +} \ No newline at end of file