From 3bd7290846274370c9bad26233924863e9de403b Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Tue, 22 Jul 2025 15:35:46 +0800 Subject: [PATCH] =?UTF-8?q?[]=20=E4=BF=AE=E5=A4=8D=E6=B5=81=E9=87=8F?= =?UTF-8?q?=E6=B1=A0=E6=9D=A5=E6=BA=90=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=B8=8D=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/SyncWechatDataToCkbTask.php | 13 ++++ .../Adapters/ChuKeBao/Adapter.php | 66 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/Server/application/command/SyncWechatDataToCkbTask.php b/Server/application/command/SyncWechatDataToCkbTask.php index 9980a630..4e1bc482 100644 --- a/Server/application/command/SyncWechatDataToCkbTask.php +++ b/Server/application/command/SyncWechatDataToCkbTask.php @@ -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(); + } + + } \ No newline at end of file diff --git a/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php b/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php index ba111c73..8da320aa 100644 --- a/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php +++ b/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php @@ -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); + } }