From 2b052ec2b43a8b6f3e86472d6d092e9b36b4d6a4 Mon Sep 17 00:00:00 2001 From: mzl Date: Fri, 25 Jul 2025 13:39:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9E=E4=B9=A6=E6=B6=88=E6=81=AF=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/NotifyController.php | 136 +++++ app/common/model/CrmCustomer.php | 2 +- app/common/model/InquiryLog.php | 4 +- app/common/utils/FeishuMessage.php | 555 +++++++++++++++++++++ app/controller/IndexController.php | 20 +- app/inquiry/service/InquiryLogService.php | 45 +- app/queue/redis/FeishuMessage.php | 127 +++++ app/queue/redis/InquiryToCrm.php | 20 +- config/route.php | 4 + config/whitelist.php | 13 - 10 files changed, 904 insertions(+), 22 deletions(-) create mode 100644 app/common/controller/NotifyController.php create mode 100644 app/common/utils/FeishuMessage.php create mode 100644 app/queue/redis/FeishuMessage.php delete mode 100644 config/whitelist.php diff --git a/app/common/controller/NotifyController.php b/app/common/controller/NotifyController.php new file mode 100644 index 0000000..9e4fffb --- /dev/null +++ b/app/common/controller/NotifyController.php @@ -0,0 +1,136 @@ +post(); + + // 解析数据 + // $param = json_decode($param['event'], true); + $orderSn = $param['event']['action']['value']; + if (strpos($orderSn, '"') !== false) { + $orderSn = str_replace('"', '', $orderSn); + } + + // 处理询单&客户线索信息 + $openId = $param['event']['operator']['open_id']; + + // 获取询单 + $order = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->where('order_no', $orderSn)->first(); + if (!$order) { + return $this->error('未找到询单记录'); + } + + // 获取客户xians + $customer = CrmCustomer::where('sn', $orderSn)->first(); + if (!$customer) { + return $this->error('未找到客户线索'); + } + + // 获取用户 + $uinfo = User::where('open_id', $openId)->first(); + + // 更新客户线索 + $customer->user_id = $uinfo->id; + + // 更新询单数据 + $order->recipient = $uinfo->id; + $order->status = 2; + $order->t_time = time(); + + // 保存 + if (!$order->save() || !$customer->save()) { + return $this->error('跟踪失败'); + } + + // 获取飞书消息模板 + $feishuMessage = new FeishuMessage(); + $content = $feishuMessage->groupUpdateTemplates( + (new InquiryLogService())->qualityName($order->quality), + $order->order_no, + $order->channelInfo ? $order->channelInfo->name : '', + $order->countryInfo ? $order->countryInfo->cn_addr : '', + $order->enter ? $order->enter->name : '', + $order->r_time ? date('Y-m-d H:i:s', $order->r_time) : '', + $order->t_time ? date('Y-m-d H:i:s', $order->t_time) : '' + ); + + // 组装飞书消息模板 + $data = '{ + "toast": { + "type": "success", + "content": "操作成功" + }, + "card": { + "type": "raw", + "data": '.$content.' + } + }'; + + // 响应消息 + return new Response(200, ['Content-Type' => 'application/json'], $data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + public function error($msg = '') + { + $data = '{ + "toast": { + "type": "error", + "content": "'.$msg.'" + } + }'; + return new Response(200, ['Content-Type' => 'application/json'], $data); + } + + /** + * 飞书事件 + * @param Request $request + * @return Response + */ + public function feishuEvent(Request $request) + { + try { + $data = $request->post(); + + var_dump($data); + + return json($data); + } catch (\Throwable $e) { + return json($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/common/model/CrmCustomer.php b/app/common/model/CrmCustomer.php index e5a40b7..49446e6 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', 'created_at', 'updated_at', 'deleted_at']; + 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']; /** * 不允许自动填充模型字段 diff --git a/app/common/model/InquiryLog.php b/app/common/model/InquiryLog.php index b8820b1..ce01b4a 100644 --- a/app/common/model/InquiryLog.php +++ b/app/common/model/InquiryLog.php @@ -65,12 +65,12 @@ class InquiryLog extends Model return $this->hasOne(User::class, 'id', 'recipient'); } - public function channel() + public function channelInfo() { return $this->hasOne(InquiryChannel::class, 'id', 'channel'); } - public function country() + public function countryInfo() { return $this->hasOne(Country::class, 'id', 'country'); } diff --git a/app/common/utils/FeishuMessage.php b/app/common/utils/FeishuMessage.php new file mode 100644 index 0000000..311ffd9 --- /dev/null +++ b/app/common/utils/FeishuMessage.php @@ -0,0 +1,555 @@ +class = new Feishu($this->app_id, $this->app_secret); + } + + /** + * 飞书消息模板 + * @param string $scene + * @param array $options + */ + public function messageTemplates(string $scene = 'group-send', array $options = []) + { + try { + $template = match ($scene) { + 'inquiry-group-send' => $this->groupNewTemplates( + $options['quality'], + $options['order_no'], + $options['channel'], + $options['country'], + $options['enter_user'], + $options['r_time'] + ), + 'inquiry-group-update' => $this->groupUpdateTemplates( + $options['quality'], + $options['order_no'], + $options['channel'], + $options['country'], + $options['enter_user'], + $options['r_time'], + $options['t_time'] + ), + 'inquiry-person-allocation' => $this->personAllocationTemplates( + $options['quality'], + $options['order_no'], + $options['channel'], + $options['country'], + $options['enter_user'], + $options['r_time'], + $options['t_time'] + ), + 'crm-person-follow-up' => $this->personFollowUpTemplates( + $options['contacts'], + $options['follow_next'], + $options['follow_last'] + ) + }; + } catch (\UnhandledMatchError $e) { + throw new BusinessException($e->getMessage()); + } + return $template; + } + + /** + * 发送飞书消息 + * @param array $options + */ + public function messageSend(string $scene = 'group-send', array $options = []) + { + $template = $this->messageTemplates($scene, $options); + $result = $this->class->sendMessages($options['receive_id'], $template, $options['msg_type'], $options['receive_id_type']); + if (!isset($result['code']) || $result['code'] !== 0) { + throw new BusinessException('发送飞书消息失败'); + } + return $result; + } + + /** + * 线索消息发送 + */ + public function groupNewTemplates($quality = '💛 银牌商机', $order_no = 'SN2025072365640', $channel = '谷歌', $country = '白俄罗斯', $enter_user = '木子李', $r_time = '2025-07-24 09:41:23') + { + $content = '{ + "schema": "2.0", + "config": { + "update_multi": true, + "style": { + "text_size": { + "normal_v2": { + "default": "normal", + "pc": "normal", + "mobile": "heading" + } + } + } + }, + "body": { + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "16px", + "horizontal_align": "left", + "vertical_align": "top", + "padding": "0px 20px 20px 20px", + "elements": [ + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "column_set", + "horizontal_align": "left", + "columns": [ + { + "tag": "column", + "width": "weighted", + "elements": [ + { + "tag": "markdown", + "content": " **'.$quality.'**\n- **编号:** '.$order_no.'\n- **渠道:** '.$channel.'\n- **国家:** '.$country.'\n- **发布人:** '.$enter_user.'\n- **发布时间:** '.$r_time.'", + "text_align": "left", + "text_size": "normal_v2", + "margin": "0px 0px 0px 0px" + } + ], + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top", + "weight": 1 + } + ] + }, + { + "tag": "form", + "elements": [ + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "column_set", + "flex_mode": "stretch", + "horizontal_spacing": "8px", + "horizontal_align": "left", + "columns": [ + { + "tag": "column", + "width": "auto", + "elements": [ + { + "tag": "button", + "text": { + "tag": "plain_text", + "content": "立即跟踪" + }, + "type": "primary_filled", + "width": "fill", + "size": "medium", + "icon": { + "tag": "standard_icon", + "token": "list-check-bold_outlined" + }, + "confirm": { + "title": { + "tag": "plain_text", + "content": "确认跟踪?" + }, + "text": { + "tag": "plain_text", + "content": "客户线索:'.$order_no.'" + } + }, + "behaviors": [ + { + "type": "callback", + "value": "'.$order_no.'" + } + ], + "form_action_type": "submit", + "name": "Button_m7d0zqa2", + "element_id": "track" + } + ], + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top" + }, + { + "tag": "column", + "width": "auto", + "elements": [], + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top" + }, + { + "tag": "column", + "width": "auto", + "elements": [], + "padding": "0px 0px 0px 0px", + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top", + "margin": "0px 0px 0px 0px" + } + ], + "margin": "4px 0px 0px 0px" + } + ], + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "12px", + "horizontal_align": "left", + "vertical_align": "top", + "padding": "0px 0px 0px 0px", + "margin": "0px 0px 0px 0px", + "name": "Form_m7d0zqa1" + } + ] + }, + "header": { + "title": { + "tag": "plain_text", + "content": "新的【公海】客户线索" + }, + "subtitle": { + "tag": "plain_text", + "content": "" + }, + "template": "default", + "icon": { + "tag": "standard_icon", + "token": "ai-common_colorful" + }, + "padding": "12px 12px 12px 20px" + } + }'; + return $content; + } + + /** + * 线索消息更新 + */ + public function groupUpdateTemplates($quality = '💛 银牌商机', $order_no = 'SN2025072365640', $channel = '谷歌', $country = '白俄罗斯', $enter_user = '木子李', $r_time = '2025-07-24 09:41:23', $t_time = '2025-07-24 14:41:23') + { + $content = '{ + "schema": "2.0", + "config": { + "update_multi": true, + "style": { + "text_size": { + "normal_v2": { + "default": "normal", + "pc": "normal", + "mobile": "heading" + } + } + } + }, + "body": { + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "16px", + "horizontal_align": "left", + "vertical_align": "top", + "padding": "0px 20px 20px 20px", + "elements": [ + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "column_set", + "horizontal_align": "left", + "columns": [ + { + "tag": "column", + "width": "weighted", + "elements": [ + { + "tag": "markdown", + "content": " **'.$quality.'**\n- **编号:** '.$order_no.'\n- **渠道:** '.$channel.'\n- **国家:** '.$country.'\n- **发布人:** '.$enter_user.'\n- **发布时间:** '.$r_time.'", + "text_align": "left", + "text_size": "normal_v2", + "margin": "0px 0px 0px 0px" + } + ], + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top", + "weight": 1 + } + ] + }, + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "div", + "text": { + "tag": "plain_text", + "content": "跟踪时间:'.$t_time.'", + "text_size": "notation", + "text_align": "left", + "text_color": "green" + }, + "icon": { + "tag": "standard_icon", + "token": "chat-done_outlined", + "color": "green" + }, + "element_id": "track_time" + } + ] + }, + "header": { + "title": { + "tag": "plain_text", + "content": "【公海】客户线索" + }, + "subtitle": { + "tag": "plain_text", + "content": "" + }, + "text_tag_list": [ + { + "tag": "text_tag", + "text": { + "tag": "plain_text", + "content": "已跟踪" + }, + "color": "orange" + } + ], + "template": "green", + "icon": { + "tag": "standard_icon", + "token": "ai-common_colorful" + }, + "padding": "12px 12px 12px 20px" + } + }'; + return $content; + } + + /** + * 线索分配消息 + */ + public function personAllocationTemplates($quality = '💛 银牌商机', $order_no = 'SN2025072365640', $channel = '谷歌', $country = '白俄罗斯', $enter_user = '木子李', $r_time = '2025-07-24 09:41:23', $t_time = '2025-07-24 14:41:23') + { + $content = '{ + "schema": "2.0", + "config": { + "update_multi": true, + "style": { + "text_size": { + "normal_v2": { + "default": "normal", + "pc": "normal", + "mobile": "heading" + } + } + } + }, + "body": { + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "16px", + "horizontal_align": "left", + "vertical_align": "top", + "padding": "0px 20px 20px 20px", + "elements": [ + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "column_set", + "horizontal_align": "left", + "columns": [ + { + "tag": "column", + "width": "weighted", + "elements": [ + { + "tag": "markdown", + "content": " **'.$quality.'**\n- **编号:** '.$order_no.'\n- **渠道:** '.$channel.'\n- **国家:** '.$country.'\n- **录单人:** '.$enter_user.'\n- **录入时间:** '.$r_time.'", + "text_align": "left", + "text_size": "normal_v2", + "margin": "0px 0px 0px 0px" + } + ], + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top", + "weight": 1 + } + ] + }, + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "div", + "text": { + "tag": "plain_text", + "content": "分配时间:'.$t_time.'", + "text_size": "notation", + "text_align": "left", + "text_color": "green" + }, + "icon": { + "tag": "standard_icon", + "token": "chat-done_outlined", + "color": "green" + }, + "element_id": "allocation_time" + } + ] + }, + "header": { + "title": { + "tag": "plain_text", + "content": "新的客户线索" + }, + "subtitle": { + "tag": "plain_text", + "content": "" + }, + "text_tag_list": [ + { + "tag": "text_tag", + "text": { + "tag": "plain_text", + "content": "指定" + }, + "color": "yellow" + } + ], + "template": "blue", + "icon": { + "tag": "standard_icon", + "token": "todo_colorful" + }, + "padding": "12px 12px 12px 20px" + } + }'; + return $content; + } + + /** + * 跟进提醒消息 + */ + public function personFollowUpTemplates($contacts = '木子李', $follow_next = '2025-07-24 14:41:23', $follow_last = '2025-07-24 14:41:23') + { + $content = '{ + "schema": "2.0", + "config": { + "update_multi": true, + "style": { + "text_size": { + "normal_v2": { + "default": "normal", + "pc": "normal", + "mobile": "heading" + } + } + } + }, + "body": { + "direction": "vertical", + "horizontal_spacing": "8px", + "vertical_spacing": "16px", + "horizontal_align": "left", + "vertical_align": "top", + "padding": "0px 20px 20px 20px", + "elements": [ + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "column_set", + "horizontal_align": "left", + "columns": [ + { + "tag": "column", + "width": "weighted", + "elements": [ + { + "tag": "markdown", + "content": "- **客户名称:** '.$contacts.'\n- **跟进时间:** '.$follow_next.'", + "text_align": "left", + "text_size": "normal_v2", + "margin": "0px 0px 0px 0px" + } + ], + "vertical_spacing": "8px", + "horizontal_align": "left", + "vertical_align": "top", + "weight": 1 + } + ] + }, + { + "tag": "hr", + "margin": "0px 0px 0px 0px" + }, + { + "tag": "div", + "text": { + "tag": "plain_text", + "content": "最近跟进:'.$follow_last.'", + "text_size": "notation", + "text_align": "left", + "text_color": "grey" + }, + "icon": { + "tag": "standard_icon", + "token": "chat_outlined", + "color": "grey" + }, + "element_id": "track_time" + } + ] + }, + "header": { + "title": { + "tag": "plain_text", + "content": "跟进提醒" + }, + "subtitle": { + "tag": "plain_text", + "content": "" + }, + "template": "green", + "icon": { + "tag": "standard_icon", + "token": "calendar_colorful" + }, + "padding": "12px 12px 12px 20px" + } + }'; + return $content; + } +} \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index c2a23df..b942887 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -9,6 +9,7 @@ use app\common\utils\scaffold\Generate; use support\Request; use support\Db; use support\Cache; +use app\inquiry\service\InquiryLogService; class IndexController { @@ -100,8 +101,23 @@ class IndexController public function test() { - $res = ['id'=>25714]; - \Webman\RedisQueue\Redis::send('inquiry-to-crm', $res); + // $res = ['id'=>25714]; + // \Webman\RedisQueue\Redis::send('inquiry-to-crm', $res); + + // $res = [ + // 'id'=>25717, + // 'category'=>'inquiry', + // 'scene'=>'inquiry-person-allocation', + // 'receive_type'=>'person' + // ]; + + // $res = [ + // 'id'=>1, + // 'category'=>'crm', + // 'scene'=>'crm-person-follow-up', + // 'receive_type'=>'person' + // ]; + // \Webman\RedisQueue\Redis::send('feishu-message', $res); return 'success'; } } \ No newline at end of file diff --git a/app/inquiry/service/InquiryLogService.php b/app/inquiry/service/InquiryLogService.php index 759c8c4..8f40a0e 100644 --- a/app/inquiry/service/InquiryLogService.php +++ b/app/inquiry/service/InquiryLogService.php @@ -97,11 +97,11 @@ class InquiryLogService } // ====== ====== 关联 ====== ====== - $config['with']['country'][] = 'cn_addr'; - $config['with']['country'][] = 'steering'; + $config['with']['countryInfo'][] = 'cn_addr'; + $config['with']['countryInfo'][] = 'steering'; $config['with']['enter'][] = 'name'; $config['with']['recipient'][] = 'name'; - $config['with']['channel'][] = 'name'; + $config['with']['channelInfo'][] = 'name'; break; case 'show': case 'update': @@ -184,4 +184,43 @@ class InquiryLogService RedisQueueRedis::send('inquiry-to-crm', $res); return $res; } + + + /** + * 获取询单ById + * @param int|string $id + * @param string $orderSn + * @return Model|null + */ + public function getInquiryLogBy(int|string $id) + { + $config = []; + $config['model'] = $this->modelClass; + $config['with']['countryInfo'][] = 'cn_addr'; + $config['with']['countryInfo'][] = 'steering'; + $config['with']['enter'][] = 'name'; + $config['with']['recipient'][] = 'name'; + $config['with']['channelInfo'][] = 'name'; + $config['orWhere'][] = ['id', '=', $id]; + $config['orWhere'][] = ['order_no', '=', $id]; + return $this->logicShow($config); + } + + /** + * 获取等级名称 + * @param $id + * @return string + */ + public function qualityName($id) + { + if (!$id) { + return '🤍 银牌商机'; + } + $quality = [ + 1 => '💛 金牌商机', + 2 => '🤍 银牌商机', + 3 => '🤍 银牌商机' + ]; + return $quality[$id]; + } } \ No newline at end of file diff --git a/app/queue/redis/FeishuMessage.php b/app/queue/redis/FeishuMessage.php new file mode 100644 index 0000000..dacb4fc --- /dev/null +++ b/app/queue/redis/FeishuMessage.php @@ -0,0 +1,127 @@ +where('id', $data['id'])->first(); + + // 跟单人 + $reInfo = User::where('id', $info->user_id)->first(); + + // 飞书应用 + $feishuApp = new CorpFeishuApp(); + $feishuAppInfo = $feishuApp->where('corp_id', $reInfo->corp_id)->first(); + + // 推送数据 + $options = [ + 'contacts' => $info->contacts, + 'follow_last' => $info->follow_last ? date('Y-m-d H:i', $info->follow_last) : '', + 'follow_next' => $info->follow_next ? date('Y-m-d H:i', $info->follow_next) : '', + + 'app_id' => $feishuAppInfo->app_id, + 'app_secret' => $feishuAppInfo->app_secret, + 'msg_type' => 'interactive', + 'receive_id_type' => 'open_id', + 'receive_id' => $reInfo->open_id + ]; + } + + if ($data['category'] === 'inquiry') { + // 询单信息 + $inquiryLogService = new InquiryLogService(); + $info = $inquiryLogService->getInquiryLogBy($data['id']); + + // 接受者处理 + if ($data['receive_type'] == 'group') { + $appId = 'cli_a72f13d6c022500d'; + $appSecret = 'Kxtbq70OQWrEhpltrufRZc76z7kjDqPT'; + $receiveId = 'oc_4f574e6f8bc5b8f3e5175e67ebc5725c'; + $receiveIdType = 'chat_id'; + } else { + // 跟单人 + $reInfo = User::where('id', $info->recipient)->first(); + // 飞书应用 + $feishuApp = new CorpFeishuApp(); + $feishuAppInfo = $feishuApp->where('corp_id', $reInfo->corp_id)->first(); + // 推送信息 + $appId = $feishuAppInfo->app_id; + $appSecret = $feishuAppInfo->app_secret; + $receiveId = $reInfo->open_id; + $receiveIdType = 'open_id'; + } + + // 推送数据 + $options = [ + 'order_no' => $info->order_no, + 'quality' => $inquiryLogService->qualityName($info->quality), + 'channel' => $info->channelInfo ? $info->channelInfo->name : '', + 'country' => $info->countryInfo ? $info->countryInfo->cn_addr : '', + 'enter_user' => $info->enter ? $info->enter->name : '', + 'r_time' => $info->r_time ? date('Y-m-d H:i:s', $info->r_time) : '', + 't_time' => $info->t_time ? date('Y-m-d H:i:s', $info->t_time) : '', + + 'app_id' => $appId, + 'app_secret' => $appSecret, + 'msg_type' => 'interactive', + 'receive_id_type' => $receiveIdType, + 'receive_id' => $receiveId + ]; + } + + $feishuMsg = new FeishuMsg(); + $feishuMsg->messageSend($data['scene'], $options); + } catch (\Throwable $th) { + throw $th; + } + } + + // 消费失败回调 + /* + $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/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 36e70dc..ecac73e 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -2,10 +2,12 @@ namespace app\queue\redis; +use app\inquiry\service\InquiryLogService; use app\common\model\CrmCustomer; use app\common\model\InquiryLog; use Webman\RedisQueue\Consumer; use app\common\model\User; +use app\common\utils\FeishuMessage; use support\exception\BusinessException; class InquiryToCrm implements Consumer @@ -21,7 +23,7 @@ class InquiryToCrm implements Consumer { try { // 获取询盘信息 - $info = InquiryLog::where('id', $data['id'])->where('sync_crm', 0)->first(); + $info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->where('id', $data['id'])->where('sync_crm', 0)->first(); if ($info) { // 获取用户信息 $recipient = 0; @@ -32,6 +34,13 @@ 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(); @@ -54,6 +63,15 @@ class InquiryToCrm implements Consumer if (!$crmCustomer->save() || !$info->save()) { throw new BusinessException('同步失败~'); } + + // 发送飞书消息 + $options = [ + 'id' => $info->id, + 'category' => 'inquiry', + 'scene' => $scene, + 'receive_type' => $receiveType + ]; + \Webman\RedisQueue\Redis::send('feishu-message', $options); } } catch (\Throwable $th) { throw $th; diff --git a/config/route.php b/config/route.php index ddd93d8..8d12177 100644 --- a/config/route.php +++ b/config/route.php @@ -29,6 +29,10 @@ use Webman\Route; Route::any('/c', [app\controller\IndexController::class, 'createResource']); Route::any('/perm', [app\controller\IndexController::class, 'perm']); +// 飞书 +Route::any('/feishu/event', [app\common\controller\NotifyController::class, 'feishuEvent']); +// 飞书回调 +Route::any('/feishu/callback', [app\common\controller\NotifyController::class, 'feishuCallback']); // 公共 Route::group('/common', function () { 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