From c9f944355ce1977fed371c7d93706bda325ca922 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 14 Dec 2025 06:10:41 -0800 Subject: [PATCH] =?UTF-8?q?fix(referral):=20=E4=BF=AE=E5=A4=8D=20getReferr?= =?UTF-8?q?alChain=20API=20=E8=BF=94=E5=9B=9E=20accountSequence=20?= =?UTF-8?q?=E8=80=8C=E9=9D=9E=20userId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 getReferralChain 方法返回的 ancestorPath 为 accountSequence 格式 - 修改 getBatchReferralChains 方法同样返回 accountSequence 格式 - 这修复了 authorization-service 查询社区层级时使用错误格式的问题 - 之前返回 userId (如 "25121400000"),现在返回 accountSequence (如 "D25121400000") 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../internal-referral-chain.controller.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/backend/services/referral-service/src/api/controllers/internal-referral-chain.controller.ts b/backend/services/referral-service/src/api/controllers/internal-referral-chain.controller.ts index f139f19e..3338bfcc 100644 --- a/backend/services/referral-service/src/api/controllers/internal-referral-chain.controller.ts +++ b/backend/services/referral-service/src/api/controllers/internal-referral-chain.controller.ts @@ -58,8 +58,21 @@ export class InternalReferralChainController { }; } - // ancestorPath 存储的是 userId (bigint),需要转换为字符串 - const ancestorPath = relationship.referralChain.map((id) => id.toString()); + // referralChain 存储的是 userId (bigint),需要转换为 accountSequence + // 因为 authorization-service 使用 accountSequence 来查询授权记录 + const ancestorUserIds = relationship.referralChain; + const ancestorPath: string[] = []; + + for (const ancestorUserId of ancestorUserIds) { + const ancestorRelationship = await this.referralRepo.findByUserId(ancestorUserId); + if (ancestorRelationship) { + ancestorPath.push(ancestorRelationship.accountSequence); + } else { + this.logger.warn(`[INTERNAL] Ancestor userId ${ancestorUserId} not found`); + } + } + + this.logger.debug(`[INTERNAL] getReferralChain result: ${ancestorPath.length} ancestors`); return { accountSequence: relationship.accountSequence, @@ -88,9 +101,18 @@ export class InternalReferralChainController { for (const seq of sequences) { const relationship = await this.referralRepo.findByAccountSequence(seq); if (relationship) { + // 转换 userId 为 accountSequence + const ancestorPath: string[] = []; + for (const ancestorUserId of relationship.referralChain) { + const ancestorRelationship = await this.referralRepo.findByUserId(ancestorUserId); + if (ancestorRelationship) { + ancestorPath.push(ancestorRelationship.accountSequence); + } + } + results[seq] = { userId: relationship.userId.toString(), - ancestorPath: relationship.referralChain.map((id) => id.toString()), + ancestorPath, referrerId: relationship.referrerId?.toString() ?? null, }; } else {