fix(referral): 修复 getReferralChain API 返回 accountSequence 而非 userId

- 修改 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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-14 06:10:41 -08:00
parent 367e34f3a6
commit c9f944355c
1 changed files with 25 additions and 3 deletions

View File

@ -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 {