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

View File

@@ -51,24 +51,27 @@ class NotificationV2Adapter(
setTextColor(ContextCompat.getColor(mContext, textColor))
}
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))
}
}
private fun getRelativeTimeString(time: Long): String {
private fun getRelativeTimeString(sendTime: String): String {
var formatDateStr = ""
val time = Utils.stringToTimestamp(sendTime)
val now = System.currentTimeMillis()
formatDateStr = if (DateUtils.isToday(time)) {
mContext.getString(R.string.txt_today) + " " + Utils.formatTime(
time, Utils.DATE_FORMAT_PATTERN_EN8
)
} else if (now - time < (48 * 60 * 60 * 1000)) {
mContext.getString(R.string.txt_yesterday)+ " " + Utils.formatTime(
mContext.getString(R.string.txt_yesterday) + " " + Utils.formatTime(
time, Utils.DATE_FORMAT_PATTERN_EN8
)
} else {
Utils.formatTime(time, Utils.DATE_FORMAT_PATTERN_EN9)
Utils.formatTime(
Utils.stringToTimestamp(sendTime, isUtc = true), Utils.DATE_FORMAT_PATTERN_EN9
)
}
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_active_time,
Utils.stringToDate(item.createTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7)
R.id.tv_subscription_annual_care_active_time, Utils.formatTime(
item.payTime, Utils.DATE_FORMAT_PATTERN_EN7
)
)
//保险时长不足一年按12个月算
val insuranceTime =
if (item.mealUnit == ConstantString.PackageUnitYear) item.mealPeriod else 1
holder.setText(
R.id.tv_subscription_annual_care_expiry_time, Utils.formatTime(
Utils.getAfterHowTimestamp(
Utils.stringToTimestamp(item.createTime), insuranceTime * 365L
Utils.timestampAddHowTimestamp(
item.payTime, insuranceTime, ConstantString.PackageUnitYear
), Utils.DATE_FORMAT_PATTERN_EN7
)
)
@@ -89,7 +90,7 @@ class SubscriptionHistoryAdapter(
)
holder.setText(
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(
@@ -109,8 +110,14 @@ class SubscriptionHistoryAdapter(
1 -> {
val updateTimestamp = Utils.stringToTimestamp(item.updateTime)
val nowTimestamp = System.currentTimeMillis()
// val nowTimestamp = Utils.stringToTimestamp(item.currentTime)
if (item.mealUnit == ConstantString.PackageUnitMonth) {
if (item.mealUnit == ConstantString.PackageUnitDay) {
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
//套餐超出7天不能退款
if (nowTimestamp - updateTimestamp <= day7Timestamp) {

View File

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

View File

@@ -63,13 +63,12 @@ class PaymentSuccessActivity :
ivPaymentSuccessAnim.load(R.drawable.pwd_reset_successful_done)
mPayResult?.let {
LogUtil.e("充值类型rechargeType=${it.rechargeType}")
// if (it.rechargeType == ConstantInt.Type0) {
// btnPaymentSuccessContinue.setText(R.string.txt_continue)
// }
tvPaymentSuccessDeviceId.text = it.deviceOutId
tvPaymentSuccessExpiresOnDate.text = Utils.stringToDate(
it.expirationTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7
tvPaymentSuccessExpiresOnDate.text = Utils.formatTime(
Utils.stringToTimestamp(
it.expirationTime, isUtc = true
), Utils.DATE_FORMAT_PATTERN_EN6
)
val times = Utils.differYear(
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.graphics.Paint
import android.text.TextUtils
import android.view.Gravity
import android.view.View
import androidx.activity.viewModels
@@ -294,20 +293,23 @@ class SureSubscriptionPlanActivity :
}
//判断套餐是否过期 或者套餐没退款
if (!TextUtils.isEmpty(it.orderNum) && it.orderStatus != 6 && it.surplusDays == 0L && it.subscriptionStatus == ConstantInt.Close) {
// mOrderBean?.reactivation = 1
mSubscriptionViewModel.getReactivationFee(it.orderNum)
} else {
if (isUpgrade) mSubscriptionViewModel.getReactivationFee(it.orderNum)
else {
// if (!TextUtils.isEmpty(it.orderNum) && it.orderStatus != 6 && it.surplusDays == 0L && it.subscriptionStatus == ConstantInt.Close) {
//// mOrderBean?.reactivation = 1
// mSubscriptionViewModel.getReactivationFee(it.orderNum)
// } else {
// if (isUpgrade) mSubscriptionViewModel.getReactivationFee(it.orderNum)
// else {
// mOrderBean?.reactivation = 0
// mOrderBean?.reactivatePrice = 0.0
// updateMoney()
// }
// }
mOrderBean?.reactivation = 0
mOrderBean?.reactivatePrice = 0.0
updateMoney()
}
}
//隐藏保险
mViewBinding.ilSubscribePlanInsurance.cbSureSubscribeInsureSwitch.isChecked=false
mViewBinding.ilSubscribePlanInsurance.cbSureSubscribeInsureSwitch.isChecked = false
}
}
@@ -327,16 +329,6 @@ class SureSubscriptionPlanActivity :
mReactivationFeeLiveData.observe(this@SureSubscriptionPlanActivity) {
dealRequestResult(it, object : GetResultCallback {
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 {
mPackageBean?.let { p ->
mTotalMoney -= mSumInsuranceMoney

View File

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

View File

@@ -10,6 +10,7 @@ import java.time.Period
import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.TimeZone
import java.util.regex.Pattern
import kotlin.math.atan2
import kotlin.math.cos
@@ -50,16 +51,15 @@ class Utils {
/**
* 时间戳转指定格式时间
*
* @param time 13位时间戳
* @param cTimestamp 13位时间戳
* @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())
return if (time < 1000000000000) {
sdf.format(Date(time * 1000))
} else {
sdf.format(Date(time))
}
// 直接将时间戳代表UTC时刻格式化为本地时间字符串
return sdf.format(Date(timeMillis))
}
/**
@@ -94,12 +94,16 @@ class Utils {
/**
* 把字符串转成时间戳,返回13位时间戳
* @param parseFormat 字符串是什么格式的日期就传什么格式
* @param isUtc 是否是0时区utc
*/
fun stringToTimestamp(
dateString: String, parseFormat: String = DATE_FORMAT_PATTERN_CN2
dateString: String,
parseFormat: String = DATE_FORMAT_PATTERN_CN2,
isUtc: Boolean = false
): Long {
return try {
val formatter = SimpleDateFormat(parseFormat, Locale.getDefault())
if (isUtc) formatter.timeZone = TimeZone.getTimeZone("UTC")
val date = formatter.parse(dateString)
date?.time ?: 0
} 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位时间戳
*/
@@ -134,7 +150,7 @@ class Utils {
val period = Period.between(LocalDate.parse(startDate), LocalDate.parse(endDate))
result[0] = "${period.years}"
result[1] = "${period.months}"
result[2] = "${if(period.days<0) 0 else period.days}"
result[2] = "${if (period.days < 0) 0 else period.days}"
} else {
val dfs = SimpleDateFormat(DATE_FORMAT_PATTERN_CN, Locale.getDefault())
val sDate = dfs.parse(startDate)!!
@@ -162,7 +178,7 @@ class Utils {
}
result[0] = "$years"
result[1] = "$months"
result[2] = "${if(days<0) 0 else days}"
result[2] = "${if (days < 0) 0 else days}"
}
return result
}