fix recharge h5 payment defaults

This commit is contained in:
zhx 2026-06-17 11:22:43 +08:00
parent cbb5dce204
commit cdd674f3d9

View File

@ -1247,6 +1247,7 @@
// render 只消费 state不发请求所有接口副作用集中在动作函数里方便排查状态流转。
function render() {
normalizeSelections();
renderAccount();
renderProducts();
renderMethods();
@ -2016,6 +2017,39 @@
);
}
// 首屏拿到 options 后必须形成一组可下单快照:默认套餐优先取后端排序第一项,支付方式优先 USDT。
// 切账号、切套餐或后端配置变更时都重新校正,避免“有 USDT 但支付区被隐藏”或旧 method_id 串到新商品。
function normalizeSelections() {
var products =
(state.options && state.options.products) || [];
if (!products.length) {
state.selectedProductID = 0;
state.selectedMethodKey = '';
return;
}
var hasSelectedProduct = products.some(function (product) {
return product.product_id === state.selectedProductID;
});
if (!hasSelectedProduct) {
state.selectedProductID = products[0].product_id;
}
var methods = availableMethods();
if (!methods.length) {
state.selectedMethodKey = '';
return;
}
var hasSelectedMethod = methods.some(function (method) {
return method.key === state.selectedMethodKey;
});
if (hasSelectedMethod) return;
var usdtMethod = methods.find(function (method) {
return method.key === 'usdt_trc20';
});
state.selectedMethodKey = (
usdtMethod || methods[0]
).key;
}
// token 模式不回传 display_user_id防止前端把 token 用户和输入账号混用。
function targetDisplayUserID() {
if (
@ -2151,9 +2185,28 @@
}
function productUSD(product) {
if (product.amount_minor) return product.amount_minor / 100;
if (product.amount_micro)
return product.amount_micro / 1000000;
var directUSDT = Number(
product.amount_usdt || product.amountUsdt || 0
);
if (Number.isFinite(directUSDT) && directUSDT > 0) {
return directUSDT;
}
var usdtMicro = Number(
product.amount_usdt_micro ||
product.amountUsdtMicro ||
product.amount_micro ||
product.amountMicro ||
0
);
if (Number.isFinite(usdtMicro) && usdtMicro > 0) {
return usdtMicro / 1000000;
}
var minor = Number(
product.amount_minor || product.amountMinor || 0
);
if (Number.isFinite(minor) && minor > 0) {
return minor / 100;
}
return 0;
}