完善租客等级免押与积分管理

This commit is contained in:
yml2213
2026-07-26 18:07:10 +08:00
parent 379536e5c5
commit c594b543d1
24 changed files with 1296 additions and 178 deletions
@@ -0,0 +1,54 @@
-- +goose Up
ALTER TABLE rental_orders
ADD COLUMN deposit_free_level_quota_cent BIGINT NOT NULL DEFAULT 0 COMMENT '下单时等级免押额度快照(分)' AFTER deposit_waived_amount_cent,
ADD COLUMN deposit_free_manual_quota_cent BIGINT NOT NULL DEFAULT 0 COMMENT '下单时人工免押额度快照(分)' AFTER deposit_free_level_quota_cent,
ADD COLUMN deposit_free_used_before_cent BIGINT NOT NULL DEFAULT 0 COMMENT '下单前进行中订单已占用免押额度(分)' AFTER deposit_free_manual_quota_cent;
ALTER TABLE renter_growth_ledger
DROP KEY uk_renter_growth_order_source,
MODIFY COLUMN order_id BIGINT UNSIGNED NULL COMMENT '租号订单ID,人工调整时为空',
ADD COLUMN operator_admin_id BIGINT UNSIGNED NULL COMMENT '人工调整管理员ID' AFTER source,
ADD UNIQUE KEY uk_renter_growth_order_source (order_id, source),
ADD KEY idx_renter_growth_ledger_operator (operator_admin_id);
INSERT INTO permissions (code, name, resource, action) VALUES
('user:growth_points', '调整成长积分', 'user', 'growth_points')
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_points';
UPDATE system_configs
SET description = '租客成长等级规则(积分门槛、租金折扣、等级免押额度)'
WHERE `key` = 'renter.growth_level_rules';
-- +goose Down
DELETE rp FROM role_permissions rp
JOIN permissions p ON p.id = rp.permission_id
WHERE p.code = 'user:growth_points';
DELETE FROM permissions WHERE code = 'user:growth_points';
ALTER TABLE renter_growth_ledger
DROP KEY idx_renter_growth_ledger_operator,
DROP KEY uk_renter_growth_order_source,
DROP COLUMN operator_admin_id;
DELETE FROM renter_growth_ledger WHERE source = 'admin_adjustment';
UPDATE renter_growth_ledger SET order_id = 0 WHERE order_id IS NULL;
ALTER TABLE renter_growth_ledger
MODIFY COLUMN order_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '租号订单ID',
ADD UNIQUE KEY uk_renter_growth_order_source (order_id, source);
ALTER TABLE rental_orders
DROP COLUMN deposit_free_used_before_cent,
DROP COLUMN deposit_free_manual_quota_cent,
DROP COLUMN deposit_free_level_quota_cent;