From 6730f11ccac542192607c0c36545ea77aef4da20 Mon Sep 17 00:00:00 2001 From: mzl Date: Sat, 23 Aug 2025 16:52:08 +0800 Subject: [PATCH] tz --- app/common/utils/email/Emails.php | 2 +- app/controller/IndexController.php | 23 ++---- app/queue/redis/InquiryToCrm.php | 7 -- app/queue/redis/InquiryToCrmNew.php | 112 ++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 23 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..766344a 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -116,27 +116,20 @@ 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', 25998)->where('sync_crm', 0)->first(); - // return json($data); + var_dump($info); - // $phone = ''; - // $email = ''; - - // $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); + return json(['code' => 0, 'msg' => 'success']); } } \ No newline at end of file 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..a076f30 --- /dev/null +++ b/app/queue/redis/InquiryToCrmNew.php @@ -0,0 +1,112 @@ +where('id', $data['id'])->where('sync_crm', 0)->first(); + + + + if ($info) { + // 获取用户信息 + $recipient = 0; + $corpId = 0; + $uinfo = null; + if ($info->recipient) { + $recipient = $info->recipient; + $uinfo = User::where('id', $info->recipient)->first(); + if ($uinfo) { + $corpId = $uinfo->corp_id; + } + } + // 同步客户数据 + $crmCustomer = new CrmCustomer(); + $crmCustomer->sn = $info->order_no; + $crmCustomer->corp_abbr = $corpId; + $crmCustomer->user_id = $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 ($uinfo && $uinfo->email) { + // $options = [ + // 'id' => $info->id, + // 'email' => $uinfo->email + // ]; + // // Log::info('发送邮件消息:' . json_encode($options)); + // \Webman\RedisQueue\Redis::send('email-message', $options); + // } + + $wsdata = [ + 'sender_id' => 0, + 'sender_type' => 'system', + 'title' => '有新的客户线索,' . $info->order_no . ',请及时处理', + 'content' => '有新的客户线索,' . $info->order_no . ',请及时处理', + 'scene' => 1, + 'recipient' => [$info->recipient] + ]; + // 异步推送 + \Webman\RedisQueue\Redis::send('notice', $wsdata); + } + } 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