feat(M04-A): 完成定价快照与并发时段预占

This commit is contained in:
Codex
2026-06-18 16:07:00 +08:00
parent 6be7fa79c5
commit af7a45d878
19 changed files with 824 additions and 22 deletions
@@ -0,0 +1,8 @@
DELETE FROM qipai_schema_migrations WHERE version = '2026061811';
DROP TABLE IF EXISTS qipai_room_reservations;
DROP TABLE IF EXISTS qipai_order_price_snapshots;
DROP TABLE IF EXISTS qipai_holiday_calendar;
ALTER TABLE qipai_orders DROP COLUMN hold_expires_at;
ALTER TABLE qipai_rooms
DROP COLUMN minimum_spend_cents,
DROP COLUMN full_day_price_cents;
@@ -0,0 +1,60 @@
ALTER TABLE qipai_rooms
ADD COLUMN full_day_price_cents INT UNSIGNED NOT NULL DEFAULT 0 AFTER overnight_price_cents,
ADD COLUMN minimum_spend_cents INT UNSIGNED NOT NULL DEFAULT 0 AFTER full_day_price_cents;
ALTER TABLE qipai_orders
ADD COLUMN hold_expires_at DATETIME(3) NULL AFTER end_at;
CREATE TABLE IF NOT EXISTS qipai_holiday_calendar (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
holiday_date DATE NOT NULL,
name VARCHAR(128) NOT NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
CONSTRAINT fk_qipai_holiday_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
UNIQUE KEY uq_qipai_holiday_date (tenant_id, holiday_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS qipai_order_price_snapshots (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
order_id BIGINT UNSIGNED NOT NULL,
currency CHAR(3) NOT NULL DEFAULT 'CNY',
pricing_mode VARCHAR(16) NOT NULL,
duration_minutes INT UNSIGNED NOT NULL,
unit_price_cents INT UNSIGNED NOT NULL,
subtotal_cents INT UNSIGNED NOT NULL,
minimum_spend_cents INT UNSIGNED NOT NULL DEFAULT 0,
deposit_cents INT UNSIGNED NOT NULL DEFAULT 0,
discount_cents INT UNSIGNED NOT NULL DEFAULT 0,
package_credit_cents INT UNSIGNED NOT NULL DEFAULT 0,
total_cents INT UNSIGNED NOT NULL,
rules JSON NOT NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
CONSTRAINT fk_qipai_price_snapshot_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
CONSTRAINT fk_qipai_price_snapshot_order FOREIGN KEY (order_id) REFERENCES qipai_orders(id),
UNIQUE KEY uq_qipai_price_snapshot_order (tenant_id, order_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS qipai_room_reservations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
order_id BIGINT UNSIGNED NOT NULL,
room_id BIGINT UNSIGNED NOT NULL,
starts_at DATETIME(3) NOT NULL,
ends_at DATETIME(3) NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'HELD',
expires_at DATETIME(3) NOT NULL,
released_at DATETIME(3) NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
CONSTRAINT fk_qipai_reservation_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
CONSTRAINT fk_qipai_reservation_order FOREIGN KEY (order_id) REFERENCES qipai_orders(id),
CONSTRAINT fk_qipai_reservation_room FOREIGN KEY (room_id) REFERENCES qipai_rooms(id),
UNIQUE KEY uq_qipai_reservation_order (tenant_id, order_id),
KEY idx_qipai_reservation_overlap (tenant_id, room_id, status, starts_at, ends_at),
KEY idx_qipai_reservation_expiry (status, expires_at),
CONSTRAINT chk_qipai_reservation_window CHECK (ends_at > starts_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO qipai_schema_migrations (version, name)
VALUES ('2026061811', 'm04a_pricing_reservations');
@@ -0,0 +1,27 @@
SELECT column_name FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'qipai_rooms'
AND column_name IN ('full_day_price_cents', 'minimum_spend_cents')
ORDER BY column_name;
SELECT column_name FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'qipai_orders'
AND column_name = 'hold_expires_at';
SELECT table_name FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name IN (
'qipai_holiday_calendar',
'qipai_order_price_snapshots',
'qipai_room_reservations'
)
ORDER BY table_name;
SELECT table_name, index_name FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND ((table_name = 'qipai_order_price_snapshots'
AND index_name = 'uq_qipai_price_snapshot_order')
OR (table_name = 'qipai_room_reservations'
AND index_name IN ('idx_qipai_reservation_overlap', 'idx_qipai_reservation_expiry')))
GROUP BY table_name, index_name ORDER BY table_name, index_name;
SELECT version, name FROM qipai_schema_migrations WHERE version = '2026061811';