优化套餐显示逻辑新增多语言
This commit is contained in:
+41
-8
@@ -372,20 +372,26 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
}
|
||||
|
||||
/// 获取套餐价格
|
||||
/// discount: 0 表示无折扣(原价),其他值表示折扣百分比
|
||||
double kr_getPlanPrice(KRPackageListItem plan, {int? discountIndex}) {
|
||||
if (discountIndex != null &&
|
||||
discountIndex >= 0 &&
|
||||
discountIndex < plan.kr_discount.length) {
|
||||
// 计算折扣价格
|
||||
final discount = plan.kr_discount[discountIndex];
|
||||
// 如果 discount 是 0,则表示原价(100%)
|
||||
final discountRate = discount.kr_discount == 0 ? 100.0 : discount.kr_discount.toDouble();
|
||||
return (plan.kr_unitPrice / 100) *
|
||||
discount.kr_quantity *
|
||||
(discount.kr_discount / 100);
|
||||
(discountRate / 100);
|
||||
}
|
||||
return plan.kr_unitPrice / 100;
|
||||
}
|
||||
|
||||
/// 获取时间字符串
|
||||
/// 根据 quantity 和 unit_time 转换成多语言描述
|
||||
/// Day: 7天 -> "一周",30天 -> "一个月",90天 -> "一个季度",180天 -> "半年",365天 -> "一年"
|
||||
/// Month: 3月 -> "一个季度",6月 -> "半年",12月 -> "一年"
|
||||
String kr_getTimeStr(KRPackageListItem plan, {int? discountIndex}) {
|
||||
final quantity = discountIndex != null &&
|
||||
discountIndex >= 0 &&
|
||||
@@ -393,25 +399,52 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
? plan.kr_discount[discountIndex].kr_quantity
|
||||
: 1;
|
||||
|
||||
if (plan.kr_unitTime == 'Month') {
|
||||
return AppTranslations.kr_purchaseMembership.month(quantity);
|
||||
// 如果是 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);
|
||||
}
|
||||
} else if (plan.kr_unitTime == 'Month') {
|
||||
// 月份也需要转换
|
||||
switch (quantity) {
|
||||
case 1:
|
||||
return AppTranslations.kr_purchaseMembership.oneMonth;
|
||||
case 3:
|
||||
return AppTranslations.kr_purchaseMembership.oneQuarter;
|
||||
case 6:
|
||||
return AppTranslations.kr_purchaseMembership.halfYear;
|
||||
case 12:
|
||||
return AppTranslations.kr_purchaseMembership.oneYear;
|
||||
default:
|
||||
return AppTranslations.kr_purchaseMembership.month(quantity);
|
||||
}
|
||||
} else if (plan.kr_unitTime == 'Year') {
|
||||
return AppTranslations.kr_purchaseMembership.year(quantity);
|
||||
} else if (plan.kr_unitTime == 'Day') {
|
||||
return AppTranslations.kr_purchaseMembership.day(quantity);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/// 获取折扣文本
|
||||
/// discount: 0 或 100 表示原价(无折扣),其他值表示折扣百分比
|
||||
String kr_getDiscountText(KRPackageListItem plan, int discountIndex) {
|
||||
if (discountIndex >= 0 && discountIndex < plan.kr_discount.length) {
|
||||
final discount = plan.kr_discount[discountIndex];
|
||||
// 折扣值为 100 表示原价,不需要显示折扣
|
||||
if (discount.kr_discount == 100) {
|
||||
// 折扣值为 0 或 100 都表示原价,不需要显示折扣
|
||||
if (discount.kr_discount == 0 || discount.kr_discount == 100) {
|
||||
return '';
|
||||
}
|
||||
// 计算折扣百分比(例如:95% 显示为 -5%)
|
||||
// 计算折扣百分比(例如:97% 显示为 -3%)
|
||||
final discountPercent = 100 - discount.kr_discount;
|
||||
return '-${discountPercent}%';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user