feat: 审核通过时按月续费订阅
This commit is contained in:
@@ -24,4 +24,9 @@ public sealed record ReviewTenantCommand : IRequest<TenantDto>
|
||||
/// 审核备注或拒绝原因。
|
||||
/// </summary>
|
||||
public string? Reason { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 审核通过后续费时长(月)。
|
||||
/// </summary>
|
||||
public int? RenewMonths { get; init; }
|
||||
}
|
||||
|
||||
@@ -53,11 +53,44 @@ public sealed class ReviewTenantCommandHandler(
|
||||
// 4. 更新租户与订阅状态
|
||||
if (request.Approve)
|
||||
{
|
||||
var renewMonths = request.RenewMonths ?? 0;
|
||||
if (renewMonths <= 0)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.ValidationFailed, "续费时长必须为正整数(月)");
|
||||
}
|
||||
|
||||
verification.Status = TenantVerificationStatus.Approved;
|
||||
tenant.Status = TenantStatus.Active;
|
||||
if (subscription != null)
|
||||
{
|
||||
subscription.Status = SubscriptionStatus.Active;
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
if (subscription.EffectiveFrom == default || subscription.EffectiveFrom > now)
|
||||
{
|
||||
subscription.EffectiveFrom = now;
|
||||
}
|
||||
|
||||
var previousEffectiveTo = subscription.EffectiveTo;
|
||||
var baseEffectiveTo = subscription.EffectiveTo > now ? subscription.EffectiveTo : now;
|
||||
subscription.EffectiveTo = baseEffectiveTo.AddMonths(renewMonths);
|
||||
subscription.NextBillingDate = subscription.EffectiveTo;
|
||||
|
||||
await tenantRepository.AddAuditLogAsync(new Domain.Tenants.Entities.TenantAuditLog
|
||||
{
|
||||
TenantId = tenant.Id,
|
||||
Action = TenantAuditAction.SubscriptionUpdated,
|
||||
Title = "订阅续费",
|
||||
Description = $"续费 {renewMonths} 月,到期时间:{previousEffectiveTo:yyyy-MM-dd HH:mm:ss} -> {subscription.EffectiveTo:yyyy-MM-dd HH:mm:ss}",
|
||||
OperatorId = currentUserAccessor.UserId == 0 ? null : currentUserAccessor.UserId,
|
||||
OperatorName = actorName,
|
||||
PreviousStatus = previousStatus,
|
||||
CurrentStatus = tenant.Status
|
||||
}, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.BadRequest, "订阅不存在,无法续费");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user