修复佣金回扣问题
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,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)
);