feat(item-purchase): /item_purchase/{info,purchase} + catalog
Schema: ItemPurchaseCatalogEntry (single table). Per-viewer quota tracked via existing ViewerEventCounter keyed by "item_purchase:<id>" with period JstPeriod.MonthKey when IsMonthlyReset else AllTime. Controller: - /info returns catalog + per-period rest (server-computed max(0, PurchaseLimit - counter)) + user_card_pack_ticket_list (every Items.Type==2 row joined to viewer count, zeros included — client unconditionally UpdateItemNum's each entry). - /purchase: sold_out check before currency check (no counter increment on currency failure), inline TryDebit covers RedEther/Crystal/Rupy/Item with post-state-total reward_list entry, grant via RewardGrantService. Request `rest` accepted but ignored (server counter is canonical). Importer mirrors PaymentItemImporter shape — idempotent find-or-create, seed-missing rows preserved. 3 entries from the prod capture. 486 tests pass (was 476; +10 item_purchase tests). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
3430
SVSim.Database/Migrations/20260528021818_AddItemPurchaseCatalog.Designer.cs
generated
Normal file
3430
SVSim.Database/Migrations/20260528021818_AddItemPurchaseCatalog.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SVSim.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddItemPurchaseCatalog : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ItemPurchaseCatalog",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false),
|
||||
RequireItemType = table.Column<int>(type: "integer", nullable: false),
|
||||
RequireItemId = table.Column<long>(type: "bigint", nullable: false),
|
||||
RequireItemNum = table.Column<int>(type: "integer", nullable: false),
|
||||
PurchaseItemType = table.Column<int>(type: "integer", nullable: false),
|
||||
PurchaseItemId = table.Column<long>(type: "bigint", nullable: false),
|
||||
PurchaseItemNum = table.Column<int>(type: "integer", nullable: false),
|
||||
PurchaseName = table.Column<string>(type: "text", nullable: false),
|
||||
IsMonthlyReset = table.Column<bool>(type: "boolean", nullable: false),
|
||||
PurchaseLimit = table.Column<int>(type: "integer", nullable: false),
|
||||
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ItemPurchaseCatalog", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ItemPurchaseCatalog");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1107,6 +1107,53 @@ namespace SVSim.Database.Migrations
|
||||
b.ToTable("Items");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.ItemPurchaseCatalogEntry", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsMonthlyReset")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<long>("PurchaseItemId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("PurchaseItemNum")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseItemType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PurchaseLimit")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("PurchaseName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("RequireItemId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("RequireItemNum")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RequireItemType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ItemPurchaseCatalog");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.LeaderSkinEntry", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
||||
39
SVSim.Database/Models/ItemPurchaseCatalogEntry.cs
Normal file
39
SVSim.Database/Models/ItemPurchaseCatalogEntry.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using SVSim.Database.Common;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// One row of the /item_purchase/info catalog — an exchange the user can perform N times per
|
||||
/// period (monthly or lifetime) by spending <c>RequireItem*</c> to acquire <c>PurchaseItem*</c>.
|
||||
/// PK = wire <c>purchase_id</c>.
|
||||
/// <para>
|
||||
/// Both sides reference <see cref="Enums.UserGoodsType"/>. Captures show the common shape is
|
||||
/// currency-for-item (RedEther 5000 → Seer's Globe ×1) or item-for-item (Orb Shard ×5 →
|
||||
/// Seer's Globe ×1). Per-viewer remaining quota lives in
|
||||
/// <see cref="ViewerEventCounter"/> keyed by <c>"item_purchase:{Id}"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class ItemPurchaseCatalogEntry : BaseEntity<int>
|
||||
{
|
||||
public int RequireItemType { get; set; }
|
||||
public long RequireItemId { get; set; }
|
||||
public int RequireItemNum { get; set; }
|
||||
|
||||
public int PurchaseItemType { get; set; }
|
||||
public long PurchaseItemId { get; set; }
|
||||
public int PurchaseItemNum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SystemText-ready display name. May be empty — the client falls back to a templated name
|
||||
/// built from <c>UserGoods.getUserGoodsName + count</c> via SystemText key "Shop_0132".
|
||||
/// </summary>
|
||||
public string PurchaseName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>True → quota resets at the start of each JST month. False → lifetime quota.</summary>
|
||||
public bool IsMonthlyReset { get; set; }
|
||||
|
||||
/// <summary>Per-period purchase cap. Wire <c>rest</c> = max(0, PurchaseLimit - counter).</summary>
|
||||
public int PurchaseLimit { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; }
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public class SVSimDbContext : DbContext
|
||||
public DbSet<BuildDeckProductEntry> BuildDeckProducts => Set<BuildDeckProductEntry>();
|
||||
public DbSet<SleeveShopSeriesEntry> SleeveShopSeries => Set<SleeveShopSeriesEntry>();
|
||||
public DbSet<SleeveShopProductEntry> SleeveShopProducts => Set<SleeveShopProductEntry>();
|
||||
public DbSet<ItemPurchaseCatalogEntry> ItemPurchaseCatalog => Set<ItemPurchaseCatalogEntry>();
|
||||
public DbSet<MaintenanceCardEntry> MaintenanceCards => Set<MaintenanceCardEntry>();
|
||||
public DbSet<FeatureMaintenanceEntry> FeatureMaintenances => Set<FeatureMaintenanceEntry>();
|
||||
public DbSet<PreReleaseInfo> PreReleaseInfos => Set<PreReleaseInfo>();
|
||||
|
||||
Reference in New Issue
Block a user