feat: upgrade widgets and affiliate commission flow
This commit is contained in:
+37
-3
@@ -383,6 +383,39 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ===== Forward-only affiliate promotion center =====
|
||||
function initAffiliatePromotion() {
|
||||
var root = document.querySelector('[data-aksrt-promotion-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('/promotion/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 || '';
|
||||
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); } }
|
||||
});
|
||||
var accountForm = root.querySelector('[data-affiliate-accounts]');
|
||||
if (accountForm) accountForm.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
var feedback = accountForm.querySelector('[data-affiliate-account-feedback]');
|
||||
var accounts = {}; new FormData(accountForm).forEach(function (value, key) { if (String(value).trim()) accounts[key] = String(value).trim(); });
|
||||
api('/promotion/payout-accounts', { method: 'PUT', body: JSON.stringify({ accounts: accounts }) }).then(function (r) { if (feedback) feedback.textContent = r.ok ? '收款方式已保存。' : ((r.json && r.json.message) || '保存失败。'); }).catch(function () { if (feedback) feedback.textContent = '网络错误,请稍后重试。'; });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ===== VIP 积分兑换 =====
|
||||
@@ -917,9 +950,9 @@
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在提交…');
|
||||
api('/pay/balance/withdraw', {
|
||||
api('/earnings/withdrawals', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ amount: amount, method: method, account_info: account })
|
||||
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)) {
|
||||
@@ -996,7 +1029,8 @@
|
||||
function bootAssets() {
|
||||
initSignin();
|
||||
initSigninGoto();
|
||||
initInvite();
|
||||
initInvite();
|
||||
initAffiliatePromotion();
|
||||
initVipShop();
|
||||
initVipPointsExchange();
|
||||
initCardPass();
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
|
||||
function request(payload) {
|
||||
return fetch(rest + '/pay/balance/withdraw', {
|
||||
return fetch(rest + '/earnings/withdrawals', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
@@ -53,7 +53,7 @@
|
||||
var values = new FormData(form);
|
||||
var amount = Number(values.get('amount') || 0);
|
||||
var method = String(values.get('method') || 'alipay');
|
||||
var account = String(values.get('account_info') || '').trim();
|
||||
var account = String(values.get('account') || values.get('account_info') || '').trim();
|
||||
var minimum = Number(page.getAttribute('data-min-amount') || 50);
|
||||
if (amount < minimum) {
|
||||
setMessage('最低提现金额为 ' + minimum, true);
|
||||
@@ -69,7 +69,7 @@
|
||||
button.disabled = true;
|
||||
button.textContent = '提交中…';
|
||||
}
|
||||
request({ amount: amount, method: method, account_info: account }).then(function (result) {
|
||||
request({ amount: amount, method: method, account: account }).then(function (result) {
|
||||
if (button) {
|
||||
button.disabled = false;
|
||||
button.textContent = '提交提现申请';
|
||||
|
||||
Reference in New Issue
Block a user