费用计算问题修复

This commit is contained in:
yanglei 2025-12-17 15:41:01 +08:00
parent a39239c327
commit 9fb8af07c3
2 changed files with 15 additions and 5 deletions

View File

@ -24,6 +24,10 @@ public interface GlobalConstants {
Integer NUMBER_FIVE = 5;
Integer NUMBER_FIFTY_NINE = 59;
Integer NUMBER_SIXTY = 60;
Integer NUMBER_ONE_HUNDRED = 100;
// 字符串状态常量
@ -54,4 +58,5 @@ public interface GlobalConstants {
Long LONG_FIVE = 5L;
Long LONG_SIXTY = 60L;
}

View File

@ -1,6 +1,7 @@
package com.cdzy.user.service.impl;
import com.cdzy.common.enums.Code;
import com.cdzy.common.enums.GlobalConstants;
import com.cdzy.common.ex.EbikeException;
import com.cdzy.common.model.request.PageParam;
import com.cdzy.common.model.response.JsonResult;
@ -54,7 +55,7 @@ import static com.cdzy.user.model.entity.table.EbikeRefundTableDef.EBIKE_REFUND;
*/
@Slf4j
@Service
public class EbikeOrderImpl extends ServiceImpl<EbikeOrderMapper, EbikeOrder> implements EbikeOrderService {
public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOrder> implements EbikeOrderService {
@Resource
private EbikeOrderMapper ebikeOrderTransactionMapper;
@ -415,14 +416,18 @@ public class EbikeOrderImpl extends ServiceImpl<EbikeOrderMapper, EbikeOrder> im
BigDecimal durationFee = bikeInfo.getDurationFee();
Integer freeDurationMinutes = bikeInfo.getFreeDurationMinutes();
Integer chargeDurationMinutes = bikeInfo.getChargeDurationMinutes();
// 骑行时长分钟
long totalRideMinutes = Duration.between(startTime, endTime).toMinutes();
// 获取总骑行时长
long totalRideSeconds = Duration.between(startTime, endTime).toSeconds();
// 免费时间
long freeDurationSeconds = freeDurationMinutes * GlobalConstants.LONG_SIXTY;
// 如果骑行时长小于等于免费时长,不收费
BigDecimal baseCost;
if (totalRideMinutes <= freeDurationMinutes) {
if (totalRideSeconds <= freeDurationSeconds) {
return BigDecimal.ZERO;
} else {
long chargeableMinutes = totalRideMinutes - freeDurationMinutes;
long totalRoundedMinutes = (totalRideSeconds + GlobalConstants.NUMBER_FIFTY_NINE) / GlobalConstants.NUMBER_SIXTY;
// 可计费分钟数 = 向上取整后的总分钟 - 免费分钟
long chargeableMinutes = totalRoundedMinutes - freeDurationMinutes;
long chargeUnits = (chargeableMinutes + chargeDurationMinutes - 1) / chargeDurationMinutes;
BigDecimal durationCost = durationFee.multiply(BigDecimal.valueOf(chargeUnits));
// 总基础费用