refactor: 清理租户API旧模块代码
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付记录命令。
|
||||
/// </summary>
|
||||
public sealed class CreatePaymentCommand : IRequest<PaymentDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单 ID。
|
||||
/// </summary>
|
||||
public long OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付方式。
|
||||
/// </summary>
|
||||
public PaymentMethod Method { get; set; } = PaymentMethod.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// 支付状态。
|
||||
/// </summary>
|
||||
public PaymentStatus Status { get; set; } = PaymentStatus.Unpaid;
|
||||
|
||||
/// <summary>
|
||||
/// 金额。
|
||||
/// </summary>
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统交易号。
|
||||
/// </summary>
|
||||
public string? TradeNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 渠道单号。
|
||||
/// </summary>
|
||||
public string? ChannelTransactionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付时间。
|
||||
/// </summary>
|
||||
public DateTime? PaidAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注。
|
||||
/// </summary>
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始回调。
|
||||
/// </summary>
|
||||
public string? Payload { get; set; }
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using MediatR;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 删除支付记录命令。
|
||||
/// </summary>
|
||||
public sealed class DeletePaymentCommand : IRequest<bool>
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付记录 ID。
|
||||
/// </summary>
|
||||
public long PaymentId { get; set; }
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 更新支付记录命令。
|
||||
/// </summary>
|
||||
public sealed record UpdatePaymentCommand : IRequest<PaymentDto?>
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付记录 ID。
|
||||
/// </summary>
|
||||
public long PaymentId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单 ID。
|
||||
/// </summary>
|
||||
public long OrderId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付方式。
|
||||
/// </summary>
|
||||
public PaymentMethod Method { get; init; } = PaymentMethod.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// 支付状态。
|
||||
/// </summary>
|
||||
public PaymentStatus Status { get; init; } = PaymentStatus.Unpaid;
|
||||
|
||||
/// <summary>
|
||||
/// 金额。
|
||||
/// </summary>
|
||||
public decimal Amount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统交易号。
|
||||
/// </summary>
|
||||
public string? TradeNo { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 渠道单号。
|
||||
/// </summary>
|
||||
public string? ChannelTransactionId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付时间。
|
||||
/// </summary>
|
||||
public DateTime? PaidAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注。
|
||||
/// </summary>
|
||||
public string? Remark { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始回调。
|
||||
/// </summary>
|
||||
public string? Payload { get; init; }
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
using TakeoutSaaS.Shared.Abstractions.Serialization;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录 DTO。
|
||||
/// </summary>
|
||||
public sealed class PaymentDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付记录 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long TenantId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long OrderId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付方式。
|
||||
/// </summary>
|
||||
public PaymentMethod Method { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付状态。
|
||||
/// </summary>
|
||||
public PaymentStatus Status { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额。
|
||||
/// </summary>
|
||||
public decimal Amount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统交易号。
|
||||
/// </summary>
|
||||
public string? TradeNo { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 渠道单号。
|
||||
/// </summary>
|
||||
public string? ChannelTransactionId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付时间。
|
||||
/// </summary>
|
||||
public DateTime? PaidAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注。
|
||||
/// </summary>
|
||||
public string? Remark { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始回调。
|
||||
/// </summary>
|
||||
public string? Payload { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 退款记录。
|
||||
/// </summary>
|
||||
public IReadOnlyList<PaymentRefundDto> Refunds { get; init; } = Array.Empty<PaymentRefundDto>();
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间。
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; init; }
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
using TakeoutSaaS.Shared.Abstractions.Serialization;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 退款记录 DTO。
|
||||
/// </summary>
|
||||
public sealed class PaymentRefundDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 退款记录 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long PaymentRecordId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long OrderId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额。
|
||||
/// </summary>
|
||||
public decimal Amount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 渠道退款号。
|
||||
/// </summary>
|
||||
public string? ChannelRefundId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态。
|
||||
/// </summary>
|
||||
public PaymentRefundStatus Status { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始回调。
|
||||
/// </summary>
|
||||
public string? Payload { get; init; }
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Payments.Commands;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Domain.Payments.Entities;
|
||||
using TakeoutSaaS.Domain.Payments.Repositories;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付记录命令处理器。
|
||||
/// </summary>
|
||||
public sealed class CreatePaymentCommandHandler(IPaymentRepository paymentRepository, ILogger<CreatePaymentCommandHandler> logger)
|
||||
: IRequestHandler<CreatePaymentCommand, PaymentDto>
|
||||
{
|
||||
private readonly IPaymentRepository _paymentRepository = paymentRepository;
|
||||
private readonly ILogger<CreatePaymentCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PaymentDto> Handle(CreatePaymentCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var payment = new PaymentRecord
|
||||
{
|
||||
OrderId = request.OrderId,
|
||||
Method = request.Method,
|
||||
Status = request.Status,
|
||||
Amount = request.Amount,
|
||||
TradeNo = request.TradeNo?.Trim(),
|
||||
ChannelTransactionId = request.ChannelTransactionId?.Trim(),
|
||||
PaidAt = request.PaidAt,
|
||||
Remark = request.Remark?.Trim(),
|
||||
Payload = request.Payload
|
||||
};
|
||||
|
||||
await _paymentRepository.AddPaymentAsync(payment, cancellationToken);
|
||||
await _paymentRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("创建支付记录 {PaymentId} 对应订单 {OrderId}", payment.Id, payment.OrderId);
|
||||
|
||||
return MapToDto(payment, []);
|
||||
}
|
||||
|
||||
private static PaymentDto MapToDto(PaymentRecord payment, IReadOnlyList<PaymentRefundRecord> refunds) => new()
|
||||
{
|
||||
Id = payment.Id,
|
||||
TenantId = payment.TenantId,
|
||||
OrderId = payment.OrderId,
|
||||
Method = payment.Method,
|
||||
Status = payment.Status,
|
||||
Amount = payment.Amount,
|
||||
TradeNo = payment.TradeNo,
|
||||
ChannelTransactionId = payment.ChannelTransactionId,
|
||||
PaidAt = payment.PaidAt,
|
||||
Remark = payment.Remark,
|
||||
Payload = payment.Payload,
|
||||
CreatedAt = payment.CreatedAt,
|
||||
Refunds = refunds.Select(x => new PaymentRefundDto
|
||||
{
|
||||
Id = x.Id,
|
||||
PaymentRecordId = x.PaymentRecordId,
|
||||
OrderId = x.OrderId,
|
||||
Amount = x.Amount,
|
||||
ChannelRefundId = x.ChannelRefundId,
|
||||
Status = x.Status,
|
||||
Payload = x.Payload
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Payments.Commands;
|
||||
using TakeoutSaaS.Domain.Payments.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 删除支付记录命令处理器。
|
||||
/// </summary>
|
||||
public sealed class DeletePaymentCommandHandler(
|
||||
IPaymentRepository paymentRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<DeletePaymentCommandHandler> logger)
|
||||
: IRequestHandler<DeletePaymentCommand, bool>
|
||||
{
|
||||
private readonly IPaymentRepository _paymentRepository = paymentRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<DeletePaymentCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Handle(DeletePaymentCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _paymentRepository.FindByIdAsync(request.PaymentId, tenantId, cancellationToken);
|
||||
if (existing == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
await _paymentRepository.DeletePaymentAsync(request.PaymentId, tenantId, cancellationToken);
|
||||
await _paymentRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("删除支付记录 {PaymentId}", request.PaymentId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Application.App.Payments.Queries;
|
||||
using TakeoutSaaS.Domain.Payments.Entities;
|
||||
using TakeoutSaaS.Domain.Payments.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录详情查询处理器。
|
||||
/// </summary>
|
||||
public sealed class GetPaymentByIdQueryHandler(
|
||||
IPaymentRepository paymentRepository,
|
||||
ITenantProvider tenantProvider)
|
||||
: IRequestHandler<GetPaymentByIdQuery, PaymentDto?>
|
||||
{
|
||||
private readonly IPaymentRepository _paymentRepository = paymentRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PaymentDto?> Handle(GetPaymentByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var payment = await _paymentRepository.FindByIdAsync(request.PaymentId, tenantId, cancellationToken);
|
||||
if (payment == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var refunds = await _paymentRepository.GetRefundsAsync(payment.Id, tenantId, cancellationToken);
|
||||
return MapToDto(payment, refunds);
|
||||
}
|
||||
|
||||
private static PaymentDto MapToDto(PaymentRecord payment, IReadOnlyList<PaymentRefundRecord> refunds) => new()
|
||||
{
|
||||
Id = payment.Id,
|
||||
TenantId = payment.TenantId,
|
||||
OrderId = payment.OrderId,
|
||||
Method = payment.Method,
|
||||
Status = payment.Status,
|
||||
Amount = payment.Amount,
|
||||
TradeNo = payment.TradeNo,
|
||||
ChannelTransactionId = payment.ChannelTransactionId,
|
||||
PaidAt = payment.PaidAt,
|
||||
Remark = payment.Remark,
|
||||
Payload = payment.Payload,
|
||||
CreatedAt = payment.CreatedAt,
|
||||
Refunds = refunds.Select(x => new PaymentRefundDto
|
||||
{
|
||||
Id = x.Id,
|
||||
PaymentRecordId = x.PaymentRecordId,
|
||||
OrderId = x.OrderId,
|
||||
Amount = x.Amount,
|
||||
ChannelRefundId = x.ChannelRefundId,
|
||||
Status = x.Status,
|
||||
Payload = x.Payload
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Application.App.Payments.Queries;
|
||||
using TakeoutSaaS.Domain.Payments.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录列表查询处理器。
|
||||
/// </summary>
|
||||
public sealed class SearchPaymentsQueryHandler(
|
||||
IPaymentRepository paymentRepository,
|
||||
ITenantProvider tenantProvider)
|
||||
: IRequestHandler<SearchPaymentsQuery, PagedResult<PaymentDto>>
|
||||
{
|
||||
private readonly IPaymentRepository _paymentRepository = paymentRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PagedResult<PaymentDto>> Handle(SearchPaymentsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var payments = await _paymentRepository.SearchAsync(tenantId, request.Status, cancellationToken);
|
||||
|
||||
if (request.OrderId.HasValue)
|
||||
{
|
||||
payments = payments.Where(x => x.OrderId == request.OrderId.Value).ToList();
|
||||
}
|
||||
|
||||
var sorted = ApplySorting(payments, request.SortBy, request.SortDescending);
|
||||
var paged = sorted
|
||||
.Skip((request.Page - 1) * request.PageSize)
|
||||
.Take(request.PageSize)
|
||||
.ToList();
|
||||
|
||||
var items = paged.Select(payment => new PaymentDto
|
||||
{
|
||||
Id = payment.Id,
|
||||
TenantId = payment.TenantId,
|
||||
OrderId = payment.OrderId,
|
||||
Method = payment.Method,
|
||||
Status = payment.Status,
|
||||
Amount = payment.Amount,
|
||||
TradeNo = payment.TradeNo,
|
||||
ChannelTransactionId = payment.ChannelTransactionId,
|
||||
PaidAt = payment.PaidAt,
|
||||
Remark = payment.Remark,
|
||||
Payload = payment.Payload,
|
||||
CreatedAt = payment.CreatedAt
|
||||
}).ToList();
|
||||
|
||||
return new PagedResult<PaymentDto>(items, request.Page, request.PageSize, payments.Count);
|
||||
}
|
||||
|
||||
private static IOrderedEnumerable<Domain.Payments.Entities.PaymentRecord> ApplySorting(
|
||||
IReadOnlyCollection<Domain.Payments.Entities.PaymentRecord> payments,
|
||||
string? sortBy,
|
||||
bool sortDescending)
|
||||
{
|
||||
return sortBy?.ToLowerInvariant() switch
|
||||
{
|
||||
"paidat" => sortDescending ? payments.OrderByDescending(x => x.PaidAt) : payments.OrderBy(x => x.PaidAt),
|
||||
"status" => sortDescending ? payments.OrderByDescending(x => x.Status) : payments.OrderBy(x => x.Status),
|
||||
"amount" => sortDescending ? payments.OrderByDescending(x => x.Amount) : payments.OrderBy(x => x.Amount),
|
||||
_ => sortDescending ? payments.OrderByDescending(x => x.CreatedAt) : payments.OrderBy(x => x.CreatedAt)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Payments.Commands;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Domain.Payments.Entities;
|
||||
using TakeoutSaaS.Domain.Payments.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 更新支付记录命令处理器。
|
||||
/// </summary>
|
||||
public sealed class UpdatePaymentCommandHandler(
|
||||
IPaymentRepository paymentRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<UpdatePaymentCommandHandler> logger)
|
||||
: IRequestHandler<UpdatePaymentCommand, PaymentDto?>
|
||||
{
|
||||
private readonly IPaymentRepository _paymentRepository = paymentRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<UpdatePaymentCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PaymentDto?> Handle(UpdatePaymentCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _paymentRepository.FindByIdAsync(request.PaymentId, tenantId, cancellationToken);
|
||||
if (existing == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
existing.OrderId = request.OrderId;
|
||||
existing.Method = request.Method;
|
||||
existing.Status = request.Status;
|
||||
existing.Amount = request.Amount;
|
||||
existing.TradeNo = request.TradeNo?.Trim();
|
||||
existing.ChannelTransactionId = request.ChannelTransactionId?.Trim();
|
||||
existing.PaidAt = request.PaidAt;
|
||||
existing.Remark = request.Remark?.Trim();
|
||||
existing.Payload = request.Payload;
|
||||
|
||||
await _paymentRepository.UpdatePaymentAsync(existing, cancellationToken);
|
||||
await _paymentRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("更新支付记录 {PaymentId}", existing.Id);
|
||||
|
||||
var refunds = await _paymentRepository.GetRefundsAsync(existing.Id, tenantId, cancellationToken);
|
||||
return MapToDto(existing, refunds);
|
||||
}
|
||||
|
||||
private static PaymentDto MapToDto(PaymentRecord payment, IReadOnlyList<PaymentRefundRecord> refunds) => new()
|
||||
{
|
||||
Id = payment.Id,
|
||||
TenantId = payment.TenantId,
|
||||
OrderId = payment.OrderId,
|
||||
Method = payment.Method,
|
||||
Status = payment.Status,
|
||||
Amount = payment.Amount,
|
||||
TradeNo = payment.TradeNo,
|
||||
ChannelTransactionId = payment.ChannelTransactionId,
|
||||
PaidAt = payment.PaidAt,
|
||||
Remark = payment.Remark,
|
||||
Payload = payment.Payload,
|
||||
CreatedAt = payment.CreatedAt,
|
||||
Refunds = refunds.Select(x => new PaymentRefundDto
|
||||
{
|
||||
Id = x.Id,
|
||||
PaymentRecordId = x.PaymentRecordId,
|
||||
OrderId = x.OrderId,
|
||||
Amount = x.Amount,
|
||||
ChannelRefundId = x.ChannelRefundId,
|
||||
Status = x.Status,
|
||||
Payload = x.Payload
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// 获取支付记录详情。
|
||||
/// </summary>
|
||||
public sealed class GetPaymentByIdQuery : IRequest<PaymentDto?>
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付记录 ID。
|
||||
/// </summary>
|
||||
public long PaymentId { get; init; }
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录列表查询。
|
||||
/// </summary>
|
||||
public sealed class SearchPaymentsQuery : IRequest<PagedResult<PaymentDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单 ID(可选)。
|
||||
/// </summary>
|
||||
public long? OrderId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付状态。
|
||||
/// </summary>
|
||||
public PaymentStatus? Status { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 页码。
|
||||
/// </summary>
|
||||
public int Page { get; init; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 每页条数。
|
||||
/// </summary>
|
||||
public int PageSize { get; init; } = 20;
|
||||
|
||||
/// <summary>
|
||||
/// 排序字段(createdAt/paidAt/status/amount)。
|
||||
/// </summary>
|
||||
public string? SortBy { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否倒序。
|
||||
/// </summary>
|
||||
public bool SortDescending { get; init; } = true;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Payments.Commands;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付记录命令验证器。
|
||||
/// </summary>
|
||||
public sealed class CreatePaymentCommandValidator : AbstractValidator<CreatePaymentCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public CreatePaymentCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.OrderId).GreaterThan(0);
|
||||
RuleFor(x => x.Amount).GreaterThan(0);
|
||||
RuleFor(x => x.Method)
|
||||
.Must(method => method != PaymentMethod.Unknown)
|
||||
.WithMessage("支付方式不可为空");
|
||||
RuleFor(x => x.TradeNo).MaximumLength(64);
|
||||
RuleFor(x => x.ChannelTransactionId).MaximumLength(64);
|
||||
RuleFor(x => x.Remark).MaximumLength(256);
|
||||
|
||||
RuleFor(x => x.Status)
|
||||
.Must(status => status is PaymentStatus.Unpaid or PaymentStatus.Paying or PaymentStatus.Paid or PaymentStatus.Failed or PaymentStatus.Refunded)
|
||||
.WithMessage("支付状态不合法");
|
||||
When(x => x.Status == PaymentStatus.Paid, () =>
|
||||
{
|
||||
RuleFor(x => x.PaidAt).NotNull().WithMessage("支付成功必须包含支付时间");
|
||||
});
|
||||
When(x => x.Status != PaymentStatus.Paid, () =>
|
||||
{
|
||||
RuleFor(x => x.PaidAt).Must(paidAt => paidAt == null).WithMessage("非支付成功状态不应包含支付时间");
|
||||
});
|
||||
|
||||
When(x => x.Method is PaymentMethod.Cash or PaymentMethod.Card or PaymentMethod.Balance, () =>
|
||||
{
|
||||
RuleFor(x => x.Status)
|
||||
.Must(status => status is not PaymentStatus.Paying)
|
||||
.WithMessage("线下/余额支付不允许处于 Paying 状态");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Payments.Queries;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录查询验证器。
|
||||
/// </summary>
|
||||
public sealed class SearchPaymentsQueryValidator : AbstractValidator<SearchPaymentsQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public SearchPaymentsQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Page).GreaterThan(0);
|
||||
RuleFor(x => x.PageSize).InclusiveBetween(1, 200);
|
||||
RuleFor(x => x.SortBy).MaximumLength(64);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Payments.Commands;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Payments.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 更新支付记录命令验证器。
|
||||
/// </summary>
|
||||
public sealed class UpdatePaymentCommandValidator : AbstractValidator<UpdatePaymentCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public UpdatePaymentCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.PaymentId).GreaterThan(0);
|
||||
RuleFor(x => x.OrderId).GreaterThan(0);
|
||||
RuleFor(x => x.Amount).GreaterThan(0);
|
||||
RuleFor(x => x.Method)
|
||||
.Must(method => method != PaymentMethod.Unknown)
|
||||
.WithMessage("支付方式不可为空");
|
||||
RuleFor(x => x.TradeNo).MaximumLength(64);
|
||||
RuleFor(x => x.ChannelTransactionId).MaximumLength(64);
|
||||
RuleFor(x => x.Remark).MaximumLength(256);
|
||||
|
||||
RuleFor(x => x.Status)
|
||||
.Must(status => status is PaymentStatus.Unpaid or PaymentStatus.Paying or PaymentStatus.Paid or PaymentStatus.Failed or PaymentStatus.Refunded)
|
||||
.WithMessage("支付状态不合法");
|
||||
When(x => x.Status == PaymentStatus.Paid, () =>
|
||||
{
|
||||
RuleFor(x => x.PaidAt).NotNull().WithMessage("支付成功必须包含支付时间");
|
||||
});
|
||||
When(x => x.Status != PaymentStatus.Paid, () =>
|
||||
{
|
||||
RuleFor(x => x.PaidAt).Must(paidAt => paidAt == null).WithMessage("非支付成功状态不应包含支付时间");
|
||||
});
|
||||
|
||||
When(x => x.Method is PaymentMethod.Cash or PaymentMethod.Card or PaymentMethod.Balance, () =>
|
||||
{
|
||||
RuleFor(x => x.Status)
|
||||
.Must(status => status is not PaymentStatus.Paying)
|
||||
.WithMessage("线下/余额支付不允许处于 Paying 状态");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user