v1.10.6: 购买页等待支付超30秒给出『付款没反应』出口——立即刷新核对 + 重新下单换新二维码

This commit is contained in:
jinghui committed 2026-10-21 09:51:03 +08:00
1 parent 40f335331b
commit f231657560
5 files changed
+118 -8

No files matched your search

+77 -7
View File
@@ -4,6 +4,9 @@ let packages = [];
let selected = null;
let orderNo = null;
let pollTimer = null;
let lastPayType = null; // 记住当前支付方式,「重新下单」时直接复用
let payHelpShown = false;
let helpTipStage = 0; // 1=30秒提示 2=120秒提示;同阶段不重复覆盖刚点出来的反馈
function esc(s) {
return String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({
@@ -60,8 +63,10 @@ function selectPackage(id) {
async function createOrder(payType) {
if (!selected) return;
lastPayType = payType;
$('order-panel').hidden = false;
$('order-panel').scrollIntoView({ behavior: 'smooth', block: 'center' });
hidePayHelp();
const status = $('order-status');
status.className = 'order-status pending';
status.textContent = '⏳ 正在创建订单…';
@@ -83,11 +88,11 @@ async function createOrder(payType) {
}
}
function startPolling() {
if (pollTimer) clearInterval(pollTimer);
let attempts = 0;
pollTimer = setInterval(async () => {
attempts++;
let attempts = 0;
/** 单次订单查询:5 秒轮询与「立即刷新核对」按钮共用同一段逻辑 */
async function queryOrderOnce() {
attempts++;
if (attempts > 240) {
clearInterval(pollTimer);
pollTimer = null;
@@ -109,6 +114,7 @@ function startPolling() {
} else if (res.cardKey) {
clearInterval(pollTimer);
pollTimer = null;
hidePayHelp();
const status = $('order-status');
status.className = 'order-status error';
status.innerHTML = '✗ <b>已支付并已发卡</b>,但自动激活未成功(' +
@@ -126,14 +132,76 @@ function startPolling() {
'</b> 付款状态为已支付,<b>权益不会丢失</b>:继续等会自动发放,或凭此订单号联系客服补发。';
}
} else {
const waited = attempts * 5;
const status = $('order-status');
status.className = 'order-status pending';
status.textContent = '⏳ 等待支付中…(订单 ' + orderNo + ',已等待 ' + attempts * 5 + ' 秒)';
status.textContent = '⏳ 等待支付中…(订单 ' + orderNo + ',已等待 ' + waited + ' 秒)';
// 30 秒还没动静就主动给出口(付款通知丢失 / 扫了过期码 / 实际没扣款)
if (waited >= 30) showPayHelp(waited);
}
} catch (e) {
/* 单次查询失败不中断轮询 */
}
}, 5000);
}
function startPolling() {
if (pollTimer) clearInterval(pollTimer);
attempts = 0;
hidePayHelp();
queryOrderOnce(); // 先立刻查一次,不干等 5 秒
pollTimer = setInterval(queryOrderOnce, 5000);
}
/** 付款迟迟没动静时给出路,别让用户对着「等待支付中」干等 */
function showPayHelp(waited) {
const box = $('pay-help');
if (!box) return;
box.hidden = false;
payHelpShown = true;
const tip = $('ph-tip');
if (!tip) return;
const stage = waited >= 120 ? 2 : 1;
if (tip.textContent && stage <= helpTipStage) return; // 不覆盖用户刚点「刷新」得到的反馈
helpTipStage = stage;
if (stage === 2) {
tip.textContent = '已等待 ' + waited + ' 秒仍未确认支付。若你确已完成付款:请勿重复支付,留好订单号 ' +
(orderNo || '') + ' 与微信/支付宝交易号;若二维码是旧的/已过期,点「重新下单」换一个新码再付。';
} else {
tip.textContent = '正在等待付款通知…已完成付款的话,点「立即刷新核对」可以马上重查一次。';
}
}
function hidePayHelp() {
const box = $('pay-help');
if (box) box.hidden = true;
payHelpShown = false;
helpTipStage = 0;
const tip = $('ph-tip');
if (tip) tip.textContent = '';
}
function wirePayHelp() {
const rf = $('ph-refresh'), rn = $('ph-renew');
if (rf) rf.addEventListener('click', async () => {
const tip = $('ph-tip');
if (tip) tip.textContent = '正在向授权系统核对…';
await queryOrderOnce();
const box = $('pay-help');
if (!box || box.hidden || !tip) return; // 已出卡激活就不必再提示
tip.textContent = '已于 ' + new Date().toLocaleTimeString() +
' 重新核对:仍未确认支付。若你确已完成付款请勿重复支付(通知可能延迟);二维码过期就点「重新下单」。';
});
if (rn) rn.addEventListener('click', () => {
if (!selected) {
const tip = $('ph-tip');
if (tip) tip.textContent = '请先在上方重新选择套餐,再选支付方式生成新订单。';
const sp = $('step-package');
if (sp) sp.scrollIntoView({ behavior: 'smooth', block: 'start' });
return;
}
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
createOrder(lastPayType || 'wxpay');
});
}
/** 支付成功后立刻把卡密展示给用户(含自动激活失败的场景) */
@@ -148,6 +216,7 @@ function showCardBox(key, activated) {
}
function showActivated(res) {
hidePayHelp();
const status = $('order-status');
const permanent = !!res.isPermanent;
const exp = String(res.expireTime || '').trim();
@@ -196,4 +265,5 @@ $('cb-copy') && $('cb-copy').addEventListener('click', async () => {
$('cb-copy-tip').textContent = ok ? '已复制,可直接粘贴到侧边栏激活' : '复制失败,请手动长按选择卡密';
});
wirePayHelp();
loadPackages();