Files
wordpress-theme-aksrt/inc/helpers/user-center-renderers/withdraw-modal.php
T
kate522 dcd306b428 feat(withdrawal): make payout channels a configurable sortable list
The payout channel was a two-item checkbox (alipay / wechat). Sites that pay
out through a bank transfer, USDT or any other route had no way to express it,
and every surface behind it — the withdrawal modal, the server-side check, the
admin review list — hard-coded those two names.

affiliate_payout_channels is now a repeater on both the PHP and Vue schemas,
using the same draggable component as the post filters and gateway config. Each
row carries a stable key, a display label, an account placeholder, an optional
note and an enabled flag. Disabled channels disappear from the front end but
stay resolvable, so historical withdrawal records still render their original
name.

PaymentRuntime::payout_channels() normalises the stored structure: it drops rows
with an empty key or label, de-duplicates keys, and falls back to the built-in
two channels when nothing is configured. enabled_payout_channels() feeds the
front end and payout_channel() resolves a single key for record display.
CommissionLedger's validation now compares against the configured, enabled keys
instead of a literal allowlist.

The withdrawal modal renders the configured list and swaps the account
placeholder and note when the channel changes; credits.js drives that. The
admin review page reads the same settings for its method labels and filter, and
the review dialog gained a "渠道说明" row so the operator sees the payout
instruction, hidden when empty.

Default channels live in SchemaPayment as plain data — the runtime imports them
rather than the reverse, because the schema layer must not depend on a runtime
settings class (doing it the other way made the schema harness fatal).

Verification: drove payout_channels() through default / custom / dirty / duplicate
inputs and confirmed enabled filtering, note lookup and disabled-channel
resolution. Added payment-withdrawal-channels-contract.test.cjs covering the
schema shape, runtime helpers, front-end wiring and admin read path. 873 tests
pass, PSR-4 audit clean, admin SPA builds.
2026-11-04 19:16:39 +08:00

48 lines
3.5 KiB
PHP

<?php
/** Shared balance withdrawal modal. @package Jio */
defined('ABSPATH') || exit;
if (!empty($GLOBALS['jio_withdraw_modal_rendered'])) {
return;
}
$GLOBALS['jio_withdraw_modal_rendered'] = true;
try {
$withdraw_min = \Jio\Ledger\AssetAmount::balance(is_string($withdraw_min ?? null) ? $withdraw_min : '')->decimal();
} catch (\InvalidArgumentException $e) {
$withdraw_min = '0.00';
}
$withdraw_usage = is_array($withdraw_usage ?? null) ? $withdraw_usage : ['remaining_count' => 0, 'remaining_amount' => '0.00'];
$withdraw_fee_rate = (int) ($withdraw_settings['service_charge_rate'] ?? 5);
// 渠道由后台「提现策略 → 收款渠道」的拖拽结构定义,可自定义名称与提示。
$withdraw_channels = array_values(array_filter(
(array) ($withdraw_settings['payout_channels'] ?? []),
static fn ($channel): bool => is_array($channel) && !empty($channel['enabled']) && (string) ($channel['key'] ?? '') !== ''
));
?>
<div class="uc-modal" id="jio-withdraw-modal" hidden data-jio-withdraw-modal>
<div class="uc-modal__overlay" data-jio-withdraw-close></div>
<div class="uc-modal__dialog" role="dialog" aria-modal="true">
<button type="button" class="uc-modal__close" data-jio-withdraw-close aria-label="<?php esc_attr_e('关闭', 'jio'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
<h3 class="uc-modal__title"><?php esc_html_e('余额提现', 'jio'); ?></h3>
<form data-jio-withdraw-form>
<label class="muted-color em09"><?php esc_html_e('提现金额', 'jio'); ?></label>
<input type="number" class="uc-card-pass__input" name="amount" min="<?php echo esc_attr($withdraw_min); ?>" max="<?php echo esc_attr((string) ($withdraw_usage['remaining_amount'] ?? '0.00')); ?>" step="0.01" inputmode="decimal" data-jio-withdraw-amount data-withdraw-min="<?php echo esc_attr($withdraw_min); ?>" data-withdraw-remaining-amount="<?php echo esc_attr((string) ($withdraw_usage['remaining_amount'] ?? '0.00')); ?>" data-withdraw-remaining-count="<?php echo esc_attr((string) ($withdraw_usage['remaining_count'] ?? 0)); ?>">
<p class="muted-2-color em09 mt6"><?php printf(esc_html__('最低提现%s 元,今日可提现%d次,提现手续费率%d%%', 'jio'), esc_html($withdraw_min), (int) ($withdraw_usage['remaining_count'] ?? 0), $withdraw_fee_rate); ?></p>
<label class="muted-color em09 mt10"><?php esc_html_e('收款方式', 'jio'); ?></label>
<select class="uc-card-pass__input" name="method" data-jio-withdraw-method>
<?php foreach ($withdraw_channels as $channel) : ?>
<option
value="<?php echo esc_attr((string) $channel['key']); ?>"
data-hint="<?php echo esc_attr((string) ($channel['account_hint'] ?? '')); ?>"
data-note="<?php echo esc_attr((string) ($channel['note'] ?? '')); ?>"
><?php echo esc_html((string) ($channel['label'] ?? $channel['key'])); ?></option>
<?php endforeach; ?>
</select>
<label class="muted-color em09 mt10"><?php esc_html_e('收款账户信息', 'jio'); ?></label>
<textarea class="uc-card-pass__input" name="account" rows="3" data-jio-withdraw-account placeholder="<?php echo esc_attr((string) ($withdraw_channels[0]['account_hint'] ?? __('姓名 + 账户 / 卡号', 'jio'))); ?>"></textarea>
<p class="muted-2-color em09 mt6" data-jio-withdraw-note<?php echo empty($withdraw_channels[0]['note']) ? ' hidden' : ''; ?>><?php echo esc_html((string) ($withdraw_channels[0]['note'] ?? '')); ?></p>
<button type="submit" class="but jb-blue btn-block" data-jio-withdraw-submit><?php esc_html_e('提交申请', 'jio'); ?></button>
</form>
</div>
</div>