feat: implement tenant member stored card module
All checks were successful
Build and Deploy TenantApi + SkuWorker / build-and-deploy (push) Successful in 2m24s

This commit is contained in:
2026-03-04 09:14:57 +08:00
parent d96ca4971a
commit 2970134200
35 changed files with 12805 additions and 1 deletions

View File

@@ -51,6 +51,7 @@ public static class AppServiceCollectionExtensions
services.AddScoped<IPromotionCampaignRepository, EfPromotionCampaignRepository>();
services.AddScoped<IPunchCardRepository, EfPunchCardRepository>();
services.AddScoped<IMemberRepository, EfMemberRepository>();
services.AddScoped<IStoredCardRepository, EfStoredCardRepository>();
services.AddScoped<IOrderRepository, EfOrderRepository>();
services.AddScoped<IPaymentRepository, EfPaymentRepository>();
services.AddScoped<IDeliveryRepository, EfDeliveryRepository>();

View File

@@ -402,6 +402,14 @@ public sealed class TakeoutAppDbContext(
/// </summary>
public DbSet<MemberPointLedger> MemberPointLedgers => Set<MemberPointLedger>();
/// <summary>
/// 会员储值方案。
/// </summary>
public DbSet<MemberStoredCardPlan> MemberStoredCardPlans => Set<MemberStoredCardPlan>();
/// <summary>
/// 会员储值充值记录。
/// </summary>
public DbSet<MemberStoredCardRechargeRecord> MemberStoredCardRechargeRecords => Set<MemberStoredCardRechargeRecord>();
/// <summary>
/// 会话记录。
/// </summary>
public DbSet<ChatSession> ChatSessions => Set<ChatSession>();
@@ -568,6 +576,8 @@ public sealed class TakeoutAppDbContext(
ConfigureMemberProfileTag(modelBuilder.Entity<MemberProfileTag>());
ConfigureMemberDaySetting(modelBuilder.Entity<MemberDaySetting>());
ConfigureMemberPointLedger(modelBuilder.Entity<MemberPointLedger>());
ConfigureMemberStoredCardPlan(modelBuilder.Entity<MemberStoredCardPlan>());
ConfigureMemberStoredCardRechargeRecord(modelBuilder.Entity<MemberStoredCardRechargeRecord>());
ConfigureChatSession(modelBuilder.Entity<ChatSession>());
ConfigureChatMessage(modelBuilder.Entity<ChatMessage>());
ConfigureSupportTicket(modelBuilder.Entity<SupportTicket>());
@@ -1846,6 +1856,42 @@ public sealed class TakeoutAppDbContext(
builder.HasIndex(x => new { x.TenantId, x.MemberId, x.OccurredAt });
}
private static void ConfigureMemberStoredCardPlan(EntityTypeBuilder<MemberStoredCardPlan> builder)
{
builder.ToTable("member_stored_card_plans");
builder.HasKey(x => x.Id);
builder.Property(x => x.StoreId).IsRequired();
builder.Property(x => x.RechargeAmount).HasPrecision(18, 2);
builder.Property(x => x.GiftAmount).HasPrecision(18, 2);
builder.Property(x => x.SortOrder).IsRequired();
builder.Property(x => x.Status).HasConversion<int>();
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.RechargeAmount, x.GiftAmount }).IsUnique();
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.SortOrder });
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.Status });
}
private static void ConfigureMemberStoredCardRechargeRecord(EntityTypeBuilder<MemberStoredCardRechargeRecord> builder)
{
builder.ToTable("member_stored_card_recharge_records");
builder.HasKey(x => x.Id);
builder.Property(x => x.StoreId).IsRequired();
builder.Property(x => x.MemberId).IsRequired();
builder.Property(x => x.PlanId);
builder.Property(x => x.RecordNo).HasMaxLength(32).IsRequired();
builder.Property(x => x.MemberName).HasMaxLength(64).IsRequired();
builder.Property(x => x.MemberMobileMasked).HasMaxLength(32).IsRequired();
builder.Property(x => x.RechargeAmount).HasPrecision(18, 2);
builder.Property(x => x.GiftAmount).HasPrecision(18, 2);
builder.Property(x => x.ArrivedAmount).HasPrecision(18, 2);
builder.Property(x => x.PaymentMethod).HasConversion<int>();
builder.Property(x => x.Remark).HasMaxLength(256);
builder.Property(x => x.RechargedAt).IsRequired();
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.RecordNo }).IsUnique();
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.MemberId, x.RechargedAt });
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.PlanId, x.RechargedAt });
builder.HasIndex(x => new { x.TenantId, x.StoreId, x.RechargedAt });
}
private static void ConfigureChatSession(EntityTypeBuilder<ChatSession> builder)
{
builder.ToTable("chat_sessions");

View File

@@ -0,0 +1,248 @@
using Microsoft.EntityFrameworkCore;
using TakeoutSaaS.Domain.Membership.Entities;
using TakeoutSaaS.Domain.Membership.Repositories;
using TakeoutSaaS.Infrastructure.App.Persistence;
namespace TakeoutSaaS.Infrastructure.App.Repositories;
/// <summary>
/// 储值卡模块 EF Core 仓储实现。
/// </summary>
public sealed class EfStoredCardRepository(TakeoutAppDbContext context) : IStoredCardRepository
{
/// <inheritdoc />
public async Task<IReadOnlyList<MemberStoredCardPlan>> GetPlansByStoreAsync(
long tenantId,
long storeId,
CancellationToken cancellationToken = default)
{
return await context.MemberStoredCardPlans
.AsNoTracking()
.Where(item => item.TenantId == tenantId && item.StoreId == storeId)
.OrderBy(item => item.SortOrder)
.ThenBy(item => item.RechargeAmount)
.ThenBy(item => item.Id)
.ToListAsync(cancellationToken);
}
/// <inheritdoc />
public Task<MemberStoredCardPlan?> FindPlanByIdAsync(
long tenantId,
long storeId,
long planId,
CancellationToken cancellationToken = default)
{
return context.MemberStoredCardPlans
.Where(item =>
item.TenantId == tenantId &&
item.StoreId == storeId &&
item.Id == planId)
.FirstOrDefaultAsync(cancellationToken);
}
/// <inheritdoc />
public Task AddPlanAsync(MemberStoredCardPlan entity, CancellationToken cancellationToken = default)
{
return context.MemberStoredCardPlans.AddAsync(entity, cancellationToken).AsTask();
}
/// <inheritdoc />
public Task UpdatePlanAsync(MemberStoredCardPlan entity, CancellationToken cancellationToken = default)
{
context.MemberStoredCardPlans.Update(entity);
return Task.CompletedTask;
}
/// <inheritdoc />
public Task DeletePlanAsync(MemberStoredCardPlan entity, CancellationToken cancellationToken = default)
{
context.MemberStoredCardPlans.Remove(entity);
return Task.CompletedTask;
}
/// <inheritdoc />
public async Task<Dictionary<long, MemberStoredCardPlanAggregateSnapshot>> GetPlanAggregatesAsync(
long tenantId,
long storeId,
IReadOnlyCollection<long> planIds,
CancellationToken cancellationToken = default)
{
if (planIds.Count == 0)
{
return [];
}
var aggregates = await context.MemberStoredCardRechargeRecords
.AsNoTracking()
.Where(item =>
item.TenantId == tenantId &&
item.StoreId == storeId &&
item.PlanId.HasValue &&
planIds.Contains(item.PlanId.Value))
.GroupBy(item => item.PlanId!.Value)
.Select(group => new MemberStoredCardPlanAggregateSnapshot
{
PlanId = group.Key,
RechargeCount = group.Count(),
TotalRechargeAmount = group.Sum(item => item.RechargeAmount)
})
.ToListAsync(cancellationToken);
return aggregates.ToDictionary(item => item.PlanId, item => item);
}
/// <inheritdoc />
public async Task<MemberStoredCardPlanStatsSnapshot> GetPlanStatsAsync(
long tenantId,
long storeId,
DateTime nowUtc,
CancellationToken cancellationToken = default)
{
var utcNow = NormalizeUtc(nowUtc);
var monthStart = new DateTime(utcNow.Year, utcNow.Month, 1, 0, 0, 0, DateTimeKind.Utc);
var summary = await context.MemberStoredCardRechargeRecords
.AsNoTracking()
.Where(item => item.TenantId == tenantId && item.StoreId == storeId)
.GroupBy(_ => 1)
.Select(group => new
{
TotalRechargeAmount = group.Sum(item => item.RechargeAmount),
TotalGiftAmount = group.Sum(item => item.GiftAmount),
CurrentMonthRechargeAmount = group
.Where(item => item.RechargedAt >= monthStart && item.RechargedAt <= utcNow)
.Sum(item => item.RechargeAmount),
RechargeMemberCount = group.Select(item => item.MemberId).Distinct().Count()
})
.FirstOrDefaultAsync(cancellationToken);
if (summary is null)
{
return new MemberStoredCardPlanStatsSnapshot();
}
return new MemberStoredCardPlanStatsSnapshot
{
TotalRechargeAmount = summary.TotalRechargeAmount,
TotalGiftAmount = summary.TotalGiftAmount,
CurrentMonthRechargeAmount = summary.CurrentMonthRechargeAmount,
RechargeMemberCount = summary.RechargeMemberCount
};
}
/// <inheritdoc />
public async Task<(IReadOnlyList<MemberStoredCardRechargeRecord> Items, int TotalCount)> SearchRechargeRecordsAsync(
long tenantId,
long storeId,
DateTime? startUtc,
DateTime? endUtc,
string? keyword,
int page,
int pageSize,
CancellationToken cancellationToken = default)
{
var normalizedPage = Math.Max(1, page);
var normalizedPageSize = Math.Clamp(pageSize, 1, 500);
var query = BuildRechargeRecordQuery(
tenantId,
storeId,
startUtc,
endUtc,
keyword);
var totalCount = await query.CountAsync(cancellationToken);
if (totalCount == 0)
{
return ([], 0);
}
var items = await query
.OrderByDescending(item => item.RechargedAt)
.ThenByDescending(item => item.Id)
.Skip((normalizedPage - 1) * normalizedPageSize)
.Take(normalizedPageSize)
.ToListAsync(cancellationToken);
return (items, totalCount);
}
/// <inheritdoc />
public async Task<IReadOnlyList<MemberStoredCardRechargeRecord>> ListRechargeRecordsForExportAsync(
long tenantId,
long storeId,
DateTime? startUtc,
DateTime? endUtc,
string? keyword,
CancellationToken cancellationToken = default)
{
return await BuildRechargeRecordQuery(
tenantId,
storeId,
startUtc,
endUtc,
keyword)
.OrderByDescending(item => item.RechargedAt)
.ThenByDescending(item => item.Id)
.Take(20_000)
.ToListAsync(cancellationToken);
}
/// <inheritdoc />
public Task AddRechargeRecordAsync(MemberStoredCardRechargeRecord entity, CancellationToken cancellationToken = default)
{
return context.MemberStoredCardRechargeRecords.AddAsync(entity, cancellationToken).AsTask();
}
/// <inheritdoc />
public Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
return context.SaveChangesAsync(cancellationToken);
}
private IQueryable<MemberStoredCardRechargeRecord> BuildRechargeRecordQuery(
long tenantId,
long storeId,
DateTime? startUtc,
DateTime? endUtc,
string? keyword)
{
var query = context.MemberStoredCardRechargeRecords
.AsNoTracking()
.Where(item => item.TenantId == tenantId && item.StoreId == storeId);
if (startUtc.HasValue)
{
var normalizedStart = NormalizeUtc(startUtc.Value);
query = query.Where(item => item.RechargedAt >= normalizedStart);
}
if (endUtc.HasValue)
{
var normalizedEnd = NormalizeUtc(endUtc.Value);
query = query.Where(item => item.RechargedAt <= normalizedEnd);
}
var normalizedKeyword = (keyword ?? string.Empty).Trim();
if (!string.IsNullOrWhiteSpace(normalizedKeyword))
{
var like = $"%{normalizedKeyword}%";
query = query.Where(item =>
EF.Functions.ILike(item.RecordNo, like) ||
EF.Functions.ILike(item.MemberName, like) ||
EF.Functions.ILike(item.MemberMobileMasked, like));
}
return query;
}
private static DateTime NormalizeUtc(DateTime value)
{
return value.Kind switch
{
DateTimeKind.Utc => value,
DateTimeKind.Local => value.ToUniversalTime(),
_ => DateTime.SpecifyKind(value, DateTimeKind.Utc)
};
}
}

View File

@@ -0,0 +1,120 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace TakeoutSaaS.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddMemberStoredCardModule : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "member_stored_card_plans",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StoreId = table.Column<long>(type: "bigint", nullable: false, comment: "门店标识。"),
RechargeAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "充值金额。"),
GiftAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "赠送金额。"),
SortOrder = table.Column<int>(type: "integer", nullable: false, comment: "排序值(越小越靠前)。"),
Status = table.Column<int>(type: "integer", nullable: false, comment: "启用状态。"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间UTC。"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间UTC从未更新时为 null。"),
DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "软删除时间UTC未删除时为 null。"),
CreatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
UpdatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
DeletedBy = table.Column<long>(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
TenantId = table.Column<long>(type: "bigint", nullable: false, comment: "所属租户 ID。")
},
constraints: table =>
{
table.PrimaryKey("PK_member_stored_card_plans", x => x.Id);
},
comment: "会员储值卡充值方案。");
migrationBuilder.CreateTable(
name: "member_stored_card_recharge_records",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StoreId = table.Column<long>(type: "bigint", nullable: false, comment: "门店标识。"),
MemberId = table.Column<long>(type: "bigint", nullable: false, comment: "会员标识。"),
PlanId = table.Column<long>(type: "bigint", nullable: true, comment: "充值方案标识(可空,表示非方案充值)。"),
RecordNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "充值单号。"),
MemberName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "会员名称快照。"),
MemberMobileMasked = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "会员手机号快照(脱敏)。"),
RechargeAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "充值金额。"),
GiftAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "赠送金额。"),
ArrivedAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "到账金额(充值+赠送)。"),
PaymentMethod = table.Column<int>(type: "integer", nullable: false, comment: "支付方式。"),
Remark = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "备注。"),
RechargedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "充值时间UTC。"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间UTC。"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间UTC从未更新时为 null。"),
DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "软删除时间UTC未删除时为 null。"),
CreatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
UpdatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
DeletedBy = table.Column<long>(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
TenantId = table.Column<long>(type: "bigint", nullable: false, comment: "所属租户 ID。")
},
constraints: table =>
{
table.PrimaryKey("PK_member_stored_card_recharge_records", x => x.Id);
},
comment: "会员储值卡充值记录。");
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_plans_TenantId_StoreId_RechargeAmount_Gi~",
table: "member_stored_card_plans",
columns: new[] { "TenantId", "StoreId", "RechargeAmount", "GiftAmount" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_plans_TenantId_StoreId_SortOrder",
table: "member_stored_card_plans",
columns: new[] { "TenantId", "StoreId", "SortOrder" });
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_plans_TenantId_StoreId_Status",
table: "member_stored_card_plans",
columns: new[] { "TenantId", "StoreId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_recharge_records_TenantId_StoreId_Member~",
table: "member_stored_card_recharge_records",
columns: new[] { "TenantId", "StoreId", "MemberId", "RechargedAt" });
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_recharge_records_TenantId_StoreId_PlanId~",
table: "member_stored_card_recharge_records",
columns: new[] { "TenantId", "StoreId", "PlanId", "RechargedAt" });
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_recharge_records_TenantId_StoreId_Rechar~",
table: "member_stored_card_recharge_records",
columns: new[] { "TenantId", "StoreId", "RechargedAt" });
migrationBuilder.CreateIndex(
name: "IX_member_stored_card_recharge_records_TenantId_StoreId_Record~",
table: "member_stored_card_recharge_records",
columns: new[] { "TenantId", "StoreId", "RecordNo" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "member_stored_card_plans");
migrationBuilder.DropTable(
name: "member_stored_card_recharge_records");
}
}
}

View File

@@ -2976,6 +2976,67 @@ namespace TakeoutSaaS.Infrastructure.Migrations
});
});
modelBuilder.Entity("TakeoutSaaS.Domain.Membership.Entities.MemberDaySetting", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasComment("实体唯一标识。");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间UTC。");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasComment("创建人用户标识,匿名或系统操作时为 null。");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone")
.HasComment("软删除时间UTC未删除时为 null。");
b.Property<long?>("DeletedBy")
.HasColumnType("bigint")
.HasComment("删除人用户标识(软删除),未删除时为 null。");
b.Property<decimal>("ExtraDiscountRate")
.HasPrecision(5, 2)
.HasColumnType("numeric(5,2)")
.HasComment("会员日额外折扣(如 9 表示 9 折)。");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean")
.HasComment("是否启用会员日。");
b.Property<long>("TenantId")
.HasColumnType("bigint")
.HasComment("所属租户 ID。");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("最近一次更新时间UTC从未更新时为 null。");
b.Property<long?>("UpdatedBy")
.HasColumnType("bigint")
.HasComment("最后更新人用户标识,匿名或系统操作时为 null。");
b.Property<int>("Weekday")
.HasColumnType("integer")
.HasComment("周几1-7对应周一到周日。");
b.HasKey("Id");
b.HasIndex("TenantId")
.IsUnique();
b.ToTable("member_day_settings", null, t =>
{
t.HasComment("会员日配置。");
});
});
modelBuilder.Entity("TakeoutSaaS.Domain.Membership.Entities.MemberPointLedger", b =>
{
b.Property<long>("Id")
@@ -3116,6 +3177,21 @@ namespace TakeoutSaaS.Infrastructure.Migrations
.HasColumnType("integer")
.HasComment("会员状态。");
b.Property<decimal>("StoredBalance")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("储值余额。");
b.Property<decimal>("StoredGiftBalance")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("储值赠金余额。");
b.Property<decimal>("StoredRechargeBalance")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("储值实充余额。");
b.Property<long>("TenantId")
.HasColumnType("bigint")
.HasComment("所属租户 ID。");
@@ -3134,6 +3210,8 @@ namespace TakeoutSaaS.Infrastructure.Migrations
b.HasKey("Id");
b.HasIndex("TenantId", "MemberTierId");
b.HasIndex("TenantId", "Mobile")
.IsUnique();
@@ -3143,6 +3221,252 @@ namespace TakeoutSaaS.Infrastructure.Migrations
});
});
modelBuilder.Entity("TakeoutSaaS.Domain.Membership.Entities.MemberProfileTag", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasComment("实体唯一标识。");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间UTC。");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasComment("创建人用户标识,匿名或系统操作时为 null。");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone")
.HasComment("软删除时间UTC未删除时为 null。");
b.Property<long?>("DeletedBy")
.HasColumnType("bigint")
.HasComment("删除人用户标识(软删除),未删除时为 null。");
b.Property<long>("MemberProfileId")
.HasColumnType("bigint")
.HasComment("会员标识。");
b.Property<string>("TagName")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasComment("标签名。");
b.Property<long>("TenantId")
.HasColumnType("bigint")
.HasComment("所属租户 ID。");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("最近一次更新时间UTC从未更新时为 null。");
b.Property<long?>("UpdatedBy")
.HasColumnType("bigint")
.HasComment("最后更新人用户标识,匿名或系统操作时为 null。");
b.HasKey("Id");
b.HasIndex("TenantId", "MemberProfileId");
b.HasIndex("TenantId", "MemberProfileId", "TagName")
.IsUnique();
b.ToTable("member_profile_tags", null, t =>
{
t.HasComment("会员标签。");
});
});
modelBuilder.Entity("TakeoutSaaS.Domain.Membership.Entities.MemberStoredCardPlan", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasComment("实体唯一标识。");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间UTC。");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasComment("创建人用户标识,匿名或系统操作时为 null。");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone")
.HasComment("软删除时间UTC未删除时为 null。");
b.Property<long?>("DeletedBy")
.HasColumnType("bigint")
.HasComment("删除人用户标识(软删除),未删除时为 null。");
b.Property<decimal>("GiftAmount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("赠送金额。");
b.Property<decimal>("RechargeAmount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("充值金额。");
b.Property<int>("SortOrder")
.HasColumnType("integer")
.HasComment("排序值(越小越靠前)。");
b.Property<int>("Status")
.HasColumnType("integer")
.HasComment("启用状态。");
b.Property<long>("StoreId")
.HasColumnType("bigint")
.HasComment("门店标识。");
b.Property<long>("TenantId")
.HasColumnType("bigint")
.HasComment("所属租户 ID。");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("最近一次更新时间UTC从未更新时为 null。");
b.Property<long?>("UpdatedBy")
.HasColumnType("bigint")
.HasComment("最后更新人用户标识,匿名或系统操作时为 null。");
b.HasKey("Id");
b.HasIndex("TenantId", "StoreId", "SortOrder");
b.HasIndex("TenantId", "StoreId", "Status");
b.HasIndex("TenantId", "StoreId", "RechargeAmount", "GiftAmount")
.IsUnique();
b.ToTable("member_stored_card_plans", null, t =>
{
t.HasComment("会员储值卡充值方案。");
});
});
modelBuilder.Entity("TakeoutSaaS.Domain.Membership.Entities.MemberStoredCardRechargeRecord", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasComment("实体唯一标识。");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<decimal>("ArrivedAmount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("到账金额(充值+赠送)。");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间UTC。");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasComment("创建人用户标识,匿名或系统操作时为 null。");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone")
.HasComment("软删除时间UTC未删除时为 null。");
b.Property<long?>("DeletedBy")
.HasColumnType("bigint")
.HasComment("删除人用户标识(软删除),未删除时为 null。");
b.Property<decimal>("GiftAmount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("赠送金额。");
b.Property<long>("MemberId")
.HasColumnType("bigint")
.HasComment("会员标识。");
b.Property<string>("MemberMobileMasked")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasComment("会员手机号快照(脱敏)。");
b.Property<string>("MemberName")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasComment("会员名称快照。");
b.Property<int>("PaymentMethod")
.HasColumnType("integer")
.HasComment("支付方式。");
b.Property<long?>("PlanId")
.HasColumnType("bigint")
.HasComment("充值方案标识(可空,表示非方案充值)。");
b.Property<decimal>("RechargeAmount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("充值金额。");
b.Property<DateTime>("RechargedAt")
.HasColumnType("timestamp with time zone")
.HasComment("充值时间UTC。");
b.Property<string>("RecordNo")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasComment("充值单号。");
b.Property<string>("Remark")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasComment("备注。");
b.Property<long>("StoreId")
.HasColumnType("bigint")
.HasComment("门店标识。");
b.Property<long>("TenantId")
.HasColumnType("bigint")
.HasComment("所属租户 ID。");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("最近一次更新时间UTC从未更新时为 null。");
b.Property<long?>("UpdatedBy")
.HasColumnType("bigint")
.HasComment("最后更新人用户标识,匿名或系统操作时为 null。");
b.HasKey("Id");
b.HasIndex("TenantId", "StoreId", "RechargedAt");
b.HasIndex("TenantId", "StoreId", "RecordNo")
.IsUnique();
b.HasIndex("TenantId", "StoreId", "MemberId", "RechargedAt");
b.HasIndex("TenantId", "StoreId", "PlanId", "RechargedAt");
b.ToTable("member_stored_card_recharge_records", null, t =>
{
t.HasComment("会员储值卡充值记录。");
});
});
modelBuilder.Entity("TakeoutSaaS.Domain.Membership.Entities.MemberTier", b =>
{
b.Property<long>("Id")
@@ -3157,6 +3481,12 @@ namespace TakeoutSaaS.Infrastructure.Migrations
.HasColumnType("text")
.HasComment("等级权益JSON。");
b.Property<string>("ColorHex")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)")
.HasComment("主题色。");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasComment("创建时间UTC。");
@@ -3173,6 +3503,20 @@ namespace TakeoutSaaS.Infrastructure.Migrations
.HasColumnType("bigint")
.HasComment("删除人用户标识(软删除),未删除时为 null。");
b.Property<int>("DowngradeWindowDays")
.HasColumnType("integer")
.HasComment("降级观察窗口天数。");
b.Property<string>("IconKey")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasComment("图标键。");
b.Property<bool>("IsDefault")
.HasColumnType("boolean")
.HasComment("是否默认等级。");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
@@ -3199,11 +3543,28 @@ namespace TakeoutSaaS.Infrastructure.Migrations
.HasColumnType("bigint")
.HasComment("最后更新人用户标识,匿名或系统操作时为 null。");
b.Property<decimal?>("UpgradeAmountThreshold")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)")
.HasComment("升级累计消费门槛。");
b.Property<int?>("UpgradeOrderCountThreshold")
.HasColumnType("integer")
.HasComment("升级消费次数门槛。");
b.Property<string>("UpgradeRuleType")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)")
.HasComment("升级规则类型none/amount/count/both。");
b.HasKey("Id");
b.HasIndex("TenantId", "Name")
.IsUnique();
b.HasIndex("TenantId", "SortOrder");
b.ToTable("member_tiers", null, t =>
{
t.HasComment("会员等级定义。");