feat(pay): 卡密兑换入口收敛到三个购买弹窗并对齐参考主题
- 移除余额卡片独立「卡密兑换」通用弹窗,兑换入口分布到充值/积分/会员三个弹窗的支付方式中 - 充值弹窗补齐卡密 logo 与仅卡密时的金额选择隐藏逻辑 - 积分购买弹窗 1:1 复刻参考主题 points-pay modal(商品档位/自定义/支付方式/立即支付),REST 改为 product+custom 契约 - 会员弹窗注入卡密渠道:视图模型透传 card_pass,前端渲染卡密盒并直兑 /pay/card-pass/redeem type=vip - 后台卡密兑换拆分为余额/积分/会员三个独立开关,VIP 段旧会员卡密组清理 - REST type 改为必填(balance/vip/credits),三类型独立闸门 - 测试重写为 card-pass-modal-redeem 契约,321 项全部通过
This commit is contained in:
@@ -25,6 +25,12 @@ export const rechargeSchema = {
|
||||
pay_balance_pass_charge_s: false,
|
||||
pay_balance_pass_charge_desc: '',
|
||||
pay_balance_pass_charge_only_password: false,
|
||||
points_pass_exchange_s: false,
|
||||
points_pass_exchange_desc: '',
|
||||
points_pass_exchange_only_password: false,
|
||||
pay_vip_pass_charge_s: false,
|
||||
pay_vip_pass_charge_desc: '',
|
||||
pay_vip_pass_charge_only_password: false,
|
||||
pay_balance_points_exchange_s: false,
|
||||
pay_balance_points_exchange_rate: 100,
|
||||
pay_balance_points_exchange_min_points: 100,
|
||||
@@ -98,9 +104,15 @@ export const rechargeSchema = {
|
||||
title: '卡密兑换',
|
||||
icon: 'fa fas fa-ticket-alt',
|
||||
fields: [
|
||||
{ key: 'pay_balance_pass_charge_s', label: '启用卡密兑换功能', type: 'switch', default: false, help: '开启后用户中心余额卡片展示通用「卡密兑换」入口,支持余额 / 会员 / 积分卡密,类型按卡密自动识别' },
|
||||
{ key: 'pay_balance_pass_charge_desc', label: '卡密兑换说明', type: 'textarea', default: '', rows: 2, dependsOn: { key: 'pay_balance_pass_charge_s', value: true }, help: '用户使用卡密兑换时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码' },
|
||||
{ key: 'pay_balance_pass_charge_only_password', label: '单密码模式', type: 'switch', default: false, dependsOn: { key: 'pay_balance_pass_charge_s', value: true }, help: '余额卡密仅需输入密码,不需要卡号' },
|
||||
{ key: 'pay_balance_pass_charge_s', label: '启用卡密兑换余额功能', type: 'switch', default: false, help: '开启后用户可在余额充值弹窗选择「卡密」渠道,使用卡密直接兑换余额' },
|
||||
{ key: 'pay_balance_pass_charge_desc', label: '卡密兑换余额说明', type: 'textarea', default: '', rows: 2, dependsOn: { key: 'pay_balance_pass_charge_s', value: true }, help: '用户使用卡密兑换余额时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码' },
|
||||
{ key: 'pay_balance_pass_charge_only_password', label: '余额卡密单密码模式', type: 'switch', default: false, dependsOn: { key: 'pay_balance_pass_charge_s', value: true }, help: '余额卡密仅需输入密码,不需要卡号' },
|
||||
{ key: 'points_pass_exchange_s', label: '启用卡密兑换积分功能', type: 'switch', default: false, help: '开启后用户可在购买积分弹窗选择「卡密」渠道,使用卡密直接兑换积分' },
|
||||
{ key: 'points_pass_exchange_desc', label: '卡密兑换积分说明', type: 'textarea', default: '', rows: 2, dependsOn: { key: 'points_pass_exchange_s', value: true }, help: '用户使用卡密兑换积分时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码' },
|
||||
{ key: 'points_pass_exchange_only_password', label: '积分卡密单密码模式', type: 'switch', default: false, dependsOn: { key: 'points_pass_exchange_s', value: true }, help: '积分卡密仅需输入密码,不需要卡号' },
|
||||
{ key: 'pay_vip_pass_charge_s', label: '启用卡密兑换会员功能', type: 'switch', default: false, help: '开启后用户可在会员购买/续费弹窗选择「卡密」渠道,使用会员卡密直接兑换会员' },
|
||||
{ key: 'pay_vip_pass_charge_desc', label: '卡密兑换会员说明', type: 'textarea', default: '', rows: 2, dependsOn: { key: 'pay_vip_pass_charge_s', value: true }, help: '用户使用卡密兑换会员时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码' },
|
||||
{ key: 'pay_vip_pass_charge_only_password', label: '会员卡密单密码模式', type: 'switch', default: true, dependsOn: { key: 'pay_vip_pass_charge_s', value: true }, help: '会员卡密仅需输入密码,不需要卡号' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -40,7 +40,6 @@ export const vipSchema = {
|
||||
vip_upgrade: true,
|
||||
vip_upgrade_desc: '',
|
||||
vip_upgrade_product: 'unit|1|按剩余天数升级\njump|199|升级永久二级会员\npermanent|299|永久一级升永久二级',
|
||||
pay_vip_pass_charge_only_password: true,
|
||||
pay_vip_points_exchange_s: false,
|
||||
payment_vip_points_packages: '1|500|30|积分月卡\n1|5000|0|积分永久',
|
||||
pay_vip_points_exchange_desc: '',
|
||||
@@ -201,14 +200,6 @@ export const vipSchema = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'pass-charge',
|
||||
title: '会员卡密',
|
||||
icon: 'fa fas fa-ticket-alt',
|
||||
fields: [
|
||||
{ key: 'pay_vip_pass_charge_only_password', label: '单密码模式', type: 'switch', default: true, help: '会员卡密核销是否仅需卡密;关闭后,带卡号的会员卡必须同时输入卡号。会员/积分卡密无独立开关,统一受「余额充值 → 卡密兑换 → 启用卡密兑换功能」控制' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'points-exchange',
|
||||
title: '积分兑换会员',
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" version="1.1">
|
||||
<path d="M 855.34776,170.36629 H 178.33999 c -64.95102,0 -117.564884,52.26845 -117.564884,116.79333 v 55.01654 H 972.91264 v -55.01654 c 0,-64.36964 -52.66906,-116.79333 -117.56488,-116.79333 z" fill="#646bee" />
|
||||
<path d="m 60.719782,754.99249 c 0,64.52488 52.669088,116.79333 117.564888,116.79333 h 677.00776 c 64.95226,0 117.56489,-52.26845 117.56489,-116.79333 V 405.87661 H 60.719782 Z M 736.7317,653.69832 H 889.98099 L 834.15842,763.29168 H 680.90913 Z m -110.428,0 h 51.94985 l -55.76726,109.59336 h -51.94984 z m -116.62436,0 h 51.94984 l -55.76724,109.59336 h -51.94986 z" fill="#585fe4" />
|
||||
<path d="m 60.775106,405.87661 v 349.11588 c 0,64.52488 52.665714,116.79333 117.564884,116.79333 H 560.79931 C 628.68799,846.31039 691.75943,809.63009 747.35404,763.29168 H 680.96446 L 736.7317,653.69832 H 851.30906 C 906.37282,580.10783 944.79505,495.57497 963.95005,405.87661 Z M 505.80661,763.29168 h -51.94985 l 55.76725,-109.59336 h 51.94985 z m 116.62437,0 h -51.94986 l 55.76725,-109.59336 h 51.94985 z" fill="#646bee" />
|
||||
<path d="m 60.775106,678.3211 c 31.369079,4.67174 63.457374,7.09004 96.154254,7.09004 221.2986,0 416.53929,-110.74756 532.61042,-279.53453 H 60.775106 Z M 789.2348,170.36629 H 178.33999 c -64.951,0 -117.564884,52.26845 -117.564884,116.79333 v 55.01654 H 728.10106 c 28.10492,-53.31272 48.96232,-111.02238 61.13374,-171.80987 z" fill="#6b72f2" />
|
||||
<path d="M 251.47919,405.87661 H 60.775106 v 49.52037 C 127.93923,448.63671 192.00518,431.54366 251.47919,405.87661 Z M 533.30296,170.36629 H 178.33999 c -64.95113,0 -117.564884,52.26845 -117.564884,116.79333 v 55.01654 H 365.66927 C 431.84559,295.79524 488.70183,237.52257 533.30296,170.36629 Z" fill="#8c91f2" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
+171
-91
@@ -266,79 +266,28 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 卡密兑换(余额 / 会员 / 积分,通用弹窗由后端自动识别类型) =====
|
||||
function initCardPass() {
|
||||
var roots = document.querySelectorAll('[data-aksrt-card-pass]');
|
||||
if (!roots || !roots.length) return;
|
||||
|
||||
var modal = document.querySelector('[data-aksrt-card-pass-modal]');
|
||||
if (modal) {
|
||||
modal.querySelectorAll('[data-aksrt-card-pass-close]').forEach(function (btn) {
|
||||
if (btn.dataset.aksrtCardPassCloseBound === '1') return;
|
||||
btn.dataset.aksrtCardPassCloseBound = '1';
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
});
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-card-pass-open]').forEach(function (btn) {
|
||||
if (btn.dataset.aksrtCardPassOpenBound === '1') return;
|
||||
btn.dataset.aksrtCardPassOpenBound = '1';
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
|
||||
Array.prototype.forEach.call(roots, function (root) {
|
||||
var busy = false;
|
||||
resetOperationKeyOnChange(root);
|
||||
|
||||
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) {
|
||||
notyf('请输入卡密', 'danger');
|
||||
if (pwInput) pwInput.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
busy = true;
|
||||
btn.disabled = true;
|
||||
notyf('正在兑换…', 'load', '', 'aksrt-card-pass-toast');
|
||||
|
||||
// ===== 卡密兑换(三个购买弹窗共用的卡密渠道提交) =====
|
||||
function redeemCardPass(type, card, password, keyOwner, toastId) {
|
||||
var body = { password: password, type: type };
|
||||
if (card) body.card = card;
|
||||
|
||||
api('/pay/card-pass/redeem', {
|
||||
return api('/pay/card-pass/redeem', {
|
||||
method: 'POST',
|
||||
headers: { 'Idempotency-Key': operationKey(root) },
|
||||
headers: { 'Idempotency-Key': operationKey(keyOwner) },
|
||||
body: JSON.stringify(body)
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
btn.disabled = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
notyf((r.json && r.json.message) || '兑换失败', 'danger', 5, 'aksrt-card-pass-toast');
|
||||
return;
|
||||
return { ok: false, message: (r.json && r.json.message) || '兑换失败' };
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
resetOperationKey(root);
|
||||
// 通用兑换(type 为空)时以后端识别出的卡密类型为准。
|
||||
var redeemedType = (data && data.type) || type;
|
||||
if (redeemedType === 'vip' && window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
|
||||
resetOperationKey(keyOwner);
|
||||
if (type === 'vip' && window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
|
||||
window.AksrtModalRuntime.invalidate(['vip', 'orders']);
|
||||
}
|
||||
notyf((data && data.message) || '兑换成功,正在刷新…', 'success', 5, 'aksrt-card-pass-toast');
|
||||
notyf((data && data.message) || '兑换成功,正在刷新…', 'success', 5, toastId);
|
||||
window.setTimeout(function () { window.location.reload(); }, 800);
|
||||
return { ok: true };
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
btn.disabled = false;
|
||||
notyf('网络错误,请重试', 'danger', 5, 'aksrt-card-pass-toast');
|
||||
});
|
||||
});
|
||||
return { ok: false, message: '网络错误,请重试' };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -471,13 +420,24 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
// 支付方式(.payment-method-radio)
|
||||
// 支付方式(.payment-method-radio);卡密渠道选中时隐藏金额选择、
|
||||
// 显示卡密输入盒(data-controller="payment_method" 契约与参考主题一致)。
|
||||
function cardPassBox() {
|
||||
return modal.querySelector('[data-controller="payment_method"][data-value="card_pass"]');
|
||||
}
|
||||
function applyMethodVisibility(value) {
|
||||
var cardBox = cardPassBox();
|
||||
if (cardBox) cardBox.style.display = value === 'card_pass' ? '' : 'none';
|
||||
var chargeBoxes = modal.querySelectorAll('.charge-box');
|
||||
chargeBoxes.forEach(function (el) { el.style.display = value === 'card_pass' ? 'none' : ''; });
|
||||
}
|
||||
function selectMethod(value) {
|
||||
modal.querySelectorAll('[data-for="payment_method"]').forEach(function (el) {
|
||||
el.classList.toggle('active', el.getAttribute('data-value') === value);
|
||||
});
|
||||
var hidden = modal.querySelector('input[name="payment_method"]');
|
||||
if (hidden) hidden.value = value;
|
||||
applyMethodVisibility(value);
|
||||
if (form) resetOperationKey(form);
|
||||
}
|
||||
modal.querySelectorAll('[data-for="payment_method"]').forEach(function (el) {
|
||||
@@ -485,11 +445,36 @@
|
||||
selectMethod(el.getAttribute('data-value'));
|
||||
});
|
||||
});
|
||||
applyMethodVisibility((modal.querySelector('input[name="payment_method"]') || {}).value || '');
|
||||
if (!form) return;
|
||||
resetOperationKeyOnChange(form);
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var methodEl = form.querySelector('input[name="payment_method"]');
|
||||
var method = methodEl ? methodEl.value : '';
|
||||
if (!method) {
|
||||
notyf('暂无可用支付方式', 'danger');
|
||||
return;
|
||||
}
|
||||
if (method === 'card_pass') {
|
||||
var cardEl = form.querySelector('input[name="card_pass[card]"]');
|
||||
var pwEl = form.querySelector('input[name="card_pass[password]"]');
|
||||
var password = pwEl ? String(pwEl.value || '').trim() : '';
|
||||
if (!password) {
|
||||
notyf('请输入卡密', 'danger');
|
||||
if (pwEl) pwEl.focus();
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
notyf('正在兑换…', 'load', '', 'aksrt-balance-charge-toast');
|
||||
redeemCardPass('balance', cardEl ? String(cardEl.value || '').trim() : '', password, form, 'aksrt-balance-charge-toast')
|
||||
.then(function (result) {
|
||||
busy = false;
|
||||
if (!result.ok) notyf(result.message, 'danger', 5, 'aksrt-balance-charge-toast');
|
||||
});
|
||||
return;
|
||||
}
|
||||
var pkgInput = form.querySelector('input[name="balance_product"]');
|
||||
var pkg = pkgInput ? pkgInput.value : 'custom';
|
||||
var customEl = form.querySelector('input[name="custom_price"]');
|
||||
@@ -686,40 +671,136 @@
|
||||
});
|
||||
}
|
||||
|
||||
function initPointsExchange() {
|
||||
var modal = document.querySelector('[data-aksrt-points-exchange-modal]');
|
||||
if (!modal || modal.dataset.aksrtPointsExchangeInitialized === '1') return;
|
||||
modal.dataset.aksrtPointsExchangeInitialized = '1';
|
||||
var form = modal.querySelector('[data-aksrt-points-exchange-form]');
|
||||
var amountEl = form ? form.querySelector('[data-aksrt-points-exchange-amount]') : null;
|
||||
var preview = form ? form.querySelector('[data-aksrt-points-exchange-preview]') : null;
|
||||
// ===== 购买积分(Zibll points-pay modal 1:1:商品/自定义 + 余额/卡密支付) =====
|
||||
function initPointsPay() {
|
||||
var modal = document.querySelector('[data-aksrt-points-pay-modal]');
|
||||
if (!modal || modal.dataset.aksrtPointsPayInitialized === '1') return;
|
||||
modal.dataset.aksrtPointsPayInitialized = '1';
|
||||
var form = modal.querySelector('[data-aksrt-points-pay-form]');
|
||||
var busy = false;
|
||||
document.querySelectorAll('[data-aksrt-points-exchange-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
var backdrop = null;
|
||||
|
||||
function openPointsModal() {
|
||||
if (modal.classList.contains('in')) return;
|
||||
modal.style.display = 'flex';
|
||||
void modal.offsetWidth;
|
||||
modal.classList.add('in');
|
||||
if (!backdrop) {
|
||||
backdrop = document.createElement('div');
|
||||
backdrop.className = 'modal-backdrop fade in';
|
||||
backdrop.setAttribute('data-aksrt-points-backdrop', '1');
|
||||
document.body.appendChild(backdrop);
|
||||
}
|
||||
document.body.classList.add('modal-open');
|
||||
}
|
||||
function closePointsModal() {
|
||||
if (!modal.classList.contains('in')) return;
|
||||
modal.classList.remove('in');
|
||||
document.body.classList.remove('modal-open');
|
||||
if (backdrop && backdrop.parentNode) backdrop.parentNode.removeChild(backdrop);
|
||||
backdrop = null;
|
||||
window.setTimeout(function () {
|
||||
if (!modal.classList.contains('in')) modal.style.display = '';
|
||||
}, 300);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-points-pay-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', openPointsModal);
|
||||
});
|
||||
modal.querySelectorAll('[data-aksrt-points-exchange-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
modal.addEventListener('click', function (e) {
|
||||
if (e.target === modal || (e.target.closest && e.target.closest('[data-dismiss="modal"]'))) {
|
||||
closePointsModal();
|
||||
}
|
||||
});
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape' && modal.classList.contains('in')) closePointsModal();
|
||||
});
|
||||
|
||||
// Zibll data-for/data-value 选中模型:积分商品档位。
|
||||
function selectProduct(value) {
|
||||
modal.querySelectorAll('[data-for="points_product"]').forEach(function (el) {
|
||||
el.classList.toggle('active', el.getAttribute('data-value') === value);
|
||||
});
|
||||
var hidden = modal.querySelector('input[name="points_product"]');
|
||||
if (hidden) hidden.value = value;
|
||||
if (form) resetOperationKey(form);
|
||||
}
|
||||
modal.querySelectorAll('[data-for="points_product"]').forEach(function (el) {
|
||||
el.addEventListener('click', function () {
|
||||
selectProduct(el.getAttribute('data-value'));
|
||||
});
|
||||
});
|
||||
var customInput = modal.querySelector('input[name="points_custom"]');
|
||||
if (customInput) {
|
||||
customInput.addEventListener('input', function () {
|
||||
if (String(customInput.value || '').trim() !== '') selectProduct('custom');
|
||||
});
|
||||
}
|
||||
// 支付方式(余额/卡密);选中卡密时隐藏商品选择、显示卡密输入盒。
|
||||
function cardPassBox() {
|
||||
return modal.querySelector('[data-controller="payment_method"][data-value="card_pass"]');
|
||||
}
|
||||
function applyMethodVisibility(value) {
|
||||
var cardBox = cardPassBox();
|
||||
if (cardBox) cardBox.style.display = value === 'card_pass' ? '' : 'none';
|
||||
modal.querySelectorAll('.charge-box').forEach(function (el) {
|
||||
el.style.display = value === 'card_pass' ? 'none' : '';
|
||||
});
|
||||
}
|
||||
function selectMethod(value) {
|
||||
modal.querySelectorAll('[data-for="payment_method"]').forEach(function (el) {
|
||||
el.classList.toggle('active', el.getAttribute('data-value') === value);
|
||||
});
|
||||
var hidden = modal.querySelector('input[name="payment_method"]');
|
||||
if (hidden) hidden.value = value;
|
||||
applyMethodVisibility(value);
|
||||
if (form) resetOperationKey(form);
|
||||
}
|
||||
modal.querySelectorAll('[data-for="payment_method"]').forEach(function (el) {
|
||||
el.addEventListener('click', function () {
|
||||
selectMethod(el.getAttribute('data-value'));
|
||||
});
|
||||
});
|
||||
applyMethodVisibility((modal.querySelector('input[name="payment_method"]') || {}).value || '');
|
||||
if (!form) return;
|
||||
resetOperationKeyOnChange(form);
|
||||
function updatePreview() {
|
||||
if (!preview || !amountEl) return;
|
||||
var amount = balanceMinor(amountEl.value);
|
||||
var rateRaw = amountEl.getAttribute('data-aksrt-points-exchange-rate') || '';
|
||||
var rate = /^[1-9]\d*$/.test(rateRaw) ? BigInt(rateRaw) : 0n;
|
||||
var scaled = amount !== null ? amount * rate : 0n;
|
||||
preview.textContent = amount !== null && amount > 0n && rate > 0n && scaled % 100n === 0n
|
||||
? '预计获得 ' + String(scaled / 100n) + ' 积分'
|
||||
: '';
|
||||
}
|
||||
amountEl.addEventListener('input', updatePreview);
|
||||
updatePreview();
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var amount = amountEl ? String(amountEl.value || '').trim() : '';
|
||||
if (!/^(0|[1-9]\d*)(?:\.\d{1,2})?$/.test(amount) || /^0(?:\.0{1,2})?$/.test(amount)) {
|
||||
notyf('请输入最多两位小数的正数余额', 'danger');
|
||||
var methodEl = form.querySelector('input[name="payment_method"]');
|
||||
var method = methodEl ? methodEl.value : '';
|
||||
if (!method) {
|
||||
notyf('暂无可用支付方式', 'danger');
|
||||
return;
|
||||
}
|
||||
if (method === 'card_pass') {
|
||||
var cardEl = form.querySelector('input[name="card_pass[card]"]');
|
||||
var pwEl = form.querySelector('input[name="card_pass[password]"]');
|
||||
var password = pwEl ? String(pwEl.value || '').trim() : '';
|
||||
if (!password) {
|
||||
notyf('请输入卡密', 'danger');
|
||||
if (pwEl) pwEl.focus();
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
notyf('正在兑换…', 'load', '', 'aksrt-balance-points-toast');
|
||||
redeemCardPass('credits', cardEl ? String(cardEl.value || '').trim() : '', password, form, 'aksrt-balance-points-toast')
|
||||
.then(function (result) {
|
||||
busy = false;
|
||||
if (!result.ok) notyf(result.message, 'danger', 5, 'aksrt-balance-points-toast');
|
||||
});
|
||||
return;
|
||||
}
|
||||
var pkgInput = form.querySelector('input[name="points_product"]');
|
||||
var pkg = pkgInput ? pkgInput.value : 'custom';
|
||||
var customEl = form.querySelector('input[name="points_custom"]');
|
||||
var custom = customEl ? String(customEl.value || '').trim() : '';
|
||||
var validCustom = /^[1-9]\d{0,8}$/.test(custom);
|
||||
if (validCustom) {
|
||||
pkg = 'custom';
|
||||
selectProduct('custom');
|
||||
}
|
||||
if ((!pkg || pkg === 'custom') && !validCustom) {
|
||||
notyf('请选择或输入需购买的积分', 'danger');
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
@@ -727,7 +808,7 @@
|
||||
api('/pay/balance/points-exchange', {
|
||||
method: 'POST',
|
||||
headers: { 'Idempotency-Key': operationKey(form) },
|
||||
body: JSON.stringify({ amount: amount })
|
||||
body: JSON.stringify({ product: pkg, custom: validCustom ? custom : '0' })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
@@ -1054,10 +1135,9 @@
|
||||
initAffiliateRevenue();
|
||||
initVipShop();
|
||||
initVipPointsExchange();
|
||||
initCardPass();
|
||||
initBalanceCharge();
|
||||
initTransfer();
|
||||
initPointsExchange();
|
||||
initPointsPay();
|
||||
initWithdraw();
|
||||
initWithdrawHistory();
|
||||
initAssetTabs();
|
||||
|
||||
+99
-3
@@ -102,7 +102,7 @@
|
||||
append(parent, wrap);
|
||||
}
|
||||
|
||||
function renderMethods(parent, methods) {
|
||||
function renderMethods(parent, methods, cardPass) {
|
||||
methods = Array.isArray(methods) ? methods : [];
|
||||
if (!methods.length) {
|
||||
append(parent, node("div", "muted-2-color text-center padding-10", "暂无可用支付方式"));
|
||||
@@ -115,8 +115,7 @@
|
||||
one.value = text(methods[0].id || "balance");
|
||||
one.setAttribute("data-aksrt-vip-method-fixed", "");
|
||||
append(parent, one);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
var wrap = node("div", "uc-vip-shop__methods mb10");
|
||||
wrap.setAttribute("data-aksrt-vip-methods", "");
|
||||
append(wrap, node("span", "uc-vip-shop__methods-label", "支付方式"));
|
||||
@@ -133,6 +132,44 @@
|
||||
});
|
||||
append(parent, wrap);
|
||||
}
|
||||
// 卡密渠道输入盒(契约与参考主题一致:data-controller="payment_method")。
|
||||
if (cardPass) {
|
||||
var box = node("div", "uc-vip-shop__card-pass mb10");
|
||||
box.setAttribute("data-controller", "payment_method");
|
||||
box.setAttribute("data-condition", "==");
|
||||
box.setAttribute("data-value", "card_pass");
|
||||
box.style.display = "none";
|
||||
if (cardPass.desc) append(box, node("div", "muted-box muted-2-color padding-10 mb10 em09", cardPass.desc));
|
||||
append(box, node("div", "muted-2-color em09 mb6", cardPass.only_password ? "请输入卡密" : "请输入卡号和密码"));
|
||||
if (!cardPass.only_password) {
|
||||
var cardInput = node("input", "form-control mb6");
|
||||
cardInput.type = "text";
|
||||
cardInput.name = "card_pass[card]";
|
||||
cardInput.placeholder = "卡号";
|
||||
cardInput.autocomplete = "off";
|
||||
append(box, cardInput);
|
||||
}
|
||||
var pwInput = node("input", "form-control");
|
||||
pwInput.type = "text";
|
||||
pwInput.name = "card_pass[password]";
|
||||
pwInput.placeholder = "卡密";
|
||||
pwInput.autocomplete = "off";
|
||||
append(box, pwInput);
|
||||
append(parent, box);
|
||||
}
|
||||
}
|
||||
|
||||
// 卡密渠道显隐:选中 card_pass 时隐藏套餐(.charge-box)、显示卡密输入盒。
|
||||
function applyVipMethodVisibility(root) {
|
||||
var pane = root.closest ? root.closest(".aksrt-vip-pane") : null;
|
||||
pane = pane || root;
|
||||
var value = selectedMethod(pane);
|
||||
var cardBox = pane.querySelector('[data-controller="payment_method"][data-value="card_pass"]');
|
||||
if (cardBox) cardBox.style.display = value === "card_pass" ? "" : "none";
|
||||
pane.querySelectorAll(".charge-box").forEach(function (el) {
|
||||
el.style.display = value === "card_pass" ? "none" : "";
|
||||
});
|
||||
}
|
||||
|
||||
function renderPointsModal(body, view) {
|
||||
view = view || {};
|
||||
@@ -248,6 +285,7 @@
|
||||
var levels = levelMap(view.levels);
|
||||
var groups = Array.isArray(catalog.level_packages) ? catalog.level_packages : [];
|
||||
var methods = Array.isArray(view.payment_methods) ? view.payment_methods : [];
|
||||
var cardPass = view.card_pass && view.card_pass.enabled ? view.card_pass : null;
|
||||
var allowed = view.allowed_actions || {};
|
||||
var reasons = view.action_reasons || {};
|
||||
var modal = node("div", "box-body payvip-modal");
|
||||
@@ -354,6 +392,11 @@
|
||||
append(pointsWrap, pointsLink);
|
||||
append(modal, pointsWrap);
|
||||
}
|
||||
|
||||
// 卡密渠道初始显隐(选中 card_pass 时隐藏套餐、显示卡密输入盒)。
|
||||
modal.querySelectorAll(".aksrt-vip-pane").forEach(function (pane) {
|
||||
applyVipMethodVisibility(pane);
|
||||
});
|
||||
append(body, modal);
|
||||
}
|
||||
|
||||
@@ -444,9 +487,62 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 卡密兑换会员(type=vip):直兑,不创建支付订单。
|
||||
function redeemVipCardPass(pane, button) {
|
||||
var pwEl = pane.querySelector('input[name="card_pass[password]"]');
|
||||
var cardEl = pane.querySelector('input[name="card_pass[card]"]');
|
||||
var password = pwEl ? String(pwEl.value || "").trim() : "";
|
||||
if (!password) {
|
||||
notyf("请输入卡密", "danger");
|
||||
if (pwEl) pwEl.focus();
|
||||
return;
|
||||
}
|
||||
if (!button || button.disabled) return;
|
||||
var request = window.AksrtRequest;
|
||||
if (!request || typeof request.request !== "function") {
|
||||
notyf("会员兑换暂不可用", "danger");
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
button.classList.add("is-loading");
|
||||
notyf("正在兑换会员…", "load", "", "aksrt-vip-purchase-toast");
|
||||
var key = typeof request.createIdempotencyKey === "function" ? request.createIdempotencyKey() : "";
|
||||
request.request("/pay/card-pass/redeem", {
|
||||
method: "POST",
|
||||
headers: key ? { "Idempotency-Key": key } : {},
|
||||
body: JSON.stringify({
|
||||
type: "vip",
|
||||
card: cardEl ? String(cardEl.value || "").trim() : "",
|
||||
password: password,
|
||||
}),
|
||||
}).then(function (response) {
|
||||
button.disabled = false;
|
||||
button.classList.remove("is-loading");
|
||||
if (!response.ok || (response.json && response.json.code && !response.json.success)) {
|
||||
notyf((response.json && response.json.message) || "兑换失败", "danger", 5, "aksrt-vip-purchase-toast");
|
||||
return;
|
||||
}
|
||||
var data = response.data || (response.json && response.json.data) || {};
|
||||
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
|
||||
window.AksrtModalRuntime.invalidate(["vip", "orders"]);
|
||||
}
|
||||
notyf(data.message || "兑换成功,正在刷新…", "success", 5, "aksrt-vip-purchase-toast");
|
||||
window.setTimeout(function () { window.location.reload(); }, 800);
|
||||
}).catch(function () {
|
||||
button.disabled = false;
|
||||
button.classList.remove("is-loading");
|
||||
notyf("网络错误,请重试", "danger", 5, "aksrt-vip-purchase-toast");
|
||||
});
|
||||
}
|
||||
|
||||
function bindModalUi(root) {
|
||||
if (!root || root.dataset.aksrtVipBound === "1") return;
|
||||
root.dataset.aksrtVipBound = "1";
|
||||
root.addEventListener("change", function (event) {
|
||||
var input = event.target.closest ? event.target.closest('input[name="aksrt_vip_pay_method"]') : null;
|
||||
if (!input) return;
|
||||
applyVipMethodVisibility(input);
|
||||
});
|
||||
root.addEventListener("click", function (event) {
|
||||
var tab = event.target.closest("[data-vip-tab]");
|
||||
if (tab) {
|
||||
|
||||
@@ -48,7 +48,7 @@ $currency = (string) ($currency_name ?? __('积分', 'aksrt'));
|
||||
<button type="button" class="but c-green mr6 hollow" data-aksrt-transfer-open="points" data-aksrt-transfer-min="<?php echo esc_attr((string) $points_transfer_min); ?>"><?php esc_html_e('转账', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
<?php if ($points_exchange_on) : ?>
|
||||
<button type="button" class="but c-green hollow" data-aksrt-points-exchange-open><?php esc_html_e('购买积分', 'aksrt'); ?></button>
|
||||
<button type="button" class="but c-green hollow" data-aksrt-points-pay-open><?php esc_html_e('购买积分', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -56,25 +56,106 @@ $currency = (string) ($currency_name ?? __('积分', 'aksrt'));
|
||||
</div>
|
||||
|
||||
<?php if ($points_exchange_on) :
|
||||
// 购买积分弹窗 — Zibll zibpay_get_points_pay_modal 1:1(商品盒 / 自定义 / 支付方式含卡密 / 立即支付)。
|
||||
$pb_rate = max(1, (int) ($points_exchange['rate'] ?? 100));
|
||||
$pb_min_points = max(1, (int) ($points_exchange['min_points'] ?? 100));
|
||||
$pb_daily_max_points = max(1, (int) ($points_exchange['daily_max_points'] ?? 100000));
|
||||
$points_packages = class_exists('\AKSRT\Credits\BalanceService')
|
||||
? \AKSRT\Credits\BalanceService::get_instance()->parse_points_packages((string) ($points_exchange['products_raw'] ?? ''))
|
||||
: [];
|
||||
// 卡密兑换积分渠道(后台 启用卡密兑换积分功能)。
|
||||
$points_card_pass = ['enabled' => false, 'desc' => '', 'only_password' => false];
|
||||
if (class_exists('\AKSRT\Payment\ChargeCard')) {
|
||||
$points_card_opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
||||
$points_card_pass = is_array($points_card_opts['credits'] ?? null) ? $points_card_opts['credits'] : $points_card_pass;
|
||||
}
|
||||
$points_methods = [['id' => 'balance', 'name' => __('余额', 'aksrt')]];
|
||||
if (!empty($points_card_pass['enabled'])) {
|
||||
$points_methods[] = ['id' => 'card_pass', 'name' => __('卡密', 'aksrt')];
|
||||
}
|
||||
$points_custom_limit_html = sprintf(__('最低购买%d积分,最高购买%d积分', 'aksrt'), $pb_min_points, $pb_daily_max_points);
|
||||
$points_gateway = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_payment_gateway_settings() : [];
|
||||
$points_mark = (string) ($points_gateway['currency']['mark'] ?? '¥');
|
||||
$points_default_product = $points_packages ? (string) $points_packages[0]['key'] : 'custom';
|
||||
?>
|
||||
<div class="uc-modal" id="aksrt-points-exchange-modal" hidden data-aksrt-points-exchange-modal>
|
||||
<div class="uc-modal__overlay" data-aksrt-points-exchange-close></div>
|
||||
<div class="uc-modal__dialog" role="dialog" aria-modal="true">
|
||||
<button type="button" class="uc-modal__close" data-aksrt-points-exchange-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
|
||||
<h3 class="uc-modal__title"><i class="fa fas fa-money-bill mr6" aria-hidden="true"></i><?php esc_html_e('购买积分', 'aksrt'); ?></h3>
|
||||
<?php if (!empty($points_exchange['desc'])) : ?>
|
||||
<div class="uc-modal__desc muted-box em09"><?php echo esc_html((string) $points_exchange['desc']); ?></div>
|
||||
<div class="modal flex jc fade" id="aksrt-points-pay-modal" tabindex="-1" role="dialog" data-aksrt-points-pay-modal>
|
||||
<div class="modal-dialog modal-mini full-sm" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<div class="mb10 touch"><button type="button" class="close" data-dismiss="modal" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><svg class="ic-close" aria-hidden="true"><use xlink:href="#icon-close"></use></svg></button><b class="modal-title flex ac"><span class="mr6 em14"><i class="fa fas fa-coins" aria-hidden="true"></i></span><?php esc_html_e('购买积分', 'aksrt'); ?></b></div>
|
||||
<form class="balance-charge-form mini-scrollbar scroll-y max-vh7" data-aksrt-points-pay-form>
|
||||
<div class="charge-box mb20">
|
||||
<?php if ($points_packages) : ?>
|
||||
<div class="muted-color mb6"><?php esc_html_e('请选择需购买的积分', 'aksrt'); ?></div>
|
||||
<?php foreach ($points_packages as $pidx => $ppkg) : ?>
|
||||
<div class="zib-widget vip-product relative product-box<?php echo $pidx === 0 ? ' active' : ''; ?>" data-for="points_product" data-value="<?php echo esc_attr((string) $ppkg['key']); ?>">
|
||||
<?php if (!empty($ppkg['tag'])) : ?>
|
||||
<div class="abs-right vip-tag badg jb-yellow"><?php echo esc_html((string) $ppkg['tag']); ?></div>
|
||||
<?php endif; ?>
|
||||
<form data-aksrt-points-exchange-form>
|
||||
<label class="muted-color em09"><?php esc_html_e('兑换余额', 'aksrt'); ?></label>
|
||||
<input type="number" class="uc-card-pass__input" name="amount" min="0.01" step="0.01" inputmode="decimal" data-aksrt-points-exchange-amount data-aksrt-points-exchange-rate="<?php echo esc_attr((string) $pb_rate); ?>">
|
||||
<p class="muted-2-color em09 mt6"><?php printf(esc_html__('1 余额 = %d 积分;单笔至少 %d 积分,每日最多 %d 积分。', 'aksrt'), $pb_rate, $pb_min_points, $pb_daily_max_points); ?></p>
|
||||
<p class="muted-2-color em09 mt6" data-aksrt-points-exchange-preview></p>
|
||||
<button type="submit" class="but jb-blue btn-block mt10"><?php esc_html_e('立即购买', 'aksrt'); ?></button>
|
||||
<div class="em14"><span class="px12"><i class="fa fas fa-coins" aria-hidden="true"></i></span><?php echo esc_html(aksrt_format_points((int) $ppkg['points'])); ?></div>
|
||||
<div class="c-red"><span class="px12"><?php echo esc_html($points_mark); ?></span><span class="em12"><?php echo esc_html((string) $ppkg['pay_price']); ?></span></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<div class="muted-color mt20 mb6"><?php printf(esc_html__('自定义积分数量(1%1$s=%2$s积分)', 'aksrt'), esc_html($points_mark), esc_html((string) $pb_rate)); ?></div>
|
||||
<div data-for="points_product" data-value="custom">
|
||||
<div class="relative flex ab">
|
||||
<span class="ml6 mr10 muted-color shrink0"><i class="fa fas fa-coins" aria-hidden="true"></i></span>
|
||||
<input class="line-form-input em16 key-color" style="padding: 1px;" name="points_custom" type="number" limit-min="<?php echo esc_attr((string) $pb_min_points); ?>" limit-max="<?php echo esc_attr((string) $pb_daily_max_points); ?>" placeholder="<?php echo esc_attr($pb_min_points . ' ~ ' . $pb_daily_max_points); ?>">
|
||||
<i class="line-form-line"></i>
|
||||
</div>
|
||||
<div class="muted-2-color em09 mt6"><?php echo esc_html($points_custom_limit_html); ?></div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="muted-color mb6"><?php esc_html_e('请输入需购买的积分数额', 'aksrt'); ?></div>
|
||||
<div data-for="points_product" data-value="custom">
|
||||
<div class="relative flex ab">
|
||||
<span class="ml6 mr10 muted-color shrink0"><i class="fa fas fa-coins" aria-hidden="true"></i></span>
|
||||
<input class="line-form-input em16 key-color" style="padding: 1px;" name="points_custom" type="number" limit-min="<?php echo esc_attr((string) $pb_min_points); ?>" limit-max="<?php echo esc_attr((string) $pb_daily_max_points); ?>" placeholder="<?php echo esc_attr($pb_min_points . ' ~ ' . $pb_daily_max_points); ?>">
|
||||
<i class="line-form-line"></i>
|
||||
</div>
|
||||
<div class="muted-2-color em09 mt6"><?php echo esc_html($points_custom_limit_html); ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!empty($points_exchange['desc'])) : ?>
|
||||
<div class="muted-box muted-2-color padding-10 mb20 em09"><?php echo esc_html((string) $points_exchange['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="dependency-box">
|
||||
<?php if (count($points_methods) > 1) : ?>
|
||||
<div class="muted-2-color em09 mb6"><?php esc_html_e('请选择支付方式', 'aksrt'); ?></div>
|
||||
<div class="flex mb10">
|
||||
<?php foreach ($points_methods as $pmi => $pm) :
|
||||
$pm_id = (string) ($pm['id'] ?? '');
|
||||
$pm_logo = 'card_pass' === $pm_id ? 'pay-card-pass-logo.svg' : 'pay-balance-logo.svg';
|
||||
?>
|
||||
<div class="flex jc hh payment-method-radio hollow-radio flex-auto pointer<?php echo $pmi === 0 ? ' active' : ''; ?>" data-for="payment_method" data-value="<?php echo esc_attr($pm_id); ?>">
|
||||
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/img/' . $pm_logo); ?>" alt="<?php echo esc_attr($pm_id); ?>-logo">
|
||||
<div><?php echo esc_html((string) ($pm['name'] ?? $pm_id)); ?></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($points_card_pass['enabled'])) : ?>
|
||||
<div class="mb10 padding-h10 padding-w6" data-controller="payment_method" data-condition="==" data-value="card_pass" style="display: none;">
|
||||
<?php if (!empty($points_card_pass['desc'])) : ?>
|
||||
<div class="muted-box muted-2-color padding-10 mb10 em09"><?php echo esc_html((string) $points_card_pass['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="muted-2-color em09 mb6"><?php echo !empty($points_card_pass['only_password']) ? esc_html__('请输入卡密', 'aksrt') : esc_html__('请输入卡号和密码', 'aksrt'); ?></div>
|
||||
<?php if (empty($points_card_pass['only_password'])) : ?>
|
||||
<div class="mb6"><input type="input" class="form-control" name="card_pass[card]" placeholder="<?php esc_attr_e('卡号', 'aksrt'); ?>" value=""></div>
|
||||
<?php endif; ?>
|
||||
<div class="">
|
||||
<input type="input" class="form-control" name="card_pass[password]" placeholder="<?php esc_attr_e('卡密', 'aksrt'); ?>" value="">
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="points_product" value="<?php echo esc_attr($points_default_product); ?>">
|
||||
<input type="hidden" name="payment_method" value="<?php echo esc_attr((string) ($points_methods[0]['id'] ?? '')); ?>">
|
||||
<button type="submit" class="mt6 but jb-red initiate-pay btn-block radius"><?php esc_html_e('立即支付', 'aksrt'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -45,12 +45,12 @@ if ($withdraw_on && class_exists('\AKSRT\Payment\Withdrawal')) {
|
||||
$withdraw_pending_hold = $wd_svc->sum_pending_hold((int) ($user_id ?? 0));
|
||||
$withdraw_usage = $wd_svc->daily_usage((int) ($user_id ?? 0), $withdraw_settings);
|
||||
}
|
||||
// 卡密兑换总开关(后台 余额充值 → 卡密兑换 → 启用卡密兑换功能),
|
||||
// 通用弹窗支持余额 / 会员 / 积分三类卡密,类型由后端按卡密自动识别。
|
||||
$card_pass_redeem = ['enabled' => false, 'desc' => ''];
|
||||
// 卡密支付渠道(后台 余额充值 → 卡密兑换 → 启用卡密兑换余额功能):
|
||||
// 兑换入口收敛到充值弹窗的支付方式,不再有独立入口。
|
||||
$card_pass_redeem = ['enabled' => false, 'desc' => '', 'only_password' => false];
|
||||
if (class_exists('\AKSRT\Payment\ChargeCard')) {
|
||||
$opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
||||
$card_pass_redeem = is_array($opts['balance'] ?? null) ? $opts['balance'] : $card_pass_redeem;
|
||||
$card_opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
||||
$card_pass_redeem = is_array($card_opts['balance'] ?? null) ? $card_opts['balance'] : $card_pass_redeem;
|
||||
}
|
||||
|
||||
$charge_view = [];
|
||||
@@ -92,43 +92,14 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
<button type="button" class="but b-blue-2" data-aksrt-charge-open><?php esc_html_e('充值', 'aksrt'); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($withdraw_on || !empty($card_pass_redeem['enabled'])) : ?>
|
||||
<div class="uc-asset-card__foot muted-2-color em09 mt6 flex jsb ac">
|
||||
<?php if ($withdraw_on) : ?>
|
||||
<div class="uc-asset-card__foot muted-2-color em09 mt6 flex jsb ac">
|
||||
<span><?php printf(esc_html__('冻结中 %s', 'aksrt'), esc_html($normalize_balance($withdraw_pending_hold)->formatted())); ?></span>
|
||||
<?php else : ?>
|
||||
<span></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($card_pass_redeem['enabled'])) : ?>
|
||||
<button type="button" class="uc-asset-card__head-action muted-color px12" data-aksrt-card-pass-open>
|
||||
<?php esc_html_e('卡密兑换', 'aksrt'); ?>
|
||||
<i class="fa fas fa-angle-right em12 ml3" aria-hidden="true"></i>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($card_pass_redeem['enabled'])) : ?>
|
||||
<div class="uc-modal" id="aksrt-card-pass-modal" hidden data-aksrt-card-pass-modal data-aksrt-card-pass="">
|
||||
<div class="uc-modal__overlay" data-aksrt-card-pass-close></div>
|
||||
<div class="uc-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="aksrt-card-pass-title">
|
||||
<button type="button" class="uc-modal__close" data-aksrt-card-pass-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
|
||||
<h3 id="aksrt-card-pass-title" class="uc-modal__title"><i class="fa fas fa-ticket-alt mr6" aria-hidden="true"></i><?php esc_html_e('卡密兑换', 'aksrt'); ?></h3>
|
||||
<?php if (!empty($card_pass_redeem['desc'])) : ?>
|
||||
<div class="uc-modal__desc muted-box em09"><?php echo esc_html((string) $card_pass_redeem['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<input type="text" class="uc-card-pass__input" name="aksrt_card_no" data-aksrt-card-no autocomplete="off" placeholder="<?php esc_attr_e('请输入卡号(选填)', 'aksrt'); ?>">
|
||||
<input type="text" class="uc-card-pass__input" name="aksrt_card_password" data-aksrt-card-password autocomplete="off" placeholder="<?php esc_attr_e('请输入卡密', 'aksrt'); ?>">
|
||||
<div class="uc-card-pass-actions">
|
||||
<button type="button" class="uc-card-pass__btn" data-aksrt-card-redeem>
|
||||
<?php esc_html_e('立即兑换', 'aksrt'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Charge modal — Zibll balance-charge modal 1:1 (refresh_modal shell + zibpay_get_balance_charge_modal) -->
|
||||
<?php
|
||||
$charge_method_logos = [
|
||||
@@ -139,9 +110,13 @@ $charge_method_logos = [
|
||||
'epay_wxpay' => 'pay-wechat-logo.svg',
|
||||
'paypal' => 'pay-paypal-logo.svg',
|
||||
'stripe' => 'pay-stripe-logo.svg',
|
||||
'card_pass' => 'pay-card-pass-logo.svg',
|
||||
];
|
||||
$charge_img_uri = get_template_directory_uri() . '/assets/img/';
|
||||
$charge_default_product = $packages ? (string) $packages[0]['key'] : 'custom';
|
||||
// 仅卡密可用时隐藏金额选择(参考主题:卡密决定充值金额)。
|
||||
$charge_card_only = count($methods) === 1 && (string) ($methods[0]['id'] ?? '') === 'card_pass';
|
||||
$charge_card_in_methods = count($methods) > 0 && $methods[count($methods) - 1]['id'] === 'card_pass';
|
||||
$charge_mark_symbol = !in_array($mark, ['', '元'], true);
|
||||
$charge_mark_html = $charge_mark_symbol
|
||||
? '<span class="px12">' . esc_html($mark) . '</span>'
|
||||
@@ -170,6 +145,7 @@ $charge_custom_block = static function () use ($mark, $charge_mark_html, $charge
|
||||
<div class="modal-body">
|
||||
<div class="mb10 touch"><button type="button" class="close" data-dismiss="modal" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><svg class="ic-close" aria-hidden="true"><use xlink:href="#icon-close"></use></svg></button><b class="modal-title flex ac"><span class="mr6 em14"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-money-color-2"></use></svg></span><?php esc_html_e('余额充值', 'aksrt'); ?></b></div>
|
||||
<form class="balance-charge-form mini-scrollbar scroll-y max-vh7" data-aksrt-charge-form>
|
||||
<?php if (!$charge_card_only) : ?>
|
||||
<?php if ($packages) : ?>
|
||||
<div class="charge-box mb20">
|
||||
<div class="muted-color mb6"><?php esc_html_e('请选择充值金额', 'aksrt'); ?></div>
|
||||
@@ -197,6 +173,7 @@ $charge_custom_block = static function () use ($mark, $charge_mark_html, $charge
|
||||
<?php $charge_custom_block(); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($charge_view['desc'])) : ?>
|
||||
<div class="muted-box muted-2-color padding-10 mb10 em09"><?php echo esc_html((string) $charge_view['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
@@ -217,6 +194,20 @@ $charge_custom_block = static function () use ($mark, $charge_mark_html, $charge
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($charge_card_in_methods) : ?>
|
||||
<div class="mb10 padding-h10 padding-w6" data-controller="payment_method" data-condition="==" data-value="card_pass"<?php echo !$charge_card_only ? ' style="display: none;"' : ''; ?>>
|
||||
<?php if (!empty($card_pass_redeem['desc'])) : ?>
|
||||
<div class="muted-box muted-2-color padding-10 mb10 em09"><?php echo esc_html((string) $card_pass_redeem['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="muted-2-color em09 mb6"><?php echo !empty($card_pass_redeem['only_password']) ? esc_html__('请输入卡密', 'aksrt') : esc_html__('请输入卡号和密码', 'aksrt'); ?></div>
|
||||
<?php if (empty($card_pass_redeem['only_password'])) : ?>
|
||||
<div class="mb6"><input type="input" class="form-control" name="card_pass[card]" placeholder="<?php esc_attr_e('卡号', 'aksrt'); ?>" value=""></div>
|
||||
<?php endif; ?>
|
||||
<div class="">
|
||||
<input type="input" class="form-control" name="card_pass[password]" placeholder="<?php esc_attr_e('卡密', 'aksrt'); ?>" value="">
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="balance_product" value="<?php echo esc_attr($charge_default_product); ?>">
|
||||
<input type="hidden" name="payment_method" value="<?php echo esc_attr((string) ($methods[0]['id'] ?? '')); ?>">
|
||||
<?php if ($methods) : ?>
|
||||
|
||||
@@ -155,9 +155,15 @@ class SchemaPayment {
|
||||
['key' => 'pay_balance_product_custom_limit', 'label' => '自定义充值金额上限', 'type' => 'number', 'default' => 9999, 'min' => 1, 'max' => 99999, 'dependsOn' => ['key' => 'pay_balance_product_custom_s', 'value' => true]],
|
||||
]],
|
||||
['key' => 'pass-charge', 'title' => '卡密兑换', 'fields' => [
|
||||
['key' => 'pay_balance_pass_charge_s', 'label' => '启用卡密兑换功能', 'type' => 'switch', 'default' => false, 'help' => '开启后用户中心余额卡片展示通用「卡密兑换」入口,支持余额 / 会员 / 积分卡密,类型按卡密自动识别'],
|
||||
['key' => 'pay_balance_pass_charge_desc', 'label' => '卡密兑换说明', 'type' => 'textarea', 'default' => '', 'rows' => 2, 'dependsOn' => ['key' => 'pay_balance_pass_charge_s', 'value' => true], 'help' => '用户使用卡密兑换时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码'],
|
||||
['key' => 'pay_balance_pass_charge_only_password', 'label' => '单密码模式', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'pay_balance_pass_charge_s', 'value' => true], 'help' => '余额卡密仅需输入密码,不需要卡号'],
|
||||
['key' => 'pay_balance_pass_charge_s', 'label' => '启用卡密兑换余额功能', 'type' => 'switch', 'default' => false, 'help' => '开启后用户可在余额充值弹窗选择「卡密」渠道,使用卡密直接兑换余额'],
|
||||
['key' => 'pay_balance_pass_charge_desc', 'label' => '卡密兑换余额说明', 'type' => 'textarea', 'default' => '', 'rows' => 2, 'dependsOn' => ['key' => 'pay_balance_pass_charge_s', 'value' => true], 'help' => '用户使用卡密兑换余额时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码'],
|
||||
['key' => 'pay_balance_pass_charge_only_password', 'label' => '余额卡密单密码模式', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'pay_balance_pass_charge_s', 'value' => true], 'help' => '余额卡密仅需输入密码,不需要卡号'],
|
||||
['key' => 'points_pass_exchange_s', 'label' => '启用卡密兑换积分功能', 'type' => 'switch', 'default' => false, 'help' => '开启后用户可在购买积分弹窗选择「卡密」渠道,使用卡密直接兑换积分'],
|
||||
['key' => 'points_pass_exchange_desc', 'label' => '卡密兑换积分说明', 'type' => 'textarea', 'default' => '', 'rows' => 2, 'dependsOn' => ['key' => 'points_pass_exchange_s', 'value' => true], 'help' => '用户使用卡密兑换积分时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码'],
|
||||
['key' => 'points_pass_exchange_only_password', 'label' => '积分卡密单密码模式', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'points_pass_exchange_s', 'value' => true], 'help' => '积分卡密仅需输入密码,不需要卡号'],
|
||||
['key' => 'pay_vip_pass_charge_s', 'label' => '启用卡密兑换会员功能', 'type' => 'switch', 'default' => false, 'help' => '开启后用户可在会员购买/续费弹窗选择「卡密」渠道,使用会员卡密直接兑换会员'],
|
||||
['key' => 'pay_vip_pass_charge_desc', 'label' => '卡密兑换会员说明', 'type' => 'textarea', 'default' => '', 'rows' => 2, 'dependsOn' => ['key' => 'pay_vip_pass_charge_s', 'value' => true], 'help' => '用户使用卡密兑换会员时显示的内容,建议为提醒事项、兑换协议等,支持HTML代码'],
|
||||
['key' => 'pay_vip_pass_charge_only_password', 'label' => '会员卡密单密码模式', 'type' => 'switch', 'default' => true, 'dependsOn' => ['key' => 'pay_vip_pass_charge_s', 'value' => true], 'help' => '会员卡密仅需输入密码,不需要卡号'],
|
||||
]],
|
||||
['key' => 'points-exchange', 'title' => '余额兑换积分', 'fields' => [
|
||||
['key' => 'pay_balance_points_exchange_s', 'label' => '启用余额兑换积分', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'pay_balance_s', 'value' => true]],
|
||||
@@ -241,9 +247,6 @@ class SchemaPayment {
|
||||
]],
|
||||
]],
|
||||
]],
|
||||
['key' => 'pass-charge', 'title' => '会员卡密', 'fields' => [
|
||||
['key' => 'pay_vip_pass_charge_only_password', 'label' => '单密码模式', 'type' => 'switch', 'default' => true, 'help' => '会员卡密核销是否仅需卡密;关闭后,带卡号的会员卡必须同时输入卡号。会员/积分卡密无独立开关,统一受「余额充值 → 卡密兑换 → 启用卡密兑换功能」控制'],
|
||||
]],
|
||||
['key' => 'points-exchange', 'title' => '积分兑换会员', 'fields' => [
|
||||
['key' => 'pay_vip_points_exchange_s', 'label' => '启用积分兑换', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'payment_vip_points_packages', 'label' => '兑换套餐', 'type' => 'textarea', 'default' => "1|500|30|积分月卡\n1|5000|0|积分永久", 'dependsOn' => ['key' => 'pay_vip_points_exchange_s', 'value' => true], 'help' => '每行:等级|积分|天数|标题(天数 0=永久;普通用户可开通,已有会员可续费同等级或升级更高等级)'],
|
||||
|
||||
@@ -64,6 +64,9 @@ trait VipServiceModal {
|
||||
}
|
||||
$points_exchange = is_array($catalog['points_exchange'] ?? null) ? $catalog['points_exchange'] : [];
|
||||
$methods = is_array($catalog['payment_methods'] ?? null) ? $catalog['payment_methods'] : [];
|
||||
$card_pass = is_array($catalog['card_pass'] ?? null)
|
||||
? array_merge(['enabled' => false, 'desc' => '', 'only_password' => false], $catalog['card_pass'])
|
||||
: ['enabled' => false, 'desc' => '', 'only_password' => false];
|
||||
$no_payment_method = $methods === [];
|
||||
$action_reasons = [
|
||||
'purchase' => $no_payment_method
|
||||
@@ -124,6 +127,7 @@ trait VipServiceModal {
|
||||
],
|
||||
'levels' => $level_view,
|
||||
'payment_methods' => $methods,
|
||||
'card_pass' => $card_pass,
|
||||
'allowed_actions' => [
|
||||
'purchase' => $package_ids !== [] && $methods !== [],
|
||||
'renew' => $has_renew && $methods !== [],
|
||||
|
||||
@@ -517,12 +517,12 @@ trait VipServicePackages {
|
||||
* @return array<int, array{id:string,name:string}>
|
||||
*/
|
||||
private function available_payment_methods(): array {
|
||||
if (function_exists('aksrt_list_cash_payment_methods')) {
|
||||
return aksrt_list_cash_payment_methods(true);
|
||||
}
|
||||
$methods = [];
|
||||
if (function_exists('aksrt_list_cash_payment_methods')) {
|
||||
$methods = aksrt_list_cash_payment_methods(true);
|
||||
} else {
|
||||
if (!class_exists('\AKSRT\Payment\Gateway')) {
|
||||
return $methods;
|
||||
return [];
|
||||
}
|
||||
$gw = \AKSRT\Payment\Gateway::get_instance();
|
||||
foreach (['balance', 'alipay', 'wechatpay', 'paypal', 'stripe', 'epay_alipay', 'epay_wxpay'] as $id) {
|
||||
@@ -538,9 +538,31 @@ trait VipServicePackages {
|
||||
'name' => method_exists($g, 'get_name') ? (string) $g->get_name() : $id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 卡密兑换会员渠道(后台 会员购买 → 启用卡密兑换会员功能):
|
||||
// 提交走 /pay/card-pass/redeem type=vip,不创建支付订单。
|
||||
$card_pass = $this->vip_card_pass_context();
|
||||
if (!empty($card_pass['enabled'])) {
|
||||
$methods[] = ['id' => 'card_pass', 'name' => __('卡密', 'aksrt')];
|
||||
}
|
||||
return $methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡密兑换会员渠道上下文(ChargeCard vip 公开选项)。
|
||||
*
|
||||
* @return array{enabled:bool,desc:string,only_password:bool}
|
||||
*/
|
||||
private function vip_card_pass_context(): array {
|
||||
$empty = ['enabled' => false, 'desc' => '', 'only_password' => false];
|
||||
if (!class_exists('\AKSRT\Payment\ChargeCard')) {
|
||||
return $empty;
|
||||
}
|
||||
$opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
||||
return is_array($opts['vip'] ?? null) ? array_merge($empty, $opts['vip']) : $empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function format_cash_label(string $amount): string {
|
||||
|
||||
@@ -260,6 +260,7 @@ trait VipServicePurchase {
|
||||
'packages' => $points_packages,
|
||||
],
|
||||
'payment_methods' => $methods,
|
||||
'card_pass' => $this->vip_card_pass_context(),
|
||||
'vip_url' => function_exists('aksrt_get_user_center_tab_url')
|
||||
? aksrt_get_user_center_tab_url('credits')
|
||||
: (function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/')),
|
||||
@@ -353,6 +354,10 @@ trait VipServicePurchase {
|
||||
if ($payment_method === '') {
|
||||
$payment_method = 'balance';
|
||||
}
|
||||
// 卡密兑换会员走 /pay/card-pass/redeem(type=vip)直兑,不创建支付订单。
|
||||
if ($payment_method === 'card_pass') {
|
||||
return new \WP_Error('aksrt_card_pass_redeem_required', __('卡密兑换会员请直接输入卡密提交', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$note = wp_json_encode([
|
||||
'vip_pay' => 1,
|
||||
|
||||
@@ -146,6 +146,21 @@ trait BalanceServiceCharge {
|
||||
$methods[] = is_array($m) ? $m : ['id' => $id, 'name' => $id];
|
||||
}
|
||||
}
|
||||
// 卡密支付渠道:受「启用卡密兑换余额功能」开关控制(开关内部已含收款接口主开关)。
|
||||
$pass_charge = is_array($cfg['pass_charge'] ?? null) ? $cfg['pass_charge'] : [];
|
||||
$card_pass_on = false;
|
||||
if (class_exists('\AKSRT\Payment\ChargeCard')) {
|
||||
$card_opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
||||
$card_pass_on = !empty($card_opts['balance']['enabled']);
|
||||
$pass_charge = [
|
||||
'balance' => is_array($card_opts['balance'] ?? null) ? $card_opts['balance'] : $pass_charge,
|
||||
'credits' => is_array($card_opts['credits'] ?? null) ? $card_opts['credits'] : [],
|
||||
'vip' => is_array($card_opts['vip'] ?? null) ? $card_opts['vip'] : [],
|
||||
];
|
||||
}
|
||||
if ($card_pass_on) {
|
||||
$methods[] = ['id' => 'card_pass', 'name' => __('卡密', 'aksrt')];
|
||||
}
|
||||
return [
|
||||
'enabled' => !empty($cfg['enabled']),
|
||||
'desc' => (string) ($cfg['desc'] ?? ''),
|
||||
@@ -160,7 +175,7 @@ trait BalanceServiceCharge {
|
||||
'service_charge' => (int) ($cfg['transfer']['service_charge'] ?? 0),
|
||||
'desc' => (string) ($cfg['transfer']['desc'] ?? ''),
|
||||
],
|
||||
'pass_charge' => is_array($cfg['pass_charge'] ?? null) ? $cfg['pass_charge'] : [],
|
||||
'pass_charge' => $pass_charge,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -206,6 +221,48 @@ trait BalanceServiceCharge {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 积分商品行解析("积分|支付|标签",参考主题 pay_points_product 同款结构)。
|
||||
*
|
||||
* @return array<int,array{key:string,points:int,pay_price:string,title:string,tag:string}>
|
||||
*/
|
||||
public function parse_points_packages(string $raw): array {
|
||||
$out = [];
|
||||
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
|
||||
$i = 0;
|
||||
foreach ($lines as $line) {
|
||||
$line = trim((string) $line);
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
$parts = array_map('trim', explode('|', $line));
|
||||
if (count($parts) < 2) {
|
||||
continue;
|
||||
}
|
||||
$points = (int) $parts[0];
|
||||
try {
|
||||
$pay = \AKSRT\Ledger\AssetAmount::balance((string) $parts[1]);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
continue;
|
||||
}
|
||||
if ($points <= 0 || $pay->minor() <= 0) {
|
||||
continue;
|
||||
}
|
||||
$title = $parts[2] ?? '';
|
||||
$out[] = [
|
||||
'key' => (string) $i,
|
||||
'points' => $points,
|
||||
'pay_price' => $pay->decimal(),
|
||||
'title' => $title !== '' ? $title : sprintf(__('购买 %d 积分', 'aksrt'), $points),
|
||||
'tag' => $title,
|
||||
];
|
||||
$i++;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|\WP_Error
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,10 @@ trait BalanceServiceRest {
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => [$this, 'rest_exchange_balance_for_points'],
|
||||
'permission_callback' => [$this, 'check_asset_rest'],
|
||||
'args' => ['amount' => ['type' => 'string', 'required' => true, 'pattern' => '^(0|[1-9]\\d*)(?:\\.\\d{1,2})?$']],
|
||||
'args' => [
|
||||
'product' => ['type' => 'string', 'default' => 'custom', 'maxLength' => 30],
|
||||
'custom' => ['type' => 'string', 'default' => '0', 'pattern' => '^\d{1,9}$'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -311,7 +314,10 @@ trait BalanceServiceRest {
|
||||
|
||||
|
||||
/**
|
||||
* Exchange integer cash-wallet balance for points.
|
||||
* Buy points with cash-wallet balance (积分购买弹窗 · 余额支付).
|
||||
*
|
||||
* Body: { product: 'custom'|<package_key>, custom?: <points int> }
|
||||
* 自定义按汇率折算支付金额;商品按配置销售金额支付(参考主题同款语义)。
|
||||
*/
|
||||
public function rest_exchange_balance_for_points(\WP_REST_Request $request) {
|
||||
if (!$this->balance_feature_enabled()) {
|
||||
@@ -329,32 +335,54 @@ trait BalanceServiceRest {
|
||||
if (!is_array($params)) {
|
||||
$params = $request->get_params();
|
||||
}
|
||||
$raw_amount = $params['amount'] ?? '';
|
||||
try {
|
||||
$amount = \AKSRT\Ledger\AssetAmount::balance(is_string($raw_amount) ? $raw_amount : '');
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return new \WP_Error('aksrt_exchange_amount', __('兑换余额格式无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if ($amount->minor() <= 0) {
|
||||
return new \WP_Error('aksrt_exchange_amount', __('兑换余额必须大于零', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$rate = max(1, (int) ($exchange['rate'] ?? 100));
|
||||
$daily_max = max(1, (int) ($exchange['daily_max_points'] ?? 100000));
|
||||
$scaled = $this->multiply_non_negative($amount->minor(), $rate);
|
||||
if (is_wp_error($scaled)) {
|
||||
return $scaled;
|
||||
$product_key = sanitize_key((string) ($params['product'] ?? 'custom'));
|
||||
$points = 0;
|
||||
$pay_minor = 0;
|
||||
$product_title = '';
|
||||
if ($product_key !== '' && $product_key !== 'custom') {
|
||||
$found = null;
|
||||
foreach ($this->parse_points_packages((string) ($exchange['products_raw'] ?? '')) as $pkg) {
|
||||
if ((string) ($pkg['key'] ?? '') === $product_key) {
|
||||
$found = $pkg;
|
||||
break;
|
||||
}
|
||||
if ($scaled % 100 !== 0) {
|
||||
return new \WP_Error('aksrt_exchange_precision', __('该金额无法兑换为整数积分', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$points = intdiv($scaled, 100);
|
||||
if (!$found) {
|
||||
return new \WP_Error('aksrt_exchange_product', __('积分商品无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$points = (int) $found['points'];
|
||||
try {
|
||||
$pay_minor = \AKSRT\Ledger\AssetAmount::balance((string) $found['pay_price'])->minor();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$pay_minor = 0;
|
||||
}
|
||||
$product_title = (string) $found['title'];
|
||||
} else {
|
||||
$product_key = 'custom';
|
||||
$points = absint((string) ($params['custom'] ?? '0'));
|
||||
$min_points = max(1, (int) ($exchange['min_points'] ?? 100));
|
||||
if ($points <= 0) {
|
||||
return new \WP_Error('aksrt_exchange_amount', __('请输入需购买的积分数额', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if ($points < $min_points) {
|
||||
return new \WP_Error('aksrt_exchange_min', sprintf(__('最低购买%d积分', 'aksrt'), $min_points), ['status' => 400]);
|
||||
}
|
||||
// 自定义按汇率折算支付金额(参考主题语义:积分 * 100 / 汇率 后四舍五入)。
|
||||
// 纯整数实现:intdiv(2a + b, 2b) 等价于 a / b 四舍五入,避免浮点。
|
||||
$pay_minor = intdiv($points * 200 + $rate, $rate * 2);
|
||||
$product_title = sprintf(__('购买 %d 积分', 'aksrt'), $points);
|
||||
}
|
||||
if ($points <= 0) {
|
||||
return new \WP_Error('aksrt_exchange_product', __('积分商品无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if ($pay_minor <= 0) {
|
||||
return new \WP_Error('aksrt_exchange_precision', __('支付金额无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if ($points > $daily_max) {
|
||||
return new \WP_Error('aksrt_exchange_daily_limit', sprintf(__('今日购买积分上限为 %d', 'aksrt'), $daily_max), ['status' => 400]);
|
||||
}
|
||||
$min_points = max(1, (int) ($exchange['min_points'] ?? 100));
|
||||
if ($points < $min_points) {
|
||||
return new \WP_Error('aksrt_exchange_min', sprintf(__('单笔至少购买 %d 积分', 'aksrt'), $min_points), ['status' => 400]);
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
$operation_key = \AKSRT\Ledger\OperationKey::from_request($request, 'points-exchange', $user_id);
|
||||
if (is_wp_error($operation_key)) {
|
||||
@@ -376,10 +404,12 @@ trait BalanceServiceRest {
|
||||
if (!class_exists('\\AKSRT\\Payment\\OrderRepository')) {
|
||||
return new \WP_Error('aksrt_order_unavailable', __('订单服务不可用', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$pay_decimal = \AKSRT\Ledger\AssetAmount::decimal_from_minor($pay_minor);
|
||||
$note = wp_json_encode([
|
||||
'points_exchange' => 1,
|
||||
'points' => $points,
|
||||
'product_title' => sprintf(__('购买 %d 积分', 'aksrt'), $points),
|
||||
'product' => $product_key,
|
||||
'product_title' => $product_title,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
$repo = \AKSRT\Payment\OrderRepository::get_instance();
|
||||
$existing_order = $repo->get_by_request_key($operation_key);
|
||||
@@ -389,11 +419,11 @@ trait BalanceServiceRest {
|
||||
$existing_meta = is_array($existing_meta) ? $existing_meta : [];
|
||||
if ((int) ($existing_order['user_id'] ?? 0) !== $user_id
|
||||
|| sanitize_key((string) ($existing_order['product_type'] ?? '')) !== \AKSRT\Core\DomainModel::ORDER_PRODUCT_POINTS
|
||||
|| (int) ($existing_order['product_id'] ?? 0) !== 0
|
||||
|| (string) ($existing_order['amount'] ?? '') !== $amount->decimal()
|
||||
|| (string) ($existing_order['amount'] ?? '') !== $pay_decimal
|
||||
|| sanitize_key((string) ($existing_order['currency'] ?? '')) !== 'cny'
|
||||
|| sanitize_key((string) ($existing_order['payment_method'] ?? '')) !== 'balance'
|
||||
|| (int) ($existing_meta['points'] ?? 0) !== $points
|
||||
|| (string) ($existing_meta['product'] ?? '') !== $product_key
|
||||
) {
|
||||
return new \WP_Error('aksrt_ledger_idempotency_conflict', __('相同操作标识已用于其他积分购买请求', 'aksrt'), ['status' => 409]);
|
||||
}
|
||||
@@ -404,7 +434,7 @@ trait BalanceServiceRest {
|
||||
if ($order_number === '') {
|
||||
return new \WP_Error('aksrt_order_create_failed', __('积分订单创建失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$business_mutation = static function (int $transaction_id) use ($is_new_order, $repo, $user_id, $amount, $points, $operation_key, $order_number, $note) {
|
||||
$business_mutation = static function (int $transaction_id) use ($is_new_order, $repo, $user_id, $pay_decimal, $points, $operation_key, $order_number, $note) {
|
||||
if (!$is_new_order) {
|
||||
return true;
|
||||
}
|
||||
@@ -413,7 +443,7 @@ trait BalanceServiceRest {
|
||||
'user_id' => $user_id,
|
||||
'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_POINTS,
|
||||
'product_id' => 0,
|
||||
'amount' => $amount->decimal(),
|
||||
'amount' => $pay_decimal,
|
||||
'currency' => 'CNY',
|
||||
'status' => \AKSRT\Payment\Order::STATUS_PAID,
|
||||
'payment_method' => 'balance',
|
||||
@@ -426,19 +456,19 @@ trait BalanceServiceRest {
|
||||
return new \WP_Error('aksrt_order_create_failed', __('积分订单创建失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
if (class_exists('\\AKSRT\\Payment\\CommissionLedger')) {
|
||||
return \AKSRT\Payment\CommissionLedger::get_instance()->record_points_exchange($user_id, $amount->decimal(), $points, $operation_key, $order_number);
|
||||
return \AKSRT\Payment\CommissionLedger::get_instance()->record_points_exchange($user_id, $pay_decimal, $points, $operation_key, $order_number);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
$result = \AKSRT\Ledger\LedgerService::get_instance()->exchange(
|
||||
$user_id,
|
||||
$amount->minor(),
|
||||
$pay_minor,
|
||||
$points,
|
||||
$operation_key,
|
||||
'points_exchange',
|
||||
['type' => 'order', 'key' => $order_number],
|
||||
sprintf(__('余额兑换 %d 积分', 'aksrt'), $points),
|
||||
['rate' => $rate],
|
||||
sprintf(__('余额购买 %d 积分', 'aksrt'), $points),
|
||||
['rate' => $rate, 'product' => $product_key],
|
||||
$guard,
|
||||
$business_mutation
|
||||
);
|
||||
@@ -446,7 +476,7 @@ trait BalanceServiceRest {
|
||||
return $result;
|
||||
}
|
||||
return rest_ensure_response(['success' => true, 'data' => [
|
||||
'message' => sprintf(__('兑换成功,获得 %d 积分', 'aksrt'), $points),
|
||||
'message' => sprintf(__('购买成功,获得 %d 积分', 'aksrt'), $points),
|
||||
'transaction_id' => $result->transaction_id,
|
||||
'replayed' => $result->replayed,
|
||||
'wallet_balance' => \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, $result->balance($user_id, \AKSRT\Ledger\AssetType::BALANCE))->decimal(),
|
||||
@@ -464,12 +494,4 @@ trait BalanceServiceRest {
|
||||
return (intdiv($amount, 100) * $rate) + intdiv(($amount % 100) * $rate, 100);
|
||||
}
|
||||
|
||||
/** @return int|\WP_Error */
|
||||
private function multiply_non_negative(int $left, int $right) {
|
||||
if ($left < 0 || $right < 0 || ($right > 0 && $left > intdiv(PHP_INT_MAX, $right))) {
|
||||
return new \WP_Error('aksrt_ledger_overflow', __('资产金额超出可用范围', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
return $left * $right;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+46
-40
@@ -49,7 +49,7 @@ class ChargeCard {
|
||||
'args' => [
|
||||
'password' => ['type' => 'string', 'required' => true, 'minLength' => 1, 'maxLength' => 80, 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'card' => ['type' => 'string', 'default' => '', 'maxLength' => 60, 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'type' => ['type' => 'string', 'default' => '', 'enum' => ['', self::TYPE_BALANCE, self::TYPE_VIP, self::TYPE_CREDITS]],
|
||||
'type' => ['type' => 'string', 'required' => true, 'enum' => [self::TYPE_BALANCE, self::TYPE_VIP, self::TYPE_CREDITS]],
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -91,9 +91,10 @@ class ChargeCard {
|
||||
}
|
||||
$password = sanitize_text_field((string) ($params['password'] ?? ''));
|
||||
$card = sanitize_text_field((string) ($params['card'] ?? ''));
|
||||
// 弹窗各带类型(余额充值 / 积分购买 / 会员购买),不再自动识别。
|
||||
$type = sanitize_key((string) ($params['type'] ?? ''));
|
||||
if ($type !== '' && !in_array($type, [self::TYPE_BALANCE, self::TYPE_VIP, self::TYPE_CREDITS], true)) {
|
||||
$type = '';
|
||||
if (!in_array($type, [self::TYPE_BALANCE, self::TYPE_VIP, self::TYPE_CREDITS], true)) {
|
||||
return new \WP_Error('aksrt_card_type', __('卡密兑换类型无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$operation_key = \AKSRT\Ledger\OperationKey::from_request($request, 'card-redeem', get_current_user_id());
|
||||
@@ -114,9 +115,11 @@ class ChargeCard {
|
||||
/**
|
||||
* 前台卡密兑换开关视图。
|
||||
*
|
||||
* 唯一类型闸门:balance.enabled =「启用卡密兑换功能」总开关
|
||||
* (后台 余额充值 → 卡密兑换),并与收款接口 card_pass 主开关共同生效;
|
||||
* 会员/积分卡密不再有独立开关。积分卡额外要求积分系统可用(系统级依赖)。
|
||||
* 三个独立类型闸门(后台 余额充值 → 卡密兑换):
|
||||
* 「启用卡密兑换余额功能」「启用卡密兑换积分功能」「启用卡密兑换会员功能」,
|
||||
* 并共同受收款接口 card_pass 主开关(任一开关开启即生效)约束;
|
||||
* 积分卡额外要求积分系统可用(系统级依赖)。
|
||||
* 各类型仅在自身开启时进入对应购买弹窗的支付方式。
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
@@ -125,38 +128,33 @@ class ChargeCard {
|
||||
$channel_on = !class_exists('\AKSRT\Settings\PaymentRuntime')
|
||||
|| \AKSRT\Settings\PaymentRuntime::is_gateway_enabled('card_pass');
|
||||
|
||||
$master_on = false;
|
||||
$balance = ['enabled' => false, 'desc' => '', 'only_password' => true];
|
||||
$vip_only_password = true;
|
||||
$credits_on = false;
|
||||
$types = [
|
||||
'balance' => ['enabled' => false, 'desc' => '', 'only_password' => false],
|
||||
'credits' => ['enabled' => false, 'desc' => '', 'only_password' => false],
|
||||
'vip' => ['enabled' => false, 'desc' => '', 'only_password' => true],
|
||||
];
|
||||
|
||||
if ($channel_on && class_exists('\AKSRT\Settings\Settings')) {
|
||||
if (method_exists('\AKSRT\Settings\Settings', 'get_payment_recharge_settings')) {
|
||||
$recharge = \AKSRT\Settings\Settings::get_payment_recharge_settings();
|
||||
$pc = is_array($recharge['pass_charge'] ?? null) ? $recharge['pass_charge'] : [];
|
||||
$master_on = !empty($pc['enabled']);
|
||||
$balance = [
|
||||
'enabled' => $master_on,
|
||||
'desc' => (string) ($pc['desc'] ?? ''),
|
||||
'only_password' => !isset($pc['only_password']) || !empty($pc['only_password']),
|
||||
$pass_charge = is_array($recharge['pass_charge'] ?? null) ? $recharge['pass_charge'] : [];
|
||||
foreach (array_keys($types) as $type_key) {
|
||||
$cfg = is_array($pass_charge[$type_key] ?? null) ? $pass_charge[$type_key] : [];
|
||||
$types[$type_key] = [
|
||||
'enabled' => !empty($cfg['enabled']),
|
||||
'desc' => (string) ($cfg['desc'] ?? ''),
|
||||
'only_password' => !empty($cfg['only_password']),
|
||||
];
|
||||
}
|
||||
if (method_exists('\AKSRT\Settings\Settings', 'get_payment_vip_settings')) {
|
||||
$vip_s = \AKSRT\Settings\Settings::get_payment_vip_settings();
|
||||
$benefit = is_array($vip_s['benefit'] ?? null) ? $vip_s['benefit'] : [];
|
||||
$vip_only_password = !isset($benefit['pass_charge_only_password']) || !empty($benefit['pass_charge_only_password']);
|
||||
}
|
||||
if ($master_on) {
|
||||
// 积分卡随总开关生效,仅要求积分系统可用(系统级依赖,非独立开关)。
|
||||
$credits_on = !method_exists('\AKSRT\Settings\Settings', 'credits_enabled') || \AKSRT\Settings\Settings::credits_enabled();
|
||||
if ($types['credits']['enabled']) {
|
||||
// 积分卡额外要求积分系统可用(系统级依赖,非独立开关)。
|
||||
$types['credits']['enabled'] = !method_exists('\AKSRT\Settings\Settings', 'credits_enabled')
|
||||
|| \AKSRT\Settings\Settings::credits_enabled();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'balance' => $balance,
|
||||
'vip' => ['only_password' => $vip_only_password],
|
||||
'credits' => ['enabled' => $credits_on],
|
||||
];
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,12 +321,7 @@ class ChargeCard {
|
||||
|
||||
// only_password: if feature requires card number and empty, fail.
|
||||
$opts = $this->get_public_options();
|
||||
$only_password = true;
|
||||
if ($type === self::TYPE_BALANCE) {
|
||||
$only_password = !empty($opts['balance']['only_password']);
|
||||
} elseif ($type === self::TYPE_VIP) {
|
||||
$only_password = !empty($opts['vip']['only_password']);
|
||||
}
|
||||
$only_password = !empty($opts[$type]['only_password']);
|
||||
if (!$only_password && $card === '' && (string) ($row['card'] ?? '') !== '') {
|
||||
return new \WP_Error('aksrt_card_need_no', __('请输入卡号', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
@@ -819,13 +812,26 @@ class ChargeCard {
|
||||
*/
|
||||
private function assert_type_enabled(string $type) {
|
||||
$opts = $this->get_public_options();
|
||||
// 唯一类型闸门:后台「余额充值 → 卡密兑换」总开关(已含收款接口 card_pass 主开关)。
|
||||
if (empty($opts['balance']['enabled'])) {
|
||||
return new \WP_Error('aksrt_card_disabled', __('卡密兑换功能未开启', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
// 积分卡额外要求积分系统可用(系统级依赖,非独立开关)。
|
||||
// 积分卡:积分系统不可用优先提示(get_public_options 已把它折叠进 enabled)。
|
||||
if ($type === self::TYPE_CREDITS && empty($opts['credits']['enabled'])) {
|
||||
return new \WP_Error('aksrt_card_disabled', __('积分系统未开启,无法兑换积分卡密', 'aksrt'), ['status' => 403]);
|
||||
$toggle_on = false;
|
||||
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_payment_recharge_settings')) {
|
||||
$recharge = \AKSRT\Settings\Settings::get_payment_recharge_settings();
|
||||
$toggle_on = !empty($recharge['pass_charge']['credits']['enabled'] ?? false);
|
||||
}
|
||||
return new \WP_Error('aksrt_card_disabled', $toggle_on
|
||||
? __('积分系统未开启,无法兑换积分卡密', 'aksrt')
|
||||
: __('卡密兑换积分功能未开启', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
// 三个独立类型闸门:各类型受自己的「启用卡密兑换XX功能」开关控制
|
||||
// (开关内部已含收款接口 card_pass 主开关判断)。
|
||||
if (empty($opts[$type]['enabled'])) {
|
||||
$messages = [
|
||||
self::TYPE_BALANCE => __('卡密兑换余额功能未开启', 'aksrt'),
|
||||
self::TYPE_CREDITS => __('卡密兑换积分功能未开启', 'aksrt'),
|
||||
self::TYPE_VIP => __('卡密兑换会员功能未开启', 'aksrt'),
|
||||
];
|
||||
return new \WP_Error('aksrt_card_disabled', (string) ($messages[$type] ?? __('卡密兑换功能未开启', 'aksrt')), ['status' => 403]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,16 +110,32 @@ class PaymentRuntime {
|
||||
'desc' => sanitize_textarea_field((string) ($settings['pay_balance_transfer_desc'] ?? '')),
|
||||
],
|
||||
'pass_charge' => [
|
||||
// 三个独立开关:各类型卡密只进入各自的购买弹窗(收款接口同款拆分)。
|
||||
'balance' => [
|
||||
'enabled' => !empty($settings['pay_balance_pass_charge_s']),
|
||||
'desc' => sanitize_textarea_field((string) ($settings['pay_balance_pass_charge_desc'] ?? '')),
|
||||
'only_password' => !empty($settings['pay_balance_pass_charge_only_password']),
|
||||
],
|
||||
'credits' => [
|
||||
'enabled' => !empty($settings['points_pass_exchange_s']),
|
||||
'desc' => sanitize_textarea_field((string) ($settings['points_pass_exchange_desc'] ?? '')),
|
||||
'only_password' => !empty($settings['points_pass_exchange_only_password']),
|
||||
],
|
||||
'vip' => [
|
||||
'enabled' => !empty($settings['pay_vip_pass_charge_s']),
|
||||
'desc' => sanitize_textarea_field((string) ($settings['pay_vip_pass_charge_desc'] ?? '')),
|
||||
'only_password' => !isset($settings['pay_vip_pass_charge_only_password']) || !empty($settings['pay_vip_pass_charge_only_password']),
|
||||
],
|
||||
],
|
||||
'points_exchange' => [
|
||||
'enabled' => !empty($settings['pay_balance_points_exchange_s']),
|
||||
'rate' => max(1, min(10000, (int) ($settings['pay_balance_points_exchange_rate'] ?? 100))),
|
||||
'min_points' => max(1, min(10000000, (int) ($settings['pay_balance_points_exchange_min_points'] ?? 100))),
|
||||
'daily_max_points' => max(1, min(10000000, (int) ($settings['pay_balance_points_exchange_daily_max_points'] ?? 100000))),
|
||||
'desc' => sanitize_textarea_field((string) ($settings['pay_balance_points_exchange_desc'] ?? '')),
|
||||
'products_raw' => is_array($settings['pay_points_product'] ?? null)
|
||||
? self::format_points_product_lines($settings['pay_points_product'])
|
||||
: (string) ($settings['pay_points_product'] ?? ''),
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -229,8 +245,6 @@ class PaymentRuntime {
|
||||
],
|
||||
'benefit' => [
|
||||
'download_limit' => max(0, min(9999, (int) ($settings['pay_download_limit'] ?? 0))),
|
||||
// 会员卡密无独立开关(随「启用卡密兑换功能」总开关),仅保留单密码模式。
|
||||
'pass_charge_only_password' => !isset($settings['pay_vip_pass_charge_only_password']) || !empty($settings['pay_vip_pass_charge_only_password']),
|
||||
],
|
||||
'renew' => [
|
||||
'enabled' => !isset($settings['vip_renew']) || !empty($settings['vip_renew']),
|
||||
@@ -377,7 +391,10 @@ class PaymentRuntime {
|
||||
$paypal_enabled = !empty($settings['pay_paypal_sdk_s']);
|
||||
$stripe_enabled = !empty($settings['pay_stripe_sdk_s']);
|
||||
$balance_enabled = !empty($settings['pay_balance_s']);
|
||||
$card_pass_enabled = !empty($settings['pay_balance_pass_charge_s']);
|
||||
// 卡密收款接口随三个兑换开关任一生效(余额 / 积分 / 会员)。
|
||||
$card_pass_enabled = !empty($settings['pay_balance_pass_charge_s'])
|
||||
|| !empty($settings['points_pass_exchange_s'])
|
||||
|| !empty($settings['pay_vip_pass_charge_s']);
|
||||
|
||||
return [
|
||||
'help_text' => __('微信 / 支付宝可在官方与易支付之间选择;PayPal、Stripe 独立开关。异步回调由各网关验签。', 'aksrt'),
|
||||
@@ -553,7 +570,10 @@ class PaymentRuntime {
|
||||
case 'balance':
|
||||
return !empty($settings['pay_balance_s']);
|
||||
case 'card_pass':
|
||||
return !empty($settings['pay_balance_pass_charge_s']);
|
||||
// 收款接口随三个兑换开关任一生效(余额 / 积分 / 会员)。
|
||||
return !empty($settings['pay_balance_pass_charge_s'])
|
||||
|| !empty($settings['points_pass_exchange_s'])
|
||||
|| !empty($settings['pay_vip_pass_charge_s']);
|
||||
case 'epay':
|
||||
return $wechat === 'epay' || $alipay === 'epay';
|
||||
case 'epay_alipay':
|
||||
@@ -607,4 +627,24 @@ class PaymentRuntime {
|
||||
}
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format points product rows (reference-theme group shape:
|
||||
* points 积分 / pay_price 销售金额 / tag 小标签) into "积分|支付|标签" lines.
|
||||
*
|
||||
* @param array<int,mixed> $products
|
||||
*/
|
||||
private static function format_points_product_lines(array $products): string {
|
||||
$lines = [];
|
||||
foreach ($products as $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
$points = max(0, (int) ($row['points'] ?? 0));
|
||||
$pay_price = max(0, (float) ($row['pay_price'] ?? 0));
|
||||
$title = trim((string) ($row['tag'] ?? ''));
|
||||
$lines[] = $points . '|' . $pay_price . '|' . $title;
|
||||
}
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ test('old asset implementations and compatibility aliases are absent', () => {
|
||||
/aksrt_credits_(?:added|deducted)/,
|
||||
/aksrt_balance_(?:added|deducted)/,
|
||||
/credits_(?:added|deducted)/,
|
||||
/points_pass_exchange_/,
|
||||
// points_pass_exchange_* 现为正式设置键(卡密兑换积分功能,对齐参考主题命名),
|
||||
// 由 card-pass-modal-redeem.test.cjs 覆盖,不再作为遗留别名禁用。
|
||||
/legacy_task_points/,
|
||||
/transfer_refund|recovery_failed/,
|
||||
/\bPayRebate\b/,
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
/**
|
||||
* 通用卡密兑换契约(/user/balance/ 余额卡片弹窗)。
|
||||
*
|
||||
* 背景:余额卡片右下角入口原为「卡密兑换余额」专用弹窗(强制 data-type="balance")。
|
||||
* 现改为通用「卡密兑换」弹窗:标题、文案与提交不再绑定余额类型,
|
||||
* 请求不带类型,由后端 ChargeCard::redeem_for_user() 按卡密自动识别
|
||||
* (balance / vip / credits),各类型仍受自身开关与收款接口 card_pass 主开关约束。
|
||||
* 前台只保留这一个兑换入口:页内联兑换块(积分/会员)与死文件 credits-vip.php
|
||||
* 已删除,会员/积分卡密统一经通用弹窗兑换。
|
||||
*
|
||||
* 后台语义:余额充值 → 卡密兑换 → 「启用卡密兑换功能」
|
||||
* (原「启用卡密充值余额功能」,设置键不变,仅语义/文案更新)。
|
||||
*
|
||||
* 卡密核销订单契约:核销不发生真实支付(现金在售卡时已确认),
|
||||
* 订单金额恒为 0(create_redeem_order 源头 + UserOrders 视图层归零覆盖历史行,
|
||||
* 不做数据迁移);订单名称按 note.meta 生成:
|
||||
* 卡密兑换-余额充值X / 卡密兑换-积分充值X / 购入[会员档位名]X天(永久)。
|
||||
*/
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const root = path.join(__dirname, '..', '..');
|
||||
const read = (...seg) => fs.readFileSync(path.join(root, ...seg), 'utf8');
|
||||
|
||||
const wallet = read('inc', 'helpers', 'user-center-renderers', 'credits-wallet.php');
|
||||
const creditsJs = read('assets', 'js', 'credits.js');
|
||||
const chargeCard = read('src', 'Payment', 'ChargeCard.php');
|
||||
const userOrders = read('src', 'Payment', 'UserOrders.php');
|
||||
const schemaPhp = read('src', 'Admin', 'Schema', 'SchemaPayment.php');
|
||||
const schemaJs = read('assets', 'admin', 'src', 'schema', 'sections', 'payment', 'recharge.js');
|
||||
const usersSchemaPhp = read('src', 'Admin', 'Schema', 'SchemaUsers.php');
|
||||
const usersSchemaJs = read('assets', 'admin', 'src', 'schema', 'sections', 'users', 'credits.js');
|
||||
const vipSchemaJs = read('assets', 'admin', 'src', 'schema', 'sections', 'payment', 'vip.js');
|
||||
const creditsRenderer = read('inc', 'helpers', 'user-center-renderers', 'credits-balance.php');
|
||||
const creditsCss = read('assets', 'css', 'routes', 'user-center', 'credits.css');
|
||||
|
||||
test('余额卡片弹窗为通用卡密兑换:标题与提交不再绑定余额类型', () => {
|
||||
assert.match(wallet, /esc_html_e\('卡密兑换', 'aksrt'\)/);
|
||||
assert.doesNotMatch(wallet, /卡密兑换余额/);
|
||||
assert.doesNotMatch(wallet, /data-type="balance"/);
|
||||
assert.doesNotMatch(wallet, /esc_html__\('兑换余额', 'aksrt'\)/);
|
||||
// 弹窗根节点不带类型值 → 前端 type='' → 后端按卡密自动识别。
|
||||
assert.match(wallet, /data-aksrt-card-pass-modal data-aksrt-card-pass=""/);
|
||||
assert.match(wallet, /data-aksrt-card-redeem(?![^>]*data-type)/);
|
||||
// 卡号输入恒展示且为选填(是否必填由后端按卡密类型判定)。
|
||||
assert.match(wallet, /data-aksrt-card-no(?![^>]*required)/);
|
||||
assert.match(wallet, /请输入卡号(选填)/);
|
||||
});
|
||||
|
||||
test('入口展示受「启用卡密兑换功能」总开关控制', () => {
|
||||
assert.match(wallet, /\$card_pass_redeem\['enabled'\]/);
|
||||
assert.doesNotMatch(wallet, /\$card_pass_balance/);
|
||||
// ChargeCard 缺失时不做 pass_charge 兜底(兑换 REST 依赖该类,兜底无意义)。
|
||||
assert.doesNotMatch(wallet, /\$recharge\['pass_charge'\]/);
|
||||
});
|
||||
|
||||
test('前台唯一兑换入口:页内联块与死文件已删除,JS 不再有 required 卡号校验', () => {
|
||||
assert.equal(
|
||||
fs.existsSync(path.join(root, 'inc', 'helpers', 'user-center-renderers', 'credits-vip.php')),
|
||||
false,
|
||||
'credits-vip.php 死文件应已删除'
|
||||
);
|
||||
assert.doesNotMatch(creditsRenderer, /data-aksrt-card-pass|data-aksrt-card-redeem|card_pass_credits/);
|
||||
assert.doesNotMatch(creditsJs, /hasAttribute\('required'\)/);
|
||||
// 会员/积分卡密无独立开关与说明/单密码配置残留。
|
||||
assert.doesNotMatch(usersSchemaPhp, /asset_points_card_/);
|
||||
assert.doesNotMatch(usersSchemaJs, /asset_points_card_/);
|
||||
assert.doesNotMatch(chargeCard, /asset_points_card_/);
|
||||
assert.doesNotMatch(chargeCard, /'pass_charge_desc'/);
|
||||
// 失去宿主的内联块样式不回潮(弹窗仍在用 __input/__btn 子元素样式;
|
||||
// 通知走全局 notyf Toast,__tip 内联提示样式已随迁移删除)。
|
||||
assert.doesNotMatch(creditsCss, /^\.uc-card-pass\s*\{/m);
|
||||
assert.doesNotMatch(creditsCss, /uc-card-pass__title|uc-card-pass__desc|uc-card-pass__tip|\.uc-assets-col > \.uc-card-pass/);
|
||||
});
|
||||
|
||||
test('兑换通知走全局 notyf Toast 固定 id 流,无内联 tip 残留', () => {
|
||||
assert.match(creditsJs, /notyf\('正在兑换…', 'load', '', 'aksrt-card-pass-toast'\)/);
|
||||
assert.match(creditsJs, /notyf\([^;]+?'danger', 5, 'aksrt-card-pass-toast'\)/);
|
||||
assert.match(creditsJs, /notyf\([^;]+?'success', 5, 'aksrt-card-pass-toast'\)/);
|
||||
// 初始化函数内不得再有 setTip 与 tip 元素查询(initCardPass 段)。
|
||||
const from = creditsJs.indexOf('function initCardPass(');
|
||||
const to = creditsJs.indexOf('function initBalanceCharge(', from + 1);
|
||||
const slice = creditsJs.slice(from, to);
|
||||
assert.ok(from !== -1 && to !== -1);
|
||||
assert.doesNotMatch(slice, /setTip|data-aksrt-card-tip/);
|
||||
assert.doesNotMatch(wallet, /data-aksrt-card-tip/);
|
||||
// 成功后延迟刷新,保证成功 Toast 可见(与其余资产操作一致)。
|
||||
assert.match(slice, /notyf\([^;]+?'success', 5, 'aksrt-card-pass-toast'\);[\s\S]{0,120}window\.setTimeout\(function \(\) \{ window\.location\.reload\(\); \}, 800\)/);
|
||||
});
|
||||
|
||||
test('前端:VIP 缓存失效按后端识别类型', () => {
|
||||
assert.match(creditsJs, /var redeemedType = \(data && data\.type\) \|\| type;/);
|
||||
assert.match(creditsJs, /redeemedType === 'vip'/);
|
||||
});
|
||||
|
||||
test('后端:核销订单金额恒为 0,options 路由与 labels 死代码不回潮', () => {
|
||||
assert.match(chargeCard, /\/pay\/card-pass\/redeem/);
|
||||
assert.doesNotMatch(chargeCard, /card-pass\/options/);
|
||||
assert.doesNotMatch(chargeCard, /rest_options/);
|
||||
assert.doesNotMatch(chargeCard, /'labels'\s+=>\s+\$labels/);
|
||||
// 通用兑换能力后端契约保持:三类可兑换 + 空类型自动识别。
|
||||
assert.match(chargeCard, /REDEEMABLE_TYPES = \[self::TYPE_BALANCE, self::TYPE_VIP, self::TYPE_CREDITS\]/);
|
||||
assert.match(chargeCard, /'enum' => \['', self::TYPE_BALANCE, self::TYPE_VIP, self::TYPE_CREDITS\]/);
|
||||
// create_redeem_order:余额卡不再把面额写进订单金额。
|
||||
assert.doesNotMatch(chargeCard, /TYPE_BALANCE\)\s*\{[^}]*parsed_amount/s);
|
||||
assert.match(chargeCard, /订单金额恒为 0/);
|
||||
// 积分卡开关仅作为后端类型闸门。
|
||||
assert.match(chargeCard, /'credits' => \['enabled' => /);
|
||||
});
|
||||
|
||||
test('唯一类型闸门:总开关统一约束三类卡密,独立开关不回潮', () => {
|
||||
// assert_type_enabled 只查总开关(+ 积分系统级依赖),不再有按类型的独立开关。
|
||||
assert.match(chargeCard, /卡密兑换功能未开启/);
|
||||
assert.match(chargeCard, /积分系统未开启/);
|
||||
assert.doesNotMatch(chargeCard, /余额卡密兑换未开启|会员卡密兑换未开启|积分卡密兑换未开启/);
|
||||
// 会员/积分卡密独立开关与说明为死代码。
|
||||
assert.doesNotMatch(chargeCard, /pay_vip_pass_charge_s|pay_vip_pass_charge_desc|pass_charge'\s*=>/);
|
||||
for (const [name, src] of [['SchemaPayment.php', schemaPhp], ['recharge.js', schemaJs], ['vip.js', vipSchemaJs]]) {
|
||||
assert.doesNotMatch(src, /pay_vip_pass_charge_s|pay_vip_pass_charge_desc|启用卡密兑换会员功能/, name);
|
||||
assert.doesNotMatch(src, /启用积分卡密兑换/, name);
|
||||
}
|
||||
assert.match(vipSchemaJs, /title: '会员卡密'/);
|
||||
assert.match(vipSchemaJs, /pay_vip_pass_charge_only_password/);
|
||||
});
|
||||
|
||||
test('订单中心:卡密核销订单实付归零并按 note 生成订单名称', () => {
|
||||
assert.match(userOrders, /if \(\$payment_method === 'card_pass'\)\s*\{\s*\$amount = \$is_points \? '0' : '0\.00';/);
|
||||
assert.match(userOrders, /if \(!empty\(\$meta\['card_pass'\]\)\)\s*\{[\s\S]*?resolve_card_pass_title\(\$meta\)/);
|
||||
assert.match(userOrders, /卡密兑换-余额充值/);
|
||||
assert.match(userOrders, /卡密兑换-积分充值/);
|
||||
assert.match(userOrders, /购入\[%1\$s\]%2\$s/);
|
||||
assert.match(userOrders, /永久/);
|
||||
});
|
||||
|
||||
test('后台 schema 语义更新为「启用卡密兑换功能」', () => {
|
||||
for (const [name, src] of [['SchemaPayment.php', schemaPhp], ['recharge.js', schemaJs]]) {
|
||||
assert.match(src, /启用卡密兑换功能/, name);
|
||||
assert.match(src, /title['"]?\s*(?::|=>)\s*'卡密兑换'/, name);
|
||||
assert.doesNotMatch(src, /启用卡密充值余额功能/, name);
|
||||
assert.doesNotMatch(src, /卡密充值说明/, name);
|
||||
}
|
||||
});
|
||||
@@ -223,10 +223,9 @@ test('balance center actions use direct fixed-id notyf flows', () => {
|
||||
|
||||
const flows = [
|
||||
[signinController, 'aksrt-balance-signin-toast'],
|
||||
[section('initCardPass', 'initBalanceCharge'), 'aksrt-card-pass-toast'],
|
||||
[section('initBalanceCharge', 'initTransfer'), 'aksrt-balance-charge-toast'],
|
||||
[section('initTransfer', 'initPointsExchange'), 'aksrt-balance-transfer-toast'],
|
||||
[section('initPointsExchange', 'initWithdraw'), 'aksrt-balance-points-toast'],
|
||||
[section('initTransfer', 'initPointsPay'), 'aksrt-balance-transfer-toast'],
|
||||
[section('initPointsPay', 'initWithdraw'), 'aksrt-balance-points-toast'],
|
||||
[section('initWithdraw', 'initAssetTabs'), 'aksrt-balance-withdraw-toast'],
|
||||
];
|
||||
|
||||
@@ -242,10 +241,10 @@ test('balance center actions use direct fixed-id notyf flows', () => {
|
||||
assert.match(signinController, /freshButtons\.forEach[\s\S]*?addEventListener\('click'/);
|
||||
assert.match(credits, /onTimeout:[\s\S]*?notyf\([^;]+?'danger'[^;]+?'aksrt-balance-charge-payment-toast'\)/);
|
||||
assert.match(credits, /auto_fun\.aksrt-credits'[\s\S]*?bootAssets\(\);/);
|
||||
assert.match(credits, /function bootAssets\(\)[\s\S]*?initSigninGoto\(\);[\s\S]*?initBalanceCharge\(\);[\s\S]*?initPointsExchange\(\);[\s\S]*?initWithdraw\(\);/);
|
||||
assert.match(credits, /function bootAssets\(\)[\s\S]*?initSigninGoto\(\);[\s\S]*?initBalanceCharge\(\);[\s\S]*?initPointsPay\(\);[\s\S]*?initWithdraw\(\);/);
|
||||
assert.doesNotMatch(credits, /function initSignin\(|\/signin\/today|POST \/signin/);
|
||||
assert.match(signinController, /aksrtSigninInitialized/);
|
||||
assert.match(credits, /aksrtPointsExchangeInitialized[\s\S]*?aksrtWithdrawInitialized/);
|
||||
assert.match(credits, /aksrtPointsPayInitialized[\s\S]*?aksrtWithdrawInitialized/);
|
||||
assert.match(scripts, /'aksrt-credits',[\s\S]*?\/assets\/js\/credits\.js',[\s\S]*?\[[^\]]*'loader_js'[^\]]*\]/);
|
||||
assert.match(scripts, /\$signin_on\s*=\s*is_user_logged_in\(\)[\s\S]*?'aksrt-signin',[\s\S]*?\/assets\/js\/signin\.js',[\s\S]*?'loader_js'/);
|
||||
assert.ok(header.indexOf('data-signin-btn') < header.indexOf('uc-header__message-btn'));
|
||||
|
||||
Reference in New Issue
Block a user