diff --git a/YD_Event.Application/Event/UnifiedRegistrationService.cs b/YD_Event.Application/Event/UnifiedRegistrationService.cs index 52455a3..c704352 100644 --- a/YD_Event.Application/Event/UnifiedRegistrationService.cs +++ b/YD_Event.Application/Event/UnifiedRegistrationService.cs @@ -2719,12 +2719,20 @@ public class UnifiedRegistrationService : ITransient /// 赛事开始时间 /// 应退金额 [NonAction] + private decimal RoundUpToTwoDecimalPlaces(decimal amount) + { + // 原理:将金额乘100转成整数,用Math.Ceiling向上取整,再除100 + // 例如:0.125 * 100 = 12.5 → Ceiling后=13 → 13/100=0.13 + // 例如:0.124 * 100 = 12.4 → Ceiling后=13 → 13/100=0.13 + var roundedAmount = Math.Ceiling(amount * 100) / 100; + return roundedAmount; + } + public async Task CalculateRefundAmountAsync(decimal totalAmount, DateTime eventStartTime) { var refundAmount = await _refundConfigService.CalculateRefundAmount(totalAmount, eventStartTime); - _logger.LogInformation("统一退款金额计算:总金额={TotalAmount}, 赛事开始时间={EventStartTime}, 计算后退款金额={RefundAmount}", - totalAmount, eventStartTime, refundAmount); - return refundAmount; + var roundedRefundAmount = RoundUpToTwoDecimalPlaces(refundAmount); + return roundedRefundAmount; } /// @@ -3358,9 +3366,9 @@ public class UnifiedRegistrationService : ITransient // 先计算按原价应该退多少 decimal originalRefundAmount = await CalculateActualRefundAmountAsync(input, registration, eventInfo, items, persons); - // 然后按比例计算实际退款金额(考虑优惠券折扣) + // 按比例计算实际退款金额 decimal actualRefundAmount = originalAmount > 0 ? originalRefundAmount * (actualPaidAmount / originalAmount) : 0; - // 确保退款金额不超过实际支付金额 + actualRefundAmount = RoundUpToTwoDecimalPlaces(actualRefundAmount); actualRefundAmount = Math.Min(actualRefundAmount, actualPaidAmount); _logger.LogInformation("统一退款金额计算:报名ID={RegistrationId}, 原价={OriginalAmount}, 实付={ActualPaidAmount}, 按原价应退={OriginalRefundAmount}, 实际退款={ActualRefundAmount}",