[] 修复流量池来源数据同步不更新问题

This commit is contained in:
wong
2025-07-22 15:35:46 +08:00
parent 3a879c5ce2
commit 3bd7290846
2 changed files with 79 additions and 0 deletions

View File

@@ -52,6 +52,8 @@ class SyncWechatDataToCkbTask extends Command
$this->syncWechatDevice($ChuKeBaoAdapter);
$this->syncWechatCustomer($ChuKeBaoAdapter);
$this->syncWechatFriendToTrafficPoolBatch($ChuKeBaoAdapter);
$this->syncTrafficSourceUser($ChuKeBaoAdapter);
$this->syncTrafficSourceGroup($ChuKeBaoAdapter);
$output->writeln("同步任务 sync_wechat_to_ckb 已结束");
return true;
@@ -96,4 +98,15 @@ class SyncWechatDataToCkbTask extends Command
{
return $ChuKeBaoAdapter->syncWechatFriendToTrafficPoolBatch();
}
protected function syncTrafficSourceUser(ChuKeBaoAdapter $ChuKeBaoAdapter)
{
return $ChuKeBaoAdapter->syncTrafficSourceUser();
}
protected function syncTrafficSourceGroup(ChuKeBaoAdapter $ChuKeBaoAdapter)
{
return $ChuKeBaoAdapter->syncTrafficSourceGroup();
}
}

View File

@@ -1225,4 +1225,70 @@ class Adapter implements WeChatServiceInterface
return false;
}
}
public function syncTrafficSourceUser()
{
$sql = "insert into ck_traffic_source(`identifier`,companyId,`fromd`,`sourceId`)
SELECT
f.wechatId identifier,
c.departmentId companyId,
f.ownerNickname fromd,
f.ownerWechatId sourceId
FROM
s2_wechat_friend f
LEFT JOIN s2_wechat_account a ON f.wechatAccountId = a.id
LEFT JOIN s2_company_account c on c.id = a.deviceAccountId
ORDER BY f.id DESC
LIMIT ?, ?
ON DUPLICATE KEY UPDATE
identifier=VALUES(identifier),
companyId=VALUES(companyId),
sourceId=VALUES(sourceId)";
$offset = 0;
$limit = 2000;
$usleepTime = 50000;
do {
$affected = Db::execute($sql, [$offset, $limit]);
$offset += $limit;
if ($affected > 0) {
usleep($usleepTime);
}
} while ($affected > 0);
}
public function syncTrafficSourceGroup()
{
$sql = "insert into ck_traffic_source(`identifier`,companyId,`fromd`,`sourceId`)
SELECT
m.wechatId identifier,
c.departmentId companyId,
r.nickname fromd,
f.ownerWechatId sourceId
FROM
s2_wechat_chatroom_member m
JOIN s2_wechat_chatroom r ON m.chatroomId = r.chatroomId
LEFT JOIN s2_wechat_account a ON a.id = r.wechatAccountId
LEFT JOIN s2_company_account c on c.id = a.deviceAccountId
ORDER BY m.id DESC
GROUP BY m.wechatId
LIMIT ?, ?
ON DUPLICATE KEY UPDATE
identifier=VALUES(identifier),
companyId=VALUES(companyId),
sourceId=VALUES(sourceId)";
$offset = 0;
$limit = 2000;
$usleepTime = 50000;
do {
$affected = Db::execute($sql, [$offset, $limit]);
$offset += $limit;
if ($affected > 0) {
usleep($usleepTime);
}
} while ($affected > 0);
}
}