fix: 增加苹果价格

This commit is contained in:
speakeloudest 2025-12-17 21:59:02 -08:00
parent 554d12193e
commit 8f347d9183
3 changed files with 54 additions and 4 deletions

View File

@ -620,6 +620,14 @@ class KRPurchaseMembershipController extends GetxController {
);
}
/// iOS ( : )
static const Map<int, double> _krIosPriceMap = {
7: 3.29,
30: 6.99,
90: 14.99,
365: 52.99,
};
///
/// discount: 0
double kr_getPlanPrice(KRPackageListItem plan, {int? discountIndex}) {
@ -628,6 +636,10 @@ class KRPurchaseMembershipController extends GetxController {
discountIndex < plan.kr_discount.length) {
//
final discount = plan.kr_discount[discountIndex];
// --- iOS 使 ---
if (Platform.isIOS) {
return _krIosPriceMap[discount.kr_quantity] ?? (plan.kr_unitPrice / 100);
}
// discount 0100%
final discountRate =
discount.kr_discount == 0 ? 100.0 : discount.kr_discount.toDouble();
@ -645,6 +657,14 @@ class KRPurchaseMembershipController extends GetxController {
discountIndex < plan.kr_discount.length) {
//
final discount = plan.kr_discount[discountIndex];
// --- iOS ---
if (Platform.isIOS) {
// 1.
// 2. kr_quantity
return (_krIosPriceMap[discount.kr_quantity] ?? (plan.kr_unitPrice / 100)) / discount.kr_quantity;
}
return (plan.kr_unitPrice / 100) * (discount.kr_discount / 100);
}
return plan.kr_unitPrice / 100;
@ -701,6 +721,20 @@ class KRPurchaseMembershipController extends GetxController {
///
/// discount: 0 100
String kr_getDiscountText(KRPackageListItem plan, int discountIndex) {
if (Platform.isIOS) {
if (discountIndex >= 0 && discountIndex < plan.kr_discount.length) {
final discount = plan.kr_discount[discountIndex];
if (discount.kr_quantity <= 7) return '';
double baseDayPrice = 3.29 / 7;
double currentDayPrice = (_krIosPriceMap[discount.kr_quantity] ?? 0.0) / discount.kr_quantity;
if (currentDayPrice >= baseDayPrice - 0.001) return '';
return '-${((1 - (currentDayPrice / baseDayPrice)) * 100).ceil()}%';
}
return '';
}
if (discountIndex >= 0 && discountIndex < plan.kr_discount.length) {
final discount = plan.kr_discount[discountIndex];
// 0 100
@ -1025,7 +1059,18 @@ class KRPurchaseMembershipController extends GetxController {
}
} catch (e) {
KRCommonUtil.kr_hideLoading();
KRCommonUtil.kr_showToast('购买服务异常,请重试$e');
//
String errorMsg = e.toString();
if (errorMsg.contains('storekit_error') || errorMsg.contains('canceled')) {
//
print(' [IAP] 支付流程被中断(用户退出或系统取消)');
// Toast
KRCommonUtil.kr_showToast('支付已取消');
} else {
// /
KRCommonUtil.kr_showToast('购买服务暂不可用,请重试');
print('❌ [IAP] 严重异常: $e');
}
}
} else {
print('⚠️ 未知的支付类型: ${checkoutResponse.type}');

View File

@ -60,8 +60,13 @@ class KRIAPService extends GetxService {
if (p.status == PurchaseStatus.pending) continue;
if (p.status == PurchaseStatus.error) {
if (p.pendingCompletePurchase) await _iap.completePurchase(p);
KRCommonUtil.kr_showToast('购买失败');
if (p.pendingCompletePurchase) {
await _iap.completePurchase(p); //
}
// orderNo
if (p.error?.message.contains('canceled') ?? false) {
await IAPPendingOrderService.clearPendingOrderNo();
}
KRCommonUtil.kr_hideLoading();
continue;
}

View File

@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.0.4+108
version: 0.0.4+109
environment:
sdk: ">=3.5.0 <4.0.0"