feat: 套餐发布状态与可见/可购开关
This commit is contained in:
@@ -65,10 +65,25 @@ public sealed record CreateTenantPackageCommand : IRequest<TenantPackageDto>
|
||||
public string? FeaturePoliciesJson { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可售。
|
||||
/// 是否仍启用(平台控制)。
|
||||
/// </summary>
|
||||
public bool IsActive { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否对外可见(展示页/套餐列表可见性)。
|
||||
/// </summary>
|
||||
public bool IsPublicVisible { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许新租户购买/选择(仅影响新购)。
|
||||
/// </summary>
|
||||
public bool IsAllowNewTenantPurchase { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 发布状态(草稿/已发布)。
|
||||
/// </summary>
|
||||
public TenantPackagePublishStatus PublishStatus { get; init; } = TenantPackagePublishStatus.Published;
|
||||
|
||||
/// <summary>
|
||||
/// 展示排序,数值越小越靠前。
|
||||
/// </summary>
|
||||
|
||||
@@ -70,10 +70,25 @@ public sealed record UpdateTenantPackageCommand : IRequest<TenantPackageDto?>
|
||||
public string? FeaturePoliciesJson { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可售。
|
||||
/// 是否仍启用(平台控制)。
|
||||
/// </summary>
|
||||
public bool IsActive { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否对外可见(展示页/套餐列表可见性)。
|
||||
/// </summary>
|
||||
public bool IsPublicVisible { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许新租户购买/选择(仅影响新购)。
|
||||
/// </summary>
|
||||
public bool IsAllowNewTenantPurchase { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 发布状态(草稿/已发布)。
|
||||
/// </summary>
|
||||
public TenantPackagePublishStatus PublishStatus { get; init; } = TenantPackagePublishStatus.Published;
|
||||
|
||||
/// <summary>
|
||||
/// 展示排序,数值越小越靠前。
|
||||
/// </summary>
|
||||
|
||||
@@ -71,10 +71,25 @@ public sealed class TenantPackageDto
|
||||
public string? FeaturePoliciesJson { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可售。
|
||||
/// 是否仍启用(平台控制)。
|
||||
/// </summary>
|
||||
public bool IsActive { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否对外可见。
|
||||
/// </summary>
|
||||
public bool IsPublicVisible { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许新租户购买/选择。
|
||||
/// </summary>
|
||||
public bool IsAllowNewTenantPurchase { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布状态。
|
||||
/// </summary>
|
||||
public TenantPackagePublishStatus PublishStatus { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 展示排序,数值越小越靠前。
|
||||
/// </summary>
|
||||
|
||||
@@ -38,6 +38,9 @@ public sealed class CreateTenantPackageCommandHandler(ITenantPackageRepository p
|
||||
MaxDeliveryOrders = request.MaxDeliveryOrders,
|
||||
FeaturePoliciesJson = request.FeaturePoliciesJson,
|
||||
IsActive = request.IsActive,
|
||||
IsPublicVisible = request.IsPublicVisible,
|
||||
IsAllowNewTenantPurchase = request.IsAllowNewTenantPurchase,
|
||||
PublishStatus = request.PublishStatus,
|
||||
SortOrder = request.SortOrder
|
||||
};
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ public sealed class GetPublicTenantPackagesQueryHandler(ITenantPackageRepository
|
||||
/// <inheritdoc />
|
||||
public async Task<PagedResult<TenantPackageDto>> Handle(GetPublicTenantPackagesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 仅查询启用套餐
|
||||
var packages = await packageRepository.SearchAsync(null, true, cancellationToken);
|
||||
// 1. 仅查询公共可选购套餐(已发布 + 对外可见 + 允许新购 + 启用)
|
||||
var packages = await packageRepository.SearchPublicPurchasableAsync(cancellationToken);
|
||||
// 2. 规范化分页参数
|
||||
var pageIndex = request.Page <= 0 ? 1 : request.Page;
|
||||
var size = request.PageSize <= 0 ? 20 : request.PageSize;
|
||||
|
||||
@@ -42,6 +42,9 @@ public sealed class UpdateTenantPackageCommandHandler(ITenantPackageRepository p
|
||||
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.SortOrder = request.SortOrder;
|
||||
|
||||
// 4. 持久化并返回
|
||||
|
||||
@@ -138,6 +138,9 @@ internal static class TenantMapping
|
||||
MaxDeliveryOrders = package.MaxDeliveryOrders,
|
||||
FeaturePoliciesJson = package.FeaturePoliciesJson,
|
||||
IsActive = package.IsActive,
|
||||
IsPublicVisible = package.IsPublicVisible,
|
||||
IsAllowNewTenantPurchase = package.IsAllowNewTenantPurchase,
|
||||
PublishStatus = package.PublishStatus,
|
||||
SortOrder = package.SortOrder
|
||||
};
|
||||
|
||||
|
||||
@@ -64,10 +64,25 @@ public sealed class TenantPackage : AuditableEntityBase
|
||||
public string? FeaturePoliciesJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否仍可售卖。
|
||||
/// 是否仍启用(平台控制)。
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否对外可见(展示页/套餐列表可见性)。
|
||||
/// </summary>
|
||||
public bool IsPublicVisible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许新租户购买/选择(仅影响新购,不影响已订阅租户)。
|
||||
/// </summary>
|
||||
public bool IsAllowNewTenantPurchase { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 发布状态(草稿/已发布)。
|
||||
/// </summary>
|
||||
public TenantPackagePublishStatus PublishStatus { get; set; } = TenantPackagePublishStatus.Published;
|
||||
|
||||
/// <summary>
|
||||
/// 展示排序,数值越小越靠前。
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace TakeoutSaaS.Domain.Tenants.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 套餐发布状态。
|
||||
/// </summary>
|
||||
public enum TenantPackagePublishStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 草稿。
|
||||
/// </summary>
|
||||
Draft = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 已发布。
|
||||
/// </summary>
|
||||
Published = 1
|
||||
}
|
||||
|
||||
@@ -24,6 +24,13 @@ public interface ITenantPackageRepository
|
||||
/// <returns>符合条件的套餐列表。</returns>
|
||||
Task<IReadOnlyList<TenantPackage>> SearchAsync(string? keyword, bool? isActive, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 查询公共可选购套餐(仅返回:已发布 + 对外可见 + 允许新购 + 启用)。
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
/// <returns>公共可选购套餐列表。</returns>
|
||||
Task<IReadOnlyList<TenantPackage>> SearchPublicPurchasableAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 新增套餐。
|
||||
/// </summary>
|
||||
|
||||
@@ -19,6 +19,7 @@ using TakeoutSaaS.Domain.Queues.Entities;
|
||||
using TakeoutSaaS.Domain.Reservations.Entities;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
using TakeoutSaaS.Domain.Tenants.Entities;
|
||||
using TakeoutSaaS.Domain.Tenants.Enums;
|
||||
using TakeoutSaaS.Infrastructure.Common.Persistence;
|
||||
using TakeoutSaaS.Shared.Abstractions.Ids;
|
||||
using TakeoutSaaS.Shared.Abstractions.Security;
|
||||
@@ -676,8 +677,12 @@ public sealed class TakeoutAppDbContext(
|
||||
builder.Property(x => x.Name).HasMaxLength(128).IsRequired();
|
||||
builder.Property(x => x.Description).HasMaxLength(512);
|
||||
builder.Property(x => x.FeaturePoliciesJson).HasColumnType("text");
|
||||
builder.Property(x => x.PublishStatus).HasConversion<int>().HasDefaultValue(TenantPackagePublishStatus.Published).HasComment("发布状态:0=草稿,1=已发布。");
|
||||
builder.Property(x => x.IsPublicVisible).HasDefaultValue(true).HasComment("是否对外可见(展示页/套餐列表可见性)。");
|
||||
builder.Property(x => x.IsAllowNewTenantPurchase).HasDefaultValue(true).HasComment("是否允许新租户购买/选择(仅影响新购)。");
|
||||
builder.Property(x => x.SortOrder).HasDefaultValue(0).HasComment("展示排序,数值越小越靠前。");
|
||||
builder.HasIndex(x => new { x.IsActive, x.SortOrder });
|
||||
builder.HasIndex(x => new { x.PublishStatus, x.IsActive, x.IsPublicVisible, x.IsAllowNewTenantPurchase, x.SortOrder });
|
||||
}
|
||||
|
||||
private static void ConfigureTenantSubscription(EntityTypeBuilder<TenantSubscription> builder)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TakeoutSaaS.Domain.Tenants.Entities;
|
||||
using TakeoutSaaS.Domain.Tenants.Enums;
|
||||
using TakeoutSaaS.Domain.Tenants.Repositories;
|
||||
using TakeoutSaaS.Infrastructure.App.Persistence;
|
||||
|
||||
@@ -42,6 +43,21 @@ public sealed class EfTenantPackageRepository(TakeoutAppDbContext context) : ITe
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<TenantPackage>> SearchPublicPurchasableAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 1. 公共可选购套餐仅返回:已发布 + 对外可见 + 允许新购 + 启用
|
||||
return await context.TenantPackages.AsNoTracking()
|
||||
.Where(x =>
|
||||
x.IsActive
|
||||
&& x.PublishStatus == TenantPackagePublishStatus.Published
|
||||
&& x.IsPublicVisible
|
||||
&& x.IsAllowNewTenantPurchase)
|
||||
.OrderBy(x => x.SortOrder)
|
||||
.ThenByDescending(x => x.CreatedAt)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task AddAsync(TenantPackage package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,107 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddTenantPackagePublishAndVisibility : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "LogoUrl",
|
||||
table: "tenants",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
comment: "LOGO 图片地址。",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(256)",
|
||||
oldMaxLength: 256,
|
||||
oldNullable: true,
|
||||
oldComment: "LOGO 图片地址。");
|
||||
|
||||
migrationBuilder.AlterColumn<bool>(
|
||||
name: "IsActive",
|
||||
table: "tenant_packages",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
comment: "是否仍启用(平台控制)。",
|
||||
oldClrType: typeof(bool),
|
||||
oldType: "boolean",
|
||||
oldComment: "是否仍可售卖。");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsAllowNewTenantPurchase",
|
||||
table: "tenant_packages",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: true,
|
||||
comment: "是否允许新租户购买/选择(仅影响新购)。");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsPublicVisible",
|
||||
table: "tenant_packages",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: true,
|
||||
comment: "是否对外可见(展示页/套餐列表可见性)。");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PublishStatus",
|
||||
table: "tenant_packages",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 1,
|
||||
comment: "发布状态:0=草稿,1=已发布。");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_tenant_packages_PublishStatus_IsActive_IsPublicVisible_IsAl~",
|
||||
table: "tenant_packages",
|
||||
columns: new[] { "PublishStatus", "IsActive", "IsPublicVisible", "IsAllowNewTenantPurchase", "SortOrder" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_tenant_packages_PublishStatus_IsActive_IsPublicVisible_IsAl~",
|
||||
table: "tenant_packages");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsAllowNewTenantPurchase",
|
||||
table: "tenant_packages");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsPublicVisible",
|
||||
table: "tenant_packages");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PublishStatus",
|
||||
table: "tenant_packages");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "LogoUrl",
|
||||
table: "tenants",
|
||||
type: "character varying(256)",
|
||||
maxLength: 256,
|
||||
nullable: true,
|
||||
comment: "LOGO 图片地址。",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true,
|
||||
oldComment: "LOGO 图片地址。");
|
||||
|
||||
migrationBuilder.AlterColumn<bool>(
|
||||
name: "IsActive",
|
||||
table: "tenant_packages",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
comment: "是否仍可售卖。",
|
||||
oldClrType: typeof(bool),
|
||||
oldType: "boolean",
|
||||
oldComment: "是否仍启用(平台控制)。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5760,8 +5760,7 @@ namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
.HasComment("法人或公司主体名称。");
|
||||
|
||||
b.Property<string>("LogoUrl")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnType("text")
|
||||
.HasComment("LOGO 图片地址。");
|
||||
|
||||
b.Property<string>("Name")
|
||||
@@ -6248,7 +6247,19 @@ namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean")
|
||||
.HasComment("是否仍可售卖。");
|
||||
.HasComment("是否仍启用(平台控制)。");
|
||||
|
||||
b.Property<bool>("IsAllowNewTenantPurchase")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(true)
|
||||
.HasComment("是否允许新租户购买/选择(仅影响新购)。");
|
||||
|
||||
b.Property<bool>("IsPublicVisible")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(true)
|
||||
.HasComment("是否对外可见(展示页/套餐列表可见性)。");
|
||||
|
||||
b.Property<int?>("MaxAccountCount")
|
||||
.HasColumnType("integer")
|
||||
@@ -6284,6 +6295,12 @@ namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
.HasColumnType("integer")
|
||||
.HasComment("套餐分类(试用、标准、旗舰等)。");
|
||||
|
||||
b.Property<int>("PublishStatus")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasComment("发布状态:0=草稿,1=已发布。");
|
||||
|
||||
b.Property<int>("SortOrder")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
@@ -6306,6 +6323,8 @@ namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
|
||||
b.HasIndex("IsActive", "SortOrder");
|
||||
|
||||
b.HasIndex("PublishStatus", "IsActive", "IsPublicVisible", "IsAllowNewTenantPurchase", "SortOrder");
|
||||
|
||||
b.ToTable("tenant_packages", null, t =>
|
||||
{
|
||||
t.HasComment("平台提供的租户套餐定义。");
|
||||
|
||||
Reference in New Issue
Block a user