订单管理

This commit is contained in:
马梓彭 2026-03-10 16:54:18 +08:00
parent db15e4c68b
commit a9dae6df69
3 changed files with 38 additions and 8 deletions

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using YD_Event.Core.Enum;
namespace YD_Event.Application.Order.Dtos; namespace YD_Event.Application.Order.Dtos;

View File

@ -20,6 +20,9 @@ public class OrderListOutput
public decimal ActualAmount { get; set; } // Paid or Refunded public decimal ActualAmount { get; set; } // Paid or Refunded
public OrderStatus OrderStatus { get; set; } public OrderStatus OrderStatus { get; set; }
public DateTime CreatedTime { 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 public class OrderDetailOutput

View File

@ -1,4 +1,5 @@
using System.Text; using System.Text;
using YD_Event.Application.Auth;
using YD_Event.Application.Order.Dtos; using YD_Event.Application.Order.Dtos;
using YD_Event.Core.Entities; using YD_Event.Core.Entities;
using YD_Event.Core.Enum; using YD_Event.Core.Enum;
@ -20,6 +21,7 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
private readonly ISqlSugarRepository<YD_Event.Core.Entities.Merchant> _merchantRepository; private readonly ISqlSugarRepository<YD_Event.Core.Entities.Merchant> _merchantRepository;
private readonly RefundConfigService _refundConfigService; private readonly RefundConfigService _refundConfigService;
private readonly IIdGenerator _idGenerator; private readonly IIdGenerator _idGenerator;
private readonly AuthManager _authManager;
public OrderService( public OrderService(
ISqlSugarRepository<YD_Event.Core.Entities.Order> orderRepository, ISqlSugarRepository<YD_Event.Core.Entities.Order> orderRepository,
@ -30,7 +32,8 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
ISqlSugarRepository<EventInfo> eventRepository, ISqlSugarRepository<EventInfo> eventRepository,
ISqlSugarRepository<YD_Event.Core.Entities.Merchant> merchantRepository, ISqlSugarRepository<YD_Event.Core.Entities.Merchant> merchantRepository,
RefundConfigService refundConfigService, RefundConfigService refundConfigService,
IIdGenerator idGenerator) : base(orderRepository) IIdGenerator idGenerator,
AuthManager authManager) : base(orderRepository)
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
_registrationRepository = registrationRepository; _registrationRepository = registrationRepository;
@ -41,6 +44,7 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
_merchantRepository = merchantRepository; _merchantRepository = merchantRepository;
_refundConfigService = refundConfigService; _refundConfigService = refundConfigService;
_idGenerator = idGenerator; _idGenerator = idGenerator;
_authManager = authManager;
} }
/// <summary> /// <summary>
@ -134,6 +138,10 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
[HttpGet("page")] [HttpGet("page")]
public async Task<PageResult<OrderListOutput>> Page([FromQuery] OrderQueryInput input) public async Task<PageResult<OrderListOutput>> Page([FromQuery] OrderQueryInput input)
{ {
var userId = _authManager.UserId;
// 判断是否是商户账号
var merchant = await _merchantRepository.GetFirstAsync(m => m.CreatedUserId == userId);
var query = _orderRepository.AsQueryable() var query = _orderRepository.AsQueryable()
.LeftJoin<EventInfo>((o, e) => o.EventId == e.Id) .LeftJoin<EventInfo>((o, e) => o.EventId == e.Id)
.LeftJoin<YD_Event.Core.Entities.Merchant>((o, e, m) => o.MerchantId == m.Id) .LeftJoin<YD_Event.Core.Entities.Merchant>((o, e, m) => o.MerchantId == m.Id)
@ -146,10 +154,24 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
.WhereIF(input.PaymentMethod.HasValue, (o, e, m, r, ro) => o.PaymentMethod == input.PaymentMethod) .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(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(!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.StartTime.HasValue, (o, e, m, r, ro) => o.PaymentTime >= input.StartTime) // 支付时间筛选
.WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.CreatedTime <= input.EndTime) .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.PaymentTime <= input.EndTime)
.OrderByDescending((o, e, m, r, ro) => o.CreatedTime) .OrderByDescending((o, e, m, r, ro) => o.CreatedTime);
.Select((o, e, m, r, ro) => new OrderListOutput
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, Id = o.Id,
OrderNo = o.OrderNo, OrderNo = o.OrderNo,
@ -166,10 +188,14 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
DiscountAmount = o.DiscountAmount, DiscountAmount = o.DiscountAmount,
ActualAmount = o.ActualAmount, ActualAmount = o.ActualAmount,
OrderStatus = o.OrderStatus, 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;
} }
/// <summary> /// <summary>