From a9dae6df6931ac1870faa87be6265624b81ac302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Tue, 10 Mar 2026 16:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Dtos/CreateOrderInput.cs | 1 + .../Order/Dtos/OrderListOutput.cs | 3 ++ YD_Event.Application/Order/OrderService.cs | 42 +++++++++++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/YD_Event.Application/Order/Dtos/CreateOrderInput.cs b/YD_Event.Application/Order/Dtos/CreateOrderInput.cs index cfaac0d..eb1b146 100644 --- a/YD_Event.Application/Order/Dtos/CreateOrderInput.cs +++ b/YD_Event.Application/Order/Dtos/CreateOrderInput.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using YD_Event.Core.Enum; namespace YD_Event.Application.Order.Dtos; diff --git a/YD_Event.Application/Order/Dtos/OrderListOutput.cs b/YD_Event.Application/Order/Dtos/OrderListOutput.cs index 54d8171..9b30646 100644 --- a/YD_Event.Application/Order/Dtos/OrderListOutput.cs +++ b/YD_Event.Application/Order/Dtos/OrderListOutput.cs @@ -20,6 +20,9 @@ public class OrderListOutput public decimal ActualAmount { get; set; } // Paid or Refunded public OrderStatus OrderStatus { get; set; } public DateTime CreatedTime { get; set; } + public DateTime? PaymentTime { get; set; } + public decimal? RefundAmount { get; set; } + public DateTime? RefundTime { get; set; } } public class OrderDetailOutput diff --git a/YD_Event.Application/Order/OrderService.cs b/YD_Event.Application/Order/OrderService.cs index 348219d..a112567 100644 --- a/YD_Event.Application/Order/OrderService.cs +++ b/YD_Event.Application/Order/OrderService.cs @@ -1,4 +1,5 @@ using System.Text; +using YD_Event.Application.Auth; using YD_Event.Application.Order.Dtos; using YD_Event.Core.Entities; using YD_Event.Core.Enum; @@ -20,6 +21,7 @@ public class OrderService : BaseService, ITransien private readonly ISqlSugarRepository _merchantRepository; private readonly RefundConfigService _refundConfigService; private readonly IIdGenerator _idGenerator; + private readonly AuthManager _authManager; public OrderService( ISqlSugarRepository orderRepository, @@ -30,7 +32,8 @@ public class OrderService : BaseService, ITransien ISqlSugarRepository eventRepository, ISqlSugarRepository merchantRepository, RefundConfigService refundConfigService, - IIdGenerator idGenerator) : base(orderRepository) + IIdGenerator idGenerator, + AuthManager authManager) : base(orderRepository) { _orderRepository = orderRepository; _registrationRepository = registrationRepository; @@ -41,6 +44,7 @@ public class OrderService : BaseService, ITransien _merchantRepository = merchantRepository; _refundConfigService = refundConfigService; _idGenerator = idGenerator; + _authManager = authManager; } /// @@ -134,6 +138,10 @@ public class OrderService : BaseService, ITransien [HttpGet("page")] public async Task> Page([FromQuery] OrderQueryInput input) { + var userId = _authManager.UserId; + // 判断是否是商户账号 + var merchant = await _merchantRepository.GetFirstAsync(m => m.CreatedUserId == userId); + var query = _orderRepository.AsQueryable() .LeftJoin((o, e) => o.EventId == e.Id) .LeftJoin((o, e, m) => o.MerchantId == m.Id) @@ -146,10 +154,24 @@ public class OrderService : BaseService, ITransien .WhereIF(input.PaymentMethod.HasValue, (o, e, m, r, ro) => o.PaymentMethod == input.PaymentMethod) .WhereIF(input.RegistrationMode.HasValue, (o, e, m, r, ro) => o.RegistrationMode == input.RegistrationMode) .WhereIF(!string.IsNullOrWhiteSpace(input.ContactPhone), (o, e, m, r, ro) => r.ContactPhone.Contains(input.ContactPhone)) - .WhereIF(input.StartTime.HasValue, (o, e, m, r, ro) => o.CreatedTime >= input.StartTime) - .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.CreatedTime <= input.EndTime) - .OrderByDescending((o, e, m, r, ro) => o.CreatedTime) - .Select((o, e, m, r, ro) => new OrderListOutput + .WhereIF(input.StartTime.HasValue, (o, e, m, r, ro) => o.PaymentTime >= input.StartTime) // 支付时间筛选 + .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.PaymentTime <= input.EndTime) + .OrderByDescending((o, e, m, r, ro) => o.CreatedTime); + + if (merchant != null) + { + // 商户只能看到自己关联的订单(例如作为收款方,或者作为发起方?) + // 假设订单中的 MerchantId 是收款商户。 + // 如果当前用户是商户,则只能查看 MerchantId 为自己的订单 + query = query.Where(o => o.MerchantId == merchant.Id); + } + else + { + // 个人用户只能看到自己创建的订单 + query = query.Where(o => o.CreatedUserId == userId); + } + + var result = await query.Select((o, e, m, r, ro) => new OrderListOutput { Id = o.Id, OrderNo = o.OrderNo, @@ -166,10 +188,14 @@ public class OrderService : BaseService, ITransien DiscountAmount = o.DiscountAmount, ActualAmount = o.ActualAmount, OrderStatus = o.OrderStatus, - CreatedTime = o.CreatedTime - }); + CreatedTime = o.CreatedTime, + PaymentTime = o.PaymentTime, + RefundAmount = o.OrderType == 2 ? o.ActualAmount : 0, // 如果是退款订单,ActualAmount即为退款金额 + RefundTime = o.OrderType == 2 ? o.PaymentTime : null // 退款时间 + }) + .ToPagedListAsync(input); - return await query.ToPagedListAsync(input); + return result; } ///