From 69ae53f545b1aa01427837bd53319d86ee0077cd Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Fri, 29 Aug 2025 18:49:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=BA=BF=E7=B4=A2=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 67 +++++++++++++++++++++++- app/model/InquiryLog.php | 74 +++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 app/model/InquiryLog.php diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index af5cacd..d08e216 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -7,10 +7,12 @@ use app\model\Corp; use app\model\Customer; use app\model\CustomerHis; use app\model\Follow; +use app\model\InquiryLog; use app\model\User; use app\service\UserService; use app\util\Util; use config\constants\Constants; +use Illuminate\Database\Eloquent\Builder; use support\Log; use support\Request; @@ -330,6 +332,7 @@ class CustomerController } $user = User::where(['id' => $request->user['id']])->first(); + $whatsApp = Util::getParam($request, 'WhatsApp', ''); $data = [ 'user_id' => $request->user['id'], 'corp_id' => $user->corp_id, @@ -340,7 +343,7 @@ class CustomerController 'magnitude' => Util::getParam($request, 'magnitude', 0), 'email' => $email, 'phone' => $phone, - 'WhatsApp' => Util::getParam($request, 'WhatsApp', ''), + 'WhatsApp' => $whatsApp, 'contacts' => $contacts, 'describe' => Util::getParam($request, 'describe'), 'lat' => Util::getParam($request, 'lat', 0), @@ -350,6 +353,16 @@ class CustomerController ]; 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); } else { 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 @@ -399,6 +432,7 @@ class CustomerController 'user_his' => 0, 'user_id' => $userId, ]); + self::inquiryUpdate($customer,$request->user['id']); if ($res) { 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 @@ -440,6 +504,7 @@ class CustomerController 'user_his' => $item->user_id, 'user_id' => $user['id'], ]); + self::inquiryUpdate($customer,$user->id); } $data = [ diff --git a/app/model/InquiryLog.php b/app/model/InquiryLog.php new file mode 100644 index 0000000..9004186 --- /dev/null +++ b/app/model/InquiryLog.php @@ -0,0 +1,74 @@ +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'); + } +} \ No newline at end of file