feat: add commission settlement endpoints

This commit is contained in:
xiong
2026-07-26 20:36:01 +08:00
parent 0385a1accd
commit 4279795d46
14 changed files with 17772 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Tiku.Domain.Content;
using Tiku.Domain.Growth;
using Tiku.Domain.Identity;
using Tiku.Domain.Tenancy;
@@ -257,3 +258,56 @@ internal sealed class CommissionSettlementItemConfiguration : IEntityTypeConfigu
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.StudentUserId).OnDelete(DeleteBehavior.SetNull);
}
}
internal sealed class CommissionSettlementProofConfiguration : IEntityTypeConfiguration<CommissionSettlementProof>
{
public void Configure(EntityTypeBuilder<CommissionSettlementProof> builder)
{
builder.ConfigureTenantEntity("commission_settlement_proofs");
builder.ConfigureTimestamps();
builder.Property(entity => entity.ProofType).HasSnakeCaseEnum();
builder.Property(entity => entity.Status).HasSnakeCaseEnum();
builder.Property(entity => entity.Title).HasMaxLength(200);
builder.Property(entity => entity.ExternalUrl).HasMaxLength(2048);
builder.Property(entity => entity.PaymentMethod).HasMaxLength(100);
builder.Property(entity => entity.PaymentAccount).HasMaxLength(200);
builder.Property(entity => entity.Metadata).IsJson("{}");
builder.HasIndex(entity => new { entity.TenantId, entity.SettlementId, entity.Status, entity.CreatedAt });
builder.ToTable(table => table.HasCheckConstraint(
"ck_commission_settlement_proofs_amount",
"amount_cents is null or amount_cents >= 0"));
builder.HasOne<CommissionSettlement>().WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.SettlementId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne<ContentAsset>().WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.AssetId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.SetNull);
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.SubmittedBy).OnDelete(DeleteBehavior.SetNull);
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ReviewedBy).OnDelete(DeleteBehavior.SetNull);
}
}
internal sealed class CommissionSettlementExportEventConfiguration : IEntityTypeConfiguration<CommissionSettlementExportEvent>
{
public void Configure(EntityTypeBuilder<CommissionSettlementExportEvent> builder)
{
builder.ToTable("commission_settlement_export_events");
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).HasDefaultValueSql("gen_random_uuid()");
builder.Property(entity => entity.ExportFormat).HasMaxLength(20);
builder.Property(entity => entity.Filename).HasMaxLength(500);
builder.Property(entity => entity.ContentSha256).HasMaxLength(128);
builder.Property(entity => entity.Metadata).IsJson("{}");
builder.Property(entity => entity.CreatedAt).HasDefaultValueSql("now()");
builder.HasIndex(entity => new { entity.TenantId, entity.SettlementId, entity.CreatedAt });
builder.ToTable(table => table.HasCheckConstraint("ck_commission_export_events_rows", "row_count >= 0"));
builder.HasOne<Tenant>().WithMany().HasForeignKey(entity => entity.TenantId).OnDelete(DeleteBehavior.Cascade);
builder.HasOne<CommissionSettlement>().WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.SettlementId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ExportedBy).OnDelete(DeleteBehavior.SetNull);
}
}