优化
This commit is contained in:
154
client/flutter/lib/models/stats.dart
Normal file
154
client/flutter/lib/models/stats.dart
Normal file
@@ -0,0 +1,154 @@
|
||||
/// My stats returned by stats.getMyStats
|
||||
class MyStats {
|
||||
final TotalStats total;
|
||||
final TodayStats today;
|
||||
final List<InviteSummary> recentInvites;
|
||||
|
||||
MyStats({
|
||||
required this.total,
|
||||
required this.today,
|
||||
this.recentInvites = const [],
|
||||
});
|
||||
|
||||
factory MyStats.fromJson(Map<String, dynamic> json) {
|
||||
return MyStats(
|
||||
total: TotalStats.fromJson(json['total'] ?? {}),
|
||||
today: TodayStats.fromJson(json['today'] ?? {}),
|
||||
recentInvites: (json['recentInvites'] as List?)
|
||||
?.map((e) => InviteSummary.fromJson(e))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TotalStats {
|
||||
final int totalInvites;
|
||||
final int totalJoins;
|
||||
final int totalConversions;
|
||||
final double totalRevenue;
|
||||
|
||||
TotalStats({
|
||||
this.totalInvites = 0,
|
||||
this.totalJoins = 0,
|
||||
this.totalConversions = 0,
|
||||
this.totalRevenue = 0,
|
||||
});
|
||||
|
||||
factory TotalStats.fromJson(Map<String, dynamic> json) {
|
||||
return TotalStats(
|
||||
totalInvites: json['totalInvites'] ?? 0,
|
||||
totalJoins: json['totalJoins'] ?? 0,
|
||||
totalConversions: json['totalConversions'] ?? 0,
|
||||
totalRevenue: (json['totalRevenue'] ?? 0).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TodayStats {
|
||||
final int invitesCreated;
|
||||
final int joins;
|
||||
final int conversions;
|
||||
final double revenue;
|
||||
|
||||
TodayStats({
|
||||
this.invitesCreated = 0,
|
||||
this.joins = 0,
|
||||
this.conversions = 0,
|
||||
this.revenue = 0,
|
||||
});
|
||||
|
||||
factory TodayStats.fromJson(Map<String, dynamic> json) {
|
||||
return TodayStats(
|
||||
invitesCreated: json['invitesCreated'] ?? 0,
|
||||
joins: json['joins'] ?? 0,
|
||||
conversions: json['conversions'] ?? 0,
|
||||
revenue: (json['revenue'] ?? 0).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class InviteSummary {
|
||||
final String? id;
|
||||
final String? code;
|
||||
final String? groupId;
|
||||
final String? link;
|
||||
final int? clickCount;
|
||||
final int? joinCount;
|
||||
final DateTime? createdAt;
|
||||
|
||||
InviteSummary({
|
||||
this.id,
|
||||
this.code,
|
||||
this.groupId,
|
||||
this.link,
|
||||
this.clickCount,
|
||||
this.joinCount,
|
||||
this.createdAt,
|
||||
});
|
||||
|
||||
factory InviteSummary.fromJson(Map<String, dynamic> json) {
|
||||
return InviteSummary(
|
||||
id: (json['_id'] ?? json['id'])?.toString(),
|
||||
code: json['code'],
|
||||
groupId: json['groupId']?.toString(),
|
||||
link: json['link'],
|
||||
clickCount: json['clickCount'],
|
||||
joinCount: json['joinCount'],
|
||||
createdAt: json['createdAt'] != null
|
||||
? DateTime.parse(json['createdAt'].toString())
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ranking entry returned by stats.getRanking
|
||||
class RankingEntry {
|
||||
final int rank;
|
||||
final String salesId;
|
||||
final int totalJoins;
|
||||
final int totalConversions;
|
||||
final double totalRevenue;
|
||||
final Map<String, dynamic>? user;
|
||||
|
||||
RankingEntry({
|
||||
this.rank = 0,
|
||||
required this.salesId,
|
||||
this.totalJoins = 0,
|
||||
this.totalConversions = 0,
|
||||
this.totalRevenue = 0,
|
||||
this.user,
|
||||
});
|
||||
|
||||
factory RankingEntry.fromJson(Map<String, dynamic> json) {
|
||||
return RankingEntry(
|
||||
rank: json['rank'] ?? 0,
|
||||
salesId: (json['_id'] ?? json['salesId'] ?? '').toString(),
|
||||
totalJoins: json['totalJoins'] ?? 0,
|
||||
totalConversions: json['totalConversions'] ?? 0,
|
||||
totalRevenue: (json['totalRevenue'] ?? 0).toDouble(),
|
||||
user: json['user'],
|
||||
);
|
||||
}
|
||||
|
||||
String get displayName =>
|
||||
user?['nickname']?.toString() ?? user?['email']?.toString() ?? salesId;
|
||||
}
|
||||
|
||||
/// Platform stats returned by stats.getPlatformStats
|
||||
class PlatformStats {
|
||||
final Map<String, dynamic> platform;
|
||||
final Map<String, dynamic> today;
|
||||
|
||||
PlatformStats({
|
||||
this.platform = const {},
|
||||
this.today = const {},
|
||||
});
|
||||
|
||||
factory PlatformStats.fromJson(Map<String, dynamic> json) {
|
||||
return PlatformStats(
|
||||
platform: json['platform'] ?? {},
|
||||
today: json['today'] ?? {},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user