diff --git a/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/ReviewTenantCommand.cs b/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/ReviewTenantCommand.cs index 7b1c6b6..1d87313 100644 --- a/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/ReviewTenantCommand.cs +++ b/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/ReviewTenantCommand.cs @@ -24,4 +24,9 @@ public sealed record ReviewTenantCommand : IRequest /// 审核备注或拒绝原因。 /// public string? Reason { get; init; } + + /// + /// 审核通过后续费时长(月)。 + /// + public int? RenewMonths { get; init; } } diff --git a/src/Application/TakeoutSaaS.Application/App/Tenants/Handlers/ReviewTenantCommandHandler.cs b/src/Application/TakeoutSaaS.Application/App/Tenants/Handlers/ReviewTenantCommandHandler.cs index 2b9b5f5..d45b6e9 100644 --- a/src/Application/TakeoutSaaS.Application/App/Tenants/Handlers/ReviewTenantCommandHandler.cs +++ b/src/Application/TakeoutSaaS.Application/App/Tenants/Handlers/ReviewTenantCommandHandler.cs @@ -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