Merge branch 'develop'

This commit is contained in:
mzl
2025-08-25 16:39:48 +08:00
parent 1bbde4562a
commit b15c03f009
6 changed files with 254 additions and 46 deletions
+1 -1
View File
@@ -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) {
+19 -13
View File
@@ -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']);
}
}
+5 -5
View File
@@ -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;
}
-7
View File
@@ -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();
+204
View File
@@ -0,0 +1,204 @@
<?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;
use support\Model;
class InquiryToCrmNew implements Consumer
{
// 要消费的队列名
public $queue = 'inquiry-to-crm-new';
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
public $connection = 'default';
// 消费
public function consume($data)
{
/*
询单 与 CRM 之间的同步场景描述
添加(询单)
添加 不发 不分 (不同步)1
添加 发了 不分 (要同步)2
添加 不发 分了 (要同步)3
添加 不发 直分 (要同步)4
更新(询单)
没发 没分 更新 (不同步)5
没发 分过 更新 (要同步)6
发过 没分 更新 (要同步)7
发过 分过 更新 (要同步)8
*/
try {
// 获取询盘信息
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
}
}
+23 -18
View File
@@ -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;
@@ -55,42 +56,46 @@ class ConversationService
$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'] = '<li>最新回复:' . $content . '</li>';
}
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']);