修复佣金回扣问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m25s

This commit is contained in:
2026-08-14 09:08:43 +08:00
parent b5285877bf
commit 586a1cccd5
8 changed files with 181 additions and 8 deletions

View File

@@ -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-提现';

View 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-提现';

View File

@@ -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'));

View File

@@ -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'));

View File

@@ -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)
);

View File

@@ -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))
);