Files
junhong_cmp_fiber/migrations/000209_allow_commission_wallet_negative_balance.up.sql
break 586a1cccd5
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m25s
修复佣金回扣问题
2026-08-14 09:08:43 +08:00

15 lines
744 B
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.
-- 允许佣金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))
);