- 新增 AdminRolesController 实现角色 CRUD 和权限管理 - 新增 BillingsController 实现账单查询功能 - 新增 SubscriptionsController 实现订阅管理功能 - 新增 TenantPackagesController 实现套餐管理功能 - 新增租户详情、配额使用、账单列表等查询功能 - 新增 TenantPackage、TenantSubscription 等领域实体 - 新增相关枚举:SubscriptionStatus、TenantPackageType 等 - 更新 appsettings 配置文件 - 更新权限授权策略提供者 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
76 lines
3.0 KiB
C#
76 lines
3.0 KiB
C#
using MediatR;
|
|
using TakeoutSaaS.Application.App.TenantPackages.Commands;
|
|
using TakeoutSaaS.Application.App.TenantPackages.Contracts;
|
|
using TakeoutSaaS.Domain.Tenants.Repositories;
|
|
|
|
namespace TakeoutSaaS.Application.App.TenantPackages.Handlers;
|
|
|
|
/// <summary>
|
|
/// 更新租户套餐命令处理器。
|
|
/// </summary>
|
|
public sealed class UpdateTenantPackageCommandHandler(ITenantPackageRepository tenantPackageRepository)
|
|
: IRequestHandler<UpdateTenantPackageCommand, TenantPackageListDto?>
|
|
{
|
|
/// <inheritdoc />
|
|
public async Task<TenantPackageListDto?> Handle(
|
|
UpdateTenantPackageCommand request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
// 1. 查询套餐(带跟踪用于更新)
|
|
var package = await tenantPackageRepository.GetByIdForUpdateAsync(request.TenantPackageId, cancellationToken);
|
|
|
|
// 2. 如果不存在,返回 null
|
|
if (package is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// 3. 更新套餐属性
|
|
package.Name = request.Name.Trim();
|
|
package.Description = request.Description;
|
|
package.PackageType = request.PackageType;
|
|
package.MonthlyPrice = request.MonthlyPrice;
|
|
package.YearlyPrice = request.YearlyPrice;
|
|
package.MaxStoreCount = request.MaxStoreCount;
|
|
package.MaxAccountCount = request.MaxAccountCount;
|
|
package.MaxStorageGb = request.MaxStorageGb;
|
|
package.MaxSmsCredits = request.MaxSmsCredits;
|
|
package.MaxDeliveryOrders = request.MaxDeliveryOrders;
|
|
package.FeaturePoliciesJson = request.FeaturePoliciesJson;
|
|
package.IsActive = request.IsActive;
|
|
package.IsPublicVisible = request.IsPublicVisible;
|
|
package.IsAllowNewTenantPurchase = request.IsAllowNewTenantPurchase;
|
|
package.PublishStatus = request.PublishStatus;
|
|
package.IsRecommended = request.IsRecommended;
|
|
package.Tags = request.Tags;
|
|
package.SortOrder = request.SortOrder;
|
|
|
|
// 4. 保存变更
|
|
await tenantPackageRepository.SaveChangesAsync(cancellationToken);
|
|
|
|
// 5. 返回 DTO
|
|
return new TenantPackageListDto
|
|
{
|
|
Id = package.Id,
|
|
Name = package.Name,
|
|
Description = package.Description,
|
|
PackageType = package.PackageType,
|
|
MonthlyPrice = package.MonthlyPrice,
|
|
YearlyPrice = package.YearlyPrice,
|
|
MaxStoreCount = package.MaxStoreCount,
|
|
MaxAccountCount = package.MaxAccountCount,
|
|
MaxStorageGb = package.MaxStorageGb,
|
|
MaxSmsCredits = package.MaxSmsCredits,
|
|
MaxDeliveryOrders = package.MaxDeliveryOrders,
|
|
FeaturePoliciesJson = package.FeaturePoliciesJson,
|
|
IsActive = package.IsActive,
|
|
IsPublicVisible = package.IsPublicVisible,
|
|
IsAllowNewTenantPurchase = package.IsAllowNewTenantPurchase,
|
|
PublishStatus = package.PublishStatus,
|
|
IsRecommended = package.IsRecommended,
|
|
Tags = package.Tags,
|
|
SortOrder = package.SortOrder
|
|
};
|
|
}
|
|
}
|