113 lines
3.2 KiB
Dart
113 lines
3.2 KiB
Dart
/// 会员套餐(《03-接口文档》7.1,价格来自服务端配置)
|
|
class MembershipPlan {
|
|
const MembershipPlan({
|
|
required this.planCode,
|
|
required this.name,
|
|
required this.days,
|
|
required this.points,
|
|
this.enabled = true,
|
|
this.desc = '',
|
|
});
|
|
|
|
final String planCode;
|
|
final String name;
|
|
|
|
/// 有效天数;0 = 终身
|
|
final int days;
|
|
final int points;
|
|
final bool enabled;
|
|
final String desc;
|
|
|
|
factory MembershipPlan.fromJson(Map<String, dynamic> json) =>
|
|
MembershipPlan(
|
|
planCode: json['plan_code'] as String,
|
|
name: json['name'] as String,
|
|
days: (json['days'] as num).toInt(),
|
|
points: (json['points'] as num).toInt(),
|
|
enabled: json['enabled'] as bool? ?? true,
|
|
desc: (json['desc'] as String?) ?? '',
|
|
);
|
|
}
|
|
|
|
/// 套餐列表响应
|
|
class PlansResult {
|
|
const PlansResult({required this.plans, this.benefits = const []});
|
|
|
|
final List<MembershipPlan> plans;
|
|
final List<String> benefits;
|
|
|
|
factory PlansResult.fromJson(Map<String, dynamic> json) => PlansResult(
|
|
plans: ((json['plans'] as List?) ?? const [])
|
|
.whereType<Map<String, dynamic>>()
|
|
.map(MembershipPlan.fromJson)
|
|
.toList(),
|
|
benefits:
|
|
((json['benefits'] as List?) ?? const []).cast<String>(),
|
|
);
|
|
}
|
|
|
|
/// 我的会员状态(《03-接口文档》7.2)
|
|
class MyMemberState {
|
|
const MyMemberState({
|
|
this.isMember = false,
|
|
this.isLifetime = false,
|
|
this.currentPlan,
|
|
this.planName,
|
|
this.expireAt,
|
|
this.remainingDays = 0,
|
|
this.history = const [],
|
|
});
|
|
|
|
final bool isMember;
|
|
final bool isLifetime;
|
|
final String? currentPlan;
|
|
final String? planName;
|
|
final String? expireAt;
|
|
final int remainingDays;
|
|
final List<MemberHistoryItem> history;
|
|
|
|
factory MyMemberState.fromJson(Map<String, dynamic> json) => MyMemberState(
|
|
isMember: json['is_member'] as bool? ?? false,
|
|
isLifetime: json['is_lifetime'] as bool? ?? false,
|
|
currentPlan: json['current_plan'] as String?,
|
|
planName: json['plan_name'] as String?,
|
|
expireAt: json['expire_at'] as String?,
|
|
remainingDays: (json['remaining_days'] as num?)?.toInt() ?? 0,
|
|
history: ((json['history'] as List?) ?? const [])
|
|
.whereType<Map<String, dynamic>>()
|
|
.map(MemberHistoryItem.fromJson)
|
|
.toList(),
|
|
);
|
|
}
|
|
|
|
/// 会员开通历史
|
|
class MemberHistoryItem {
|
|
const MemberHistoryItem({
|
|
required this.orderNo,
|
|
required this.planName,
|
|
required this.pointsCost,
|
|
this.startAt = '',
|
|
this.endAt = '',
|
|
this.source = 0,
|
|
});
|
|
|
|
final String orderNo;
|
|
final String planName;
|
|
final int pointsCost;
|
|
final String startAt;
|
|
final String endAt;
|
|
final int source; // 1 积分开通 2 活动赠送
|
|
|
|
String get sourceLabel => source == 2 ? '活动赠送' : '积分开通';
|
|
|
|
factory MemberHistoryItem.fromJson(Map<String, dynamic> json) =>
|
|
MemberHistoryItem(
|
|
orderNo: json['order_no'] as String,
|
|
planName: json['plan_name'] as String,
|
|
pointsCost: (json['points_cost'] as num).toInt(),
|
|
startAt: (json['start_at'] as String?) ?? '',
|
|
endAt: (json['end_at'] as String?) ?? '',
|
|
source: (json['source'] as num?)?.toInt() ?? 1,
|
|
);
|
|
}
|