From 79d07c92be2db370ea6e5a00ba280c01e413f9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Tue, 12 May 2026 22:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Client/EventClientController.cs | 11 +-- YD_Event.Application/Client/MyController.cs | 76 +++++++++++++++---- .../Event/UnifiedRegistrationService.cs | 11 +-- 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/YD_Event.Application/Client/EventClientController.cs b/YD_Event.Application/Client/EventClientController.cs index 615bbdb..5b2795e 100644 --- a/YD_Event.Application/Client/EventClientController.cs +++ b/YD_Event.Application/Client/EventClientController.cs @@ -1671,11 +1671,12 @@ public class EventClientController : IDynamicApiController }; await _orderRepository.InsertAsync(refundOrder); - // 更新原订单状态 - originalOrder.OrderStatus = OrderStatus.Refunded; - originalOrder.UpdatedTime = now; - originalOrder.UpdatedUserId = userId; - await _orderRepository.UpdateAsync(originalOrder); + // 不更新原订单状态,保持原订单状态不变 + // // 更新原订单状态 + // originalOrder.OrderStatus = OrderStatus.Refunded; + // originalOrder.UpdatedTime = now; + // originalOrder.UpdatedUserId = userId; + // await _orderRepository.UpdateAsync(originalOrder); // 更新报名状态,清空订单号,确保下次重新报名时创建新订单 registration.PaymentStatus = 3; diff --git a/YD_Event.Application/Client/MyController.cs b/YD_Event.Application/Client/MyController.cs index 0a258c6..40a05c0 100644 --- a/YD_Event.Application/Client/MyController.cs +++ b/YD_Event.Application/Client/MyController.cs @@ -517,23 +517,62 @@ public class MyController : IDynamicApiController public async Task> GetOrders([FromQuery] MyPageInput input) { var userId = GetCurrentUserId(); - var query = _orderRepository.AsQueryable() + + // 先查询所有订单 + var orders = await _orderRepository.AsQueryable() .LeftJoin((o, e) => o.EventId == e.Id) .Where((o, e) => o.CreatedUserId == userId && !o.DeleteMark && o.OrderStatus != OrderStatus.Cancelled) - .Select((o, e) => new MyOrderDto + .Select((o, e) => new { - Id = o.Id, - OrderNo = o.OrderNo, + o.Id, + o.OrderNo, EventName = e.EventName, - ActualAmount = o.ActualAmount, - RefundAmount = o.OrderType == 2 ? o.ActualAmount : null, - OrderStatus = o.OrderStatus, - PaymentTime = o.PaymentTime, - CreatedTime = o.CreatedTime + o.ActualAmount, + o.OrderType, + o.RelatedOrderId, + o.OrderStatus, + o.PaymentTime, + o.CreatedTime }) - .OrderByDescending(o => o.CreatedTime); - - return await query.ToPagedListAsync(input); + .OrderByDescending(o => o.CreatedTime) + .ToPagedListAsync(input); + + // 处理退款订单的金额显示 + var resultList = new List(); + foreach (var order in orders.Rows) + { + var dto = new MyOrderDto + { + Id = order.Id, + OrderNo = order.OrderNo, + EventName = order.EventName, + ActualAmount = order.ActualAmount, + RefundAmount = order.OrderType == 2 ? order.ActualAmount : null, + OrderStatus = order.OrderStatus, + PaymentTime = order.PaymentTime, + CreatedTime = order.CreatedTime + }; + + // 如果是退款订单,查找关联的原始订单,显示原始支付金额 + if (order.OrderType == 2 && order.RelatedOrderId > 0) + { + var originalOrder = await _orderRepository.GetByIdAsync(order.RelatedOrderId); + if (originalOrder != null) + { + dto.ActualAmount = originalOrder.ActualAmount; + } + } + + resultList.Add(dto); + } + + return new PageResult + { + PageNo = orders.PageNo, + PageSize = orders.PageSize, + Total = orders.Total, + Rows = resultList + }; } /// @@ -578,12 +617,23 @@ public class MyController : IDynamicApiController .ToListAsync(); } + // 如果是退款订单,查找关联的原始订单,显示原始支付金额 + decimal displayAmount = order.ActualAmount; + if (order.OrderType == 2 && order.RelatedOrderId > 0) + { + var originalOrder = await _orderRepository.GetByIdAsync(order.RelatedOrderId); + if (originalOrder != null) + { + displayAmount = originalOrder.ActualAmount; + } + } + return new MyOrderDetailDto { Id = order.Id, OrderNo = order.OrderNo, EventName = eventName, - ActualAmount = order.ActualAmount, + ActualAmount = displayAmount, RefundAmount = order.OrderType == 2 ? order.ActualAmount : null, RefundTime = order.OrderType == 2 ? order.PaymentTime : null, OrderStatus = order.OrderStatus, diff --git a/YD_Event.Application/Event/UnifiedRegistrationService.cs b/YD_Event.Application/Event/UnifiedRegistrationService.cs index f74eb5d..c02d789 100644 --- a/YD_Event.Application/Event/UnifiedRegistrationService.cs +++ b/YD_Event.Application/Event/UnifiedRegistrationService.cs @@ -3728,11 +3728,12 @@ public class UnifiedRegistrationService : ITransient } } - if (!isPartialCancel || registration.PaymentStatus == 3 || registration.PaymentStatus == 4) - { - var orderStatus = registration.PaymentMethod == 1 ? OrderStatus.Cancelled : OrderStatus.Refunded; - await UpdateOrderStatusAsync(registration.OrderNo, orderStatus, operatorUserId); - } + // 不修改原订单状态,只创建退款订单记录 + // if (!isPartialCancel || registration.PaymentStatus == 3 || registration.PaymentStatus == 4) + // { + // var orderStatus = registration.PaymentMethod == 1 ? OrderStatus.Cancelled : OrderStatus.Refunded; + // await UpdateOrderStatusAsync(registration.OrderNo, orderStatus, operatorUserId); + // } _logger.LogInformation("统一取消报名完成:报名ID={RegistrationId}, 操作人={UserId}, 退款金额={RefundAmount}, 成功={Success}", registration.Id, operatorUserId, actualRefundAmount, output.Success);