feat: 接入旧站管理端并完整迁移后台能力
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
-- 后台返利流水按完整被邀请人手机号搜索时,先经 users(phone) 解析 ID,
|
||||
-- 再由该索引定位流水,避免回退为用户表与流水表的跨表全扫描。
|
||||
ALTER TABLE invitation_rebate_ledgers
|
||||
ADD KEY idx_invitation_rebate_invitee (invitee_id, settled_at);
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE invitation_rebate_ledgers
|
||||
DROP KEY idx_invitation_rebate_invitee;
|
||||
@@ -0,0 +1,35 @@
|
||||
-- +goose Up
|
||||
-- 财务仪表盘按时间窗口聚合支付、退款和结算数据。
|
||||
-- 支付索引避免退款统计扫描全部历史状态;结算与结账索引避免日报聚合回表。
|
||||
ALTER TABLE payment_orders
|
||||
ADD KEY idx_payment_orders_dashboard_created (created_at, biz_type, status, order_id, amount_cent),
|
||||
ADD KEY idx_payment_orders_dashboard_order (order_id, biz_type, status, amount_cent);
|
||||
|
||||
ALTER TABLE rental_orders
|
||||
ADD KEY idx_rental_orders_dashboard_settled (
|
||||
settled_at,
|
||||
id,
|
||||
settlement_mode,
|
||||
offline_settlement_status,
|
||||
offline_settlement_amount_cent,
|
||||
refund_status
|
||||
);
|
||||
|
||||
ALTER TABLE order_checkouts
|
||||
ADD KEY idx_order_checkouts_dashboard_accepted (
|
||||
status,
|
||||
order_id,
|
||||
platform_fee_cent,
|
||||
owner_income_amount_cent
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE order_checkouts
|
||||
DROP KEY idx_order_checkouts_dashboard_accepted;
|
||||
|
||||
ALTER TABLE rental_orders
|
||||
DROP KEY idx_rental_orders_dashboard_settled;
|
||||
|
||||
ALTER TABLE payment_orders
|
||||
DROP KEY idx_payment_orders_dashboard_order,
|
||||
DROP KEY idx_payment_orders_dashboard_created;
|
||||
@@ -0,0 +1,43 @@
|
||||
-- +goose Up
|
||||
-- 预计后续利润需要扫描时间范围内的未结算订单。订单表包含较大的 JSON 字段,
|
||||
-- 覆盖索引避免统计时回表读取整行订单。
|
||||
ALTER TABLE rental_orders
|
||||
ADD KEY idx_rental_orders_dashboard_estimates (
|
||||
created_at,
|
||||
settlement_status,
|
||||
status,
|
||||
platform_fee_cent,
|
||||
id
|
||||
),
|
||||
ADD KEY idx_rental_orders_dashboard_offline_settlement (
|
||||
settlement_mode,
|
||||
offline_settlement_status,
|
||||
offline_settled_at,
|
||||
offline_settlement_amount_cent,
|
||||
id
|
||||
);
|
||||
|
||||
ALTER TABLE admin_pickups
|
||||
ADD KEY idx_admin_pickups_dashboard_completed (
|
||||
status,
|
||||
completed_at,
|
||||
settle_amount_cent,
|
||||
profit_amount_cent,
|
||||
id
|
||||
),
|
||||
ADD KEY idx_admin_pickups_dashboard_offline_settlement (
|
||||
settlement_mode,
|
||||
offline_settlement_status,
|
||||
offline_settled_at,
|
||||
settle_amount_cent,
|
||||
id
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE rental_orders
|
||||
DROP KEY idx_rental_orders_dashboard_offline_settlement,
|
||||
DROP KEY idx_rental_orders_dashboard_estimates;
|
||||
|
||||
ALTER TABLE admin_pickups
|
||||
DROP KEY idx_admin_pickups_dashboard_offline_settlement,
|
||||
DROP KEY idx_admin_pickups_dashboard_completed;
|
||||
@@ -0,0 +1,79 @@
|
||||
-- +goose Up
|
||||
|
||||
-- 优质号主、极品专区、无忧租号保险及保证金支付。
|
||||
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,
|
||||
ADD COLUMN quality_owner_deposit_source VARCHAR(16) NOT NULL DEFAULT '' COMMENT '保证金来源: paid用户缴纳/manual后台设置' AFTER quality_owner_deposit_cent,
|
||||
ADD COLUMN quality_owner_activated_at DATETIME NULL COMMENT '优质号主开通时间' AFTER quality_owner_deposit_source,
|
||||
ADD KEY idx_users_quality_owner_status (quality_owner_status);
|
||||
|
||||
ALTER TABLE rental_listings
|
||||
ADD COLUMN is_premium TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否极品专区' AFTER distribution_site_id,
|
||||
ADD COLUMN compensation_plan VARCHAR(16) NOT NULL DEFAULT 'normal' COMMENT '赔付方案: normal普通赔付/insurance无忧租号保险' AFTER is_premium,
|
||||
ADD COLUMN insurance_fee_bps INT NOT NULL DEFAULT 0 COMMENT '保险服务费率快照(万分比)' AFTER compensation_plan,
|
||||
ADD KEY idx_rental_listings_premium_status (is_premium, status, review_status);
|
||||
|
||||
ALTER TABLE rental_orders
|
||||
ADD COLUMN is_premium TINYINT(1) NOT NULL DEFAULT 0 COMMENT '下单时是否极品专区' AFTER distribution_rule_version_id,
|
||||
ADD COLUMN compensation_plan VARCHAR(16) NOT NULL DEFAULT 'normal' COMMENT '下单时赔付方案快照' AFTER is_premium,
|
||||
ADD COLUMN insurance_fee_bps INT NOT NULL DEFAULT 0 COMMENT '下单时保险服务费率快照(万分比)' AFTER compensation_plan,
|
||||
ADD COLUMN insurance_fee_cent BIGINT NOT NULL DEFAULT 0 COMMENT '实际保险服务费(分)' AFTER insurance_fee_bps;
|
||||
|
||||
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;
|
||||
|
||||
-- 通用业务支付单:订单支付继续使用 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),
|
||||
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 = 'user:quality_owner'
|
||||
WHERE r.code IN ('ops', 'super_admin');
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DELETE rp
|
||||
FROM role_permissions rp
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE p.code = 'user:quality_owner';
|
||||
|
||||
DELETE FROM permissions WHERE code = 'user:quality_owner';
|
||||
|
||||
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,
|
||||
DROP COLUMN compensation_plan,
|
||||
DROP COLUMN is_premium;
|
||||
|
||||
ALTER TABLE rental_listings
|
||||
DROP KEY idx_rental_listings_premium_status,
|
||||
DROP COLUMN insurance_fee_bps,
|
||||
DROP COLUMN compensation_plan,
|
||||
DROP COLUMN is_premium;
|
||||
|
||||
ALTER TABLE users
|
||||
DROP KEY idx_users_quality_owner_status,
|
||||
DROP COLUMN quality_owner_activated_at,
|
||||
DROP COLUMN quality_owner_deposit_source,
|
||||
DROP COLUMN quality_owner_deposit_cent,
|
||||
DROP COLUMN quality_owner_status;
|
||||
@@ -0,0 +1,126 @@
|
||||
-- +goose Up
|
||||
|
||||
-- 双边积分与虚拟积分商城。
|
||||
ALTER TABLE users
|
||||
ADD COLUMN points_available BIGINT NOT NULL DEFAULT 0 COMMENT '积分商城可用积分' AFTER renter_growth_level;
|
||||
|
||||
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,
|
||||
ADD COLUMN points_multiplier_bps INT NOT NULL DEFAULT 10000 COMMENT '积分倍率基点' AFTER points_per_yuan,
|
||||
ADD COLUMN available_before BIGINT NOT NULL DEFAULT 0 COMMENT '变动前可用积分' AFTER after_points,
|
||||
ADD COLUMN available_after BIGINT NOT NULL DEFAULT 0 COMMENT '变动后可用积分' AFTER available_before,
|
||||
ADD COLUMN redemption_id BIGINT NOT NULL DEFAULT 0 COMMENT '积分商城兑换单 ID' AFTER order_id,
|
||||
ADD COLUMN biz_key VARCHAR(128) NULL COMMENT '幂等业务键' AFTER source,
|
||||
ADD UNIQUE KEY uk_renter_growth_biz_key (biz_key),
|
||||
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);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS points_mall_products (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
title VARCHAR(128) NOT NULL,
|
||||
subtitle VARCHAR(255) NOT NULL DEFAULT '',
|
||||
description TEXT NOT NULL,
|
||||
cover_url VARCHAR(512) NOT NULL DEFAULT '',
|
||||
redemption_instructions TEXT NOT NULL,
|
||||
points_price BIGINT NOT NULL DEFAULT 0,
|
||||
stock BIGINT NOT NULL DEFAULT 0,
|
||||
redeemed_count BIGINT NOT NULL DEFAULT 0,
|
||||
per_user_limit INT NOT NULL DEFAULT 1,
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'offline',
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_points_mall_products_status_sort (status, sort_order, id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分商城虚拟商品';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS points_mall_redemptions (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
redemption_no VARCHAR(32) NOT NULL,
|
||||
user_id BIGINT UNSIGNED NOT NULL,
|
||||
product_id BIGINT UNSIGNED NOT NULL,
|
||||
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,
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'pending',
|
||||
admin_remark VARCHAR(255) NOT NULL DEFAULT '',
|
||||
completed_by BIGINT UNSIGNED NULL,
|
||||
completed_at DATETIME NULL,
|
||||
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_points_mall_redemption_no (redemption_no),
|
||||
KEY idx_points_mall_redemptions_user (user_id, created_at),
|
||||
KEY idx_points_mall_redemptions_status (status, created_at),
|
||||
KEY idx_points_mall_redemptions_product (product_id, user_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分商城兑换记录';
|
||||
|
||||
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);
|
||||
|
||||
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 ('ops', 'super_admin');
|
||||
|
||||
-- +goose Down
|
||||
|
||||
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;
|
||||
|
||||
ALTER TABLE rental_orders
|
||||
DROP COLUMN owner_growth_points_awarded_at,
|
||||
DROP COLUMN owner_growth_points_awarded,
|
||||
DROP COLUMN owner_growth_points_multiplier_bps,
|
||||
DROP COLUMN owner_growth_points_per_yuan,
|
||||
DROP COLUMN owner_growth_points_basis_cent,
|
||||
DROP COLUMN growth_points_multiplier_bps;
|
||||
|
||||
ALTER TABLE renter_growth_ledger
|
||||
DROP KEY idx_renter_growth_user_role_created,
|
||||
DROP KEY uk_renter_growth_order_role_source,
|
||||
DROP KEY uk_renter_growth_biz_key,
|
||||
DROP COLUMN biz_key,
|
||||
DROP COLUMN redemption_id,
|
||||
DROP COLUMN available_after,
|
||||
DROP COLUMN available_before,
|
||||
DROP COLUMN points_multiplier_bps,
|
||||
DROP COLUMN role,
|
||||
ADD UNIQUE KEY uk_renter_growth_order_source (order_id, source);
|
||||
|
||||
ALTER TABLE users
|
||||
DROP COLUMN points_available;
|
||||
@@ -0,0 +1,26 @@
|
||||
-- +goose Up
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN renter_growth_level_override VARCHAR(32) NOT NULL DEFAULT '' COMMENT '后台手动锁定成长等级,空值表示按积分自动计算' AFTER renter_growth_level;
|
||||
|
||||
INSERT INTO permissions (code, name, resource, action) VALUES
|
||||
('user:growth_level', '调整成长等级', 'user', 'growth_level')
|
||||
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, permissions p
|
||||
WHERE r.code IN ('super_admin', 'ops') AND p.code = 'user:growth_level';
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DELETE rp FROM role_permissions rp
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE p.code = 'user:growth_level';
|
||||
|
||||
DELETE FROM permissions WHERE code = 'user:growth_level';
|
||||
|
||||
ALTER TABLE users
|
||||
DROP COLUMN renter_growth_level_override;
|
||||
@@ -0,0 +1,27 @@
|
||||
-- +goose Up
|
||||
|
||||
-- 客服手动录单:区分「收号 / 出号」两组客服。
|
||||
-- entry_group: collect=收号, sell=出号;唯一约束从 entry_no 放宽为 (entry_no, entry_group),
|
||||
-- 同一编号允许收号、出号各登记一次。
|
||||
-- cs_manual_entry_options.group_tag 给操作人选项打组别标记,录单选操作人后自动带出组别。
|
||||
ALTER TABLE cs_manual_entries
|
||||
ADD COLUMN entry_group VARCHAR(16) NOT NULL DEFAULT 'collect' COMMENT '录单组别: collect=收号, sell=出号' AFTER entry_no,
|
||||
DROP KEY uk_cs_manual_entries_entry_no,
|
||||
ADD UNIQUE KEY uk_cs_manual_entries_entry_no_group (entry_no, entry_group),
|
||||
ADD KEY idx_cs_manual_entries_group (entry_group);
|
||||
|
||||
ALTER TABLE cs_manual_entry_options
|
||||
ADD COLUMN group_tag VARCHAR(16) NOT NULL DEFAULT '' COMMENT '操作人组别标记: collect=收号, sell=出号, 空=未分组' AFTER name;
|
||||
|
||||
-- +goose Down
|
||||
|
||||
-- 注意:若升级后同一编号已在收号/出号两组各登记过,Down 恢复 entry_no 唯一键会因重复失败,
|
||||
-- 需先人工清理重复编号后再执行回滚。
|
||||
ALTER TABLE cs_manual_entry_options
|
||||
DROP COLUMN group_tag;
|
||||
|
||||
ALTER TABLE cs_manual_entries
|
||||
DROP KEY idx_cs_manual_entries_group,
|
||||
DROP KEY uk_cs_manual_entries_entry_no_group,
|
||||
ADD UNIQUE KEY uk_cs_manual_entries_entry_no (entry_no),
|
||||
DROP COLUMN entry_group;
|
||||
Reference in New Issue
Block a user