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/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