diff --git a/backend/migrations/000093_quality_owner_and_premium_listings.sql b/backend/migrations/000093_quality_owner_and_premium_listings.sql index b4a9dad..2e2c8b3 100644 --- a/backend/migrations/000093_quality_owner_and_premium_listings.sql +++ b/backend/migrations/000093_quality_owner_and_premium_listings.sql @@ -1,9 +1,6 @@ -- +goose Up --- 优质号主与无忧租号保险: --- users 保存优质号主资格及保证金快照; --- rental_listings 标记极品专区商品,并保存发布时赔付方案/费率快照; --- rental_orders / order_checkouts 保存下单时费率快照和实际保险服务费。 +-- 优质号主、极品专区、无忧租号保险及保证金支付。 ALTER TABLE users ADD COLUMN quality_owner_status VARCHAR(16) NOT NULL DEFAULT 'none' COMMENT '优质号主状态: none普通/active优质' AFTER status, ADD COLUMN quality_owner_deposit_cent BIGINT NOT NULL DEFAULT 0 COMMENT '优质号主保证金(分)' AFTER quality_owner_status, @@ -27,8 +24,13 @@ ALTER TABLE order_checkouts ADD COLUMN insurance_fee_bps INT NOT NULL DEFAULT 0 COMMENT '保险服务费率快照(万分比)' AFTER platform_fee_cent, ADD COLUMN insurance_fee_cent BIGINT NOT NULL DEFAULT 0 COMMENT '保险服务费(分)' AFTER insurance_fee_bps; -INSERT INTO permissions (code, name, resource, action) VALUES -('user:quality_owner', '设置优质号主', 'user', 'quality_owner') +-- 通用业务支付单:订单支付继续使用 order_id;优质号主保证金等非订单业务使用 biz_id。 +ALTER TABLE payment_orders + ADD COLUMN biz_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '业务对象ID(非订单业务使用)' AFTER order_no, + ADD KEY idx_payment_orders_user_biz (user_id, biz_type, biz_id, status); + +INSERT INTO permissions (code, name, resource, action) +VALUES ('user:quality_owner', '设置优质号主', 'user', 'quality_owner') ON DUPLICATE KEY UPDATE name = VALUES(name), resource = VALUES(resource), @@ -53,6 +55,10 @@ ALTER TABLE order_checkouts DROP COLUMN insurance_fee_cent, DROP COLUMN insurance_fee_bps; +ALTER TABLE payment_orders + DROP KEY idx_payment_orders_user_biz, + DROP COLUMN biz_id; + ALTER TABLE rental_orders DROP COLUMN insurance_fee_cent, DROP COLUMN insurance_fee_bps, diff --git a/backend/migrations/000095_points_mall.sql b/backend/migrations/000094_points_mall.sql similarity index 88% rename from backend/migrations/000095_points_mall.sql rename to backend/migrations/000094_points_mall.sql index d948aff..ea089a1 100644 --- a/backend/migrations/000095_points_mall.sql +++ b/backend/migrations/000094_points_mall.sql @@ -1,4 +1,6 @@ -- +goose Up + +-- 双边积分与虚拟积分商城。 ALTER TABLE users ADD COLUMN points_available BIGINT NOT NULL DEFAULT 0 COMMENT '积分商城可用积分' AFTER renter_growth_level; @@ -6,6 +8,14 @@ UPDATE users SET points_available = renter_growth_points WHERE points_available = 0 AND renter_growth_points > 0; +ALTER TABLE rental_orders + ADD COLUMN growth_points_multiplier_bps INT NOT NULL DEFAULT 10000 COMMENT '租客积分倍率基点' AFTER growth_points_per_yuan, + ADD COLUMN owner_growth_points_basis_cent BIGINT NOT NULL DEFAULT 0 COMMENT '卖家积分基数(分)' AFTER growth_points_awarded_at, + ADD COLUMN owner_growth_points_per_yuan BIGINT NOT NULL DEFAULT 0 COMMENT '卖家基础每元积分' AFTER owner_growth_points_basis_cent, + ADD COLUMN owner_growth_points_multiplier_bps INT NOT NULL DEFAULT 10000 COMMENT '卖家积分倍率基点' AFTER owner_growth_points_per_yuan, + ADD COLUMN owner_growth_points_awarded BIGINT NOT NULL DEFAULT 0 COMMENT '卖家已发放积分' AFTER owner_growth_points_multiplier_bps, + ADD COLUMN owner_growth_points_awarded_at DATETIME NULL COMMENT '卖家积分发放时间' AFTER owner_growth_points_awarded; + ALTER TABLE renter_growth_ledger DROP KEY uk_renter_growth_order_source, ADD COLUMN role VARCHAR(16) NOT NULL DEFAULT 'renter' COMMENT '积分角色: renter/owner/admin' AFTER user_id, @@ -18,14 +28,6 @@ ALTER TABLE renter_growth_ledger ADD UNIQUE KEY uk_renter_growth_order_role_source (order_id, source, role), ADD KEY idx_renter_growth_user_role_created (user_id, role, created_at); -ALTER TABLE rental_orders - ADD COLUMN growth_points_multiplier_bps INT NOT NULL DEFAULT 10000 COMMENT '租客积分倍率基点' AFTER growth_points_per_yuan, - ADD COLUMN owner_growth_points_basis_cent BIGINT NOT NULL DEFAULT 0 COMMENT '卖家积分基数(分)' AFTER growth_points_awarded_at, - ADD COLUMN owner_growth_points_per_yuan BIGINT NOT NULL DEFAULT 0 COMMENT '卖家基础每元积分' AFTER owner_growth_points_basis_cent, - ADD COLUMN owner_growth_points_multiplier_bps INT NOT NULL DEFAULT 10000 COMMENT '卖家积分倍率基点' AFTER owner_growth_points_per_yuan, - ADD COLUMN owner_growth_points_awarded BIGINT NOT NULL DEFAULT 0 COMMENT '卖家已发放积分' AFTER owner_growth_points_multiplier_bps, - ADD COLUMN owner_growth_points_awarded_at DATETIME NULL COMMENT '卖家积分发放时间' AFTER owner_growth_points_awarded; - CREATE TABLE IF NOT EXISTS points_mall_products ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, title VARCHAR(128) NOT NULL, @@ -53,6 +55,9 @@ CREATE TABLE IF NOT EXISTS points_mall_redemptions ( product_title VARCHAR(128) NOT NULL, product_cover_url VARCHAR(512) NOT NULL DEFAULT '', redemption_instructions TEXT NOT NULL, + contact_name VARCHAR(32) NOT NULL DEFAULT '' COMMENT '兑换联系人', + contact_phone VARCHAR(32) NOT NULL DEFAULT '' COMMENT '兑换联系人手机号', + customer_remark VARCHAR(500) NOT NULL DEFAULT '' COMMENT '用户兑换备注', points_price BIGINT NOT NULL DEFAULT 0, quantity INT NOT NULL DEFAULT 1, total_points BIGINT NOT NULL DEFAULT 0, @@ -73,20 +78,27 @@ INSERT INTO permissions (code, name, resource, action) VALUES ('points_mall:view', '查看积分商城', 'points_mall', 'view'), ('points_mall:manage', '管理积分商城', 'points_mall', 'manage') -ON DUPLICATE KEY UPDATE name = VALUES(name), resource = VALUES(resource), action = VALUES(action); +ON DUPLICATE KEY UPDATE + name = VALUES(name), + resource = VALUES(resource), + action = VALUES(action); INSERT IGNORE INTO role_permissions (role_id, permission_id) SELECT r.id, p.id FROM roles r JOIN permissions p ON p.code IN ('points_mall:view', 'points_mall:manage') -WHERE r.code IN ('super_admin', 'ops'); +WHERE r.code IN ('ops', 'super_admin'); -- +goose Down -DELETE FROM role_permissions -WHERE permission_id IN ( - SELECT id FROM permissions WHERE code IN ('points_mall:view', 'points_mall:manage') -); -DELETE FROM permissions WHERE code IN ('points_mall:view', 'points_mall:manage'); + +DELETE rp +FROM role_permissions rp +JOIN permissions p ON p.id = rp.permission_id +WHERE p.code IN ('points_mall:view', 'points_mall:manage'); + +DELETE FROM permissions +WHERE code IN ('points_mall:view', 'points_mall:manage'); + DROP TABLE IF EXISTS points_mall_redemptions; DROP TABLE IF EXISTS points_mall_products; diff --git a/backend/migrations/000094_quality_owner_payment.sql b/backend/migrations/000094_quality_owner_payment.sql deleted file mode 100644 index cb83fb5..0000000 --- a/backend/migrations/000094_quality_owner_payment.sql +++ /dev/null @@ -1,13 +0,0 @@ --- +goose Up - --- 通用业务支付单:订单支付继续使用 order_id;优质号主保证金等非订单业务使用 biz_id, --- 避免把用户 ID 写入订单外键语义。 -ALTER TABLE payment_orders - ADD COLUMN biz_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '业务对象ID(非订单业务使用)' AFTER order_no, - ADD KEY idx_payment_orders_user_biz (user_id, biz_type, biz_id, status); - --- +goose Down - -ALTER TABLE payment_orders - DROP KEY idx_payment_orders_user_biz, - DROP COLUMN biz_id;