feat(M03-B): 完成装修广告与媒体管理

This commit is contained in:
Codex
2026-06-18 15:06:16 +08:00
parent 7e9b53487b
commit f74624296d
19 changed files with 1241 additions and 13 deletions
@@ -0,0 +1,4 @@
DELETE FROM qipai_schema_migrations WHERE version = '2026061808';
DROP TABLE IF EXISTS qipai_advertisements;
DROP TABLE IF EXISTS qipai_store_decorations;
DROP TABLE IF EXISTS qipai_media_assets;
@@ -0,0 +1,74 @@
CREATE TABLE IF NOT EXISTS qipai_media_assets (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
store_id BIGINT UNSIGNED NULL,
kind VARCHAR(32) NOT NULL DEFAULT 'IMAGE',
storage_path VARCHAR(512) NOT NULL,
public_url VARCHAR(512) NOT NULL,
mime_type VARCHAR(64) NOT NULL,
byte_size INT UNSIGNED NOT NULL,
width INT UNSIGNED NOT NULL,
height INT UNSIGNED NOT NULL,
checksum_sha256 CHAR(64) NOT NULL,
created_by BIGINT UNSIGNED NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
deleted_at DATETIME(3) NULL,
CONSTRAINT fk_qipai_media_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
CONSTRAINT fk_qipai_media_store FOREIGN KEY (store_id) REFERENCES qipai_stores(id),
CONSTRAINT fk_qipai_media_creator FOREIGN KEY (created_by) REFERENCES qipai_users(id),
UNIQUE KEY uq_qipai_media_tenant_checksum (tenant_id, checksum_sha256),
KEY idx_qipai_media_store_time (tenant_id, store_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS qipai_store_decorations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
store_id BIGINT UNSIGNED NOT NULL,
template_code VARCHAR(64) NOT NULL,
schema_version INT UNSIGNED NOT NULL,
content_json JSON NOT NULL,
status VARCHAR(32) NOT NULL DEFAULT 'DRAFT',
version INT UNSIGNED NOT NULL DEFAULT 1,
published_at DATETIME(3) NULL,
created_by BIGINT UNSIGNED NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
deleted_at DATETIME(3) NULL,
CONSTRAINT fk_qipai_decorations_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
CONSTRAINT fk_qipai_decorations_store FOREIGN KEY (store_id) REFERENCES qipai_stores(id),
CONSTRAINT fk_qipai_decorations_creator FOREIGN KEY (created_by) REFERENCES qipai_users(id),
UNIQUE KEY uq_qipai_decorations_version (tenant_id, store_id, version),
KEY idx_qipai_decorations_published (tenant_id, store_id, status, published_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS qipai_advertisements (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
scope_type VARCHAR(32) NOT NULL,
store_id BIGINT UNSIGNED NULL,
title VARCHAR(128) NOT NULL,
image_asset_id BIGINT UNSIGNED NOT NULL,
target_type VARCHAR(32) NOT NULL DEFAULT 'NONE',
target_value VARCHAR(512) NOT NULL DEFAULT '',
starts_at DATETIME(3) NULL,
ends_at DATETIME(3) NULL,
status VARCHAR(32) NOT NULL DEFAULT 'DRAFT',
sort_order INT NOT NULL DEFAULT 0,
created_by BIGINT UNSIGNED NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
deleted_at DATETIME(3) NULL,
CONSTRAINT fk_qipai_ads_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
CONSTRAINT fk_qipai_ads_store FOREIGN KEY (store_id) REFERENCES qipai_stores(id),
CONSTRAINT fk_qipai_ads_asset FOREIGN KEY (image_asset_id) REFERENCES qipai_media_assets(id),
CONSTRAINT fk_qipai_ads_creator FOREIGN KEY (created_by) REFERENCES qipai_users(id),
KEY idx_qipai_ads_delivery (tenant_id, scope_type, store_id, status, starts_at, ends_at),
CONSTRAINT chk_qipai_ads_scope CHECK (
(scope_type = 'STORE' AND store_id IS NOT NULL)
OR (scope_type IN ('PLATFORM', 'TENANT') AND store_id IS NULL)
),
CONSTRAINT chk_qipai_ads_window CHECK (ends_at IS NULL OR starts_at IS NULL OR ends_at > starts_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO qipai_schema_migrations (version, name)
VALUES ('2026061808', 'm03b_decoration_ads_media');
@@ -0,0 +1,13 @@
SELECT table_name FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name IN ('qipai_media_assets', 'qipai_store_decorations', 'qipai_advertisements')
ORDER BY table_name;
SELECT table_name, index_name FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND ((table_name = 'qipai_media_assets' AND index_name = 'uq_qipai_media_tenant_checksum')
OR (table_name = 'qipai_store_decorations' AND index_name = 'uq_qipai_decorations_version')
OR (table_name = 'qipai_advertisements' AND index_name = 'idx_qipai_ads_delivery'))
GROUP BY table_name, index_name ORDER BY table_name;
SELECT version, name FROM qipai_schema_migrations WHERE version = '2026061808';