feat(user-center): points buy, balance withdraw, and asset record tabs
Add cash purchase of points (points_pay_s), wallet withdraw requests via AKSRT_Withdrawal, Zibll-style dual-card layout with tabbed balance/points ledgers, and admin switches for buy-points packages and balance withdraw.
This commit is contained in:
1 parent
0529ab5fb9
commit
d57fc6f934
10 files changed
+780
-16
No files matched your search
@@ -775,6 +775,152 @@
|
||||
});
|
||||
}
|
||||
|
||||
function initPointsBuy() {
|
||||
var modal = document.querySelector('[data-aksrt-points-buy-modal]');
|
||||
if (!modal) return;
|
||||
var form = modal.querySelector('[data-aksrt-points-buy-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-points-buy-tip]');
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-points-buy-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
modal.querySelectorAll('[data-aksrt-points-buy-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
});
|
||||
modal.querySelectorAll('.uc-charge-package input').forEach(function (inp) {
|
||||
inp.addEventListener('change', function () {
|
||||
modal.querySelectorAll('.uc-charge-package').forEach(function (el) {
|
||||
el.classList.toggle('is-active', el.contains(inp) && inp.checked);
|
||||
});
|
||||
});
|
||||
});
|
||||
if (!form) return;
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var pkgInput = form.querySelector('input[name="points_package"]:checked') || form.querySelector('input[name="points_package"]');
|
||||
var pkg = pkgInput ? pkgInput.value : 'custom';
|
||||
var customEl = form.querySelector('[data-aksrt-points-buy-custom]');
|
||||
var custom = customEl ? parseInt(customEl.value || '0', 10) : 0;
|
||||
if (custom > 0) pkg = 'custom';
|
||||
if (pkg === 'custom' && !(custom > 0)) {
|
||||
setTip('请输入购买积分数量', true);
|
||||
return;
|
||||
}
|
||||
var methodEl = form.querySelector('input[name="points_pay_method"]:checked');
|
||||
var method = methodEl ? methodEl.value : 'alipay';
|
||||
busy = true;
|
||||
setTip('正在创建订单…');
|
||||
api('/pay/points/buy', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
package: pkg,
|
||||
custom_points: custom,
|
||||
payment_method: method
|
||||
})
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '购买失败', true);
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
if (data && data.redirect && (data.payment_url || data.qr_content)) {
|
||||
if (data.payment_url) window.open(data.payment_url, '_blank');
|
||||
setTip(data.message || '请完成支付,支付成功后将自动刷新。');
|
||||
if (data.order_number) pollPaidOrder(data.order_number);
|
||||
return;
|
||||
}
|
||||
setTip((data && data.message) || '购买成功,正在刷新…');
|
||||
window.location.reload();
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initWithdraw() {
|
||||
var modal = document.querySelector('[data-aksrt-withdraw-modal]');
|
||||
if (!modal) return;
|
||||
var form = modal.querySelector('[data-aksrt-withdraw-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-withdraw-tip]');
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-withdraw-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
modal.querySelectorAll('[data-aksrt-withdraw-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
});
|
||||
if (!form) return;
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var amountEl = form.querySelector('[data-aksrt-withdraw-amount]');
|
||||
var methodEl = form.querySelector('[data-aksrt-withdraw-method]');
|
||||
var accountEl = form.querySelector('[data-aksrt-withdraw-account]');
|
||||
var amount = amountEl ? parseFloat(amountEl.value || '0') : 0;
|
||||
var method = methodEl ? methodEl.value : 'alipay';
|
||||
var account = accountEl ? String(accountEl.value || '').trim() : '';
|
||||
if (!(amount > 0)) {
|
||||
setTip('请输入提现金额', true);
|
||||
return;
|
||||
}
|
||||
if (!account) {
|
||||
setTip('请填写收款账号信息', true);
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在提交…');
|
||||
api('/pay/balance/withdraw', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ amount: amount, method: method, account_info: account })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '提现失败', true);
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
setTip((data && data.message) || '申请已提交,正在刷新…');
|
||||
window.location.reload();
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initAssetTabs() {
|
||||
var nav = document.querySelectorAll('[data-aksrt-asset-tab]');
|
||||
if (!nav.length) return;
|
||||
nav.forEach(function (link) {
|
||||
link.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
var key = link.getAttribute('data-aksrt-asset-tab');
|
||||
document.querySelectorAll('[data-aksrt-asset-tab]').forEach(function (a) {
|
||||
var li = a.closest('li');
|
||||
if (li) li.classList.toggle('active', a === link);
|
||||
});
|
||||
document.querySelectorAll('[data-aksrt-asset-pane]').forEach(function (pane) {
|
||||
var on = pane.getAttribute('data-aksrt-asset-pane') === key;
|
||||
pane.classList.toggle('is-active', on);
|
||||
pane.hidden = !on;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bootAssets() {
|
||||
initSignin();
|
||||
initInvite();
|
||||
@@ -784,6 +930,9 @@
|
||||
initBalanceCharge();
|
||||
initTransfer();
|
||||
initExchange();
|
||||
initPointsBuy();
|
||||
initWithdraw();
|
||||
initAssetTabs();
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
|
||||
Reference in new issue
Block a user