feat(pay): VIP package purchase service and user-center open flow

Add AKSRT_Vip_Service (GET/POST /pay/vip), activate aksrt_vip_level/expires on
order paid, package UI in credits panel, and deep-link VIP CTA to credits tab.
This commit is contained in:
kate522 committed 2026-07-14 18:16:15 +08:00
1 parent 8e9e05c859
commit d0b8f7805f
10 files changed
+957 -24

No files matched your search

+85
View File
@@ -317,13 +317,98 @@
});
}
// ===== VIP 开通 =====
function initVipShop() {
var root = document.querySelector('[data-aksrt-vip-shop]');
if (!root) return;
var tip = root.querySelector('[data-aksrt-vip-tip]');
var busy = false;
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';
}
function pollOrder(orderNumber) {
if (!orderNumber) return;
var tries = 0;
var maxTries = 40;
var timer = setInterval(function () {
tries += 1;
api('/pay/content/order/' + encodeURIComponent(orderNumber)).then(function (r) {
if (r.ok && r.json && r.json.paid) {
clearInterval(timer);
setTip('支付成功,正在刷新…');
window.location.reload();
}
}).catch(function () { /* ignore */ });
if (tries >= maxTries) clearInterval(timer);
}, 3000);
}
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.classList.add('is-loading');
setTip('正在创建订单…');
api('/pay/vip', {
method: 'POST',
body: JSON.stringify({
package_id: packageId,
payment_method: selectedMethod()
})
}).then(function (r) {
busy = false;
btn.classList.remove('is-loading');
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
var msg = (r.json && r.json.message) || '开通失败';
setTip(msg, 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) pollOrder(data.order_number);
return;
}
setTip((data && data.message) || '开通成功,正在刷新…');
window.location.reload();
}).catch(function () {
busy = false;
btn.classList.remove('is-loading');
setTip('网络错误,请重试', true);
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function () {
initSignin();
initInvite();
initVipShop();
});
} else {
initSignin();
initInvite();
initVipShop();
}
})();