feat: 新增配额包/支付相关实体与迁移

App:新增 operation_logs/quota_packages/tenant_payments/tenant_quota_package_purchases 表

Identity:修正 Avatar 字段类型(varchar(256)->text),保持现有数据不变
This commit is contained in:
2025-12-17 17:27:45 +08:00
parent 9c28790f5e
commit ab59e2e3e2
103 changed files with 14450 additions and 4 deletions

View File

@@ -62,6 +62,10 @@ public sealed class TakeoutAppDbContext(
/// </summary>
public DbSet<TenantBillingStatement> TenantBillingStatements => Set<TenantBillingStatement>();
/// <summary>
/// 租户支付记录。
/// </summary>
public DbSet<TenantPayment> TenantPayments => Set<TenantPayment>();
/// <summary>
/// 租户通知。
/// </summary>
public DbSet<TenantNotification> TenantNotifications => Set<TenantNotification>();
@@ -86,6 +90,18 @@ public sealed class TakeoutAppDbContext(
/// </summary>
public DbSet<TenantReviewClaim> TenantReviewClaims => Set<TenantReviewClaim>();
/// <summary>
/// 运营操作日志。
/// </summary>
public DbSet<OperationLog> OperationLogs => Set<OperationLog>();
/// <summary>
/// 配额包定义。
/// </summary>
public DbSet<QuotaPackage> QuotaPackages => Set<QuotaPackage>();
/// <summary>
/// 租户配额包购买记录。
/// </summary>
public DbSet<TenantQuotaPackagePurchase> TenantQuotaPackagePurchases => Set<TenantQuotaPackagePurchase>();
/// <summary>
/// 商户实体。
/// </summary>
public DbSet<Merchant> Merchants => Set<Merchant>();
@@ -374,12 +390,16 @@ public sealed class TakeoutAppDbContext(
ConfigureTenantSubscriptionHistory(modelBuilder.Entity<TenantSubscriptionHistory>());
ConfigureTenantQuotaUsage(modelBuilder.Entity<TenantQuotaUsage>());
ConfigureTenantBilling(modelBuilder.Entity<TenantBillingStatement>());
ConfigureTenantPayment(modelBuilder.Entity<TenantPayment>());
ConfigureTenantNotification(modelBuilder.Entity<TenantNotification>());
ConfigureTenantAnnouncement(modelBuilder.Entity<TenantAnnouncement>());
ConfigureTenantAnnouncementRead(modelBuilder.Entity<TenantAnnouncementRead>());
ConfigureTenantVerificationProfile(modelBuilder.Entity<TenantVerificationProfile>());
ConfigureTenantAuditLog(modelBuilder.Entity<TenantAuditLog>());
ConfigureTenantReviewClaim(modelBuilder.Entity<TenantReviewClaim>());
ConfigureOperationLog(modelBuilder.Entity<OperationLog>());
ConfigureQuotaPackage(modelBuilder.Entity<QuotaPackage>());
ConfigureTenantQuotaPackagePurchase(modelBuilder.Entity<TenantQuotaPackagePurchase>());
ConfigureMerchantDocument(modelBuilder.Entity<MerchantDocument>());
ConfigureMerchantContract(modelBuilder.Entity<MerchantContract>());
ConfigureMerchantStaff(modelBuilder.Entity<MerchantStaff>());
@@ -511,6 +531,22 @@ public sealed class TakeoutAppDbContext(
builder.HasIndex(x => x.TenantId).IsUnique().HasFilter("\"ReleasedAt\" IS NULL AND \"DeletedAt\" IS NULL");
}
private static void ConfigureOperationLog(EntityTypeBuilder<OperationLog> builder)
{
builder.ToTable("operation_logs");
builder.HasKey(x => x.Id);
builder.Property(x => x.OperationType).HasMaxLength(64).IsRequired();
builder.Property(x => x.TargetType).HasMaxLength(64).IsRequired();
builder.Property(x => x.TargetIds).HasColumnType("text");
builder.Property(x => x.OperatorId).HasMaxLength(64);
builder.Property(x => x.OperatorName).HasMaxLength(128);
builder.Property(x => x.Parameters).HasColumnType("text");
builder.Property(x => x.Result).HasColumnType("text");
builder.Property(x => x.Success).IsRequired();
builder.HasIndex(x => new { x.OperationType, x.CreatedAt });
builder.HasIndex(x => x.CreatedAt);
}
private static void ConfigureTenantSubscriptionHistory(EntityTypeBuilder<TenantSubscriptionHistory> builder)
{
builder.ToTable("tenant_subscription_histories");
@@ -736,6 +772,20 @@ public sealed class TakeoutAppDbContext(
builder.HasIndex(x => new { x.TenantId, x.StatementNo }).IsUnique();
}
private static void ConfigureTenantPayment(EntityTypeBuilder<TenantPayment> builder)
{
builder.ToTable("tenant_payments");
builder.HasKey(x => x.Id);
builder.Property(x => x.BillingStatementId).IsRequired();
builder.Property(x => x.Amount).HasPrecision(18, 2).IsRequired();
builder.Property(x => x.Method).HasConversion<int>();
builder.Property(x => x.Status).HasConversion<int>();
builder.Property(x => x.TransactionNo).HasMaxLength(64);
builder.Property(x => x.ProofUrl).HasMaxLength(512);
builder.Property(x => x.Notes).HasMaxLength(512);
builder.HasIndex(x => new { x.TenantId, x.BillingStatementId });
}
private static void ConfigureTenantNotification(EntityTypeBuilder<TenantNotification> builder)
{
builder.ToTable("tenant_notifications");
@@ -1413,4 +1463,31 @@ public sealed class TakeoutAppDbContext(
builder.Property(x => x.NotificationChannels).HasMaxLength(256);
builder.HasIndex(x => new { x.TenantId, x.MetricDefinitionId, x.Severity });
}
private static void ConfigureQuotaPackage(EntityTypeBuilder<QuotaPackage> builder)
{
builder.ToTable("quota_packages");
builder.HasKey(x => x.Id);
builder.Property(x => x.Name).HasMaxLength(128).IsRequired();
builder.Property(x => x.QuotaType).HasConversion<int>().IsRequired();
builder.Property(x => x.QuotaValue).HasPrecision(18, 2).IsRequired();
builder.Property(x => x.Price).HasPrecision(18, 2).IsRequired();
builder.Property(x => x.IsActive).IsRequired();
builder.Property(x => x.SortOrder).HasDefaultValue(0);
builder.Property(x => x.Description).HasMaxLength(512);
builder.HasIndex(x => new { x.QuotaType, x.IsActive, x.SortOrder });
}
private static void ConfigureTenantQuotaPackagePurchase(EntityTypeBuilder<TenantQuotaPackagePurchase> builder)
{
builder.ToTable("tenant_quota_package_purchases");
builder.HasKey(x => x.Id);
builder.Property(x => x.TenantId).IsRequired();
builder.Property(x => x.QuotaPackageId).IsRequired();
builder.Property(x => x.QuotaValue).HasPrecision(18, 2).IsRequired();
builder.Property(x => x.Price).HasPrecision(18, 2).IsRequired();
builder.Property(x => x.PurchasedAt).IsRequired();
builder.Property(x => x.Notes).HasMaxLength(512);
builder.HasIndex(x => new { x.TenantId, x.QuotaPackageId, x.PurchasedAt });
}
}