60 lines
1.7 KiB
Dart
60 lines
1.7 KiB
Dart
import '../core/network/api_client.dart';
|
|
import '../core/network/endpoints.dart';
|
|
import '../models/membership_models.dart';
|
|
|
|
/// 会员服务(《03-接口文档》第 7 章)
|
|
class MembershipService {
|
|
MembershipService._();
|
|
|
|
/// 7.1 套餐列表(游客可,价格来自服务端配置)
|
|
static Future<PlansResult> fetchPlans() async {
|
|
final data = await ApiClient.get<Map<String, dynamic>>(
|
|
Endpoints.membershipPlans,
|
|
);
|
|
return PlansResult.fromJson(data);
|
|
}
|
|
|
|
/// 7.2 我的会员状态(需登录)
|
|
static Future<MyMemberState> fetchMe() async {
|
|
final data = await ApiClient.get<Map<String, dynamic>>(
|
|
Endpoints.membershipMe,
|
|
);
|
|
return MyMemberState.fromJson(data);
|
|
}
|
|
|
|
/// 7.3 积分开通会员(需登录)
|
|
/// 错误码:2004 终身卡重复开通,2001 积分不足
|
|
static Future<RedeemResult> redeem(String planCode) async {
|
|
final data = await ApiClient.post<Map<String, dynamic>>(
|
|
Endpoints.membershipRedeem,
|
|
data: {'plan_code': planCode},
|
|
);
|
|
return RedeemResult.fromJson(data);
|
|
}
|
|
}
|
|
|
|
/// 开通结果
|
|
class RedeemResult {
|
|
const RedeemResult({
|
|
required this.orderNo,
|
|
required this.planName,
|
|
required this.pointsCost,
|
|
required this.remainingPoints,
|
|
required this.expireAt,
|
|
});
|
|
|
|
final String orderNo;
|
|
final String planName;
|
|
final int pointsCost;
|
|
final int remainingPoints;
|
|
final String expireAt;
|
|
|
|
factory RedeemResult.fromJson(Map<String, dynamic> json) => RedeemResult(
|
|
orderNo: json['order_no'] as String,
|
|
planName: json['plan_name'] as String,
|
|
pointsCost: (json['points_cost'] as num).toInt(),
|
|
remainingPoints: (json['remaining_points'] as num).toInt(),
|
|
expireAt: json['expire_at'] as String,
|
|
);
|
|
}
|