105 lines
3.4 KiB
Dart
105 lines
3.4 KiB
Dart
/// 推荐信息响应 (来自 referral-service)
|
||
class ReferralInfoResponse {
|
||
final String userId;
|
||
final String referralCode;
|
||
final String? referrerId;
|
||
final int referralChainDepth;
|
||
final int directReferralCount;
|
||
final int totalTeamCount;
|
||
final int personalPlantingCount;
|
||
final int teamPlantingCount;
|
||
final double leaderboardScore;
|
||
final int? leaderboardRank;
|
||
final DateTime createdAt;
|
||
|
||
ReferralInfoResponse({
|
||
required this.userId,
|
||
required this.referralCode,
|
||
this.referrerId,
|
||
required this.referralChainDepth,
|
||
required this.directReferralCount,
|
||
required this.totalTeamCount,
|
||
required this.personalPlantingCount,
|
||
required this.teamPlantingCount,
|
||
required this.leaderboardScore,
|
||
this.leaderboardRank,
|
||
required this.createdAt,
|
||
});
|
||
|
||
factory ReferralInfoResponse.fromJson(Map<String, dynamic> json) {
|
||
return ReferralInfoResponse(
|
||
userId: json['userId']?.toString() ?? '',
|
||
referralCode: json['referralCode'] ?? '',
|
||
referrerId: json['referrerId']?.toString(),
|
||
referralChainDepth: json['referralChainDepth'] ?? 0,
|
||
directReferralCount: json['directReferralCount'] ?? 0,
|
||
totalTeamCount: json['totalTeamCount'] ?? 0,
|
||
personalPlantingCount: json['personalPlantingCount'] ?? 0,
|
||
teamPlantingCount: json['teamPlantingCount'] ?? 0,
|
||
leaderboardScore: (json['leaderboardScore'] ?? 0).toDouble(),
|
||
leaderboardRank: json['leaderboardRank'],
|
||
createdAt: json['createdAt'] != null
|
||
? DateTime.parse(json['createdAt'])
|
||
: DateTime.now(),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 直推成员信息
|
||
class DirectReferralInfo {
|
||
final String userId;
|
||
final String accountSequence; // 账户序列号(新格式: D + YYMMDD + 5位序号),用于显示
|
||
final String referralCode;
|
||
final int personalPlantingCount; // 个人认种量
|
||
final int teamPlantingCount; // 团队认种量
|
||
final int directReferralCount; // 直推人数(用于判断是否有下级)
|
||
final DateTime joinedAt;
|
||
|
||
DirectReferralInfo({
|
||
required this.userId,
|
||
required this.accountSequence,
|
||
required this.referralCode,
|
||
required this.personalPlantingCount,
|
||
required this.teamPlantingCount,
|
||
required this.directReferralCount,
|
||
required this.joinedAt,
|
||
});
|
||
|
||
factory DirectReferralInfo.fromJson(Map<String, dynamic> json) {
|
||
return DirectReferralInfo(
|
||
userId: json['userId']?.toString() ?? '',
|
||
accountSequence: json['accountSequence']?.toString() ?? '',
|
||
referralCode: json['referralCode'] ?? '',
|
||
personalPlantingCount: json['personalPlantingCount'] ?? 0,
|
||
teamPlantingCount: json['teamPlantingCount'] ?? 0,
|
||
directReferralCount: json['directReferralCount'] ?? 0,
|
||
joinedAt: json['joinedAt'] != null
|
||
? DateTime.parse(json['joinedAt'])
|
||
: DateTime.now(),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 直推列表响应
|
||
class DirectReferralsResponse {
|
||
final List<DirectReferralInfo> referrals;
|
||
final int total;
|
||
final bool hasMore;
|
||
|
||
DirectReferralsResponse({
|
||
required this.referrals,
|
||
required this.total,
|
||
required this.hasMore,
|
||
});
|
||
|
||
factory DirectReferralsResponse.fromJson(Map<String, dynamic> json) {
|
||
return DirectReferralsResponse(
|
||
referrals: (json['referrals'] as List? ?? [])
|
||
.map((e) => DirectReferralInfo.fromJson(e))
|
||
.toList(),
|
||
total: json['total'] ?? 0,
|
||
hasMore: json['hasMore'] ?? false,
|
||
);
|
||
}
|
||
}
|