1.修复套餐过期续费计算价格错误的bug

2.优化套餐时间显示,亚马逊服务器时间转换当前时区时间
This commit is contained in:
yezhiqiu
2026-01-21 17:40:14 +08:00
parent 66160b45e0
commit d6d1ad93f2
8 changed files with 87 additions and 61 deletions

View File

@@ -65,7 +65,7 @@ class MySubscriptionAdapter(
} }
holder.setText( holder.setText(
R.id.tv_my_subscription_active_time, R.id.tv_my_subscription_active_time,
Utils.stringToDate(item.updateTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN6) Utils.formatTime(item.payTime, Utils.DATE_FORMAT_PATTERN_EN6)
) )
holder.getTextView(R.id.tv_my_subscription_annual_care).apply { holder.getTextView(R.id.tv_my_subscription_annual_care).apply {
@@ -74,13 +74,17 @@ class MySubscriptionAdapter(
else mContext.getString(R.string.txt_no) else mContext.getString(R.string.txt_no)
} }
// val timestamp = getAfterHowTimestamp( holder.getTextView(R.id.tv_my_subscription_expires_on).apply {
// Utils.stringToTimestamp(item.currentTime), item.surplusDays if (item.orderStatus == 6 && item.refundTime > 0L) {
// ) text = Utils.formatTime(item.refundTime, Utils.DATE_FORMAT_PATTERN_EN6)
holder.setText( } else {
R.id.tv_my_subscription_expires_on, text = Utils.formatTime(
Utils.formatTime(item.endTime, Utils.DATE_FORMAT_PATTERN_EN7) Utils.timestampAddHowTimestamp(
item.payTime, item.mealPeriod, item.mealUnit
), Utils.DATE_FORMAT_PATTERN_EN7
) )
}
}
if (item.subscriptionStatus == ConstantInt.Close) { if (item.subscriptionStatus == ConstantInt.Close) {
holder.setText( holder.setText(

View File

@@ -51,13 +51,14 @@ class NotificationV2Adapter(
setTextColor(ContextCompat.getColor(mContext, textColor)) setTextColor(ContextCompat.getColor(mContext, textColor))
} }
holder.getTextView(R.id.tv_home_route_notification_date).apply { holder.getTextView(R.id.tv_home_route_notification_date).apply {
text = getRelativeTimeString(Utils.stringToTimestamp(item.sendTime)) text = getRelativeTimeString(item.sendTime)
setTextColor(ContextCompat.getColor(mContext, textColor)) setTextColor(ContextCompat.getColor(mContext, textColor))
} }
} }
private fun getRelativeTimeString(time: Long): String { private fun getRelativeTimeString(sendTime: String): String {
var formatDateStr = "" var formatDateStr = ""
val time = Utils.stringToTimestamp(sendTime)
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
formatDateStr = if (DateUtils.isToday(time)) { formatDateStr = if (DateUtils.isToday(time)) {
mContext.getString(R.string.txt_today) + " " + Utils.formatTime( mContext.getString(R.string.txt_today) + " " + Utils.formatTime(
@@ -68,7 +69,9 @@ class NotificationV2Adapter(
time, Utils.DATE_FORMAT_PATTERN_EN8 time, Utils.DATE_FORMAT_PATTERN_EN8
) )
} else { } else {
Utils.formatTime(time, Utils.DATE_FORMAT_PATTERN_EN9) Utils.formatTime(
Utils.stringToTimestamp(sendTime, isUtc = true), Utils.DATE_FORMAT_PATTERN_EN9
)
} }
return formatDateStr return formatDateStr
} }

View File

@@ -59,16 +59,17 @@ class SubscriptionHistoryAdapter(
} }
holder.setText(R.id.tv_subscription_annual_care_state, state) holder.setText(R.id.tv_subscription_annual_care_state, state)
holder.setText( holder.setText(
R.id.tv_subscription_annual_care_active_time, R.id.tv_subscription_annual_care_active_time, Utils.formatTime(
Utils.stringToDate(item.createTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7) item.payTime, Utils.DATE_FORMAT_PATTERN_EN7
)
) )
//保险时长不足一年按12个月算 //保险时长不足一年按12个月算
val insuranceTime = val insuranceTime =
if (item.mealUnit == ConstantString.PackageUnitYear) item.mealPeriod else 1 if (item.mealUnit == ConstantString.PackageUnitYear) item.mealPeriod else 1
holder.setText( holder.setText(
R.id.tv_subscription_annual_care_expiry_time, Utils.formatTime( R.id.tv_subscription_annual_care_expiry_time, Utils.formatTime(
Utils.getAfterHowTimestamp( Utils.timestampAddHowTimestamp(
Utils.stringToTimestamp(item.createTime), insuranceTime * 365L item.payTime, insuranceTime, ConstantString.PackageUnitYear
), Utils.DATE_FORMAT_PATTERN_EN7 ), Utils.DATE_FORMAT_PATTERN_EN7
) )
) )
@@ -89,7 +90,7 @@ class SubscriptionHistoryAdapter(
) )
holder.setText( holder.setText(
R.id.tv_subscription_history_order_time, R.id.tv_subscription_history_order_time,
Utils.stringToDate(item.createTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN10) Utils.formatTime(item.payTime, Utils.DATE_FORMAT_PATTERN_EN10)
) )
holder.setText(R.id.tv_subscription_history_package_name, item.mealName) holder.setText(R.id.tv_subscription_history_package_name, item.mealName)
holder.setText( holder.setText(
@@ -109,8 +110,14 @@ class SubscriptionHistoryAdapter(
1 -> { 1 -> {
val updateTimestamp = Utils.stringToTimestamp(item.updateTime) val updateTimestamp = Utils.stringToTimestamp(item.updateTime)
val nowTimestamp = System.currentTimeMillis() val nowTimestamp = System.currentTimeMillis()
// val nowTimestamp = Utils.stringToTimestamp(item.currentTime) if (item.mealUnit == ConstantString.PackageUnitDay) {
if (item.mealUnit == ConstantString.PackageUnitMonth) { if (item.enabled == ConstantInt.Type0 || (item.surplusDays == 0L && item.subscriptionStatus == ConstantInt.Close)) {
visibility = View.GONE
} else {
visibility = View.VISIBLE
setText(R.string.txt_refund)
}
} else if (item.mealUnit == ConstantString.PackageUnitMonth) {
val day7Timestamp = 7 * 24 * 60 * 60 * 1000L val day7Timestamp = 7 * 24 * 60 * 60 * 1000L
//套餐超出7天不能退款 //套餐超出7天不能退款
if (nowTimestamp - updateTimestamp <= day7Timestamp) { if (nowTimestamp - updateTimestamp <= day7Timestamp) {

View File

@@ -31,7 +31,7 @@ data class SubscriptionsOrderBean(
var mealDiscountPrice: Double, var mealDiscountPrice: Double,
var orderNum: String, var orderNum: String,
var orderStatus: Int,//0支付取消 1支付成功 2支付失败 3待支付 4申请审核中 5退款中 6退款成功 7退款失败 8审核失败 var orderStatus: Int,//0支付取消 1支付成功 2支付失败 3待支付 4申请审核中 5退款中 6退款成功 7退款失败 8审核失败
var payTime: String, var payTime: Long,
var payType: Int, var payType: Int,
var planCategory: String, var planCategory: String,
var planId: String, var planId: String,
@@ -53,6 +53,7 @@ data class SubscriptionsOrderBean(
var username: String, var username: String,
var iccid: String, var iccid: String,
var endTime: Long, var endTime: Long,
var refundTime: Long,
var planTimeMonthsCount: Int, var planTimeMonthsCount: Int,
@MultipleEntity var menuType: Int, @MultipleEntity var menuType: Int,
var isUpdateOrder: Int = 0//是否是升级订单 1:是 0:否 var isUpdateOrder: Int = 0//是否是升级订单 1:是 0:否
@@ -76,7 +77,7 @@ data class SubscriptionsOrderBean(
0.0, 0.0,
"", "",
0, 0,
"", 0L,
0, 0,
"", "",
"", "",
@@ -98,6 +99,7 @@ data class SubscriptionsOrderBean(
"", "",
"", "",
0L, 0L,
0L,
0, 0,
menuType, menuType,
0 0
@@ -122,7 +124,7 @@ data class SubscriptionsOrderBean(
0.0, 0.0,
"", "",
0, 0,
"", 0L,
0, 0,
"", "",
"", "",
@@ -144,6 +146,7 @@ data class SubscriptionsOrderBean(
"", "",
"", "",
0L, 0L,
0L,
0, 0,
MultipleEntity.TEXT, MultipleEntity.TEXT,
0 0

View File

@@ -63,13 +63,12 @@ class PaymentSuccessActivity :
ivPaymentSuccessAnim.load(R.drawable.pwd_reset_successful_done) ivPaymentSuccessAnim.load(R.drawable.pwd_reset_successful_done)
mPayResult?.let { mPayResult?.let {
LogUtil.e("充值类型rechargeType=${it.rechargeType}") LogUtil.e("充值类型rechargeType=${it.rechargeType}")
// if (it.rechargeType == ConstantInt.Type0) {
// btnPaymentSuccessContinue.setText(R.string.txt_continue)
// }
tvPaymentSuccessDeviceId.text = it.deviceOutId tvPaymentSuccessDeviceId.text = it.deviceOutId
tvPaymentSuccessExpiresOnDate.text = Utils.stringToDate( tvPaymentSuccessExpiresOnDate.text = Utils.formatTime(
it.expirationTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7 Utils.stringToTimestamp(
it.expirationTime, isUtc = true
), Utils.DATE_FORMAT_PATTERN_EN6
) )
val times = Utils.differYear( val times = Utils.differYear(
System.currentTimeMillis(), Utils.stringToTimestamp(it.expirationTime) System.currentTimeMillis(), Utils.stringToTimestamp(it.expirationTime)

View File

@@ -2,7 +2,6 @@ package com.abbidot.tracker.ui.activity.subscribe
import android.content.Intent import android.content.Intent
import android.graphics.Paint import android.graphics.Paint
import android.text.TextUtils
import android.view.Gravity import android.view.Gravity
import android.view.View import android.view.View
import androidx.activity.viewModels import androidx.activity.viewModels
@@ -294,18 +293,21 @@ class SureSubscriptionPlanActivity :
} }
//判断套餐是否过期 或者套餐没退款 //判断套餐是否过期 或者套餐没退款
if (!TextUtils.isEmpty(it.orderNum) && it.orderStatus != 6 && it.surplusDays == 0L && it.subscriptionStatus == ConstantInt.Close) { // if (!TextUtils.isEmpty(it.orderNum) && it.orderStatus != 6 && it.surplusDays == 0L && it.subscriptionStatus == ConstantInt.Close) {
// mOrderBean?.reactivation = 1 //// mOrderBean?.reactivation = 1
mSubscriptionViewModel.getReactivationFee(it.orderNum) // mSubscriptionViewModel.getReactivationFee(it.orderNum)
} else { // } else {
if (isUpgrade) mSubscriptionViewModel.getReactivationFee(it.orderNum) // if (isUpgrade) mSubscriptionViewModel.getReactivationFee(it.orderNum)
else { // else {
// mOrderBean?.reactivation = 0
// mOrderBean?.reactivatePrice = 0.0
// updateMoney()
// }
// }
mOrderBean?.reactivation = 0 mOrderBean?.reactivation = 0
mOrderBean?.reactivatePrice = 0.0 mOrderBean?.reactivatePrice = 0.0
updateMoney() updateMoney()
}
}
//隐藏保险 //隐藏保险
mViewBinding.ilSubscribePlanInsurance.cbSureSubscribeInsureSwitch.isChecked = false mViewBinding.ilSubscribePlanInsurance.cbSureSubscribeInsureSwitch.isChecked = false
@@ -327,16 +329,6 @@ class SureSubscriptionPlanActivity :
mReactivationFeeLiveData.observe(this@SureSubscriptionPlanActivity) { mReactivationFeeLiveData.observe(this@SureSubscriptionPlanActivity) {
dealRequestResult(it, object : GetResultCallback { dealRequestResult(it, object : GetResultCallback {
override fun onResult(any: Any) { override fun onResult(any: Any) {
// it.getOrNull()?.apply {
// mOrderBean?.reactivatePrice = this
// mSummaryAdapter.getData().add(
// 2, MenuTxtBean(
// getString(R.string.txt_reactivation), Utils.formatDecimal(this, 1)
// ).apply {
// colorRedId = R.color.data_black_color
// })
// mTotalMoney += this
// }
it.getOrNull()?.apply { it.getOrNull()?.apply {
mPackageBean?.let { p -> mPackageBean?.let { p ->
mTotalMoney -= mSumInsuranceMoney mTotalMoney -= mSumInsuranceMoney

View File

@@ -38,6 +38,7 @@
style="@style/my_TextView_style_v2" style="@style/my_TextView_style_v2"
android:layout_below="@id/tv_subscription_history_order_time" android:layout_below="@id/tv_subscription_history_order_time"
android:text="@string/txt_annual_care_text1" android:text="@string/txt_annual_care_text1"
android:visibility="gone"
android:layout_marginTop="@dimen/dp_4" android:layout_marginTop="@dimen/dp_4"
android:textSize="@dimen/textSize14" android:textSize="@dimen/textSize14"
android:textStyle="bold" /> android:textStyle="bold" />
@@ -49,13 +50,14 @@
android:layout_marginStart="@dimen/dp_4" android:layout_marginStart="@dimen/dp_4"
android:layout_toEndOf="@id/tv_subscription_history_annual_care_title" android:layout_toEndOf="@id/tv_subscription_history_annual_care_title"
android:text="@string/app_name" android:text="@string/app_name"
android:visibility="gone"
android:textSize="@dimen/textSize14" android:textSize="@dimen/textSize14"
app:typeface="@string/roboto_regular_font" /> app:typeface="@string/roboto_regular_font" />
<com.abbidot.tracker.widget.TypefaceTextView <com.abbidot.tracker.widget.TypefaceTextView
android:id="@+id/tv_subscription_history_package_name" android:id="@+id/tv_subscription_history_package_name"
style="@style/my_TextView_style_v2" style="@style/my_TextView_style_v2"
android:layout_below="@id/tv_subscription_history_annual_care_title" android:layout_below="@id/tv_subscription_history_order_time"
android:layout_marginTop="@dimen/dp_6" android:layout_marginTop="@dimen/dp_6"
android:text="@string/txt_order_id" android:text="@string/txt_order_id"
android:textSize="@dimen/textSize14" android:textSize="@dimen/textSize14"

View File

@@ -10,6 +10,7 @@ import java.time.Period
import java.util.Calendar import java.util.Calendar
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
import java.util.TimeZone
import java.util.regex.Pattern import java.util.regex.Pattern
import kotlin.math.atan2 import kotlin.math.atan2
import kotlin.math.cos import kotlin.math.cos
@@ -50,16 +51,15 @@ class Utils {
/** /**
* 时间戳转指定格式时间 * 时间戳转指定格式时间
* *
* @param time 13位时间戳 * @param cTimestamp 13位时间戳
* @return 时间 * @return 时间
*/ */
fun formatTime(time: Long, format: String): String { fun formatTime(cTimestamp: Long, format: String): String {
val timeMillis = if (cTimestamp < 1000000000000) cTimestamp * 1000 else cTimestamp
// 创建一个使用系统默认时区的格式化器
val sdf = SimpleDateFormat(format, Locale.getDefault()) val sdf = SimpleDateFormat(format, Locale.getDefault())
return if (time < 1000000000000) { // 直接将时间戳代表UTC时刻格式化为本地时间字符串
sdf.format(Date(time * 1000)) return sdf.format(Date(timeMillis))
} else {
sdf.format(Date(time))
}
} }
/** /**
@@ -94,12 +94,16 @@ class Utils {
/** /**
* 把字符串转成时间戳,返回13位时间戳 * 把字符串转成时间戳,返回13位时间戳
* @param parseFormat 字符串是什么格式的日期就传什么格式 * @param parseFormat 字符串是什么格式的日期就传什么格式
* @param isUtc 是否是0时区utc
*/ */
fun stringToTimestamp( fun stringToTimestamp(
dateString: String, parseFormat: String = DATE_FORMAT_PATTERN_CN2 dateString: String,
parseFormat: String = DATE_FORMAT_PATTERN_CN2,
isUtc: Boolean = false
): Long { ): Long {
return try { return try {
val formatter = SimpleDateFormat(parseFormat, Locale.getDefault()) val formatter = SimpleDateFormat(parseFormat, Locale.getDefault())
if (isUtc) formatter.timeZone = TimeZone.getTimeZone("UTC")
val date = formatter.parse(dateString) val date = formatter.parse(dateString)
date?.time ?: 0 date?.time ?: 0
} catch (e: Exception) { } catch (e: Exception) {
@@ -109,6 +113,18 @@ class Utils {
} }
} }
fun timestampAddHowTimestamp(cTimestamp: Long, period: Int, timeUnit: String): Long {
val timeMillis = if (cTimestamp < 1000000000000) cTimestamp * 1000 else cTimestamp
val calendar = Calendar.getInstance()
calendar.timeInMillis = timeMillis
when (timeUnit) {
"DAY" -> calendar.add(Calendar.DAY_OF_MONTH, period)
"MONTH" -> calendar.add(Calendar.MONTH, period)
"YEAR" -> calendar.add(Calendar.YEAR, period)
}
return calendar.timeInMillis
}
/** /**
* 获取这个时间戳的,前几天13位时间戳 * 获取这个时间戳的,前几天13位时间戳
*/ */