From cc7290e8edf12ea1d540c1cfb0fc8ea3b861516b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Mon, 11 May 2026 16:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E6=95=B0=E5=90=8E=E4=B8=A4=E4=BD=8D?= =?UTF-8?q?=E5=90=91=E4=B8=8A=E5=8F=96=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/UnifiedRegistrationService.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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}",