Files
junhong_cmp_fiber/migrations/000043_simplify_commission_allocation.down.sql
huang b18ecfeb55
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m29s
refactor: 一次性佣金配置从套餐级别提升到系列级别
主要变更:
- 新增 tb_shop_series_allocation 表,存储系列级别的一次性佣金配置
- ShopPackageAllocation 移除 one_time_commission_amount 字段
- PackageSeries 新增 enable_one_time_commission 字段控制是否启用一次性佣金
- 新增 /api/admin/shop-series-allocations CRUD 接口
- 佣金计算逻辑改为从 ShopSeriesAllocation 获取一次性佣金金额
- 删除废弃的 ShopSeriesOneTimeCommissionTier 模型
- OpenAPI Tag '系列分配' 和 '单套餐分配' 合并为 '套餐分配'

迁移脚本:
- 000042: 重构佣金套餐模型
- 000043: 简化佣金分配
- 000044: 一次性佣金分配重构
- 000045: PackageSeries 添加 enable_one_time_commission 字段

测试:
- 新增验收测试 (shop_series_allocation, commission_calculation)
- 新增流程测试 (one_time_commission_chain)
- 删除过时的单元测试(已被验收测试覆盖)
2026-02-04 14:28:44 +08:00

69 lines
2.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 回滚:恢复 ShopSeriesAllocation 层
-- ============================================
-- 1. 重建 ShopSeriesAllocation 表
-- ============================================
CREATE TABLE IF NOT EXISTS tb_shop_series_allocation (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
creator BIGINT NOT NULL DEFAULT 0,
updater BIGINT NOT NULL DEFAULT 0,
shop_id BIGINT NOT NULL,
series_id BIGINT NOT NULL,
allocator_shop_id BIGINT NOT NULL DEFAULT 0,
cost_price_markup BIGINT NOT NULL DEFAULT 0,
one_time_commission_amount BIGINT NOT NULL DEFAULT 0,
status INTEGER NOT NULL DEFAULT 1
);
COMMENT ON TABLE tb_shop_series_allocation IS '店铺系列分配表';
COMMENT ON COLUMN tb_shop_series_allocation.shop_id IS '被分配店铺ID';
COMMENT ON COLUMN tb_shop_series_allocation.series_id IS '套餐系列ID';
COMMENT ON COLUMN tb_shop_series_allocation.allocator_shop_id IS '分配者店铺ID0表示平台分配';
COMMENT ON COLUMN tb_shop_series_allocation.cost_price_markup IS '成本价加价(分)';
COMMENT ON COLUMN tb_shop_series_allocation.one_time_commission_amount IS '一次性佣金金额(分)';
CREATE INDEX IF NOT EXISTS idx_shop_series_allocation_shop_id ON tb_shop_series_allocation(shop_id);
CREATE INDEX IF NOT EXISTS idx_shop_series_allocation_series_id ON tb_shop_series_allocation(series_id);
-- ============================================
-- 2. 重建 ShopSeriesAllocationConfig 表
-- ============================================
CREATE TABLE IF NOT EXISTS tb_shop_series_allocation_config (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
creator BIGINT NOT NULL DEFAULT 0,
updater BIGINT NOT NULL DEFAULT 0,
allocation_id BIGINT NOT NULL,
config_type VARCHAR(50) NOT NULL,
config_value JSONB
);
COMMENT ON TABLE tb_shop_series_allocation_config IS '店铺系列分配配置表';
-- ============================================
-- 3. 恢复 allocation_id 字段
-- ============================================
ALTER TABLE tb_shop_package_allocation
ADD COLUMN IF NOT EXISTS allocation_id BIGINT NOT NULL DEFAULT 0;
-- ============================================
-- 4. 删除新增的字段
-- ============================================
DROP INDEX IF EXISTS idx_shop_package_allocation_series_id;
DROP INDEX IF EXISTS idx_shop_package_allocation_allocator_shop_id;
ALTER TABLE tb_shop_package_allocation
DROP COLUMN IF EXISTS series_id;
ALTER TABLE tb_shop_package_allocation
DROP COLUMN IF EXISTS allocator_shop_id;