This commit is contained in:
mzl
2025-08-23 16:52:08 +08:00
parent 8c4c2eeb89
commit 6730f11cca
4 changed files with 121 additions and 23 deletions
+1 -1
View File
@@ -436,7 +436,7 @@ class Emails
// 初始化 UID 轮询器 // 初始化 UID 轮询器
$uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804'); $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) EmailParsedResult::where('status', 0)
->chunkById($batchSize, function ($records) use ($delaySeconds, $throttleAfter, $throttleSeconds, $enterUser, $channelInfo, $uidRotator) { ->chunkById($batchSize, function ($records) use ($delaySeconds, $throttleAfter, $throttleSeconds, $enterUser, $channelInfo, $uidRotator) {
+8 -15
View File
@@ -116,27 +116,20 @@ class IndexController
// 'recipient' => [1], // 'recipient' => [1],
// ]; // ];
$data['recipient'] = [1, 74]; // $data['recipient'] = [1, 74];
// // 同步推送 // // // 同步推送
// (new MessageNotificationsService())->pushNotice($data); // // (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 = ''; return json(['code' => 0, 'msg' => 'success']);
// $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);
} }
} }
-7
View File
@@ -37,13 +37,6 @@ class InquiryToCrm implements Consumer
if ($uinfo) { if ($uinfo) {
$corpId = $uinfo->corp_id; $corpId = $uinfo->corp_id;
} }
// // 消息推送参数 分配
// $scene = 'inquiry-person-allocation';
// $receiveType = 'person';
} else {
// // 消息推送参数 发布
// $scene = 'inquiry-group-send';
// $receiveType = 'group';
} }
// 同步客户数据 // 同步客户数据
$crmCustomer = new CrmCustomer(); $crmCustomer = new CrmCustomer();
+112
View File
@@ -0,0 +1,112 @@
<?php
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;
use support\Log;
class InquiryToCrm implements Consumer
{
// 要消费的队列名
public $queue = 'inquiry-to-crm-new';
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
public $connection = 'default';
// 消费
public function consume($data)
{
try {
// 获取询盘信息
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
}
}