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:
kate522 committed 2026-09-28 21:27:44 +08:00
1 parent cded20ae02
commit 61667aa03c
22 files changed
+569 -268

No files matched your search

+7
View File
@@ -37,6 +37,13 @@ final class AssetAmount {
return self::balance($decimal)->minor();
}
/**
* 佣金池与余额同为两位小数、同一 minor 口径,仅资产标签不同。
*/
public static function commission(string $decimal): self {
return new self(AssetType::COMMISSION, self::balance($decimal)->minor());
}
public static function decimal_from_minor(int $minor): string {
return self::from_minor(AssetType::BALANCE, $minor)->decimal();
}
+6
View File
@@ -10,8 +10,14 @@ defined('ABSPATH') || exit;
enum AssetType: string {
case POINTS = 'points';
case BALANCE = 'balance';
case COMMISSION = 'commission';
public static function from_value(self|string $asset): self {
return $asset instanceof self ? $asset : self::from($asset);
}
/** 是否为两位小数的货币型资产(非积分)。 */
public function is_currency(): bool {
return $this !== self::POINTS;
}
}
+8
View File
@@ -21,6 +21,14 @@ final class OperationKey {
return $key;
}
/**
* 生成一次性唯一 operation_key。用于自身已带并发守卫、且每次执行金额可能不同、
* 因而不能被幂等重放的账务操作(如机会性偿债、退款分次收回)。
*/
public static function unique(string $scope): string {
return self::deterministic($scope, [wp_generate_uuid4()]);
}
/** @return string|\WP_Error */
public static function from_request(\WP_REST_Request $request, string $scope, int $actor_user_id) {
$request_id = trim((string) $request->get_header('Idempotency-Key'));