feat(M04-C): 完成续费换房与订单调整

This commit is contained in:
Codex
2026-06-20 14:05:31 +08:00
parent 4122db45ec
commit 089d34877b
20 changed files with 940 additions and 20 deletions
@@ -0,0 +1,8 @@
DELETE FROM qipai_schema_migrations WHERE version = '2026062013';
DROP TABLE IF EXISTS qipai_order_adjustments;
ALTER TABLE qipai_orders
DROP COLUMN operator_note,
DROP COLUMN adjustment_amount_cents;
ALTER TABLE qipai_stores
DROP COLUMN cancellation_fee_bps,
DROP COLUMN cancellation_cutoff_minutes;
@@ -0,0 +1,35 @@
ALTER TABLE qipai_stores
ADD COLUMN cancellation_cutoff_minutes INT UNSIGNED NOT NULL DEFAULT 120
AFTER notification_url,
ADD COLUMN cancellation_fee_bps SMALLINT UNSIGNED NOT NULL DEFAULT 0
AFTER cancellation_cutoff_minutes;
ALTER TABLE qipai_orders
ADD COLUMN adjustment_amount_cents INT NOT NULL DEFAULT 0 AFTER paid_amount_cents,
ADD COLUMN operator_note VARCHAR(512) NOT NULL DEFAULT '' AFTER adjustment_amount_cents;
CREATE TABLE IF NOT EXISTS qipai_order_adjustments (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
tenant_id BIGINT UNSIGNED NOT NULL,
order_id BIGINT UNSIGNED NOT NULL,
adjustment_type VARCHAR(32) NOT NULL,
actor_id BIGINT UNSIGNED NOT NULL,
source VARCHAR(32) NOT NULL,
trace_id VARCHAR(128) NOT NULL,
reason VARCHAR(512) NOT NULL DEFAULT '',
before_values JSON NOT NULL,
after_values JSON NOT NULL,
amount_delta_cents INT NOT NULL DEFAULT 0,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
CONSTRAINT fk_qipai_order_adjustment_tenant
FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
CONSTRAINT fk_qipai_order_adjustment_order
FOREIGN KEY (order_id) REFERENCES qipai_orders(id),
CONSTRAINT fk_qipai_order_adjustment_actor
FOREIGN KEY (actor_id) REFERENCES qipai_users(id),
UNIQUE KEY uq_qipai_order_adjustment_trace (tenant_id, order_id, trace_id),
KEY idx_qipai_order_adjustment_order (tenant_id, order_id, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO qipai_schema_migrations (version, name)
VALUES ('2026062013', 'm04c_order_adjustments');
@@ -0,0 +1,19 @@
SELECT column_name FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'qipai_stores'
AND column_name IN ('cancellation_cutoff_minutes', 'cancellation_fee_bps')
ORDER BY column_name;
SELECT column_name FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'qipai_orders'
AND column_name IN ('adjustment_amount_cents', 'operator_note')
ORDER BY column_name;
SELECT table_name FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_name = 'qipai_order_adjustments';
SELECT index_name FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'qipai_order_adjustments'
AND index_name IN ('uq_qipai_order_adjustment_trace', 'idx_qipai_order_adjustment_order')
GROUP BY index_name ORDER BY index_name;
SELECT version, name FROM qipai_schema_migrations WHERE version = '2026062013';