From d86125b1303ff5d9b1a4822a7c4ce3bac92af34a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Aug 2026 14:33:24 +0800 Subject: [PATCH] fix(user-center): reuse balance withdrawal modal Co-Authored-By: Claude Fable 5 --- assets/js/credits.js | 9 +- assets/js/revenue-invite.js | 92 +------------------ .../user-center-renderers/credits-wallet.php | 33 ++----- .../user-center-renderers/profile-revenue.php | 26 ++---- .../user-center-renderers/withdraw-modal.php | 39 ++++++++ src/Core/ScriptsPart1b.php | 7 +- 6 files changed, 65 insertions(+), 141 deletions(-) create mode 100644 inc/helpers/user-center-renderers/withdraw-modal.php diff --git a/assets/js/credits.js b/assets/js/credits.js index 4eb8c216..1c0692f4 100644 --- a/assets/js/credits.js +++ b/assets/js/credits.js @@ -905,9 +905,10 @@ }); } - function initWithdraw() { - var modal = document.querySelector('[data-aksrt-withdraw-modal]'); - if (!modal) return; + function initWithdraw() { + var modal = document.querySelector('[data-aksrt-withdraw-modal]'); + if (!modal || modal.dataset.aksrtWithdrawInitialized === '1') return; + modal.dataset.aksrtWithdrawInitialized = '1'; var form = modal.querySelector('[data-aksrt-withdraw-form]'); var tip = modal.querySelector('[data-aksrt-withdraw-tip]'); var busy = false; @@ -1002,6 +1003,8 @@ }); } + window.AKSRTWithdrawInit = initWithdraw; + function bootAssets() { initSignin(); initSigninGoto(); diff --git a/assets/js/revenue-invite.js b/assets/js/revenue-invite.js index af53bfcb..daf851ce 100644 --- a/assets/js/revenue-invite.js +++ b/assets/js/revenue-invite.js @@ -163,97 +163,6 @@ }); }); } - - var withdrawModal = root.querySelector('[data-aksrt-commission-withdraw-modal]') || document.querySelector('[data-aksrt-commission-withdraw-modal]'); - var withdrawForm = withdrawModal && withdrawModal.querySelector('[data-aksrt-commission-withdraw-form]'); - var withdrawTip = withdrawModal && withdrawModal.querySelector('[data-aksrt-commission-withdraw-tip]'); - var withdrawSubmit = withdrawModal && withdrawModal.querySelector('[data-aksrt-commission-withdraw-submit]'); - var lastWithdrawTrigger = null; - var withdrawBusy = false; - function setWithdrawTip(text, error) { - if (!withdrawTip) return; - withdrawTip.textContent = text || ''; - withdrawTip.classList.toggle('is-error', !!error); - } - function setWithdrawBusy(isBusy) { - withdrawBusy = isBusy; - if (withdrawSubmit) withdrawSubmit.disabled = isBusy; - } - function getWithdrawFocusable() { - return Array.prototype.slice.call(withdrawModal.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')); - } - function closeWithdrawModal() { - if (!withdrawModal || withdrawModal.hidden) return; - withdrawModal.hidden = true; - document.body.classList.remove('uc-modal-open'); - if (lastWithdrawTrigger && typeof lastWithdrawTrigger.focus === 'function') { - lastWithdrawTrigger.focus(); - } - } - if (withdrawModal && withdrawForm) { - document.querySelectorAll('[data-aksrt-commission-withdraw-open]').forEach(function (button) { - button.addEventListener('click', function () { - lastWithdrawTrigger = button; - withdrawModal.hidden = false; - document.body.classList.add('uc-modal-open'); - window.requestAnimationFrame(function () { - var amountInput = withdrawForm.querySelector('[data-aksrt-commission-withdraw-amount]'); - if (amountInput) amountInput.focus(); - }); - }); - }); - withdrawModal.querySelectorAll('[data-aksrt-commission-withdraw-close]').forEach(function (button) { - button.addEventListener('click', closeWithdrawModal); - }); - document.addEventListener('keydown', function (event) { - if (withdrawModal.hidden) return; - if (event.key === 'Escape') { - event.preventDefault(); - closeWithdrawModal(); - return; - } - if (event.key !== 'Tab') return; - var focusable = getWithdrawFocusable(); - if (!focusable.length) return; - var first = focusable[0]; - var last = focusable[focusable.length - 1]; - if (event.shiftKey && document.activeElement === first) { - event.preventDefault(); - last.focus(); - } else if (!event.shiftKey && document.activeElement === last) { - event.preventDefault(); - first.focus(); - } - }); - withdrawForm.addEventListener('submit', function (event) { - event.preventDefault(); - if (withdrawBusy) return; - var values = new FormData(withdrawForm); - var amount = Number(values.get('amount') || 0); - var minimum = Number(root.getAttribute('data-min-amount') || 50); - var account = String(values.get('account_info') || '').trim(); - if (amount < minimum) { setWithdrawTip('提现金额未达到最低额度', true); return; } - if (!account) { setWithdrawTip('请填写收款账户信息', true); return; } - setWithdrawTip('正在提交...', false); - setWithdrawBusy(true); - fetch(rest + '/pay/balance/withdraw', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': data.restNonce || data.nonce || '' }, body: JSON.stringify({ amount: amount, method: values.get('method') || 'alipay', account_info: account }) }).then(function (response) { - return response.json().catch(function () { return {}; }).then(function (json) { return { ok: response.ok, json: json }; }); - }).then(function (result) { - if (!result.ok || !result.json || !result.json.success) { setWithdrawBusy(false); setWithdrawTip((result.json && result.json.message) || '提现申请失败', true); return; } - setWithdrawTip('提现申请已提交', false); - if (result.json.data && typeof result.json.data.wallet_balance !== 'undefined') { - var balanceEl = root.querySelector('[data-aksrt-revenue-balance]'); - if (balanceEl) balanceEl.textContent = Number(result.json.data.wallet_balance).toFixed(2); - } - withdrawForm.reset(); - setWithdrawBusy(false); - closeWithdrawModal(); - reloadRevenuePanel().catch(function () { - if (typeof showToast === 'function') showToast('提现已提交,但收益数据刷新失败'); - }); - }).catch(function () { setWithdrawBusy(false); setWithdrawTip('网络错误,请稍后重试', true); }); - }); - } } function initRewardNavigation(root, rest, data) { @@ -278,6 +187,7 @@ current.replaceWith(next); window.history.pushState({}, '', targetUrl); window.AKSRTRevenueCenterInit(next); + if (typeof window.AKSRTWithdrawInit === 'function') window.AKSRTWithdrawInit(); }); }).catch(function () { if (typeof showToast === 'function') showToast('加载失败,请重试'); diff --git a/inc/helpers/user-center-renderers/credits-wallet.php b/inc/helpers/user-center-renderers/credits-wallet.php index e43d15da..59590781 100644 --- a/inc/helpers/user-center-renderers/credits-wallet.php +++ b/inc/helpers/user-center-renderers/credits-wallet.php @@ -237,37 +237,18 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元'); - - - + __('待处理', 'aksrt'), - 'approved' => __('已通过', 'aksrt'), - 'processing' => __('处理中', 'aksrt'), + 'processing' => __('处理中', 'aksrt'), 'completed' => __('已完成', 'aksrt'), 'rejected' => __('已拒绝', 'aksrt'), ]; diff --git a/inc/helpers/user-center-renderers/profile-revenue.php b/inc/helpers/user-center-renderers/profile-revenue.php index 07dc5004..2c502e01 100644 --- a/inc/helpers/user-center-renderers/profile-revenue.php +++ b/inc/helpers/user-center-renderers/profile-revenue.php @@ -30,6 +30,9 @@ if ($withdraw_on && class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Sett $withdraw_on = false; } $withdraw_min = max(1, (float) ($all_settings['pay_balance_withdraw_lowest_money'] ?? $all_settings['pay_rebate_withdraw_lowest_money'] ?? $withdrawal['min_amount'] ?? 50)); +$wallet_fmt = class_exists('\AKSRT\Credits\Balance') + ? \AKSRT\Credits\Balance::format((float) \AKSRT\Credits\Balance::balance($user_id)) + : '0.00'; $commission_stats = class_exists('\AKSRT\Payment\Rebate') ? \AKSRT\Payment\Rebate::get_instance()->get_stats($user_id) @@ -110,7 +113,7 @@ $status_labels = [ - + @@ -175,21 +178,6 @@ $status_labels = [ - - - - + diff --git a/inc/helpers/user-center-renderers/withdraw-modal.php b/inc/helpers/user-center-renderers/withdraw-modal.php new file mode 100644 index 00000000..5dc442e5 --- /dev/null +++ b/inc/helpers/user-center-renderers/withdraw-modal.php @@ -0,0 +1,39 @@ + + diff --git a/src/Core/ScriptsPart1b.php b/src/Core/ScriptsPart1b.php index 508c02b1..03608fe2 100644 --- a/src/Core/ScriptsPart1b.php +++ b/src/Core/ScriptsPart1b.php @@ -215,6 +215,9 @@ $hmb_js = get_template_directory() . '/assets/js/header-newadd.js'; $credits_on = is_user_logged_in() && class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::credits_enabled(); + $balance_on = is_user_logged_in() + && class_exists('\AKSRT\Credits\Balance') + && \AKSRT\Credits\Balance::enabled(); $vip_coordinator = get_template_directory() . '/assets/js/vip-purchase-coordinator.js'; if (($vip_on || $credits_on) && file_exists($vip_coordinator)) { wp_enqueue_script( @@ -890,10 +893,10 @@ $hmb_js = get_template_directory() . '/assets/js/header-newadd.js'; } // 积分相关:已登录 + 启用积分功能时全站加载 - if ($credits_on) { + if ($credits_on || $balance_on) { $enqueue_module('credits'); - // profile 页:加载 credits.js(签到 + 邀请交互) + // profile 页:加载 credits.js(签到 + 邀请 + 提现交互) if ($is_profile_page) { $credits_js_path = get_template_directory() . '/assets/js/credits.js'; wp_enqueue_script(