fix(referral): fix direct referral list display and count issues
1. Return accountSequence instead of userId for direct referral list display 2. Create missing team statistics record when referrer doesn't have one 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b508d9b201
commit
13f670e9dd
|
|
@ -84,6 +84,9 @@ export class DirectReferralResponseDto {
|
|||
@ApiProperty({ description: '用户ID' })
|
||||
userId: string;
|
||||
|
||||
@ApiProperty({ description: '账户序列号 (8位)' })
|
||||
accountSequence: number;
|
||||
|
||||
@ApiProperty({ description: '推荐码' })
|
||||
referralCode: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export class GetDirectReferralsQuery {
|
|||
|
||||
export interface DirectReferralResult {
|
||||
userId: string;
|
||||
accountSequence: number; // 8位账户序列号,显示用
|
||||
referralCode: string;
|
||||
teamCount: number;
|
||||
joinedAt: Date;
|
||||
|
|
|
|||
|
|
@ -91,11 +91,14 @@ export class ReferralService {
|
|||
|
||||
// 如果有推荐人,更新推荐人的直推计数
|
||||
if (referrerId) {
|
||||
const referrerStats = await this.teamStatsRepo.findByUserId(referrerId);
|
||||
if (referrerStats) {
|
||||
referrerStats.addDirectReferral(command.userId);
|
||||
await this.teamStatsRepo.save(referrerStats);
|
||||
let referrerStats = await this.teamStatsRepo.findByUserId(referrerId);
|
||||
// 如果推荐人没有统计记录(历史用户),先创建
|
||||
if (!referrerStats) {
|
||||
this.logger.warn(`Creating missing team statistics for referrer ${referrerId}`);
|
||||
referrerStats = await this.teamStatsRepo.create(referrerId);
|
||||
}
|
||||
referrerStats.addDirectReferral(command.userId);
|
||||
await this.teamStatsRepo.save(referrerStats);
|
||||
}
|
||||
|
||||
// 发布领域事件
|
||||
|
|
@ -160,6 +163,7 @@ export class ReferralService {
|
|||
|
||||
const referrals = paginated.map((r) => ({
|
||||
userId: r.userId.toString(),
|
||||
accountSequence: r.accountSequence, // 8位账户序列号,用于前端显示
|
||||
referralCode: r.referralCode,
|
||||
teamCount: directStats.get(r.userId) ?? 0,
|
||||
joinedAt: r.createdAt,
|
||||
|
|
|
|||
|
|
@ -52,12 +52,14 @@ class ReferralInfoResponse {
|
|||
/// 直推成员信息
|
||||
class DirectReferralInfo {
|
||||
final String userId;
|
||||
final int accountSequence; // 8位账户序列号,用于显示
|
||||
final String referralCode;
|
||||
final int teamCount;
|
||||
final DateTime joinedAt;
|
||||
|
||||
DirectReferralInfo({
|
||||
required this.userId,
|
||||
required this.accountSequence,
|
||||
required this.referralCode,
|
||||
required this.teamCount,
|
||||
required this.joinedAt,
|
||||
|
|
@ -66,6 +68,7 @@ class DirectReferralInfo {
|
|||
factory DirectReferralInfo.fromJson(Map<String, dynamic> json) {
|
||||
return DirectReferralInfo(
|
||||
userId: json['userId']?.toString() ?? '',
|
||||
accountSequence: json['accountSequence'] ?? 0,
|
||||
referralCode: json['referralCode'] ?? '',
|
||||
teamCount: json['teamCount'] ?? 0,
|
||||
joinedAt: json['joinedAt'] != null
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
|
||||
// 转换直推列表格式
|
||||
_referrals = directReferrals.referrals.map((r) => <String, dynamic>{
|
||||
'serial': r.userId,
|
||||
'serial': r.accountSequence, // 使用8位账户序列号显示
|
||||
'personal': 0, // API暂未返回个人认种量
|
||||
'team': r.teamCount,
|
||||
}).toList();
|
||||
|
|
|
|||
Loading…
Reference in New Issue