This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
-- 回滚到旧的交易类型白名单(不含 commission_deduct 与 adjustment)。
|
||||
-- 注意:若已存在 commission_deduct 或 adjustment 流水,回滚会因违反检查约束而失败,属预期保护。
|
||||
ALTER TABLE tb_agent_wallet_transaction
|
||||
DROP CONSTRAINT chk_agent_tx_type;
|
||||
|
||||
ALTER TABLE tb_agent_wallet_transaction
|
||||
ADD CONSTRAINT chk_agent_tx_type
|
||||
CHECK (transaction_type IN ('recharge', 'deduct', 'refund', 'commission', 'withdrawal'));
|
||||
|
||||
COMMENT ON COLUMN tb_agent_wallet_transaction.transaction_type IS '交易类型:recharge-充值 adjustment-人工调整 deduct-扣款 refund-退款 commission-分佣 withdrawal-提现';
|
||||
20
migrations/000207_fix_agent_wallet_tx_type_constraint.up.sql
Normal file
20
migrations/000207_fix_agent_wallet_tx_type_constraint.up.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- 修复代理钱包交易类型检查约束缺少 commission_deduct 与 adjustment 的问题。
|
||||
-- 代码常量与列注释早已包含这两种类型,但 chk_agent_tx_type 从未同步,
|
||||
-- 导致写入退款佣金回扣(commission_deduct)和人工余额调整(adjustment)流水时
|
||||
-- 违反检查约束,退款佣金回扣因此持续失败、无法收回佣金。
|
||||
ALTER TABLE tb_agent_wallet_transaction
|
||||
DROP CONSTRAINT chk_agent_tx_type;
|
||||
|
||||
ALTER TABLE tb_agent_wallet_transaction
|
||||
ADD CONSTRAINT chk_agent_tx_type
|
||||
CHECK (transaction_type IN (
|
||||
'recharge',
|
||||
'deduct',
|
||||
'refund',
|
||||
'commission',
|
||||
'withdrawal',
|
||||
'commission_deduct',
|
||||
'adjustment'
|
||||
));
|
||||
|
||||
COMMENT ON COLUMN tb_agent_wallet_transaction.transaction_type IS '交易类型:recharge-充值 adjustment-人工调整 deduct-扣款 refund-退款 commission-分佣 commission_deduct-退款佣金回扣 withdrawal-提现';
|
||||
@@ -0,0 +1,8 @@
|
||||
-- 回滚到旧的交易类型白名单(不含 exchange)。
|
||||
-- 注意:若已存在 exchange 流水,回滚会因违反检查约束而失败,属预期保护。
|
||||
ALTER TABLE tb_asset_wallet_transaction
|
||||
DROP CONSTRAINT chk_card_tx_type;
|
||||
|
||||
ALTER TABLE tb_asset_wallet_transaction
|
||||
ADD CONSTRAINT chk_card_tx_type
|
||||
CHECK (transaction_type IN ('recharge', 'deduct', 'refund'));
|
||||
@@ -0,0 +1,9 @@
|
||||
-- 修复资产钱包交易类型检查约束缺少 exchange 的问题。
|
||||
-- 代码常量 AssetTransactionTypeExchange 已用于换货余额迁移,
|
||||
-- 但 chk_card_tx_type 从未同步,导致写入 exchange 流水时违反检查约束。
|
||||
ALTER TABLE tb_asset_wallet_transaction
|
||||
DROP CONSTRAINT chk_card_tx_type;
|
||||
|
||||
ALTER TABLE tb_asset_wallet_transaction
|
||||
ADD CONSTRAINT chk_card_tx_type
|
||||
CHECK (transaction_type IN ('recharge', 'deduct', 'refund', 'exchange'));
|
||||
@@ -0,0 +1,13 @@
|
||||
-- 回滚:恢复佣金(commission)钱包不允许负余额的旧约束。
|
||||
-- 注意:若已存在负余额佣金数据,回滚会因违反检查约束而失败,属预期保护。
|
||||
ALTER TABLE tb_agent_wallet
|
||||
DROP CONSTRAINT chk_agent_wallet_available_balance;
|
||||
|
||||
ALTER TABLE tb_agent_wallet
|
||||
ADD CONSTRAINT chk_agent_wallet_available_balance
|
||||
CHECK (
|
||||
(wallet_type = 'main' AND (balance::numeric - frozen_balance::numeric +
|
||||
CASE WHEN credit_enabled THEN credit_limit::numeric ELSE 0::numeric END) >= 0::numeric)
|
||||
OR
|
||||
(wallet_type = 'commission' AND balance >= 0 AND frozen_balance <= balance)
|
||||
);
|
||||
@@ -0,0 +1,14 @@
|
||||
-- 允许佣金(commission)钱包出现负余额:退款佣金回扣优先于提现,
|
||||
-- 回扣后店铺佣金可能倒欠平台,负余额由回扣流程显式允许。
|
||||
-- 提现冻结仍受 frozen_balance <= GREATEST(balance, 0) 约束:负余额时不允许冻结新提现。
|
||||
ALTER TABLE tb_agent_wallet
|
||||
DROP CONSTRAINT chk_agent_wallet_available_balance;
|
||||
|
||||
ALTER TABLE tb_agent_wallet
|
||||
ADD CONSTRAINT chk_agent_wallet_available_balance
|
||||
CHECK (
|
||||
(wallet_type = 'main' AND (balance::numeric - frozen_balance::numeric +
|
||||
CASE WHEN credit_enabled THEN credit_limit::numeric ELSE 0::numeric END) >= 0::numeric)
|
||||
OR
|
||||
(wallet_type = 'commission' AND frozen_balance <= GREATEST(balance, 0))
|
||||
);
|
||||
Reference in New Issue
Block a user