feat(revenue): immediate commission credit with independent withdrawable pool
Aligns affiliate commission with the reference theme: commission is credited to a dedicated COMMISSION asset pool the moment an order is paid, removing the 7-day settlement freeze, the settlement cron, and the settlement_days setting. - Ledger: add AssetType::COMMISSION (isolated from the recharge balance wallet) - CommissionLedger: credit-on-record + opportunistic debt repayment; refunds claw back the full commission from the pool, carrying any shortfall as debt (aksrt_commission_debt) that future commission pays down first - Withdrawal: make asset-aware via a source discriminator (commission vs balance); each pool keeps independent daily limits, pending gate, and reject-refund. Balance withdrawal (recharge + creator income) is unchanged - Fix pay_rebate_self_s: honor self-commission at purchase time - Revenue card: show pool balance + 累计/已提现 (drop 待结算), debt when present - Schema 2.0.0 -> 2.1.0: add commission_debt, drop freeze columns
This commit is contained in:
@@ -435,6 +435,8 @@ trait DBMigratorPart2 {
|
||||
dbDelta($sql_affiliate_relation);
|
||||
|
||||
// ── immutable commission ledger ──
|
||||
// 佣金即时入账(无冻结/结算期):下单支付即 credit 到 COMMISSION 资金池,
|
||||
// 本表仅作佣金明细账 + 退款冲正的溯源记录。status: credited | cancelled。
|
||||
$sql_commission_ledger = "CREATE TABLE {$prefix}aksrt_commission_ledger (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
promoter_id BIGINT UNSIGNED NOT NULL,
|
||||
@@ -445,12 +447,10 @@ trait DBMigratorPart2 {
|
||||
ratio DECIMAL(8,4) NOT NULL DEFAULT 0,
|
||||
original_amount DECIMAL(18,2) NOT NULL DEFAULT 0,
|
||||
adjustment_total DECIMAL(18,2) NOT NULL DEFAULT 0,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'credited',
|
||||
idempotency_key VARCHAR(128) NOT NULL,
|
||||
cancel_operation_key VARCHAR(191) DEFAULT NULL,
|
||||
cancel_payload_hash CHAR(64) DEFAULT NULL,
|
||||
available_at DATETIME NOT NULL,
|
||||
settled_at DATETIME DEFAULT NULL,
|
||||
created_at DATETIME NOT NULL,
|
||||
note TEXT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
@@ -458,11 +458,20 @@ trait DBMigratorPart2 {
|
||||
UNIQUE KEY uniq_commission_cancel_operation (cancel_operation_key),
|
||||
KEY idx_promoter_status (promoter_id, status),
|
||||
KEY idx_order_type (order_number, order_type),
|
||||
KEY idx_available (status, available_at),
|
||||
KEY idx_created (created_at)
|
||||
) ENGINE=InnoDB {$charset_collate};";
|
||||
dbDelta($sql_commission_ledger);
|
||||
|
||||
// 佣金欠款挂账:退款全额收回后,若佣金池不足产生的差额记为欠款,
|
||||
// 后续新增佣金先抵扣欠款再入池。每用户一行。
|
||||
$sql_commission_debt = "CREATE TABLE {$prefix}aksrt_commission_debt (
|
||||
user_id BIGINT UNSIGNED NOT NULL,
|
||||
debt_minor BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
updated_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (user_id)
|
||||
) ENGINE=InnoDB {$charset_collate};";
|
||||
dbDelta($sql_commission_debt);
|
||||
|
||||
// ── immutable commission adjustments (refund/debt/manual) ──
|
||||
$sql_commission_adjustment = "CREATE TABLE {$prefix}aksrt_commission_adjustment (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
||||
Reference in New Issue
Block a user