861 lines
31 KiB
JavaScript
861 lines
31 KiB
JavaScript
/**
|
|
* AKSRT Credits Frontend
|
|
*
|
|
* 功能:
|
|
* - 签到 panel:拉取 /signin/today,按钮触发 POST /signin
|
|
* - revenue panel:拉取 /revenue/me,复制推广链接
|
|
*
|
|
* 仅在 page-profile 页面 + 启用积分时加载。
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var aksrt = window.aksrtData;
|
|
if (!aksrt) {
|
|
return;
|
|
}
|
|
var activePoll = null;
|
|
|
|
function api(path, options) {
|
|
return window.AksrtRequest.request(path, options || {}).then(function (response) {
|
|
return {
|
|
ok: response.ok,
|
|
status: response.status,
|
|
json: response.json || {},
|
|
data: response.data,
|
|
};
|
|
}).catch(function (error) {
|
|
var response = error && error.response ? error.response : {};
|
|
return {
|
|
ok: false,
|
|
status: error && error.status ? error.status : (response.status || 0),
|
|
json: error && error.json ? error.json : (response.json || { message: error && error.message }),
|
|
};
|
|
});
|
|
}
|
|
|
|
// ===== 签到 =====
|
|
function initSignin() {
|
|
var root = document.querySelector('[data-aksrt-signin]');
|
|
if (!root) return;
|
|
var status = root.querySelector('[data-signin-status]');
|
|
var btn = root.querySelector('[data-signin-btn]');
|
|
var tip = root.querySelector('[data-signin-tip]');
|
|
if (!btn) return;
|
|
|
|
function setStatus(text) { if (status) status.textContent = text; }
|
|
function setStatusHtml(html) { if (status) status.innerHTML = html; }
|
|
function setTip(text) { if (tip) tip.textContent = text; }
|
|
|
|
function refresh() {
|
|
api('/signin/today').then(function (r) {
|
|
if (!r.ok) {
|
|
setStatus((r.json && r.json.message) || '加载失败 (HTTP ' + r.status + ')');
|
|
return;
|
|
}
|
|
var j = r.json;
|
|
if (!j.enabled) {
|
|
setStatus('签到功能未启用');
|
|
btn.disabled = true;
|
|
setTip('');
|
|
return;
|
|
}
|
|
if (j.signed) {
|
|
setStatusHtml('已签到 <strong>' + j.streak + '</strong> 天 +' + j.reward_today);
|
|
btn.disabled = true;
|
|
btn.innerHTML = '已签到';
|
|
setTip('');
|
|
} else {
|
|
setStatusHtml('连续 <strong>' + j.streak + '</strong> 天,+' + j.reward_if_signin);
|
|
btn.disabled = false;
|
|
setTip('');
|
|
}
|
|
}).catch(function (err) {
|
|
if (window.console) console.error('[AKSRT Credits] /signin/today 请求失败:', err);
|
|
setStatus('加载失败,请刷新重试');
|
|
});
|
|
}
|
|
|
|
function collectCaptcha() {
|
|
var el = document.querySelector('[data-signin-captcha]');
|
|
if (!el) return {};
|
|
var out = {};
|
|
var keys = [
|
|
'captcha_verified', 'cf_turnstile_response',
|
|
'tencent_ticket', 'tencent_randstr', 'tencent_sid',
|
|
'geetest_lot_number', 'geetest_captcha_output', 'geetest_pass_token', 'geetest_gen_time',
|
|
'aliyun_captcha_verify_param',
|
|
];
|
|
keys.forEach(function (k) {
|
|
var inp = el.querySelector('input[name="' + k + '"]');
|
|
if (inp && inp.value !== '') out[k] = inp.value;
|
|
});
|
|
return out;
|
|
}
|
|
|
|
function resetCaptcha() {
|
|
try {
|
|
var state = window.AKSRTCaptchaState;
|
|
var scene = state && state.scenes && state.scenes.signin;
|
|
if (scene && typeof scene.reset === 'function') scene.reset();
|
|
} catch (_) {}
|
|
}
|
|
|
|
function triggerCaptcha(onSuccess, onFail) {
|
|
var mount = document.querySelector('[data-signin-captcha]');
|
|
var state = window.AKSRTCaptchaState;
|
|
var scene = state && state.scenes && state.scenes.signin;
|
|
|
|
if (scene && typeof scene.verify === 'function') {
|
|
scene.verify(function (ok) {
|
|
if (ok === false) {
|
|
if (typeof onFail === 'function') onFail('已取消验证');
|
|
return;
|
|
}
|
|
onSuccess();
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (mount) {
|
|
if (typeof onFail === 'function') onFail('人机验证加载中,请稍候再试');
|
|
return;
|
|
}
|
|
|
|
onSuccess();
|
|
}
|
|
|
|
btn.addEventListener('click', function () {
|
|
btn.disabled = true;
|
|
btn.innerHTML = '…';
|
|
setTip('');
|
|
|
|
triggerCaptcha(function () {
|
|
doSignin();
|
|
}, function (msg) {
|
|
resetCaptcha();
|
|
if (msg) setTip(msg);
|
|
btn.disabled = false;
|
|
btn.innerHTML = '签到';
|
|
});
|
|
|
|
function doSignin() {
|
|
api('/signin', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ captcha: collectCaptcha() })
|
|
}).then(function (r) {
|
|
if (!r.ok) {
|
|
resetCaptcha();
|
|
setTip((r.json && r.json.message) || '签到失败');
|
|
btn.disabled = false;
|
|
btn.innerHTML = '签到';
|
|
return;
|
|
}
|
|
setTip('签到成功,获得 ' + r.json.reward + ' 积分(连续 ' + r.json.streak + ' 天)');
|
|
var balanceEls = document.querySelectorAll('[data-credits-value]');
|
|
balanceEls.forEach(function (el) { el.textContent = r.json.balance.toLocaleString(); });
|
|
refresh();
|
|
}).catch(function () {
|
|
resetCaptcha();
|
|
setTip('网络错误,请重试');
|
|
btn.disabled = false;
|
|
btn.innerHTML = '签到';
|
|
});
|
|
}
|
|
});
|
|
|
|
refresh();
|
|
}
|
|
|
|
// Task-list "去签到" → scroll + click the real asset-card sign-in button.
|
|
function initSigninGoto() {
|
|
document.querySelectorAll('[data-aksrt-signin-goto]').forEach(function (el) {
|
|
el.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
var root = document.querySelector('[data-aksrt-signin]');
|
|
var btn = root ? root.querySelector('[data-signin-btn]') : null;
|
|
if (!btn) return;
|
|
try {
|
|
if (root && typeof root.scrollIntoView === 'function') {
|
|
root.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
}
|
|
} catch (_) {}
|
|
if (!btn.disabled) {
|
|
btn.click();
|
|
} else {
|
|
btn.focus();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// ===== Forward-only affiliate revenue center =====
|
|
function initAffiliateRevenue() {
|
|
var root = document.querySelector('[data-aksrt-revenue-page]');
|
|
if (!root || root.dataset.affiliateBound) return;
|
|
root.dataset.affiliateBound = '1';
|
|
var input = root.querySelector('[data-affiliate-link]');
|
|
var copy = root.querySelector('[data-affiliate-copy]');
|
|
var feedback = root.querySelector('[data-affiliate-feedback]');
|
|
function setFeedback(text, error) { if (feedback) { feedback.textContent = text; feedback.classList.toggle('is-error', !!error); } }
|
|
api('/revenue/me').then(function (r) {
|
|
if (!r.ok) { setFeedback((r.json && r.json.message) || '推广数据加载失败。', true); return; }
|
|
var j = r.json || {}, stats = j.stats || {};
|
|
if (input) {
|
|
input.value = j.url || '';
|
|
/* Keep the complete ref URL readable on desktop; mobile CSS still caps it. */
|
|
var linkLength = String(j.url || '').length;
|
|
input.setAttribute('size', String(Math.max(28, Math.min(96, linkLength || 28))));
|
|
input.style.width = Math.max(28, Math.min(96, linkLength || 28)) + 'ch';
|
|
}
|
|
if (copy) copy.disabled = !j.url;
|
|
var ratio = root.querySelector('[data-affiliate-ratio]'); if (ratio) ratio.textContent = String(j.ratio || 0) + '%';
|
|
var promoters = root.querySelector('[data-affiliate-promoters]'); if (promoters) promoters.textContent = String(stats.promoters || 0);
|
|
var payers = root.querySelector('[data-affiliate-payers]'); if (payers) payers.textContent = String(stats.effective_payers || 0);
|
|
}).catch(function () { setFeedback('推广数据加载失败。', true); });
|
|
if (copy) copy.addEventListener('click', function () {
|
|
if (!input || !input.value) return;
|
|
var done = function () { setFeedback('推广链接已复制。'); };
|
|
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(input.value).then(done).catch(function () { input.focus(); input.select(); setFeedback('复制失败,请手动复制。', true); });
|
|
else { input.focus(); input.select(); try { document.execCommand('copy'); done(); } catch (e) { setFeedback('复制失败,请手动复制。', true); } }
|
|
});
|
|
}
|
|
|
|
window.AKSRTAffiliateRevenueInit = initAffiliateRevenue;
|
|
|
|
|
|
|
|
// ===== VIP 积分兑换 =====
|
|
function initVipPointsExchange() {
|
|
var root = document.querySelector('[data-aksrt-vip-points]');
|
|
if (!root || !window.AksrtModalRuntime.isRolloutEnabled('vip')) return;
|
|
var tip = root.querySelector('[data-aksrt-vip-points-tip]');
|
|
var busy = false;
|
|
var coordinator = window.AksrtVipPurchaseCoordinator;
|
|
function setTip(text, isError) {
|
|
if (!tip) return;
|
|
tip.textContent = text || '';
|
|
tip.classList.toggle('is-error', !!isError);
|
|
}
|
|
root.addEventListener('click', function (e) {
|
|
var btn = e.target.closest('[data-aksrt-vip-points-buy]');
|
|
if (!btn || busy || btn.disabled) return;
|
|
e.preventDefault();
|
|
var packageId = parseInt(btn.getAttribute('data-package-id') || '0', 10);
|
|
if (!packageId) return;
|
|
busy = true;
|
|
btn.classList.add('is-loading');
|
|
setTip('正在兑换…');
|
|
coordinator.exchange({
|
|
packageId: packageId,
|
|
tags: ['vip', 'orders']
|
|
}).then(function (r) {
|
|
busy = false;
|
|
btn.classList.remove('is-loading');
|
|
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;
|
|
btn.classList.remove('is-loading');
|
|
setTip('网络错误,请重试', true);
|
|
});
|
|
});
|
|
}
|
|
|
|
// ===== VIP 开通 =====
|
|
function initVipShop() {
|
|
var root = document.querySelector('[data-aksrt-vip-shop]');
|
|
if (!root || !window.AksrtModalRuntime.isRolloutEnabled('vip')) return;
|
|
var tip = root.querySelector('[data-aksrt-vip-tip]');
|
|
var busy = false;
|
|
var coordinator = window.AksrtVipPurchaseCoordinator;
|
|
|
|
function setTip(text, isError) {
|
|
if (!tip) return;
|
|
tip.textContent = text || '';
|
|
tip.classList.toggle('is-error', !!isError);
|
|
}
|
|
|
|
function selectedMethod() {
|
|
var fixed = root.querySelector('[data-aksrt-vip-method-fixed]');
|
|
if (fixed && fixed.value) return fixed.value;
|
|
var checked = root.querySelector('input[name="aksrt_vip_pay_method"]:checked');
|
|
if (checked) return checked.value;
|
|
var first = root.querySelector('input[name="aksrt_vip_pay_method"]');
|
|
return first ? first.value : 'balance';
|
|
}
|
|
|
|
root.addEventListener('click', function (e) {
|
|
var btn = e.target.closest('[data-aksrt-vip-buy]');
|
|
if (!btn || busy) return;
|
|
e.preventDefault();
|
|
var packageId = parseInt(btn.getAttribute('data-package-id') || '0', 10);
|
|
if (!packageId) return;
|
|
busy = true;
|
|
btn.disabled = true;
|
|
btn.classList.add('is-loading');
|
|
setTip('正在创建订单…');
|
|
|
|
coordinator.start({
|
|
packageId: packageId,
|
|
paymentMethod: selectedMethod(),
|
|
tags: ['vip', 'orders'],
|
|
onPending: function (data) {
|
|
busy = false;
|
|
btn.disabled = false;
|
|
btn.classList.remove('is-loading');
|
|
if (data.payment_url) window.open(data.payment_url, '_blank');
|
|
setTip(data.message || '请完成支付,支付成功后将自动刷新。');
|
|
},
|
|
onSuccess: function (result) {
|
|
busy = false;
|
|
btn.disabled = false;
|
|
btn.classList.remove('is-loading');
|
|
setTip((result.data && result.data.message) || '开通成功,正在刷新…');
|
|
window.location.reload();
|
|
},
|
|
onFailure: function () {
|
|
busy = false;
|
|
btn.disabled = false;
|
|
btn.classList.remove('is-loading');
|
|
setTip('支付未完成,请重试。', true);
|
|
},
|
|
onTimeout: function () {
|
|
busy = false;
|
|
btn.disabled = false;
|
|
btn.classList.remove('is-loading');
|
|
setTip('支付状态暂未确认,请稍后在订单中心查看。', true);
|
|
},
|
|
onError: function (response) {
|
|
busy = false;
|
|
btn.disabled = false;
|
|
btn.classList.remove('is-loading');
|
|
setTip((response.json && response.json.message) || '开通失败', true);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// ===== 卡密兑换(余额 / 会员) =====
|
|
function initCardPass() {
|
|
var roots = document.querySelectorAll('[data-aksrt-card-pass]');
|
|
if (!roots || !roots.length) return;
|
|
|
|
Array.prototype.forEach.call(roots, function (root) {
|
|
var tip = root.querySelector('[data-aksrt-card-tip]');
|
|
var busy = false;
|
|
|
|
function setTip(text, isError) {
|
|
if (!tip) return;
|
|
tip.textContent = text || '';
|
|
tip.classList.toggle('is-error', !!isError);
|
|
}
|
|
|
|
var btn = root.querySelector('[data-aksrt-card-redeem]');
|
|
if (!btn) return;
|
|
|
|
btn.addEventListener('click', function () {
|
|
if (busy || btn.disabled) return;
|
|
var type = btn.getAttribute('data-type') || root.getAttribute('data-aksrt-card-pass') || '';
|
|
var pwInput = root.querySelector('[data-aksrt-card-password]');
|
|
var cardInput = root.querySelector('[data-aksrt-card-no]');
|
|
var password = pwInput ? String(pwInput.value || '').trim() : '';
|
|
var card = cardInput ? String(cardInput.value || '').trim() : '';
|
|
if (!password) {
|
|
setTip('请输入卡密', true);
|
|
if (pwInput) pwInput.focus();
|
|
return;
|
|
}
|
|
if (cardInput && !card) {
|
|
setTip('请输入卡号', true);
|
|
cardInput.focus();
|
|
return;
|
|
}
|
|
|
|
busy = true;
|
|
btn.disabled = true;
|
|
setTip('正在兑换…');
|
|
|
|
var body = { password: password, type: type };
|
|
if (card) body.card = card;
|
|
|
|
api('/pay/card-pass/redeem', {
|
|
method: 'POST',
|
|
body: JSON.stringify(body)
|
|
}).then(function (r) {
|
|
busy = false;
|
|
btn.disabled = 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 (type === 'vip' && window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
|
|
window.AksrtModalRuntime.invalidate(['vip', 'orders']);
|
|
}
|
|
setTip((data && data.message) || '兑换成功,正在刷新…');
|
|
window.location.reload();
|
|
}).catch(function () {
|
|
busy = false;
|
|
btn.disabled = false;
|
|
setTip('网络错误,请重试', true);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
// ===== 余额充值 / 转账 / 积分兑余额(Zibll 资产中心) =====
|
|
function openModal(el) {
|
|
if (!el) return;
|
|
el.hidden = false;
|
|
el.classList.add('is-open');
|
|
document.body.classList.add('uc-modal-open');
|
|
}
|
|
function closeModal(el) {
|
|
if (!el) return;
|
|
if (activePoll && typeof activePoll.abort === 'function') activePoll.abort();
|
|
activePoll = null;
|
|
el.hidden = true;
|
|
el.classList.remove('is-open');
|
|
if (!document.querySelector('.uc-modal.is-open')) {
|
|
document.body.classList.remove('uc-modal-open');
|
|
}
|
|
}
|
|
function pollPaidOrder(orderNumber, setTip, tags) {
|
|
var coordinator = window.AksrtVipPurchaseCoordinator;
|
|
if (!orderNumber) return;
|
|
var handle = coordinator.poll(orderNumber, {
|
|
tags: tags || ['credits', 'orders'],
|
|
onTerminal: function (result) {
|
|
activePoll = null;
|
|
if (result.success) {
|
|
if (typeof setTip === 'function') setTip('支付成功,正在刷新…');
|
|
window.location.reload();
|
|
}
|
|
}
|
|
});
|
|
return handle;
|
|
}
|
|
|
|
function initBalanceCharge() {
|
|
var modal = document.querySelector('[data-aksrt-charge-modal]');
|
|
if (!modal) return;
|
|
var form = modal.querySelector('[data-aksrt-charge-form]');
|
|
var tip = modal.querySelector('[data-aksrt-charge-tip]');
|
|
var busy = false;
|
|
function setTip(text, isError) {
|
|
if (!tip) return;
|
|
tip.textContent = text || '';
|
|
tip.classList.toggle('is-error', !!isError);
|
|
}
|
|
document.querySelectorAll('[data-aksrt-charge-open]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () { openModal(modal); });
|
|
});
|
|
modal.querySelectorAll('[data-aksrt-charge-close]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
if (activePoll && typeof activePoll.abort === 'function') activePoll.abort();
|
|
activePoll = null;
|
|
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="balance_package"]:checked') || form.querySelector('input[name="balance_package"]');
|
|
var pkg = pkgInput ? pkgInput.value : 'custom';
|
|
var customEl = form.querySelector('input[name="custom_price"]');
|
|
var custom = customEl ? parseFloat(customEl.value || '0') : 0;
|
|
if (custom > 0) {
|
|
pkg = 'custom';
|
|
}
|
|
if ((!pkg || pkg === 'custom') && !(custom > 0) && !pkgInput) {
|
|
setTip('请选择或输入充值金额', true);
|
|
return;
|
|
}
|
|
if (pkg === 'custom' && !(custom > 0)) {
|
|
setTip('请输入有效充值金额', true);
|
|
return;
|
|
}
|
|
var methodEl = form.querySelector('input[name="payment_method"]:checked');
|
|
var method = methodEl ? methodEl.value : 'alipay';
|
|
busy = true;
|
|
setTip('正在创建订单…');
|
|
api('/pay/balance/charge', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
package: pkg,
|
|
custom_price: 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) activePoll = pollPaidOrder(data.order_number, setTip, ['credits', 'orders']);
|
|
return;
|
|
}
|
|
setTip((data && data.message) || '充值成功,正在刷新…');
|
|
window.location.reload();
|
|
}).catch(function () {
|
|
busy = false;
|
|
setTip('网络错误,请重试', true);
|
|
});
|
|
});
|
|
}
|
|
|
|
function initTransfer() {
|
|
var modal = document.querySelector('[data-aksrt-transfer-modal]');
|
|
if (!modal) return;
|
|
var form = modal.querySelector('[data-aksrt-transfer-form]');
|
|
var tip = modal.querySelector('[data-aksrt-transfer-tip]');
|
|
var results = modal.querySelector('[data-aksrt-transfer-results]');
|
|
var selected = modal.querySelector('[data-aksrt-transfer-selected]');
|
|
var recipientInput = modal.querySelector('[data-aksrt-transfer-recipient]');
|
|
var typeInput = modal.querySelector('[data-aksrt-transfer-type]');
|
|
var title = modal.querySelector('[data-aksrt-transfer-title]');
|
|
var amountLabel = modal.querySelector('[data-aksrt-transfer-amount-label]');
|
|
var balanceInfo = modal.querySelector('[data-aksrt-transfer-balance-info]');
|
|
var pointsInfo = modal.querySelector('[data-aksrt-transfer-points-info]');
|
|
var pointsTransferMin = 1;
|
|
var searchTimer = null;
|
|
var busy = false;
|
|
function setTip(text, isError) {
|
|
if (!tip) return;
|
|
tip.textContent = text || '';
|
|
tip.classList.toggle('is-error', !!isError);
|
|
}
|
|
document.querySelectorAll('[data-aksrt-transfer-open]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
var type = btn.getAttribute('data-aksrt-transfer-open') || 'balance';
|
|
pointsTransferMin = type === 'points'
|
|
? Math.max(1, parseInt(btn.getAttribute('data-aksrt-transfer-min') || '1', 10) || 1)
|
|
: 1;
|
|
if (typeInput) typeInput.value = type;
|
|
if (title) title.textContent = type === 'points' ? '积分转账' : '余额转账';
|
|
var amountEl = form ? form.querySelector('[data-aksrt-transfer-amount]') : null;
|
|
if (amountEl) {
|
|
amountEl.min = type === 'points' ? String(pointsTransferMin) : '0.01';
|
|
amountEl.step = type === 'points' ? '1' : '0.01';
|
|
amountEl.inputMode = type === 'points' ? 'numeric' : 'decimal';
|
|
amountEl.value = '';
|
|
}
|
|
if (amountLabel) amountLabel.textContent = type === 'points' ? '积分' : '金额';
|
|
if (balanceInfo) balanceInfo.hidden = type === 'points';
|
|
if (pointsInfo) pointsInfo.hidden = type !== 'points';
|
|
if (results) results.innerHTML = '';
|
|
if (selected) selected.textContent = '';
|
|
if (recipientInput) recipientInput.value = '';
|
|
setTip('');
|
|
openModal(modal);
|
|
});
|
|
});
|
|
modal.querySelectorAll('[data-aksrt-transfer-close]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () { closeModal(modal); });
|
|
});
|
|
var searchEl = modal.querySelector('[data-aksrt-transfer-search]');
|
|
if (searchEl) {
|
|
searchEl.addEventListener('input', function () {
|
|
var q = String(searchEl.value || '').trim();
|
|
if (searchTimer) clearTimeout(searchTimer);
|
|
if (q.length < 1) {
|
|
if (results) results.innerHTML = '';
|
|
return;
|
|
}
|
|
searchTimer = setTimeout(function () {
|
|
api('/pay/transfer/search?s=' + encodeURIComponent(q)).then(function (r) {
|
|
if (!results) return;
|
|
results.innerHTML = '';
|
|
if (!r.ok) return;
|
|
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
|
var users = (data && data.users) || [];
|
|
if (!users.length) {
|
|
results.innerHTML = '<div class="muted-2-color em09">未找到相关用户</div>';
|
|
return;
|
|
}
|
|
users.forEach(function (u) {
|
|
var item = document.createElement('button');
|
|
item.type = 'button';
|
|
item.className = 'uc-transfer-user';
|
|
item.innerHTML = '<img src="' + (u.avatar || '') + '" alt="" class="uc-transfer-user__avatar"><span>' + (u.display_name || u.user_login) + '</span><span class="muted-2-color em09">@' + (u.user_login || '') + '</span>';
|
|
item.addEventListener('click', function () {
|
|
if (recipientInput) recipientInput.value = String(u.id);
|
|
if (selected) selected.textContent = '已选择:' + (u.display_name || u.user_login);
|
|
results.innerHTML = '';
|
|
});
|
|
results.appendChild(item);
|
|
});
|
|
});
|
|
}, 280);
|
|
});
|
|
}
|
|
if (!form) return;
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
if (busy) return;
|
|
var type = typeInput ? typeInput.value : 'balance';
|
|
var recipient = recipientInput ? parseInt(recipientInput.value || '0', 10) : 0;
|
|
var amountEl = form.querySelector('[data-aksrt-transfer-amount]');
|
|
var amount = amountEl ? amountEl.value : 0;
|
|
if (!recipient) {
|
|
setTip('请选择收款用户', true);
|
|
return;
|
|
}
|
|
if (!(parseFloat(amount) > 0) || (type === 'points' && (!Number.isInteger(Number(amount)) || Number(amount) < pointsTransferMin))) {
|
|
setTip('请输入有效金额', true);
|
|
return;
|
|
}
|
|
busy = true;
|
|
setTip('正在转账…');
|
|
api('/pay/transfer', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ type: type, recipient: recipient, amount: amount })
|
|
}).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 initPointsExchange() {
|
|
var modal = document.querySelector('[data-aksrt-points-exchange-modal]');
|
|
if (!modal) return;
|
|
var form = modal.querySelector('[data-aksrt-points-exchange-form]');
|
|
var tip = modal.querySelector('[data-aksrt-points-exchange-tip]');
|
|
var amountEl = form ? form.querySelector('[data-aksrt-points-exchange-amount]') : null;
|
|
var preview = form ? form.querySelector('[data-aksrt-points-exchange-preview]') : null;
|
|
var busy = false;
|
|
function setTip(text, isError) {
|
|
if (!tip) return;
|
|
tip.textContent = text || '';
|
|
tip.classList.toggle('is-error', !!isError);
|
|
}
|
|
document.querySelectorAll('[data-aksrt-points-exchange-open]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () { openModal(modal); });
|
|
});
|
|
modal.querySelectorAll('[data-aksrt-points-exchange-close]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () { closeModal(modal); });
|
|
});
|
|
if (!form) return;
|
|
function updatePreview() {
|
|
if (!preview || !amountEl) return;
|
|
var amount = Number(amountEl.value || '0');
|
|
var rate = Number(amountEl.getAttribute('data-aksrt-points-exchange-rate') || '0');
|
|
preview.textContent = Number.isInteger(amount) && amount > 0 && rate > 0
|
|
? '预计获得 ' + (amount * rate) + ' 积分'
|
|
: '';
|
|
}
|
|
amountEl.addEventListener('input', updatePreview);
|
|
updatePreview();
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
if (busy) return;
|
|
var amount = amountEl ? Number(amountEl.value || '0') : 0;
|
|
if (!Number.isInteger(amount) || !(amount > 0)) {
|
|
setTip('请输入正整数余额', true);
|
|
return;
|
|
}
|
|
busy = true;
|
|
setTip('正在兑换…');
|
|
api('/pay/balance/points-exchange', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ amount: amount })
|
|
}).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 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;
|
|
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 rawAmount = amountEl ? String(amountEl.value || '').trim() : '';
|
|
var amount = rawAmount ? Number(rawAmount) : 0;
|
|
var minAmount = amountEl ? Number(amountEl.getAttribute('data-withdraw-min') || '0') : 0;
|
|
var remainingAmount = amountEl ? Number(amountEl.getAttribute('data-withdraw-remaining-amount') || '0') : 0;
|
|
var remainingCount = amountEl ? Number(amountEl.getAttribute('data-withdraw-remaining-count') || '0') : 0;
|
|
var method = methodEl ? methodEl.value : 'alipay';
|
|
var account = accountEl ? String(accountEl.value || '').trim() : '';
|
|
if (!Number.isInteger(amount) || !(amount > 0)) {
|
|
setTip('提现金额必须为正整数', true);
|
|
return;
|
|
}
|
|
if (amount < minAmount) {
|
|
setTip('提现金额低于最低提现门槛', true);
|
|
return;
|
|
}
|
|
if (remainingCount <= 0) {
|
|
setTip('当日提现次数已用尽', true);
|
|
return;
|
|
}
|
|
if (amount > remainingAmount) {
|
|
setTip('本次提现后将超出单日提现总额上限', true);
|
|
return;
|
|
}
|
|
if (!account) {
|
|
setTip('请填写收款账号信息', true);
|
|
return;
|
|
}
|
|
busy = true;
|
|
setTip('正在提交…');
|
|
api('/earnings/withdrawals', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ amount: amount, method: method, account: 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) || '申请已提交');
|
|
closeModal(modal);
|
|
var panel = modal.closest ? modal.closest('.dashboard-panel') : null;
|
|
panel = panel || document.getElementById('panel-credits');
|
|
var rest = (window.aksrtData && (window.aksrtData.restUrl || window.aksrtData.apiUrl)) || (window.aksrtUserCenter && window.aksrtUserCenter.restUrl) || '';
|
|
if (panel && rest) {
|
|
fetch(rest.replace(/\/$/, '') + '/user-center/panel/credits', { credentials: 'same-origin', headers: { 'X-WP-Nonce': (window.aksrtData && (window.aksrtData.restNonce || window.aksrtData.nonce)) || '' } })
|
|
.then(function (response) { return response.json(); })
|
|
.then(function (payload) {
|
|
if (!payload || !payload.success || !payload.data || typeof payload.data.html !== 'string') return;
|
|
panel.innerHTML = payload.data.html;
|
|
if (window.AksrtFrontend && typeof window.AksrtFrontend.rehydrate === 'function') window.AksrtFrontend.rehydrate(panel, 'ajax');
|
|
});
|
|
}
|
|
}).catch(function () {
|
|
busy = false;
|
|
setTip('网络错误,请重试', true);
|
|
});
|
|
});
|
|
}
|
|
|
|
function initAssetTabs() {
|
|
var nav = document.querySelectorAll('[data-aksrt-asset-tab]');
|
|
if (!nav.length) return;
|
|
nav.forEach(function (link) {
|
|
if (link.dataset.aksrtAssetTabBound === 'true') return;
|
|
link.dataset.aksrtAssetTabBound = 'true';
|
|
link.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
var key = link.getAttribute('data-aksrt-asset-tab');
|
|
document.querySelectorAll('.uc-asset-tabs__nav [data-aksrt-asset-tab]').forEach(function (a) {
|
|
var li = a.closest('li');
|
|
if (!li) return;
|
|
var aKey = a.getAttribute('data-aksrt-asset-tab');
|
|
var on = aKey === key || (key === 'points_date' && aKey === 'points_free');
|
|
li.classList.toggle('active', on);
|
|
});
|
|
var tabs = document.querySelector('.uc-asset-tabs');
|
|
if (tabs && typeof tabs.scrollIntoView === 'function') {
|
|
tabs.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
}
|
|
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 initWithdrawHistory() {
|
|
var modal = document.querySelector('[data-aksrt-withdraw-history-modal]');
|
|
if (!modal) return;
|
|
function open() { modal.hidden = false; document.body.classList.add('uc-modal-open'); }
|
|
function close() { modal.hidden = true; document.body.classList.remove('uc-modal-open'); }
|
|
document.querySelectorAll('[data-aksrt-withdraw-history-open]').forEach(function (btn) {
|
|
btn.addEventListener('click', function (e) { e.preventDefault(); open(); });
|
|
});
|
|
modal.querySelectorAll('[data-aksrt-withdraw-history-close]').forEach(function (btn) {
|
|
btn.addEventListener('click', function (e) { e.preventDefault(); close(); });
|
|
});
|
|
}
|
|
|
|
window.AKSRTWithdrawInit = initWithdraw;
|
|
|
|
function bootAssets() {
|
|
initSignin();
|
|
initSigninGoto();
|
|
initAffiliateRevenue();
|
|
initVipShop();
|
|
initVipPointsExchange();
|
|
initCardPass();
|
|
initBalanceCharge();
|
|
initTransfer();
|
|
initPointsExchange();
|
|
initWithdraw();
|
|
initWithdrawHistory();
|
|
initAssetTabs();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', bootAssets);
|
|
} else {
|
|
bootAssets();
|
|
}
|
|
|
|
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
|
|
window.AksrtFrontend.register('credits', function () { initAssetTabs(); });
|
|
}
|
|
})();
|