代码提交

This commit is contained in:
wong
2025-07-29 17:04:00 +08:00
parent 9726518a46
commit 2b67bd6b77
5 changed files with 194 additions and 70 deletions

View File

@@ -155,7 +155,7 @@ class Adapter implements WeChatServiceInterface
{
$task = Db::name('customer_acquisition_task')
->where(['status' => 1,'deleteTime' => 0])
->whereRaw("id % $process_count_for_status_0 = {$current_worker_id}")
// ->whereRaw("id % $process_count_for_status_0 = {$current_worker_id}")
->order('id desc')
->select();
@@ -179,7 +179,6 @@ class Adapter implements WeChatServiceInterface
$taskData = array_merge($taskData, $tasks);
}
if ($taskData) {
foreach ($taskData as $task) {
@@ -197,9 +196,9 @@ class Adapter implements WeChatServiceInterface
$friendAddTaskCreated = false;
foreach ($wechatIdAccountIdMap as $accountId => $wechatId) {
// 是否已经是好友的判断如果已经是好友直接break; 但状态还是维持1让另外一个进程处理发消息的逻辑
$isFriend = $this->checkIfIsWeChatFriendByPhone($wechatId, $task['phone']);
$wechatTags = json_decode($task['tags'], true);
$isFriend = $this->checkIfIsWeChatFriendByPhone($wechatId, $task['phone'],$task['siteTags']);
if (!empty($isFriend)) {
$friendAddTaskCreated = true;
$task['processed_wechat_ids'] = $task['processed_wechat_ids'] . ',' . $wechatId; // 处理失败任务用,用于过滤已处理的微信号
@@ -221,10 +220,15 @@ class Adapter implements WeChatServiceInterface
// 采取乐观尝试的策略,假设第一个可以添加的人可以添加成功的; 回头再另外一个任务进程去判断
// 创建好友添加任务, 对接触客宝
$tags = array_merge($task_info['tagConf']['customTags'],$task_info['tagConf']['scenarioTags']);
if (!empty($wechatTags)){
$tags = array_merge($tags,$wechatTags);
}
$tags = array_unique($tags);
$tags = array_values($tags);
$conf = array_merge($task_info['reqConf'], ['task_name' => $task_info['name'],'tags' => $tags]);
$this->createFriendAddTask($accountId, $task['phone'], $conf);
$friendAddTaskCreated = true;
$task['processed_wechat_ids'] = $task['processed_wechat_ids'] . ',' . $wechatId; // 处理失败任务用,用于过滤已处理的微信号
@@ -459,21 +463,36 @@ class Adapter implements WeChatServiceInterface
}
// 检查是否是好友关系
public function checkIfIsWeChatFriendByPhone(string $wxId, string $phone): bool
public function checkIfIsWeChatFriendByPhone(string $wxId, string $phone,string $siteTags): bool
{
if (empty($wxId) || empty($phone)) {
return false;
}
try {
$id = Db::table('s2_wechat_friend')
$friend = Db::table('s2_wechat_friend')
->where('ownerWechatId', $wxId)
->where(['isPassed' => 1,'isDeleted' => 0])
->where('phone|alias|wechatId', 'like', $phone . '%')
->order('createTime', 'desc')
->value('id');
return (bool)$id;
->find();
if (!empty($friend)) {
if (!empty($siteTags)) {
$siteTags = json_decode($siteTags, true);
$siteLabels = json_decode($friend['siteLabels'], true);
$tags = array_merge($siteTags,$siteLabels);
$tags = array_unique($tags);
$tags = array_values($tags);
if (empty($tags)){
$tags = [];
}
$tags = json_encode($tags,256);
Db::table('s2_wechat_friend')->where(['id' => $friend['id']])->update(['siteLabels' => $tags,'updateTime' => time()]);
}
return true;
}else{
return false;
}
} catch (\Exception $e) {
Log::error("Error in checkIfIsWeChatFriendByPhone (wxId: {$wxId}, phone: {$phone}): " . $e->getMessage());
return false;