From 8fa760a3bd27cce6820115a6eb2d9c5bc3b47144 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 15 Jul 2025 09:07:15 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/service/CategorieService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ticket/service/CategorieService.php b/app/ticket/service/CategorieService.php index 4954c85..67d1d74 100644 --- a/app/ticket/service/CategorieService.php +++ b/app/ticket/service/CategorieService.php @@ -14,7 +14,7 @@ class CategorieService public function list($params) { $result = (new CategorieLogic())->list($params); - $value=$result[0]->toArray(); +// $value=$result[0]->toArray(); foreach ($result as $key => &$value) { $value['name'] = isset($value['translation']) ? $value['translation']['name'] : ''; unset($value['translation']); From a9666cfd0fe767261f92a152f58715698781541d Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 25 Aug 2025 16:04:42 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=8F=90=E9=86=92?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/service/ConversationService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index 852fc0c..972938e 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -81,7 +81,7 @@ class ConversationService $ticket_status = $locale == 'zh'? Constants::TICKET_STATUS_ZH:Constants::TICKET_STATUS_EN; $content = str_replace($status_fanyi,$ticket_status,$data['content']); - $reply = $content?($content.'\n'.'工单内容:'):'' ; + $reply = $content?($content."\n".'工单内容:'):'' ; } $notice = ['sender_id' => 0, //发送人ID 0默认系统 From e1a10f9fb0c781866f4f1cdafc0f0b561a328e1b Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 25 Aug 2025 16:36:18 +0800 Subject: [PATCH 03/13] Revert "Merge branch 'feature/ticket' into develop" This reverts commit 69731bf0db07cfa47165415434319b4b361c3fad, reversing changes made to 375f77189e977005f3bc720a8f6c5bce1d8cebdc. --- config/whitelist.php | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 config/whitelist.php diff --git a/config/whitelist.php b/config/whitelist.php deleted file mode 100644 index 1736876..0000000 --- a/config/whitelist.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - '/', // 首页 - '/index/index', // 首页 - '/index/view', // 飞书调试 - '/perm', // 调试-添加权限 - - '/common/preset/corps', // 公司列表 - '/common/preset/feishu/app', // 飞书应用信息 - ] -]; \ No newline at end of file From b15c03f009cdcecbbc06a9b39ffd45ed731fb95e Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 25 Aug 2025 16:39:48 +0800 Subject: [PATCH 04/13] Merge branch 'develop' --- app/common/utils/email/Emails.php | 2 +- app/controller/IndexController.php | 34 ++-- app/inquiry/service/InquiryLogService.php | 10 +- app/queue/redis/InquiryToCrm.php | 7 - app/queue/redis/InquiryToCrmNew.php | 204 +++++++++++++++++++++ app/ticket/service/ConversationService.php | 43 +++-- 6 files changed, 254 insertions(+), 46 deletions(-) create mode 100644 app/queue/redis/InquiryToCrmNew.php diff --git a/app/common/utils/email/Emails.php b/app/common/utils/email/Emails.php index 6d67f1a..18b06c2 100644 --- a/app/common/utils/email/Emails.php +++ b/app/common/utils/email/Emails.php @@ -436,7 +436,7 @@ class Emails // 初始化 UID 轮询器 $uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804'); - $uidRotator->setUids([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158], false); + $uidRotator->setUids([64, 63, 83, 93, 108, 118, 132, 145, 150, 143, 156, 157, 158], false); EmailParsedResult::where('status', 0) ->chunkById($batchSize, function ($records) use ($delaySeconds, $throttleAfter, $throttleSeconds, $enterUser, $channelInfo, $uidRotator) { diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 8e15d2a..ba87d98 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -116,27 +116,33 @@ class IndexController // 'recipient' => [1], // ]; - $data['recipient'] = [1, 74]; - // // 同步推送 - // (new MessageNotificationsService())->pushNotice($data); + // $data['recipient'] = [1, 74]; + // // // 同步推送 + // // (new MessageNotificationsService())->pushNotice($data); - // 异步推送 - \Webman\RedisQueue\Redis::send('notice', $data); + // // 异步推送 + // \Webman\RedisQueue\Redis::send('notice', $data); - return 'success'; + $info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->where('id', 1)->where('sync_crm', 0)->first(); - // return json($data); + var_dump(empty($info->recipient)); - // $phone = ''; - // $email = ''; + if ($info) { + var_dump(11); + } else { + var_dump(22); + } - // $userByPhone = User::where('corp_id', 2)->where('phone', $phone)->where('phone', '!=', '')->first(); - // $userByEmail = User::where('corp_id', 2)->where('email', $email)->where('email', '!=', '')->first(); - // $user = $userByPhone ?: $userByEmail; - - // return json($user); + + if ($info !== NULL) { + var_dump(33); + } else { + var_dump(44); + } + + return json(['code' => 0, 'msg' => 'success']); } } \ No newline at end of file diff --git a/app/inquiry/service/InquiryLogService.php b/app/inquiry/service/InquiryLogService.php index 31c161a..8f189ea 100644 --- a/app/inquiry/service/InquiryLogService.php +++ b/app/inquiry/service/InquiryLogService.php @@ -262,7 +262,7 @@ class InquiryLogService */ protected function afterServiceRelease($res) { - RedisQueueRedis::send('inquiry-to-crm', $res); + RedisQueueRedis::send('inquiry-to-crm-new', $res); return $res; } @@ -271,7 +271,7 @@ class InquiryLogService */ protected function afterServiceAllocation($res) { - RedisQueueRedis::send('inquiry-to-crm', $res); + RedisQueueRedis::send('inquiry-to-crm-new', $res); return $res; } @@ -280,7 +280,7 @@ class InquiryLogService */ protected function afterServiceStore($res) { - RedisQueueRedis::send('inquiry-to-crm', $res); + RedisQueueRedis::send('inquiry-to-crm-new', $res); return $res; } @@ -290,7 +290,7 @@ class InquiryLogService protected function afterServiceUpdate($res) { if ($res['recipient']) { - RedisQueueRedis::send('inquiry-to-crm-update', $res); + RedisQueueRedis::send('inquiry-to-crm-new', $res); } return $res; } @@ -300,7 +300,7 @@ class InquiryLogService */ protected function afterServiceReAllocation($res) { - RedisQueueRedis::send('inquiry-to-crm-update', $res); + RedisQueueRedis::send('inquiry-to-crm-new', $res); return $res; } diff --git a/app/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 4d48d1c..4d7ca3e 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -37,13 +37,6 @@ class InquiryToCrm implements Consumer if ($uinfo) { $corpId = $uinfo->corp_id; } - // // 消息推送参数 分配 - // $scene = 'inquiry-person-allocation'; - // $receiveType = 'person'; - } else { - // // 消息推送参数 发布 - // $scene = 'inquiry-group-send'; - // $receiveType = 'group'; } // 同步客户数据 $crmCustomer = new CrmCustomer(); diff --git a/app/queue/redis/InquiryToCrmNew.php b/app/queue/redis/InquiryToCrmNew.php new file mode 100644 index 0000000..a350c7e --- /dev/null +++ b/app/queue/redis/InquiryToCrmNew.php @@ -0,0 +1,204 @@ +where('id', $data['id'])->first(); + + // 无论添加 或 更新,询单必然要存在 + if (!$info) { + throw new BusinessException('询盘不存在:' . $data['id']); + } + + if ($info->status == 0 && $info->recipient == 0) { + // 如果询单未发、未分,则不与crm同步,不做任何处理 + return true; + } + + // 更改库信息 + $this->syncCustomer($info); + } catch (\Throwable $th) { + throw $th; + } + } + + public function pushWs($title, $content, $recipient = []) + { + $wsdata = [ + 'sender_id' => 0, + 'sender_type' => 'system', + 'title' => $title, + 'content' => $content, + 'scene' => 1, + 'recipient' => $recipient + ]; + // 异步推送 + \Webman\RedisQueue\Redis::send('notice', $wsdata); + } + + public function syncCustomer(Model $info) + { + $uInfo = $this->recipientInfo($info); + $crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first(); + if ($crmCustomerInfo) { + + // 消息推送 + if ($info->status == 2 && empty($crmCustomerInfo->user_id)) { + // $notice = '分配'; + $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; + $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; + $recipient = [$info->recipient]; + $this->pushWs($title, $content, $recipient); + } else { + if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) { + // $notice = '更新'; + $title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; + $content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; + $recipient = [$info->recipient]; + $this->pushWs($title, $content, $recipient); + } else { + // $notice = '重新分配'; + $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; + $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; + $recipient = [$info->recipient]; + $this->pushWs($title, $content, $recipient); + } + } + + $udata = [ + 'corp_abbr' => $uInfo['corpId'], + 'user_id' => $info->recipient, + 'channel_id' => $info->channel, + 'country_id' => $info->country, + 'magnitude' => $info->quality, + 'email' => $info->email, + 'phone' => $info->tel, + 'WhatsApp' => $info->whatsapp, + 'contacts' => $info->contacts, + 'desc_collect' => $info->content, + ]; + if (!$crmCustomerInfo->update($udata)) { + throw new BusinessException('同步失败,更新客户线索失败'); + } + } else { + $crmCustomer = new CrmCustomer(); + $crmCustomer->sn = $info->order_no; + $crmCustomer->corp_abbr = $uInfo['corpId']; + $crmCustomer->user_id = $uInfo['recipient']; + $crmCustomer->type = 1; + $crmCustomer->channel_id = $info->channel; + $crmCustomer->country_id = $info->country; + $crmCustomer->magnitude = $info->quality; + $crmCustomer->email = $info->email; + $crmCustomer->phone = $info->tel; + $crmCustomer->WhatsApp = $info->whatsapp; + $crmCustomer->contacts = $info->contacts; + $crmCustomer->desc_collect = $info->content; + $crmCustomer->enter_user_id = $info->enter_user_id; + $crmCustomer->obtain = time(); + // 修改同步CRM状态 + $info->sync_crm = 1; + // 保存 + if (!$crmCustomer->save() || !$info->save()) { + throw new BusinessException('同步失败,创建客户线索失败'); + } + + // 消息推送 + if ($info->status == 1) { + // $notice = '发布'; + $title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; + $content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; + $recipient = [$info->recipient]; + $this->pushWs($title, $content); + } + + if ($info->status == 2) { + // $notice = '分配'; + $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; + $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; + $recipient = [$info->recipient]; + $this->pushWs($title, $content, $recipient); + } + } + return true; + } + + public function recipientInfo(Model $info) + { + $recipient = 0; + $corpId = 0; + $uinfo = null; + if (!empty($info->recipient)) { + $recipient = $info->recipient; + $uinfo = User::where('id', $info->recipient)->first(); + if ($uinfo) { + $corpId = $uinfo->corp_id; + } + } + return [ + 'recipient' => $recipient, + 'corpId' => $corpId, + 'uinfo' => $uinfo + ]; + } + + // 消费失败回调 + /* + $package = [ + 'id' => 1357277951, // 消息ID + 'time' => 1709170510, // 消息时间 + 'delay' => 0, // 延迟时间 + 'attempts' => 2, // 消费次数 + 'queue' => 'send-mail', // 队列名 + 'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容 + 'max_attempts' => 5, // 最大重试次数 + 'error' => '错误信息' // 错误信息 + ] + */ + public function onConsumeFailure(\Throwable $e, $package) + { + echo "consume failure\n"; + echo $e->getMessage() . "\n"; + // 无需反序列化 + var_export($package); + } +} \ No newline at end of file diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index ea97cef..972938e 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -3,6 +3,7 @@ namespace app\ticket\service; use app\common\model\User; +use app\common\service\MessageNotificationsService; use app\common\service\OssService; use app\ticket\logic\CategorieLogic; use app\ticket\logic\ConversationLogic; @@ -54,43 +55,47 @@ class ConversationService $ticket = (new TicketLogic())->find($data['ticket_id']); $categorie= (new CategorieLogic())->find($ticket['categorie_id']); $categorieName = isset($categorie['translation']) ? $categorie['translation']['name'] : ''; - - $notice = [ - 'code' => $ticket['code'], - 'category' => $categorieName, - 'content' => $data['content'], - 'reply' => '', - ]; - //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 - //$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱 - $emailDefault = env('TICKET_EMAIL_DEFAULT'); - if (empty($conversation)) { - $email = $emailDefault; + + $userDefault = [1, 75, 78]; + $tiket_content = $ticket['content']; + if (empty($conversation)) { //没有沟通记录 + $title = '新工单提醒-'.$categorieName; + $notice_user_id = $userDefault; }else{ + $title = '工单回复'; $tiket = (new TicketLogic())->find($conversation['ticket_id']); if($data['user_id'] != $tiket['user_id']){ - $email = User::where('id',$tiket['user_id'])->value('email'); + $notice_user_id = [$tiket['user_id']]; }else{ $conversationLast = Conversation::where('ticket_id', '=', $conversation['ticket_id']) ->where('user_id', '!=', $data['user_id']) ->orderBy('id', 'desc') ->first(); - $email = (!empty($conversationLast['user_id']))?User::where('id',$conversationLast['user_id'])->value('email',$emailDefault):$emailDefault; + $notice_user_id = (!empty($conversationLast['user_id']))? [$conversationLast['user_id']]:$userDefault; } - $notice['content'] = $tiket['content']; + $tiket_content = $tiket['content']; $status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS)); $locale = locale(); $ticket_status = $locale == 'zh'? Constants::TICKET_STATUS_ZH:Constants::TICKET_STATUS_EN; $content = str_replace($status_fanyi,$ticket_status,$data['content']); - $notice['reply'] = '
  • 最新回复:' . $content . '
  • '; - } - if(!empty($emailDefault)){ - \app\common\utils\email\MailSend::send($email, '【XYH】新的工单提醒', replaceTpl($notice, 'work_order')); + $reply = $content?($content."\n".'工单内容:'):'' ; } + $notice = ['sender_id' => 0, //发送人ID 0默认系统 + 'sender_type' => 'system', //发送者类型 user admin system + 'title' => $title, //标题 + 'content' => ($reply??'') . $tiket_content, //内容 + 'scene' => 1, //场景 0系统公共 1系统通知 + 'recipient' => $notice_user_id, //接收人 空为全部 + 'push_method' => 0 //推送方式0系统推送1手动推送 + ]; + + // 异步推送 + \Webman\RedisQueue\Redis::send('notice', $notice); + unset($data['categorie_id']); unset($data['code']); From 53294c795f52aaf847a3267180f32788d2602893 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 25 Aug 2025 17:46:40 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E8=84=B1=E6=95=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/utils/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/crm/utils/Util.php b/app/crm/utils/Util.php index 0701f5e..7bf4efd 100644 --- a/app/crm/utils/Util.php +++ b/app/crm/utils/Util.php @@ -126,7 +126,7 @@ class Util public static function mask($str) { - $length = strlen($str); + $length = mb_strlen($str); if(empty($str)){ return ''; From 7b280afd72372b86c41bc876353407ac2c39272d Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 25 Aug 2025 18:13:16 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/CustomerController.php | 19 +++++++++-- app/crm/controller/FollowController.php | 2 +- app/crm/service/CustomerService.php | 32 +++++++++++++++++++ .../controller/CustomerController.php | 4 +-- app/crmAdmin/service/CustomerService.php | 2 ++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index e51b83f..3b4b9a4 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -163,7 +163,7 @@ class CustomerController extends BaseController $perPage = $request->input('size', 10); $where = [ ['user_id', '=', $userId], -// ['corp_abbr', '=', $request->basic_data['corp_abbr']], + //['corp_abbr', '=', $request->basic_data['corp_abbr']], ['follow_next', '<>', 0], ]; @@ -306,6 +306,7 @@ class CustomerController extends BaseController $contacts = Util::getParam($request, 'contacts'); $email = Util::getParam($request, 'email'); $phone = Util::getParam($request, 'phone'); + $whatsApp = Util::getParam($request, 'WhatsApp', ''); if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) { return $this->error(trans('contacts_not_null')); } @@ -314,7 +315,7 @@ class CustomerController extends BaseController $corpId = $corpInfo->id; $data = [ 'user_id' => $request->user->uid, - 'corp_abbr' => $corpId, + 'corp_id' => $corpId, 'grade' => Util::getParam($request, 'grade', 0), 'channel_id' => $channel_id, 'country_id' => $country_id, @@ -322,7 +323,7 @@ class CustomerController extends BaseController '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), @@ -335,6 +336,15 @@ class CustomerController extends BaseController if (Util::isEmpty($id)) { $data['enter_user_id'] = $request->user->uid; + $distinct = [ + 'email' => $email, + 'phone' => $phone, + 'whatsapp' => $whatsApp, + ]; + $dis = (new CustomerService())->distinct($distinct,$corpId); + if($dis){ + return $this->error('客户线索重复,已经有人在跟进'); + } $res = Customer::create($data); } else { unset($data['grade']); @@ -506,12 +516,14 @@ class CustomerController extends BaseController { $customerId = Util::getParam($request, 'customer_id'); $userId = $request->user->uid; + $user = User::where(['id' => $userId])->first(); if (Util::isEmpty($customerId)) { return $this->error(trans('customer_id').trans('not_null')); } $data = [ 'user_id' => $request->user->uid, 'obtain' => time(), + 'corp_id' => $user->corp_id, ]; try { @@ -592,6 +604,7 @@ class CustomerController extends BaseController $data = [ 'user_id' => $user->id, 'obtain' => time(), + 'corp_id' => $user->corp_id, ]; $res = $query->update($data); diff --git a/app/crm/controller/FollowController.php b/app/crm/controller/FollowController.php index 42d6a01..9dc9ae0 100644 --- a/app/crm/controller/FollowController.php +++ b/app/crm/controller/FollowController.php @@ -103,7 +103,7 @@ class FollowController extends BaseController $corpId = $corpInfo->id; $data = [ 'user_id' => $request->user->uid, - 'corp_abbr' => $corpId, + 'corp_id' => $corpId, 'customer_id' => $customer_id, 'type' => $type, 'picture' => $picture, diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index a3559d5..3275d34 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -319,4 +319,36 @@ class CustomerService return $customer; } + + public function distinct($params,$corpId){ + + $customer = Customer::Orwhere('email', '=', $params['email']) + ->Orwhere('phone', '=', $params['phone']) + ->Orwhere('whatsApp', '=', $params['whatsApp']) + ->first(); + if (!empty($customer)) { + //客户重复,消息通知 + $user = User::where('id', $customer->user_id)->first(); + if($corpId != $customer->corp_id){ + return false; + } + $contacts = $customer->contacts??$params['phone']; + $contacts = $contacts??$params['whatsApp']; + $contacts = $contacts??$params['email']; + $data = [ + 'sender_id' => 0, //发送人ID 0默认系统 + 'sender_type' => 'system', //发送者类型 user admin system + 'title' => '客户跟进提醒 - ' . $contacts, //标题 + 'content' => $contacts . '有新的询单,请及时跟进', //内容 + 'scene' => 1, //场景 0系统公共 1系统通知 + 'recipient' => [$customer->user_id], //接收人 空为全部 + 'push_method' => 0 //推送方式0系统推送1手动推送 + ]; + + // 异步推送 + \Webman\RedisQueue\Redis::send('notice', $data); + return true; + } + return false; + } } \ No newline at end of file diff --git a/app/crmAdmin/controller/CustomerController.php b/app/crmAdmin/controller/CustomerController.php index c68bd18..6104fcd 100644 --- a/app/crmAdmin/controller/CustomerController.php +++ b/app/crmAdmin/controller/CustomerController.php @@ -29,7 +29,7 @@ class CustomerController extends BaseController try { $param = $request->all(); $corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first(); - $param['corp_abbr'] = $corp->id; + $param['corp_id'] = $corp->id; // $param['corp_abbr'] = $request->basic_data['corp_abbr']; $result = (new CustomerService())->list($param); @@ -49,7 +49,7 @@ class CustomerController extends BaseController try { $param = $request->all(); // $corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first(); -// $param['corp_abbr'] = $corp->id; +// $param['corp_id'] = $corp->id; $result = (new CustomerService())->export($param); $excelContent = file_get_contents($result['filepath']); diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 635b6cf..43682e5 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -339,6 +339,7 @@ class CustomerService $query= Customer::whereIn('id',explode(',',$customerId)); $customer = $query->get(); + $user = User::where(['id' => $userId])->first(); foreach ($customer as $item) { //记录客户关系变化 @@ -357,6 +358,7 @@ class CustomerService } $data = [ 'user_id' => $userId, + 'corp_id' => $user->corp_id, 'obtain' => time(), ]; $res = $query->update($data); From 958f4448d61dac40ead3c8fd8e0f53f6e627a18c Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 25 Aug 2025 18:17:14 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E8=AF=A2=E5=8D=95=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E5=88=B0crm=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queue/redis/InquiryToCrm.php | 5 ++++- app/queue/redis/InquiryToCrmNew.php | 7 +++++-- app/queue/redis/InquiryToCrmUpdate.php | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 4d7ca3e..ad973fd 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -41,7 +41,7 @@ class InquiryToCrm implements Consumer // 同步客户数据 $crmCustomer = new CrmCustomer(); $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_abbr = $corpId; + $crmCustomer->corp_id = $corpId; $crmCustomer->user_id = $recipient; $crmCustomer->type = 1; $crmCustomer->channel_id = $info->channel; @@ -54,6 +54,9 @@ class InquiryToCrm implements Consumer $crmCustomer->desc_collect = $info->content; $crmCustomer->enter_user_id = $info->enter_user_id; $crmCustomer->obtain = time(); + if(empty($recipient)){ + $crmCustomer->deleted_at = time(); + } // 修改同步CRM状态 $info->sync_crm = 1; // 保存 diff --git a/app/queue/redis/InquiryToCrmNew.php b/app/queue/redis/InquiryToCrmNew.php index a350c7e..075deda 100644 --- a/app/queue/redis/InquiryToCrmNew.php +++ b/app/queue/redis/InquiryToCrmNew.php @@ -105,7 +105,7 @@ class InquiryToCrmNew implements Consumer } $udata = [ - 'corp_abbr' => $uInfo['corpId'], + 'corp_id' => $uInfo['corpId'], 'user_id' => $info->recipient, 'channel_id' => $info->channel, 'country_id' => $info->country, @@ -122,7 +122,7 @@ class InquiryToCrmNew implements Consumer } else { $crmCustomer = new CrmCustomer(); $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_abbr = $uInfo['corpId']; + $crmCustomer->corp_id = $uInfo['corpId']; $crmCustomer->user_id = $uInfo['recipient']; $crmCustomer->type = 1; $crmCustomer->channel_id = $info->channel; @@ -135,6 +135,9 @@ class InquiryToCrmNew implements Consumer $crmCustomer->desc_collect = $info->content; $crmCustomer->enter_user_id = $info->enter_user_id; $crmCustomer->obtain = time(); + if(empty($uInfo['recipient'])){ + $crmCustomer->deleted_at = time(); + } // 修改同步CRM状态 $info->sync_crm = 1; // 保存 diff --git a/app/queue/redis/InquiryToCrmUpdate.php b/app/queue/redis/InquiryToCrmUpdate.php index c4e6d02..5a5a330 100644 --- a/app/queue/redis/InquiryToCrmUpdate.php +++ b/app/queue/redis/InquiryToCrmUpdate.php @@ -38,7 +38,7 @@ class InquiryToCrmUpdate implements Consumer $crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first(); if ($crmCustomerInfo) { $udata = [ - 'corp_abbr' => $corpId, + 'corp_id' => $corpId, 'user_id' => $info->recipient, 'channel_id' => $info->channel, 'country_id' => $info->country, @@ -54,7 +54,7 @@ class InquiryToCrmUpdate implements Consumer // 同步客户数据 $crmCustomer = new CrmCustomer(); $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_abbr = $corpId; + $crmCustomer->corp_id = $corpId; $crmCustomer->user_id = $info->recipient; $crmCustomer->type = 1; $crmCustomer->channel_id = $info->channel; @@ -66,6 +66,9 @@ class InquiryToCrmUpdate implements Consumer $crmCustomer->contacts = $info->contacts; $crmCustomer->desc_collect = $info->content; $crmCustomer->enter_user_id = $info->enter_user_id; + if(empty($info->recipient)){ + $crmCustomer->deleted_at = time(); + } // 修改同步CRM状态 $info->sync_crm = 1; // 保存 From e031c6dbd5899d637b82db5f76e9a9a78f9f7dbe Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 26 Aug 2025 09:29:46 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/traits/ResponseTrait.php | 7 +++-- app/crm/controller/CustomerController.php | 23 +++++++++++++-- app/crm/service/CustomerService.php | 36 ++++++++++++++++------- config/route.php | 1 + 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/app/common/traits/ResponseTrait.php b/app/common/traits/ResponseTrait.php index a8adc90..cc20773 100644 --- a/app/common/traits/ResponseTrait.php +++ b/app/common/traits/ResponseTrait.php @@ -18,12 +18,13 @@ trait ResponseTrait */ public function success( $data = [], - string $message = '请求成功', - int $code = 200, + string $message = '请求成功', + string $status = 'success', + int $code = 200, int $httpStatus = 200, array $header = ['Content-Type' => 'application/json'] ): Response { - return $this->result('success', $code, $httpStatus, $message, $data, $header); + return $this->result($status, $code, $httpStatus, $message, $data, $header); } /** diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 3b4b9a4..104eae5 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -339,11 +339,11 @@ class CustomerController extends BaseController $distinct = [ 'email' => $email, 'phone' => $phone, - 'whatsapp' => $whatsApp, + 'whatsApp' => $whatsApp, ]; $dis = (new CustomerService())->distinct($distinct,$corpId); if($dis){ - return $this->error('客户线索重复,已经有人在跟进'); + return $this->success($dis,'客户线索重复,已经业务跟进','distinct'); } $res = Customer::create($data); } else { @@ -361,6 +361,25 @@ class CustomerController extends BaseController } } + /** + * 重复通知 + * @param Request $request + * @return \support\Response + */ + public function distinctNotice(Request $request){ + $customer_id = Util::getParam($request, 'customer_id'); + if (Util::isEmpty($customer_id)) { + return $this->error('客户id不能为空'); + } + $res = (new CustomerService())->distinctNotice($customer_id); + + if ($res) { + return $this->success($res, '成功'); + } else { + return $this->error(trans('fail')); + } + } + /** diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 3275d34..fc1215c 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -322,24 +322,40 @@ class CustomerService public function distinct($params,$corpId){ - $customer = Customer::Orwhere('email', '=', $params['email']) + $customer = Customer::where('corp_id',$corpId) + ->Orwhere('email', '=', $params['email']) ->Orwhere('phone', '=', $params['phone']) ->Orwhere('whatsApp', '=', $params['whatsApp']) ->first(); if (!empty($customer)) { //客户重复,消息通知 - $user = User::where('id', $customer->user_id)->first(); - if($corpId != $customer->corp_id){ - return false; - } - $contacts = $customer->contacts??$params['phone']; - $contacts = $contacts??$params['whatsApp']; - $contacts = $contacts??$params['email']; +// if($corpId != $customer->corp_id){ +// return false; +// } + return $customer; + } + return false; + } + + /** + * 客户重复通知 + * @param $params + * @param $corpId + * @return Customer|false|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object + */ + public function distinctNotice($customer_id){ + + $customer = Customer::where('id', $customer_id) + ->first(); + if (!empty($customer)) { + $contacts = $customer->contacts??$customer['phone']; + $contacts = $contacts??$customer['whatsApp']; + $contacts = $contacts??$customer['email']; $data = [ 'sender_id' => 0, //发送人ID 0默认系统 'sender_type' => 'system', //发送者类型 user admin system 'title' => '客户跟进提醒 - ' . $contacts, //标题 - 'content' => $contacts . '有新的询单,请及时跟进', //内容 + 'content' => $contacts . ' 产生了新的询单,请及时跟进', //内容 'scene' => 1, //场景 0系统公共 1系统通知 'recipient' => [$customer->user_id], //接收人 空为全部 'push_method' => 0 //推送方式0系统推送1手动推送 @@ -347,7 +363,7 @@ class CustomerService // 异步推送 \Webman\RedisQueue\Redis::send('notice', $data); - return true; + return $customer; } return false; } diff --git a/config/route.php b/config/route.php index 6393f2d..86aa1a0 100644 --- a/config/route.php +++ b/config/route.php @@ -234,6 +234,7 @@ Route::group('/crm', function () { Route::any('/customer/getCountry', [app\crm\controller\CustomerController::class, 'getCountry']); Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']); Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']); + Route::any('/customer/distinctNotice', [app\crm\controller\CustomerController::class, 'distinctNotice']); Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']); Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']); From 8ba58958104a202ac62a511acfe2e56cba9e6e18 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 26 Aug 2025 15:50:29 +0800 Subject: [PATCH 09/13] =?UTF-8?q?crm=E5=8F=8D=E6=94=B9=E8=AF=A2=E5=8D=95?= =?UTF-8?q?=E5=BD=92=E5=B1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...UpdateInquiryLogFromCrmCustomerCommand.php | 144 ++++++++++++++++++ app/crm/controller/CustomerController.php | 20 +-- app/crm/service/CustomerService.php | 33 ++++ app/crmAdmin/service/CustomerService.php | 11 +- 4 files changed, 187 insertions(+), 21 deletions(-) create mode 100644 app/command/UpdateInquiryLogFromCrmCustomerCommand.php diff --git a/app/command/UpdateInquiryLogFromCrmCustomerCommand.php b/app/command/UpdateInquiryLogFromCrmCustomerCommand.php new file mode 100644 index 0000000..06afbc0 --- /dev/null +++ b/app/command/UpdateInquiryLogFromCrmCustomerCommand.php @@ -0,0 +1,144 @@ +setHelp('该命令将crm_customer表的user_id更新到inquiry_log表的recipient字段,将obtain字段更新到t_time字段。') + ->addOption('dry-run', null, InputOption::VALUE_NONE, '仅显示将要执行的更新操作,不实际执行') + ->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, '限制处理的记录数量', 5000); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $isDryRun = $input->getOption('dry-run'); + $limit = (int) $input->getOption('limit'); + + if ($isDryRun) { + $output->writeln('DRY RUN 模式 - 不会实际执行更新操作'); + } + + $output->writeln('开始更新 inquiry_log 表...'); + $output->writeln("处理限制: {$limit} 条记录"); + + try { + // 使用事务确保数据一致性 + DB::transaction(function () use ($output, $isDryRun, $limit) { + // 查询需要更新的记录 + $customers = Db::table('crm_customer') + ->select('id', 'sn', 'user_id', 'obtain','created_at') + ->whereNotNull('sn') + ->where('sn', '<>', '') + ->offset($limit) + ->limit(4000) + ->orderBy('id', 'asc') + ->get(); + + $output->writeln("找到 " . count($customers) . " 条客户记录需要处理"); + + $updatedCount = 0; + $skippedCount = 0; + $defaultTimestamp = strtotime('2025-08-26 00:00:00'); + + $output->writeln("找到 " . count($customers) . " 条客户记录需要处理"); + $step = []; + $updateId = []; + foreach ($customers as $customer) { + $output->writeln("处理客户 ID: {$customer->id}, SN: {$customer->sn}, User ID: {$customer->user_id}, obtain: {$customer->obtain}, created_at: {$customer->created_at}"); + // 查找匹配的 inquiry_log 记录 + $inquiryLog = Db::table('inquiry_log') + ->where('order_no', $customer->sn) + ->first(['id', 'recipient', 't_time']); + + if (!$inquiryLog) { + $step[] = $customer->id; + $output->writeln("跳过客户 ID {$customer->id} (sn: {$customer->sn}) - 未找到对应的 inquiry_log 记录"); + $skippedCount++; + continue; + } + $output->writeln("$inquiryLog->id"); + + // 准备更新数据 + $updateData = []; + + // 更新 recipient 字段 (user_id) + if ($customer->user_id != $inquiryLog->recipient) { + $updateData['recipient'] = $customer->user_id; + $output->writeln("客户 ID {$customer->id}: recipient 将从 {$inquiryLog->recipient} 更新为 {$customer->user_id}"); + } + + if(empty($customer->obtain)&& !empty($customer->user_id)){ + if($customer->user_id == $inquiryLog->recipient){ + $obtain = $inquiryLog->t_time; + }else{ + $obtain = strtotime('2025-08-01 10:00:00'); + $obtain = $customer->created_at > $obtain?$customer->created_at:$obtain; + } + Db::table('crm_customer') + ->where('id', $customer->id) + ->update(['obtain' => $obtain]); + $output->writeln("更新obtain $obtain"); + } + + // 更新 t_time 字段 (obtain) + $newTTime = $customer->obtain > 0 ? $customer->obtain : $defaultTimestamp; + if ($newTTime != $inquiryLog->t_time && !empty($updateData['recipient'])) { + $updateData['t_time'] = $newTTime; + $timeStr = date('Y-m-d H:i:s', $newTTime); + $output->writeln("客户 ID {$customer->id}: t_time 将从 " . ($inquiryLog->t_time ? date('Y-m-d H:i:s', $inquiryLog->t_time) : 'NULL') . " 更新为 {$timeStr}"); + } + if($customer->user_id == 0 && $inquiryLog->recipient != 0){ + $updateData['recipient'] = 0; + $updateData['t_time'] = time(); + $updateData['status'] = 1; + $updateData['r_time'] = time(); + + } + + // 如果有需要更新的字段,执行更新 + if (!empty($updateData)) { + $updateId[] = $customer->id; + if (!$isDryRun) { + Db::table('inquiry_log') + ->where('id', $inquiryLog->id) + ->update($updateData); + } + $updatedCount++; + $output->writeln("已更新 inquiry_log ID {$inquiryLog->id}"); + } else { + $output->writeln("客户 ID {$customer->id} - 无需更新"); + } + } + + $output->writeln("处理完成!"); + $output->writeln("总记录数: " . count($customers) . ""); + $updateIdstr = implode(",", $updateId); + $output->writeln("更新记录数: {$updatedCount},更新id:$updateIdstr"); + $stepstr = implode(",", $step); + $output->writeln("跳过记录数: {$skippedCount},跳过id: {$stepstr}"); + + if ($isDryRun) { + $output->writeln("DRY RUN 模式 - 未实际执行任何更新操作"); + } + }); + + return self::SUCCESS; + } catch (\Exception $e) { + $output->writeln('执行过程中发生错误: ' . $e->getMessage() . ''); + $output->writeln('错误位置: ' . $e->getFile() . ':' . $e->getLine() . ''); + return self::FAILURE; + } + } +} \ No newline at end of file diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 104eae5..2779b4c 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -444,6 +444,8 @@ class CustomerController extends BaseController 'user_his' => $userId, 'user_id' => 0, ]); + + CustomerService::inquiryUpdate($customer); } //软删除 @@ -562,13 +564,8 @@ class CustomerController extends BaseController 'user_his' => 0, 'user_id' => $userId, ]); - if (!empty($customer->sn) && $customer->type==1){ - $inquiryLog = InquiryLog::where('order_no', $customer->sn)->first(); - if (!empty($inquiryLog)) { - $inquiryLog->recipient = $userId; - $inquiryLog->save(); - } - } + + CustomerService::inquiryUpdate($customer, $data['user_id']); Db::commit(); } catch (\Throwable $e) { Db::rollback(); @@ -609,13 +606,8 @@ class CustomerController extends BaseController 'user_his' => $item->user_id, 'user_id' => $user['id'], ]); - if (!empty($customer->sn) && $customer->type==1){ - $inquiryLog = InquiryLog::where('order_no', $customer->sn)->first(); - if (!empty($inquiryLog)) { - $inquiryLog->recipient = $userId; - $inquiryLog->save(); - } - } + + CustomerService::inquiryUpdate($customer,$userId); $item->restore(); } diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index fc1215c..81909b1 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -4,6 +4,7 @@ namespace app\crm\service; use app\common\model\Corp; use app\common\model\CustomerAudit; +use app\common\model\InquiryLog; use app\common\model\User; use app\common\traits\crud\CrudServiceTrait; use app\crm\logic\CustomerLogic; @@ -246,12 +247,44 @@ class CustomerService $customer->status = 2; $res = $customer->save(); + self::inquiryUpdate($customer); + //软删除 $customer->delete(); return $res; } + /** + * 询单修改 + */ + 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 $customer * @param $request diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 43682e5..41bf5d7 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -348,13 +348,8 @@ class CustomerService 'user_his' => $item->user_id, 'user_id' => $userId, ]); - if (!empty($item->sn) && $item->type==1){ - $inquiryLog = InquiryLog::where('order_no', $item->sn)->first(); - if (!empty($inquiryLog)) { - $inquiryLog->recipient = $userId; - $inquiryLog->save(); - } - } + + \app\crm\service\CustomerService::inquiryUpdate($item,$userId); } $data = [ 'user_id' => $userId, @@ -391,6 +386,8 @@ class CustomerService 'user_his' => $item->user_id, 'user_id' => 0, ]); + + \app\crm\service\CustomerService::inquiryUpdate($item,0); } $res = $query->update(['user_id' => 0]); From 0f075a81f6c8316b9e063474c2f6f07e567146c6 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 26 Aug 2025 16:11:55 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/CustomerController.php | 2 +- app/crm/service/CustomerService.php | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 104eae5..5f3638a 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -307,7 +307,7 @@ class CustomerController extends BaseController $email = Util::getParam($request, 'email'); $phone = Util::getParam($request, 'phone'); $whatsApp = Util::getParam($request, 'WhatsApp', ''); - if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) { + if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone) && Util::isEmpty($whatsApp)) { return $this->error(trans('contacts_not_null')); } diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index fc1215c..ee4b695 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -15,6 +15,7 @@ use app\crm\model\CustomerHis; use app\crm\model\Follow; use app\crm\utils\Util; use config\constants\Constants; +use Illuminate\Database\Eloquent\Builder; use support\Request; /** @@ -320,13 +321,26 @@ class CustomerService return $customer; } + /** + * 查询客户关系是否重复 + */ public function distinct($params,$corpId){ $customer = Customer::where('corp_id',$corpId) - ->Orwhere('email', '=', $params['email']) - ->Orwhere('phone', '=', $params['phone']) - ->Orwhere('whatsApp', '=', $params['whatsApp']) + ->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']); +// $query->where('email', '=', $params['email']) +// ->Orwhere('phone', '=', $params['phone']) +// ->Orwhere('whatsApp', '=', $params['whatsApp']); + return $query; + })) ->first(); + if (!empty($customer)) { //客户重复,消息通知 // if($corpId != $customer->corp_id){ From cfda56cb9a1c0912f7a6bf83170c0837ba848a41 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 26 Aug 2025 16:24:46 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E8=B7=9F=E8=BF=9B=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/FollowController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/crm/controller/FollowController.php b/app/crm/controller/FollowController.php index 42d6a01..c60fa51 100644 --- a/app/crm/controller/FollowController.php +++ b/app/crm/controller/FollowController.php @@ -119,7 +119,7 @@ class FollowController extends BaseController $res = Follow::create($data); $customer = Customer::find($customer_id); - $customer->follow_last = strtotime($res->created_at); + $customer->follow_last = $res->created_at; $customer->follow_next = null; $customer->warn = 0; $customer->save(); From b176c01f54abc97bb2bc3b9c882c2b6c1ee0de51 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 27 Aug 2025 15:39:47 +0800 Subject: [PATCH 12/13] =?UTF-8?q?crm=E5=AE=A2=E6=88=B7=E6=89=80=E5=B1=9E?= =?UTF-8?q?=E5=85=AC=E5=8F=B8=E5=AD=97=E6=AE=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/CrmCustomer.php | 2 +- app/common/utils/email/Emails.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/model/CrmCustomer.php b/app/common/model/CrmCustomer.php index bc439db..2c262b3 100644 --- a/app/common/model/CrmCustomer.php +++ b/app/common/model/CrmCustomer.php @@ -40,7 +40,7 @@ class CrmCustomer extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'sn', 'corp_abbr', 'user_id', 'user_sn', 'type', 'grade', 'sex', 'channel_id', 'country_id', 'car_type_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'desc_collect', 'address', 'lat', 'lng', 'follow_last', 'follow_next', 'warn', 'follow_remark', 'enter_user_id', 'created_at', 'updated_at', 'deleted_at']; + protected $fillable = ['id', 'sn', 'corp_id', 'user_id', 'user_sn', 'type', 'grade', 'sex', 'channel_id', 'country_id', 'car_type_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'desc_collect', 'address', 'lat', 'lng', 'follow_last', 'follow_next', 'warn', 'follow_remark', 'enter_user_id', 'created_at', 'updated_at', 'deleted_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/utils/email/Emails.php b/app/common/utils/email/Emails.php index 18b06c2..933e6b4 100644 --- a/app/common/utils/email/Emails.php +++ b/app/common/utils/email/Emails.php @@ -480,7 +480,7 @@ class Emails // 同步客户 $crmCustomer = new CrmCustomer(); $crmCustomer->sn = $inquiryLogResult->order_no; - $crmCustomer->corp_abbr = $recipientInfo->corp_id; + $crmCustomer->corp_id = $recipientInfo->corp_id; $crmCustomer->user_id = $assignedUid; $crmCustomer->type = 1; $crmCustomer->channel_id = $inquiryLogResult->channel; From 45de47dd3d937c21af1d036ff46ae3462d4bf047 Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 1 Sep 2025 13:47:23 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E6=8A=A5=E9=87=8D=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/service/CustomerService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 01d8115..c20ceab 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -358,7 +358,10 @@ class CustomerService * 查询客户关系是否重复 */ public function distinct($params,$corpId){ - + // 9.1 add 报重修正 + if (!$params['email'] && !$params['phone'] && !$params['whatsApp']) { + return false; + } $customer = Customer::where('corp_id',$corpId) ->where((function (Builder $query) use ($params) { if(!empty($params['email']))