- 在MarketingCode聚合中新增品类ID和品类名称字段,完善产品信息结构 - 迁移生成营销码命令,支持传入品类ID和品类名称参数 - 积分发放失败时发送积分获得失败通知集成事件 - 新增通知发送及积分失败通知的集成事件处理器,使用SSE推送通知 - 在积分相关集成事件处理器中添加发送积分变动通知功能 - 移除Notification聚合,相关数据库表删除 - 新增分页结果类型PagedResult,支持营销码查询分页返回 - 营销码查询支持分页参数,返回分页结果数据
136 lines
5.1 KiB
C#
136 lines
5.1 KiB
C#
using Fengling.Backend.Domain.AggregatesModel.RedemptionOrderAggregate;
|
|
using Fengling.Backend.Infrastructure;
|
|
|
|
namespace Fengling.Backend.Web.Application.Queries.RedemptionOrders;
|
|
|
|
/// <summary>
|
|
/// 兑换订单列表查询
|
|
/// </summary>
|
|
public record GetRedemptionOrdersQuery(Guid? MemberId = null, int? Status = null) : IQuery<List<RedemptionOrderDto>>;
|
|
|
|
public record RedemptionOrderDto
|
|
{
|
|
public Guid Id { get; init; }
|
|
public string OrderNo { get; init; } = string.Empty;
|
|
public Guid MemberId { get; init; }
|
|
public Guid GiftId { get; init; }
|
|
public string GiftName { get; init; } = string.Empty;
|
|
public int GiftType { get; init; }
|
|
public int Quantity { get; init; }
|
|
public int ConsumedPoints { get; init; }
|
|
public RedemptionOrderAddressDto? ShippingAddress { get; init; }
|
|
public string? TrackingNo { get; init; }
|
|
public int Status { get; init; }
|
|
public string? CancelReason { get; init; }
|
|
public DateTime CreatedAt { get; init; }
|
|
public DateTime UpdatedAt { get; init; }
|
|
}
|
|
|
|
public record RedemptionOrderAddressDto
|
|
{
|
|
public string ReceiverName { get; init; } = string.Empty;
|
|
public string Phone { get; init; } = string.Empty;
|
|
public string Province { get; init; } = string.Empty;
|
|
public string City { get; init; } = string.Empty;
|
|
public string District { get; init; } = string.Empty;
|
|
public string DetailAddress { get; init; } = string.Empty;
|
|
}
|
|
|
|
public class GetRedemptionOrdersQueryHandler(ApplicationDbContext dbContext)
|
|
: IQueryHandler<GetRedemptionOrdersQuery, List<RedemptionOrderDto>>
|
|
{
|
|
public async Task<List<RedemptionOrderDto>> Handle(GetRedemptionOrdersQuery request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var query = dbContext.RedemptionOrders.AsQueryable();
|
|
|
|
if (request.MemberId.HasValue)
|
|
{
|
|
query = query.Where(x => x.MemberId == request.MemberId.Value);
|
|
}
|
|
|
|
if (request.Status.HasValue)
|
|
{
|
|
query = query.Where(x => (int)x.Status == request.Status.Value);
|
|
}
|
|
|
|
var orders = await query
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(x => new RedemptionOrderDto
|
|
{
|
|
Id = x.Id.Id,
|
|
OrderNo = x.OrderNo,
|
|
MemberId = x.MemberId,
|
|
GiftId = x.GiftId,
|
|
GiftName = x.GiftName,
|
|
GiftType = x.GiftType,
|
|
Quantity = x.Quantity,
|
|
ConsumedPoints = x.ConsumedPoints,
|
|
ShippingAddress = x.ShippingAddress == null
|
|
? null
|
|
: new RedemptionOrderAddressDto
|
|
{
|
|
ReceiverName = x.ShippingAddress.ReceiverName,
|
|
Phone = x.ShippingAddress.Phone,
|
|
Province = x.ShippingAddress.Province,
|
|
City = x.ShippingAddress.City,
|
|
District = x.ShippingAddress.District,
|
|
DetailAddress = x.ShippingAddress.DetailAddress
|
|
},
|
|
TrackingNo = x.TrackingNo,
|
|
Status = (int)x.Status,
|
|
CancelReason = x.CancelReason,
|
|
CreatedAt = x.CreatedAt,
|
|
UpdatedAt = x.UpdatedAt
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return orders;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 订单详情查询
|
|
/// </summary>
|
|
public record GetRedemptionOrderByIdQuery(Guid OrderId) : IQuery<RedemptionOrderDto?>;
|
|
|
|
public class GetRedemptionOrderByIdQueryHandler(ApplicationDbContext dbContext)
|
|
: IQueryHandler<GetRedemptionOrderByIdQuery, RedemptionOrderDto?>
|
|
{
|
|
public async Task<RedemptionOrderDto?> Handle(GetRedemptionOrderByIdQuery request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var order = await dbContext.RedemptionOrders
|
|
.Where(x => x.Id == new RedemptionOrderId(request.OrderId))
|
|
.Select(x => new RedemptionOrderDto
|
|
{
|
|
Id = x.Id.Id,
|
|
OrderNo = x.OrderNo,
|
|
MemberId = x.MemberId,
|
|
GiftId = x.GiftId,
|
|
GiftName = x.GiftName,
|
|
GiftType = x.GiftType,
|
|
Quantity = x.Quantity,
|
|
ConsumedPoints = x.ConsumedPoints,
|
|
ShippingAddress = x.ShippingAddress == null
|
|
? null
|
|
: new RedemptionOrderAddressDto
|
|
{
|
|
ReceiverName = x.ShippingAddress.ReceiverName,
|
|
Phone = x.ShippingAddress.Phone,
|
|
Province = x.ShippingAddress.Province,
|
|
City = x.ShippingAddress.City,
|
|
District = x.ShippingAddress.District,
|
|
DetailAddress = x.ShippingAddress.DetailAddress
|
|
},
|
|
TrackingNo = x.TrackingNo,
|
|
Status = (int)x.Status,
|
|
CancelReason = x.CancelReason,
|
|
CreatedAt = x.CreatedAt,
|
|
UpdatedAt = x.UpdatedAt
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
|
|
return order;
|
|
}
|
|
} |