feat: 更新代码仓库全部修改
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
This commit is contained in:
+72
-50
@@ -43,7 +43,7 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
final kr_isDescriptionExpanded = false.obs;
|
||||
|
||||
/// 当前余额
|
||||
var _kr_balance = 0;
|
||||
RxInt _kr_balance = 0.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -114,20 +114,7 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
|
||||
/// 初始化用户信息
|
||||
Future<void> _iniUserInfo() async {
|
||||
// ⚠️ 已废弃:新版本后端不再提供 kr_getUserInfo 接口
|
||||
// 余额现在使用 AppConfig 中的固定值,等待新接口实现
|
||||
// final either0 = await KRUserApi().kr_getUserInfo();
|
||||
// either0.fold(
|
||||
// (error) {
|
||||
// KRLogUtil.kr_e(error.msg, tag: 'AppRunData');
|
||||
// },
|
||||
// (userInfo) async {
|
||||
// _kr_balance = userInfo.balance;
|
||||
// },
|
||||
// );
|
||||
|
||||
// 使用 AppConfig 中的固定余额
|
||||
_kr_balance = AppConfig.kr_userBalance;
|
||||
_kr_balance = KRAppRunData().kr_balance;
|
||||
}
|
||||
|
||||
/// 获取用户已订阅套餐
|
||||
@@ -297,7 +284,6 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
// 查找余额支付方式的索引
|
||||
final balanceMethodIndex =
|
||||
kr_paymentMethods.indexWhere((method) => method.platform == 'balance');
|
||||
|
||||
// 如果找到余额支付方式且余额足够,选择余额支付
|
||||
if (balanceMethodIndex != -1 && selectedPrice <= _kr_balance / 100) {
|
||||
kr_selectPaymentMethod(balanceMethodIndex);
|
||||
@@ -332,7 +318,7 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
/// 开始订阅流程
|
||||
Future<void> kr_startSubscription() async {
|
||||
if (!kr_validateSubscriptionData()) return;
|
||||
|
||||
print('开始订阅流程,选定支付');
|
||||
kr_errorMessage.value = '';
|
||||
|
||||
try {
|
||||
@@ -361,6 +347,7 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
|
||||
/// 处理购买和结账流程
|
||||
Future<void> kr_processPurchaseAndCheckout() async {
|
||||
|
||||
final selectedPlan = kr_plans[kr_selectedPlanIndex.value];
|
||||
|
||||
// ⚠️ 支付方式接口暂未实现,使用默认支付方式 ID (1) 和平台 'alipay'
|
||||
@@ -377,12 +364,13 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
// 判断是续订还是新购
|
||||
final isRenewal = _kr_alreadySubscribe
|
||||
.any((subscribe) => subscribe.subscribeId == selectedPlan.kr_id);
|
||||
|
||||
final subscribeId = isRenewal
|
||||
? _kr_alreadySubscribe
|
||||
.firstWhere(
|
||||
(subscribe) => subscribe.subscribeId == selectedPlan.kr_id)
|
||||
.userSubscribeId
|
||||
.firstWhere(
|
||||
(subscribe) => subscribe.subscribeId == selectedPlan.kr_id,
|
||||
orElse: () => KRAlreadySubscribe(userSubscribeId: 0, subscribeId: 0), // 默认值
|
||||
)
|
||||
.userSubscribeId
|
||||
: 0;
|
||||
|
||||
// 根据判断结果调用不同的接口
|
||||
@@ -400,18 +388,8 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
'',
|
||||
);
|
||||
|
||||
// 打印下单请求和响应
|
||||
print('═══════════════════════════════════════');
|
||||
print('🔗 下单接口: /v1/public/order/purchase');
|
||||
print('📤 请求参数:');
|
||||
print(' subscribe_id: ${selectedPlan.kr_id}');
|
||||
print(' quantity: $quantity');
|
||||
print(' payment: $paymentMethodId');
|
||||
print(' coupon: ""');
|
||||
print('');
|
||||
|
||||
purchaseEither.fold(
|
||||
(error) {
|
||||
(error) {
|
||||
print('❌ 请求失败:');
|
||||
print(' 错误码: ${error.code}');
|
||||
print(' 错误信息: ${error.msg}');
|
||||
@@ -419,6 +397,19 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
KRCommonUtil.kr_showToast(error.msg);
|
||||
},
|
||||
(order) async {
|
||||
// 所有支付方式都需要调用 checkout 接口
|
||||
// final checkoutEither = await _kr_subscribeApi.kr_checkout(order);
|
||||
// checkoutEither.fold(
|
||||
// (error) => KRCommonUtil.kr_showToast(error.msg),
|
||||
// (uri) => Get.toNamed(
|
||||
// Routes.KR_ORDER_STATUS,
|
||||
// arguments: {
|
||||
// 'url': uri,
|
||||
// 'order': order,
|
||||
// 'payment_type': paymentPlatform,
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
print('✅ 请求成功:');
|
||||
print(' 订单号: $order');
|
||||
print('═══════════════════════════════════════');
|
||||
@@ -446,6 +437,19 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
return plan.kr_unitPrice / 100;
|
||||
}
|
||||
|
||||
/// 获取套餐每天价格
|
||||
double kr_getDayPlanPrice(KRPackageListItem plan, {int? discountIndex}) {
|
||||
if (discountIndex != null &&
|
||||
discountIndex >= 0 &&
|
||||
discountIndex < plan.kr_discount.length) {
|
||||
// 计算折扣价格
|
||||
final discount = plan.kr_discount[discountIndex];
|
||||
return (plan.kr_unitPrice / 100) *
|
||||
(discount.kr_discount / 100);
|
||||
}
|
||||
return plan.kr_unitPrice / 100;
|
||||
}
|
||||
|
||||
/// 获取时间字符串
|
||||
/// 根据 quantity 和 unit_time 转换成多语言描述
|
||||
/// Day: 7天 -> "一周",30天 -> "一个月",90天 -> "一个季度",180天 -> "半年",365天 -> "一年"
|
||||
@@ -459,20 +463,21 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
|
||||
// 如果是 Day 单位,需要转换为对应的描述
|
||||
if (plan.kr_unitTime == 'Day') {
|
||||
switch (quantity) {
|
||||
case 7:
|
||||
return AppTranslations.kr_purchaseMembership.oneWeek;
|
||||
case 30:
|
||||
return AppTranslations.kr_purchaseMembership.oneMonth;
|
||||
case 90:
|
||||
return AppTranslations.kr_purchaseMembership.oneQuarter;
|
||||
case 180:
|
||||
return AppTranslations.kr_purchaseMembership.halfYear;
|
||||
case 365:
|
||||
return AppTranslations.kr_purchaseMembership.oneYear;
|
||||
default:
|
||||
return AppTranslations.kr_purchaseMembership.days(quantity);
|
||||
}
|
||||
return AppTranslations.kr_purchaseMembership.days(quantity);
|
||||
// switch (quantity) {
|
||||
// case 7:
|
||||
// return AppTranslations.kr_purchaseMembership.oneWeek;
|
||||
// case 30:
|
||||
// return AppTranslations.kr_purchaseMembership.oneMonth;
|
||||
// case 90:
|
||||
// return AppTranslations.kr_purchaseMembership.oneQuarter;
|
||||
// case 180:
|
||||
// return AppTranslations.kr_purchaseMembership.halfYear;
|
||||
// case 365:
|
||||
// return AppTranslations.kr_purchaseMembership.oneYear;
|
||||
// default:
|
||||
// return AppTranslations.kr_purchaseMembership.days(quantity);
|
||||
// }
|
||||
} else if (plan.kr_unitTime == 'Month') {
|
||||
// 月份也需要转换
|
||||
switch (quantity) {
|
||||
@@ -504,7 +509,7 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
}
|
||||
// 计算折扣百分比(例如:97% 显示为 -3%)
|
||||
final discountPercent = 100 - discount.kr_discount;
|
||||
return '-${discountPercent}%';
|
||||
return '${discountPercent}%';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -621,14 +626,14 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
final checkoutEither = await _kr_subscribeApi.kr_checkout(orderNo);
|
||||
|
||||
checkoutEither.fold(
|
||||
(error) {
|
||||
(error) {
|
||||
print('❌ Checkout 失败:');
|
||||
print(' 错误码: ${error.code}');
|
||||
print(' 错误信息: ${error.msg}');
|
||||
print('═══════════════════════════════════════');
|
||||
KRCommonUtil.kr_showToast(error.msg);
|
||||
},
|
||||
(checkoutResponse) async {
|
||||
(checkoutResponse) async {
|
||||
print('✅ Checkout 成功:');
|
||||
print(' 支付类型: ${checkoutResponse.type}');
|
||||
|
||||
@@ -697,10 +702,27 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
'stripe': checkoutResponse.stripe,
|
||||
},
|
||||
);
|
||||
} else if (checkoutResponse.type == 'balance') {
|
||||
// Stripe 类型:显示 Stripe 支付表单
|
||||
print(' Stripe Method: ${checkoutResponse.stripe?.method}');
|
||||
print(' Stripe Client Secret: ${checkoutResponse.stripe?.clientSecret}');
|
||||
print('💳 显示 Stripe 支付表单...');
|
||||
print('═══════════════════════════════════════');
|
||||
|
||||
Get.toNamed(
|
||||
Routes.KR_ORDER_STATUS,
|
||||
arguments: {
|
||||
'order': orderNo,
|
||||
'payment_type': paymentPlatform,
|
||||
'uri': '',
|
||||
'checkout_type': 'balance',
|
||||
},
|
||||
);
|
||||
} else {
|
||||
print('⚠️ 未知的支付类型: ${checkoutResponse.type}');
|
||||
print('═══════════════════════════════════════');
|
||||
KRCommonUtil.kr_showToast('不支持的支付类型: ${checkoutResponse.type}');
|
||||
// KRCommonUtil.kr_showToast('不支持的支付类型: ${checkoutResponse.type}');
|
||||
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user