feat(billing): enforce image generation quota with admin API and user display
Memind CI / Test, build, and release guards (push) Failing after 3s

Add period_images_bonus and ledger tracking, gate image_make on remaining quota,
expose admin image-quota routes, show remaining image quota in the balance popover,
and document that admin UI must live in memind_adm (5174) not ops.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-03 14:58:38 +08:00
parent 36d8e74784
commit 946d8756c8
14 changed files with 639 additions and 23 deletions
+16
View File
@@ -1181,6 +1181,7 @@ CREATE TABLE IF NOT EXISTS h5_subscriptions (
period_tokens_used BIGINT NOT NULL DEFAULT 0,
period_images_limit INT NOT NULL DEFAULT 0,
period_images_used INT NOT NULL DEFAULT 0,
period_images_bonus INT NOT NULL DEFAULT 0,
period_start BIGINT NOT NULL,
period_end BIGINT NOT NULL,
expires_at BIGINT NOT NULL,
@@ -1195,6 +1196,21 @@ CREATE TABLE IF NOT EXISTS h5_subscriptions (
CONSTRAINT fk_h5_sub_user FOREIGN KEY (user_id) REFERENCES h5_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS h5_image_quota_ledger (
id CHAR(36) PRIMARY KEY,
user_id CHAR(36) NOT NULL,
delta INT NOT NULL,
balance_after INT NULL,
reason ENUM('admin_grant', 'admin_adjust', 'consume', 'period_reset', 'plan_change') NOT NULL,
ref_id VARCHAR(128) NULL,
operator_id CHAR(36) NULL,
note VARCHAR(512) NULL,
created_at BIGINT NOT NULL,
KEY idx_h5_image_quota_user_created (user_id, created_at),
KEY idx_h5_image_quota_ref (user_id, ref_id),
CONSTRAINT fk_h5_image_quota_user FOREIGN KEY (user_id) REFERENCES h5_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS h5_blocked_words (
id CHAR(36) PRIMARY KEY,
word VARCHAR(200) NOT NULL,