Merge pull request 'feat(user-center): Zibll-like assets charge, transfer, and dual cards' (#176) from worktree-single-post-zibll-align into main
Reviewed-on: CYL/wordpress-theme-aksrt#176
This commit is contained in:
@@ -1,27 +1,285 @@
|
||||
/**
|
||||
* User Center — credits balance + transactions
|
||||
* User Center — assets (wallet + points) Zibll parity
|
||||
*/
|
||||
|
||||
.uc-balance-card {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* Dual assets: wallet + points cards stack with gap */
|
||||
.uc-wallet-grid {
|
||||
/* Dual asset row */
|
||||
.uc-assets-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.uc-balance-card--wallet .uc-balance-card__bg--wallet,
|
||||
.uc-balance-card__bg--wallet {
|
||||
background: linear-gradient(135deg, #0f766e 0%, #14b8a6 45%, #2dd4bf 100%);
|
||||
.uc-assets-row--dual {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.uc-assets-row--dual {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.uc-balance-card + .uc-balance-card {
|
||||
margin-top: 12px;
|
||||
.uc-asset-card {
|
||||
background: var(--main-bg-color, var(--surface-1, #fff));
|
||||
border-radius: var(--main-radius, 8px);
|
||||
box-shadow: 0 0 10px var(--main-shadow, rgba(116, 116, 116, 0.08));
|
||||
padding: 16px 20px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.uc-asset-card__head {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.uc-asset-card__title {
|
||||
font-weight: 600;
|
||||
color: var(--main-color, #4e5358);
|
||||
}
|
||||
.uc-asset-card__amount {
|
||||
font-size: 1.75rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.uc-asset-card__mark {
|
||||
font-size: 12px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
.uc-asset-card__actions .but {
|
||||
min-width: 4.2em;
|
||||
}
|
||||
.uc-asset-card__link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.uc-asset-card__link:hover {
|
||||
color: var(--focus-color, #f04494);
|
||||
}
|
||||
|
||||
/* Sidebar mini dual cards (Zibll) */
|
||||
.uc-asset-mini {
|
||||
gap: 8px;
|
||||
}
|
||||
.uc-asset-mini__card {
|
||||
display: block;
|
||||
background: var(--muted-bg-color, #f3f4f6);
|
||||
border-radius: 6px;
|
||||
padding: 10px 12px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.uc-asset-mini__card:hover {
|
||||
background: var(--color-line-soft, rgba(0, 0, 0, 0.06));
|
||||
}
|
||||
.uc-asset-mini__label {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.c-blue-2 {
|
||||
color: #3b82f6;
|
||||
}
|
||||
.c-yellow {
|
||||
color: #eab308;
|
||||
}
|
||||
.c-green {
|
||||
color: #16a34a;
|
||||
}
|
||||
.col-ml6 {
|
||||
margin-left: -6px;
|
||||
}
|
||||
.col-ml6 > * {
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
/* Charge packages */
|
||||
.uc-charge-packages {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.uc-charge-package {
|
||||
position: relative;
|
||||
display: block;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--color-line, rgba(0, 0, 0, 0.08));
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
background: var(--surface-1, #fff);
|
||||
}
|
||||
.uc-charge-package input {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.uc-charge-package.is-active,
|
||||
.uc-charge-package:has(input:checked) {
|
||||
border-color: var(--focus-color, #f04494);
|
||||
box-shadow: 0 0 0 1px var(--focus-color, #f04494);
|
||||
}
|
||||
.uc-charge-package__credit {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.uc-charge-package__tag {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 0 8px 0 8px;
|
||||
background: #fbbf24;
|
||||
color: #333;
|
||||
}
|
||||
.uc-charge-custom__input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--color-line, #ddd);
|
||||
padding: 6px 0;
|
||||
font-size: 1.1rem;
|
||||
outline: none;
|
||||
}
|
||||
.uc-charge-methods {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.uc-charge-method {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Modal shell */
|
||||
.uc-modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1100;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
}
|
||||
.uc-modal.is-open,
|
||||
.uc-modal:not([hidden]) {
|
||||
display: flex;
|
||||
}
|
||||
.uc-modal[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
.uc-modal__overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
.uc-modal__dialog {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
max-height: 85vh;
|
||||
overflow: auto;
|
||||
background: var(--main-bg-color, #fff);
|
||||
border-radius: 12px;
|
||||
padding: 18px 18px 20px;
|
||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.uc-modal__close {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 12px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
}
|
||||
.uc-modal__title {
|
||||
margin: 0 0 14px;
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.uc-modal__desc {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.uc-modal__tip {
|
||||
min-height: 1.4em;
|
||||
margin: 10px 0 0;
|
||||
font-size: 13px;
|
||||
color: var(--muted-color, #777);
|
||||
}
|
||||
.uc-modal__tip.is-error {
|
||||
color: #ef4444;
|
||||
}
|
||||
body.uc-modal-open {
|
||||
overflow: hidden;
|
||||
}
|
||||
.btn-block {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
.but.jb-blue,
|
||||
.but.b-blue-2 {
|
||||
background: #3b82f6;
|
||||
color: #fff;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
padding: 0.45em 1em;
|
||||
cursor: pointer;
|
||||
}
|
||||
.but.c-blue-2.hollow,
|
||||
.but.c-green.hollow {
|
||||
background: transparent;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 4px;
|
||||
padding: 0.4em 0.9em;
|
||||
cursor: pointer;
|
||||
}
|
||||
.but.c-blue-2 {
|
||||
color: #3b82f6;
|
||||
}
|
||||
.but.c-green {
|
||||
color: #16a34a;
|
||||
}
|
||||
|
||||
/* Transfer search results */
|
||||
.uc-transfer-results {
|
||||
margin-top: 8px;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
}
|
||||
.uc-transfer-user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 0;
|
||||
background: var(--muted-bg-color, #f5f5f5);
|
||||
border-radius: 6px;
|
||||
margin-bottom: 6px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
.uc-transfer-user:hover {
|
||||
background: var(--color-primary-soft, rgba(240, 68, 148, 0.08));
|
||||
}
|
||||
.uc-transfer-user__avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.uc-transactions--wallet {
|
||||
margin-bottom: 20px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.uc-content #panel-credits .uc-transactions {
|
||||
|
||||
+269
-8
@@ -515,19 +515,280 @@
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
initSignin();
|
||||
initInvite();
|
||||
initVipShop();
|
||||
initVipPointsExchange();
|
||||
initCardPass();
|
||||
// ===== 余额充值 / 转账 / 积分兑余额(Zibll 资产中心) =====
|
||||
function openModal(el) {
|
||||
if (!el) return;
|
||||
el.hidden = false;
|
||||
el.classList.add('is-open');
|
||||
document.body.classList.add('uc-modal-open');
|
||||
}
|
||||
function closeModal(el) {
|
||||
if (!el) return;
|
||||
el.hidden = true;
|
||||
el.classList.remove('is-open');
|
||||
if (!document.querySelector('.uc-modal.is-open')) {
|
||||
document.body.classList.remove('uc-modal-open');
|
||||
}
|
||||
}
|
||||
function pollPaidOrder(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);
|
||||
window.location.reload();
|
||||
}
|
||||
}).catch(function () {});
|
||||
if (tries >= maxTries) clearInterval(timer);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function initBalanceCharge() {
|
||||
var modal = document.querySelector('[data-aksrt-charge-modal]');
|
||||
if (!modal) return;
|
||||
var form = modal.querySelector('[data-aksrt-charge-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-charge-tip]');
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-charge-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
} else {
|
||||
modal.querySelectorAll('[data-aksrt-charge-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
});
|
||||
modal.querySelectorAll('.uc-charge-package input').forEach(function (inp) {
|
||||
inp.addEventListener('change', function () {
|
||||
modal.querySelectorAll('.uc-charge-package').forEach(function (el) {
|
||||
el.classList.toggle('is-active', el.contains(inp) && inp.checked);
|
||||
});
|
||||
});
|
||||
});
|
||||
if (!form) return;
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var pkgInput = form.querySelector('input[name="balance_package"]:checked') || form.querySelector('input[name="balance_package"]');
|
||||
var pkg = pkgInput ? pkgInput.value : 'custom';
|
||||
var customEl = form.querySelector('input[name="custom_price"]');
|
||||
var custom = customEl ? parseFloat(customEl.value || '0') : 0;
|
||||
if (custom > 0) {
|
||||
pkg = 'custom';
|
||||
}
|
||||
if ((!pkg || pkg === 'custom') && !(custom > 0) && !pkgInput) {
|
||||
setTip('请选择或输入充值金额', true);
|
||||
return;
|
||||
}
|
||||
if (pkg === 'custom' && !(custom > 0)) {
|
||||
setTip('请输入有效充值金额', true);
|
||||
return;
|
||||
}
|
||||
var methodEl = form.querySelector('input[name="payment_method"]:checked');
|
||||
var method = methodEl ? methodEl.value : 'alipay';
|
||||
busy = true;
|
||||
setTip('正在创建订单…');
|
||||
api('/pay/balance/charge', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
package: pkg,
|
||||
custom_price: custom,
|
||||
payment_method: method
|
||||
})
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '充值失败', 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) pollPaidOrder(data.order_number);
|
||||
return;
|
||||
}
|
||||
setTip((data && data.message) || '充值成功,正在刷新…');
|
||||
window.location.reload();
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initTransfer() {
|
||||
var modal = document.querySelector('[data-aksrt-transfer-modal]');
|
||||
if (!modal) return;
|
||||
var form = modal.querySelector('[data-aksrt-transfer-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-transfer-tip]');
|
||||
var results = modal.querySelector('[data-aksrt-transfer-results]');
|
||||
var selected = modal.querySelector('[data-aksrt-transfer-selected]');
|
||||
var recipientInput = modal.querySelector('[data-aksrt-transfer-recipient]');
|
||||
var typeInput = modal.querySelector('[data-aksrt-transfer-type]');
|
||||
var title = modal.querySelector('[data-aksrt-transfer-title]');
|
||||
var searchTimer = null;
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-transfer-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var type = btn.getAttribute('data-aksrt-transfer-open') || 'balance';
|
||||
if (typeInput) typeInput.value = type;
|
||||
if (title) title.textContent = type === 'points' ? '积分转账' : '余额转账';
|
||||
if (results) results.innerHTML = '';
|
||||
if (selected) selected.textContent = '';
|
||||
if (recipientInput) recipientInput.value = '';
|
||||
setTip('');
|
||||
openModal(modal);
|
||||
});
|
||||
});
|
||||
modal.querySelectorAll('[data-aksrt-transfer-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
});
|
||||
var searchEl = modal.querySelector('[data-aksrt-transfer-search]');
|
||||
if (searchEl) {
|
||||
searchEl.addEventListener('input', function () {
|
||||
var q = String(searchEl.value || '').trim();
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
if (q.length < 1) {
|
||||
if (results) results.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
searchTimer = setTimeout(function () {
|
||||
api('/pay/transfer/search?s=' + encodeURIComponent(q)).then(function (r) {
|
||||
if (!results) return;
|
||||
results.innerHTML = '';
|
||||
if (!r.ok) return;
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
var users = (data && data.users) || [];
|
||||
if (!users.length) {
|
||||
results.innerHTML = '<div class="muted-2-color em09">未找到相关用户</div>';
|
||||
return;
|
||||
}
|
||||
users.forEach(function (u) {
|
||||
var item = document.createElement('button');
|
||||
item.type = 'button';
|
||||
item.className = 'uc-transfer-user';
|
||||
item.innerHTML = '<img src="' + (u.avatar || '') + '" alt="" class="uc-transfer-user__avatar"><span>' + (u.display_name || u.user_login) + '</span><span class="muted-2-color em09">@' + (u.user_login || '') + '</span>';
|
||||
item.addEventListener('click', function () {
|
||||
if (recipientInput) recipientInput.value = String(u.id);
|
||||
if (selected) selected.textContent = '已选择:' + (u.display_name || u.user_login);
|
||||
results.innerHTML = '';
|
||||
});
|
||||
results.appendChild(item);
|
||||
});
|
||||
});
|
||||
}, 280);
|
||||
});
|
||||
}
|
||||
if (!form) return;
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var type = typeInput ? typeInput.value : 'balance';
|
||||
var recipient = recipientInput ? parseInt(recipientInput.value || '0', 10) : 0;
|
||||
var amountEl = form.querySelector('[data-aksrt-transfer-amount]');
|
||||
var amount = amountEl ? amountEl.value : 0;
|
||||
if (!recipient) {
|
||||
setTip('请选择收款用户', true);
|
||||
return;
|
||||
}
|
||||
if (!(parseFloat(amount) > 0)) {
|
||||
setTip('请输入有效金额', true);
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在转账…');
|
||||
api('/pay/transfer', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ type: type, recipient: recipient, amount: amount })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '转账失败', true);
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
setTip((data && data.message) || '转账成功,正在刷新…');
|
||||
window.location.reload();
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initExchange() {
|
||||
var modal = document.querySelector('[data-aksrt-exchange-modal]');
|
||||
if (!modal) return;
|
||||
var form = modal.querySelector('[data-aksrt-exchange-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-exchange-tip]');
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-exchange-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
modal.querySelectorAll('[data-aksrt-exchange-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { closeModal(modal); });
|
||||
});
|
||||
if (!form) return;
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
var pointsEl = form.querySelector('[data-aksrt-exchange-points]');
|
||||
var points = pointsEl ? parseInt(pointsEl.value || '0', 10) : 0;
|
||||
if (!(points > 0)) {
|
||||
setTip('请输入兑换积分数量', true);
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在兑换…');
|
||||
api('/pay/balance/exchange', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ points: points })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '兑换失败', true);
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
setTip((data && data.message) || '兑换成功,正在刷新…');
|
||||
window.location.reload();
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bootAssets() {
|
||||
initSignin();
|
||||
initInvite();
|
||||
initVipShop();
|
||||
initVipPointsExchange();
|
||||
initCardPass();
|
||||
initBalanceCharge();
|
||||
initTransfer();
|
||||
initExchange();
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', bootAssets);
|
||||
} else {
|
||||
bootAssets();
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -189,6 +189,9 @@ if (class_exists('AKSRT_Vip_Service')) {
|
||||
if (class_exists('AKSRT_Charge_Card')) {
|
||||
AKSRT_Charge_Card::get_instance()->init();
|
||||
}
|
||||
if (class_exists('AKSRT_Balance_Service')) {
|
||||
AKSRT_Balance_Service::get_instance()->init();
|
||||
}
|
||||
// Download State & Docs Presenter are pure service singletons (no hooks)
|
||||
if (class_exists('AKSRT_Download_State')) {
|
||||
AKSRT_Download_State::get_instance();
|
||||
|
||||
@@ -226,6 +226,7 @@ require_once AKSRT_DIR . '/inc/classes/class-aksrt-db-migrator.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-credits.php';
|
||||
// 站内现金钱包(与积分分离)
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-balance.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-balance-service.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-credits-earn.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-signin.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-invite.php';
|
||||
|
||||
@@ -0,0 +1,609 @@
|
||||
<?php
|
||||
/**
|
||||
* AKSRT Balance Service — recharge packages + transfer REST.
|
||||
*
|
||||
* Zibll parity targets:
|
||||
* - balance charge packages (pay_balance_product)
|
||||
* - balance/points transfer
|
||||
* - credit wallet after paid recharge orders
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_Balance_Service {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
add_action('rest_api_init', [$this, 'register_routes']);
|
||||
add_action('aksrt_order_paid', [$this, 'on_order_paid'], 20, 2);
|
||||
}
|
||||
|
||||
public function register_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/pay/balance/charge', [
|
||||
[
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => [$this, 'rest_charge_options'],
|
||||
'permission_callback' => static function () {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
],
|
||||
[
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => [$this, 'rest_charge_create'],
|
||||
'permission_callback' => static function () {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
register_rest_route('aksrt/v1', '/pay/transfer', [
|
||||
[
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => [$this, 'rest_transfer'],
|
||||
'permission_callback' => static function () {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
register_rest_route('aksrt/v1', '/pay/transfer/search', [
|
||||
[
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => [$this, 'rest_transfer_search'],
|
||||
'permission_callback' => static function () {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
register_rest_route('aksrt/v1', '/pay/balance/exchange', [
|
||||
[
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => [$this, 'rest_exchange_from_credits'],
|
||||
'permission_callback' => static function () {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET charge options (packages + methods + limits).
|
||||
*/
|
||||
public function rest_charge_options(WP_REST_Request $request) {
|
||||
if (!class_exists('AKSRT_Balance') || !AKSRT_Balance::enabled()) {
|
||||
return new WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
return rest_ensure_response([
|
||||
'success' => true,
|
||||
'data' => $this->get_charge_view($user_id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST create recharge order and initiate payment.
|
||||
*/
|
||||
public function rest_charge_create(WP_REST_Request $request) {
|
||||
if (!class_exists('AKSRT_Balance') || !AKSRT_Balance::enabled()) {
|
||||
return new WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
$params = $request->get_json_params();
|
||||
if (!is_array($params)) {
|
||||
$params = $request->get_params();
|
||||
}
|
||||
$package_key = sanitize_text_field((string) ($params['package'] ?? 'custom'));
|
||||
$custom_price = isset($params['custom_price']) ? (float) $params['custom_price'] : 0.0;
|
||||
$payment_method = sanitize_key((string) ($params['payment_method'] ?? 'alipay'));
|
||||
|
||||
$result = $this->create_charge_order($user_id, $package_key, $custom_price, $payment_method);
|
||||
if (is_wp_error($result)) {
|
||||
return $result;
|
||||
}
|
||||
return rest_ensure_response(['success' => true, 'data' => $result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer balance or points between users.
|
||||
*/
|
||||
public function rest_transfer(WP_REST_Request $request) {
|
||||
$params = $request->get_json_params();
|
||||
if (!is_array($params)) {
|
||||
$params = $request->get_params();
|
||||
}
|
||||
$type = sanitize_key((string) ($params['type'] ?? 'balance'));
|
||||
$recipient = (int) ($params['recipient'] ?? 0);
|
||||
$amount_raw = $params['amount'] ?? $params['price'] ?? 0;
|
||||
$from_id = get_current_user_id();
|
||||
|
||||
if (!in_array($type, ['balance', 'points'], true)) {
|
||||
return new WP_Error('aksrt_transfer_type', __('转账类型无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if ($from_id <= 0) {
|
||||
return new WP_Error('aksrt_need_login', __('请先登录', 'aksrt'), ['status' => 401]);
|
||||
}
|
||||
if ($recipient <= 0 || $recipient === $from_id) {
|
||||
return new WP_Error('aksrt_transfer_user', __('请选择有效的收款用户', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if (!get_userdata($recipient)) {
|
||||
return new WP_Error('aksrt_transfer_user', __('收款用户不存在', 'aksrt'), ['status' => 404]);
|
||||
}
|
||||
|
||||
$cfg = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_payment_recharge_settings() : [];
|
||||
if ($type === 'balance') {
|
||||
if (empty($cfg['enabled']) || empty($cfg['transfer']['enabled'])) {
|
||||
return new WP_Error('aksrt_transfer_closed', __('余额转账未开启', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
$amount = round((float) $amount_raw, 2);
|
||||
if ($amount <= 0) {
|
||||
return new WP_Error('aksrt_transfer_amount', __('请输入有效金额', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if (!class_exists('AKSRT_Balance')) {
|
||||
return new WP_Error('aksrt_balance_unavailable', __('余额系统不可用', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$from_bal = AKSRT_Balance::balance($from_id);
|
||||
if ($from_bal < $amount) {
|
||||
return new WP_Error('aksrt_balance_insufficient', __('余额不足', 'aksrt'), ['status' => 402]);
|
||||
}
|
||||
$fee_rate = max(0, min(50, (int) ($cfg['transfer']['service_charge'] ?? 0)));
|
||||
$credit = $fee_rate > 0 ? round($amount * (100 - $fee_rate) / 100, 2) : $amount;
|
||||
|
||||
$from_user = wp_get_current_user();
|
||||
$to_user = get_userdata($recipient);
|
||||
$deduct = AKSRT_Balance::deduct(
|
||||
$from_id,
|
||||
$amount,
|
||||
'transfer_out',
|
||||
['type' => 'user', 'id' => $recipient],
|
||||
sprintf(__('转账给用户[%s]', 'aksrt'), $to_user ? $to_user->display_name : (string) $recipient)
|
||||
);
|
||||
if (is_wp_error($deduct)) {
|
||||
return $deduct;
|
||||
}
|
||||
AKSRT_Balance::add(
|
||||
$recipient,
|
||||
$credit,
|
||||
'transfer_in',
|
||||
['type' => 'user', 'id' => $from_id],
|
||||
sprintf(__('来自用户[%s]的转账', 'aksrt'), $from_user->display_name ?: (string) $from_id)
|
||||
);
|
||||
return rest_ensure_response([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'message' => __('转账成功', 'aksrt'),
|
||||
'reload' => true,
|
||||
'balance' => AKSRT_Balance::balance($from_id),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// points transfer
|
||||
$points_transfer_on = !empty(AKSRT_Settings::get_all()['points_transfer_s']);
|
||||
if (!class_exists('AKSRT_Settings') || !AKSRT_Settings::credits_enabled() || !$points_transfer_on) {
|
||||
return new WP_Error('aksrt_transfer_closed', __('积分转账未开启', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
$amount = (int) $amount_raw;
|
||||
if ($amount <= 0) {
|
||||
return new WP_Error('aksrt_transfer_amount', __('请输入有效积分', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if (!class_exists('AKSRT_Credits')) {
|
||||
return new WP_Error('aksrt_credits_unavailable', __('积分系统不可用', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$fee_rate = max(0, min(50, (int) (AKSRT_Settings::get_all()['points_service_charge'] ?? 0)));
|
||||
$credit = $fee_rate > 0 ? (int) floor($amount * (100 - $fee_rate) / 100) : $amount;
|
||||
$from_user = wp_get_current_user();
|
||||
$to_user = get_userdata($recipient);
|
||||
$deduct = AKSRT_Credits::deduct(
|
||||
$from_id,
|
||||
$amount,
|
||||
'transfer_out',
|
||||
['type' => 'user', 'id' => $recipient],
|
||||
sprintf(__('转账给用户[%s]', 'aksrt'), $to_user ? $to_user->display_name : (string) $recipient)
|
||||
);
|
||||
if (is_wp_error($deduct)) {
|
||||
return $deduct;
|
||||
}
|
||||
AKSRT_Credits::add(
|
||||
$recipient,
|
||||
$credit,
|
||||
'transfer_in',
|
||||
['type' => 'user', 'id' => $from_id],
|
||||
sprintf(__('来自用户[%s]的转账', 'aksrt'), $from_user->display_name ?: (string) $from_id)
|
||||
);
|
||||
return rest_ensure_response([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'message' => __('转账成功', 'aksrt'),
|
||||
'reload' => true,
|
||||
'balance' => AKSRT_Credits::balance($from_id),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function rest_transfer_search(WP_REST_Request $request) {
|
||||
$s = sanitize_text_field((string) $request->get_param('s'));
|
||||
if (mb_strlen($s) < 1) {
|
||||
return rest_ensure_response(['success' => true, 'data' => ['users' => []]]);
|
||||
}
|
||||
$exclude = [get_current_user_id()];
|
||||
$q = new WP_User_Query([
|
||||
'search' => '*' . $s . '*',
|
||||
'search_columns' => ['user_login', 'user_nicename', 'display_name', 'user_email'],
|
||||
'exclude' => $exclude,
|
||||
'number' => 20,
|
||||
'fields' => ['ID', 'display_name', 'user_login'],
|
||||
]);
|
||||
$users = [];
|
||||
foreach ((array) $q->get_results() as $u) {
|
||||
$users[] = [
|
||||
'id' => (int) $u->ID,
|
||||
'display_name' => (string) $u->display_name,
|
||||
'user_login' => (string) $u->user_login,
|
||||
'avatar' => get_avatar_url((int) $u->ID, ['size' => 48]),
|
||||
];
|
||||
}
|
||||
return rest_ensure_response(['success' => true, 'data' => ['users' => $users]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange points → cash wallet (pay_balance_exchange_*).
|
||||
*/
|
||||
public function rest_exchange_from_credits(WP_REST_Request $request) {
|
||||
if (!class_exists('AKSRT_Balance') || !AKSRT_Balance::enabled()) {
|
||||
return new WP_Error('aksrt_balance_disabled', __('余额功能未启用', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
$cfg = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_payment_recharge_settings() : [];
|
||||
if (empty($cfg['exchange']['enabled'])) {
|
||||
return new WP_Error('aksrt_exchange_closed', __('积分兑换余额未开启', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
if (!class_exists('AKSRT_Credits') || !AKSRT_Settings::credits_enabled()) {
|
||||
return new WP_Error('aksrt_credits_disabled', __('积分功能未启用', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
$params = $request->get_json_params();
|
||||
if (!is_array($params)) {
|
||||
$params = $request->get_params();
|
||||
}
|
||||
$points = (int) ($params['points'] ?? 0);
|
||||
$rate = max(1, (int) ($cfg['exchange']['rate'] ?? 100)); // N points = 1 yuan
|
||||
if ($points < $rate) {
|
||||
return new WP_Error('aksrt_exchange_min', sprintf(__('最少兑换 %d 积分', 'aksrt'), $rate), ['status' => 400]);
|
||||
}
|
||||
// Floor to whole yuan.
|
||||
$yuan = (int) floor($points / $rate);
|
||||
$cost = $yuan * $rate;
|
||||
if ($yuan <= 0 || $cost <= 0) {
|
||||
return new WP_Error('aksrt_exchange_amount', __('兑换数量无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
$deduct = AKSRT_Credits::deduct(
|
||||
$user_id,
|
||||
$cost,
|
||||
'exchange_to_balance',
|
||||
['type' => 'balance'],
|
||||
sprintf(__('积分兑换余额 %d 元', 'aksrt'), $yuan)
|
||||
);
|
||||
if (is_wp_error($deduct)) {
|
||||
return $deduct;
|
||||
}
|
||||
$add = AKSRT_Balance::add(
|
||||
$user_id,
|
||||
(float) $yuan,
|
||||
'exchange_from_credits',
|
||||
['type' => 'credits'],
|
||||
sprintf(__('积分兑换:消耗 %d 积分', 'aksrt'), $cost)
|
||||
);
|
||||
if (is_wp_error($add)) {
|
||||
// best-effort refund points
|
||||
AKSRT_Credits::add($user_id, $cost, 'exchange_refund', [], __('兑换失败退回积分', 'aksrt'));
|
||||
return $add;
|
||||
}
|
||||
return rest_ensure_response([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'message' => sprintf(__('兑换成功:+%d 元', 'aksrt'), $yuan),
|
||||
'wallet_balance' => AKSRT_Balance::balance($user_id),
|
||||
'credit_balance' => AKSRT_Credits::balance($user_id),
|
||||
'reload' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* When a recharge order is paid, credit the wallet.
|
||||
*
|
||||
* @param string $order_number Order number.
|
||||
* @param array<string,mixed> $order Order row.
|
||||
*/
|
||||
public function on_order_paid(string $order_number, array $order = []): void {
|
||||
if ($order === [] && class_exists('AKSRT_Order_Repository')) {
|
||||
$order = AKSRT_Order_Repository::get_instance()->get($order_number) ?: [];
|
||||
}
|
||||
if (!$order) {
|
||||
return;
|
||||
}
|
||||
$type = sanitize_key((string) ($order['product_type'] ?? ''));
|
||||
if ($type !== AKSRT_Domain_Model::ORDER_PRODUCT_RECHARGE) {
|
||||
return;
|
||||
}
|
||||
$user_id = (int) ($order['user_id'] ?? 0);
|
||||
if ($user_id <= 0 || !class_exists('AKSRT_Balance')) {
|
||||
return;
|
||||
}
|
||||
// Prevent double credit.
|
||||
$note = json_decode((string) ($order['note'] ?? ''), true);
|
||||
if (!is_array($note)) {
|
||||
$note = [];
|
||||
}
|
||||
if (!empty($note['balance_credited'])) {
|
||||
return;
|
||||
}
|
||||
$credit_amount = isset($note['credit_amount'])
|
||||
? round((float) $note['credit_amount'], 2)
|
||||
: round((float) ($order['amount'] ?? 0), 2);
|
||||
if ($credit_amount <= 0) {
|
||||
return;
|
||||
}
|
||||
$result = AKSRT_Balance::add(
|
||||
$user_id,
|
||||
$credit_amount,
|
||||
'recharge',
|
||||
['type' => 'order', 'order' => $order_number],
|
||||
sprintf(__('余额充值订单 %s', 'aksrt'), $order_number)
|
||||
);
|
||||
if (is_wp_error($result)) {
|
||||
return;
|
||||
}
|
||||
$note['balance_credited'] = 1;
|
||||
$note['credited_amount'] = $credit_amount;
|
||||
// Mark credited in note (best-effort; private table accessor).
|
||||
global $wpdb;
|
||||
$tbl = $wpdb->prefix . 'aksrt_order';
|
||||
$wpdb->update(
|
||||
$tbl,
|
||||
['note' => wp_json_encode($note, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)],
|
||||
['order_number' => $order_number],
|
||||
['%s'],
|
||||
['%s']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function get_charge_view(int $user_id): array {
|
||||
$cfg = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_payment_recharge_settings() : [];
|
||||
$packages = $this->parse_packages((string) ($cfg['packages_raw'] ?? ''));
|
||||
$custom_s = !isset($cfg['product']['custom_s']) || !empty($cfg['product']['custom_s']);
|
||||
$custom_limit = max(1, (int) ($cfg['product']['custom_limit'] ?? 9999));
|
||||
$methods = [];
|
||||
if (function_exists('aksrt_list_cash_payment_methods')) {
|
||||
// Exclude balance gateway for recharge (cannot pay wallet with wallet).
|
||||
foreach (aksrt_list_cash_payment_methods(true) as $m) {
|
||||
$id = is_array($m) ? (string) ($m['id'] ?? '') : (string) $m;
|
||||
if ($id === '' || $id === 'balance') {
|
||||
continue;
|
||||
}
|
||||
$methods[] = is_array($m) ? $m : ['id' => $id, 'name' => $id];
|
||||
}
|
||||
}
|
||||
return [
|
||||
'enabled' => !empty($cfg['enabled']),
|
||||
'desc' => (string) ($cfg['desc'] ?? ''),
|
||||
'wallet' => class_exists('AKSRT_Balance') ? AKSRT_Balance::balance($user_id) : 0.0,
|
||||
'packages' => $packages,
|
||||
'custom_s' => $custom_s,
|
||||
'custom_limit' => $custom_limit,
|
||||
'currency_mark' => (string) ($cfg['product']['tag'] ?? '元'),
|
||||
'payment_methods' => $methods,
|
||||
'transfer' => [
|
||||
'enabled' => !empty($cfg['transfer']['enabled']),
|
||||
'service_charge' => (int) ($cfg['transfer']['service_charge'] ?? 0),
|
||||
'desc' => (string) ($cfg['transfer']['desc'] ?? ''),
|
||||
],
|
||||
'exchange' => [
|
||||
'enabled' => !empty($cfg['exchange']['enabled']),
|
||||
'rate' => (int) ($cfg['exchange']['rate'] ?? 100),
|
||||
'desc' => (string) ($cfg['exchange']['desc'] ?? ''),
|
||||
],
|
||||
'pass_charge' => is_array($cfg['pass_charge'] ?? null) ? $cfg['pass_charge'] : [],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,array{key:string,price:float,pay_price:float,title:string,tag:string}>
|
||||
*/
|
||||
public function parse_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;
|
||||
}
|
||||
// pay|credit|title OR credit|pay|title — Zibll uses price(credit)|pay_price|tag
|
||||
// Admin help: 支付金额|到账金额|标题
|
||||
$parts = array_map('trim', explode('|', $line));
|
||||
if (count($parts) < 2) {
|
||||
continue;
|
||||
}
|
||||
$pay = (float) $parts[0];
|
||||
$credit = (float) $parts[1];
|
||||
$title = $parts[2] ?? '';
|
||||
if ($pay <= 0 || $credit <= 0) {
|
||||
continue;
|
||||
}
|
||||
$out[] = [
|
||||
'key' => (string) $i,
|
||||
'pay_price' => round($pay, 2),
|
||||
'price' => round($credit, 2),
|
||||
'title' => $title !== '' ? $title : sprintf(__('充值 %s 元', 'aksrt'), (string) $credit),
|
||||
'tag' => $title,
|
||||
];
|
||||
$i++;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|WP_Error
|
||||
*/
|
||||
public function create_charge_order(int $user_id, string $package_key, float $custom_price, string $payment_method) {
|
||||
if ($user_id <= 0) {
|
||||
return new WP_Error('aksrt_need_login', __('请先登录', 'aksrt'), ['status' => 401]);
|
||||
}
|
||||
if (!class_exists('AKSRT_Order_Repository') || !class_exists('AKSRT_Order')) {
|
||||
return new WP_Error('aksrt_pay_unavailable', __('订单系统不可用', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$view = $this->get_charge_view($user_id);
|
||||
$credit_amount = 0.0;
|
||||
$pay_amount = 0.0;
|
||||
$title = __('余额充值', 'aksrt');
|
||||
|
||||
if ($package_key === 'custom' || $package_key === '') {
|
||||
if (empty($view['custom_s'])) {
|
||||
return new WP_Error('aksrt_custom_closed', __('未开放自定义金额', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$custom_price = round($custom_price, 2);
|
||||
$min = 1.0;
|
||||
$max = (float) $view['custom_limit'];
|
||||
if ($custom_price < $min || $custom_price > $max) {
|
||||
return new WP_Error('aksrt_custom_limit', sprintf(__('充值金额需在 %s ~ %s 之间', 'aksrt'), (string) $min, (string) $max), ['status' => 400]);
|
||||
}
|
||||
$pay_amount = $custom_price;
|
||||
$credit_amount = $custom_price;
|
||||
$title = sprintf(__('自定义充值 %s 元', 'aksrt'), (string) $custom_price);
|
||||
$package_key = 'custom';
|
||||
} else {
|
||||
$found = null;
|
||||
foreach ((array) $view['packages'] as $pkg) {
|
||||
if ((string) ($pkg['key'] ?? '') === (string) $package_key) {
|
||||
$found = $pkg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
return new WP_Error('aksrt_invalid_package', __('充值套餐无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$pay_amount = (float) $found['pay_price'];
|
||||
$credit_amount = (float) $found['price'];
|
||||
$title = (string) $found['title'];
|
||||
}
|
||||
|
||||
if ($pay_amount <= 0 || $credit_amount <= 0) {
|
||||
return new WP_Error('aksrt_invalid_price', __('金额无效', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$payment_method = sanitize_key($payment_method);
|
||||
if ($payment_method === '' || $payment_method === 'balance') {
|
||||
// Prefer first non-balance method.
|
||||
$methods = $view['payment_methods'] ?? [];
|
||||
$payment_method = !empty($methods[0]['id']) ? (string) $methods[0]['id'] : 'alipay';
|
||||
}
|
||||
|
||||
$note = wp_json_encode([
|
||||
'balance_recharge' => 1,
|
||||
'package' => $package_key,
|
||||
'credit_amount' => $credit_amount,
|
||||
'pay_amount' => $pay_amount,
|
||||
'title' => $title,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$order_number = AKSRT_Order_Repository::get_instance()->create([
|
||||
'user_id' => $user_id,
|
||||
'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RECHARGE,
|
||||
'product_id' => 0,
|
||||
'amount' => $pay_amount,
|
||||
'currency' => 'CNY',
|
||||
'status' => AKSRT_Order::STATUS_PENDING,
|
||||
'payment_method' => $payment_method,
|
||||
'note' => is_string($note) ? $note : '',
|
||||
'expires_at' => gmdate('Y-m-d H:i:s', time() + 30 * MINUTE_IN_SECONDS),
|
||||
]);
|
||||
if ($order_number === '') {
|
||||
return new WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
|
||||
$order = AKSRT_Order_Repository::get_instance()->get($order_number);
|
||||
if (!$order) {
|
||||
return new WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$order['subject'] = $title;
|
||||
$order['payment_method'] = $payment_method;
|
||||
|
||||
if (!class_exists('AKSRT_Payment_Gateway')) {
|
||||
return new WP_Error('aksrt_pay_unavailable', __('支付网关不可用', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$gateway = AKSRT_Payment_Gateway::get_instance()->get_gateway($payment_method);
|
||||
if (!$gateway) {
|
||||
return new WP_Error('aksrt_gateway_unavailable', __('当前支付方式不可用', 'aksrt'), [
|
||||
'status' => 400,
|
||||
'order_number' => $order_number,
|
||||
]);
|
||||
}
|
||||
if (method_exists($gateway, 'is_configured') && !$gateway->is_configured()) {
|
||||
return new WP_Error('aksrt_gateway_unconfigured', __('该支付方式尚未配置,请联系站长。', 'aksrt'), [
|
||||
'status' => 400,
|
||||
'order_number' => $order_number,
|
||||
]);
|
||||
}
|
||||
|
||||
$payment_result = $gateway->create_payment($order);
|
||||
if (empty($payment_result['success'])) {
|
||||
return new WP_Error(
|
||||
'aksrt_pay_failed',
|
||||
(string) ($payment_result['message'] ?? __('支付失败', 'aksrt')),
|
||||
['status' => 402, 'order_number' => $order_number]
|
||||
);
|
||||
}
|
||||
|
||||
$code_url = (string) ($payment_result['payment_data']['code_url'] ?? '');
|
||||
$payment_url = (string) ($payment_result['payment_url'] ?? '');
|
||||
if ($payment_url !== '' || $code_url !== '') {
|
||||
return [
|
||||
'redirect' => true,
|
||||
'payment_url' => $payment_url,
|
||||
'qr_content' => $code_url,
|
||||
'order_number' => $order_number,
|
||||
'amount' => $pay_amount,
|
||||
'credit_amount' => $credit_amount,
|
||||
'message' => $payment_result['message'] ?? __('请在新页面完成支付。', 'aksrt'),
|
||||
'reload' => false,
|
||||
'poll' => true,
|
||||
];
|
||||
}
|
||||
|
||||
// Synchronous gateway (rare for recharge): mark paid → on_order_paid credits wallet.
|
||||
$paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
|
||||
'payment_method' => $payment_method,
|
||||
'payment_transaction_id' => sanitize_text_field((string) ($payment_result['transaction_id'] ?? '')),
|
||||
'note' => __('余额充值支付完成', 'aksrt'),
|
||||
]);
|
||||
if (!$paid) {
|
||||
return new WP_Error('aksrt_order_confirm_failed', __('支付确认失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
// Ensure credit even if status hook shape differs.
|
||||
$this->on_order_paid($order_number, AKSRT_Order_Repository::get_instance()->get($order_number) ?: $order);
|
||||
|
||||
return [
|
||||
'redirect' => false,
|
||||
'order_number' => $order_number,
|
||||
'amount' => $pay_amount,
|
||||
'credit_amount' => $credit_amount,
|
||||
'wallet' => AKSRT_Balance::balance($user_id),
|
||||
'message' => __('充值成功', 'aksrt'),
|
||||
'reload' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* User center credits: points card + sign-in controls + credits card-pass redeem.
|
||||
*
|
||||
* Cash wallet UI lives in credits-wallet.php.
|
||||
* User center credits: points asset card + sign-in + credits card-pass.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -20,26 +18,32 @@ if (class_exists('AKSRT_Charge_Card')) {
|
||||
$opts = AKSRT_Charge_Card::get_instance()->get_public_options();
|
||||
$card_pass_credits = is_array($opts['credits'] ?? null) ? $opts['credits'] : $card_pass_credits;
|
||||
}
|
||||
$points_transfer_on = class_exists('AKSRT_Settings') && !empty(AKSRT_Settings::get_all()['points_transfer_s']);
|
||||
$currency = (string) ($currency_name ?? __('积分', 'aksrt'));
|
||||
?>
|
||||
<div class="uc-balance-card">
|
||||
<div class="uc-balance-card__bg"></div>
|
||||
<div class="uc-balance-card__content">
|
||||
<div class="uc-balance-card__header">
|
||||
<span class="uc-balance-card__label"><?php echo esc_html(sprintf(__('%s余额', 'aksrt'), $currency_name)); ?></span>
|
||||
<span class="uc-balance-card__currency"><?php echo esc_html($currency_name); ?></span>
|
||||
<div class="uc-asset-card uc-asset-card--points zib-widget">
|
||||
<div class="uc-asset-card__head flex jsb ac">
|
||||
<div class="uc-asset-card__title">
|
||||
<i class="fas fa-coins em12 mr6" aria-hidden="true"></i><?php echo esc_html($currency); ?>
|
||||
</div>
|
||||
<div class="uc-balance-card__amount">
|
||||
<span class="uc-balance-card__value"><?php echo esc_html(aksrt_format_credits((int) $balance)); ?></span>
|
||||
</div>
|
||||
<div class="uc-balance-card__actions" data-aksrt-signin>
|
||||
<span class="uc-balance-card__sign-status" data-signin-status></span>
|
||||
<button type="button" class="uc-balance-card__sign-btn" data-signin-btn disabled>
|
||||
<i class="fas fa-calendar-check" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('签到', 'aksrt'); ?></span>
|
||||
<span class="uc-asset-card__head-action muted-color px12" data-aksrt-signin>
|
||||
<button type="button" class="uc-asset-card__signin muted-color px12" data-signin-btn disabled>
|
||||
<?php esc_html_e('签到领积分', 'aksrt'); ?><i class="fa fa-angle-right em12 ml3" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
<p class="uc-balance-card__tip" data-signin-tip></p>
|
||||
<span class="uc-asset-card__signin-status" data-signin-status></span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="uc-asset-card__body flex jsb ac">
|
||||
<div class="uc-asset-card__amount c-green">
|
||||
<span class="uc-asset-card__value font-bold"><?php echo esc_html(function_exists('aksrt_format_credits') ? aksrt_format_credits((int) $balance) : (string) (int) $balance); ?></span>
|
||||
</div>
|
||||
<div class="uc-asset-card__actions flex0">
|
||||
<?php if ($points_transfer_on) : ?>
|
||||
<button type="button" class="but c-green mr6 hollow" data-aksrt-transfer-open="points"><?php esc_html_e('转账', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<p class="uc-balance-card__tip muted-2-color em09" data-signin-tip></p>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($card_pass_credits['enabled'])) : ?>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* User center: cash wallet (站内余额) card + ledger.
|
||||
* User center: cash wallet (站内余额) — Zibll-like asset card.
|
||||
*
|
||||
* Expects extracted $context vars: $user_id, $wallet_balance, $balance_enabled, $card pass opts.
|
||||
* Expects extracted $context vars.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -14,43 +14,60 @@ if (empty($balance_enabled)) {
|
||||
}
|
||||
|
||||
$wallet = (float) ($wallet_balance ?? 0.0);
|
||||
$wallet_fmt = class_exists('AKSRT_Balance')
|
||||
? AKSRT_Balance::format($wallet)
|
||||
: number_format_i18n($wallet, 2);
|
||||
|
||||
$recharge = class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_payment_recharge_settings')
|
||||
? AKSRT_Settings::get_payment_recharge_settings()
|
||||
: [];
|
||||
$transfer_on = !empty($recharge['transfer']['enabled']);
|
||||
$exchange_on = !empty($recharge['exchange']['enabled']);
|
||||
$card_pass_balance = ['enabled' => false, 'desc' => '', 'only_password' => true];
|
||||
if (class_exists('AKSRT_Charge_Card')) {
|
||||
$opts = AKSRT_Charge_Card::get_instance()->get_public_options();
|
||||
$card_pass_balance = is_array($opts['balance'] ?? null) ? $opts['balance'] : $card_pass_balance;
|
||||
} elseif (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_payment_recharge_settings')) {
|
||||
$recharge = AKSRT_Settings::get_payment_recharge_settings();
|
||||
$pc = is_array($recharge['pass_charge'] ?? null) ? $recharge['pass_charge'] : [];
|
||||
$card_pass_balance = [
|
||||
'enabled' => !empty($pc['enabled']),
|
||||
'desc' => (string) ($pc['desc'] ?? ''),
|
||||
'only_password' => !isset($pc['only_password']) || !empty($pc['only_password']),
|
||||
];
|
||||
} elseif (!empty($recharge['pass_charge'])) {
|
||||
$card_pass_balance = is_array($recharge['pass_charge']) ? $recharge['pass_charge'] : $card_pass_balance;
|
||||
}
|
||||
|
||||
$charge_view = [];
|
||||
if (class_exists('AKSRT_Balance_Service')) {
|
||||
$charge_view = AKSRT_Balance_Service::get_instance()->get_charge_view((int) $user_id);
|
||||
}
|
||||
$packages = is_array($charge_view['packages'] ?? null) ? $charge_view['packages'] : [];
|
||||
$methods = is_array($charge_view['payment_methods'] ?? null) ? $charge_view['payment_methods'] : [];
|
||||
$custom_s = !empty($charge_view['custom_s']);
|
||||
$custom_limit = (int) ($charge_view['custom_limit'] ?? 9999);
|
||||
$mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
?>
|
||||
<div class="uc-wallet-grid">
|
||||
<div class="uc-balance-card uc-balance-card--wallet">
|
||||
<div class="uc-balance-card__bg uc-balance-card__bg--wallet"></div>
|
||||
<div class="uc-balance-card__content">
|
||||
<div class="uc-balance-card__header">
|
||||
<span class="uc-balance-card__label"><?php esc_html_e('钱包余额', 'aksrt'); ?></span>
|
||||
<span class="uc-balance-card__currency"><?php esc_html_e('元', 'aksrt'); ?></span>
|
||||
</div>
|
||||
<div class="uc-balance-card__amount">
|
||||
<span class="uc-balance-card__value">
|
||||
<?php
|
||||
echo esc_html(
|
||||
class_exists('AKSRT_Balance')
|
||||
? AKSRT_Balance::format($wallet)
|
||||
: number_format_i18n($wallet, 2)
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
</div>
|
||||
<p class="uc-balance-card__tip"><?php esc_html_e('可用于站内余额支付、卡密充值入账', 'aksrt'); ?></p>
|
||||
<div class="uc-asset-card uc-asset-card--wallet zib-widget">
|
||||
<div class="uc-asset-card__head flex jsb ac">
|
||||
<div class="uc-asset-card__title">
|
||||
<i class="fas fa-wallet em12 mr6" aria-hidden="true"></i><?php esc_html_e('余额', 'aksrt'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uc-asset-card__body flex jsb ac">
|
||||
<div class="uc-asset-card__amount c-blue-2">
|
||||
<span class="uc-asset-card__mark px12"><?php echo esc_html($mark === '元' ? '¥' : $mark); ?></span>
|
||||
<span class="uc-asset-card__value font-bold"><?php echo esc_html($wallet_fmt); ?></span>
|
||||
</div>
|
||||
<div class="uc-asset-card__actions flex0">
|
||||
<?php if ($transfer_on) : ?>
|
||||
<button type="button" class="but c-blue-2 mr6 hollow" data-aksrt-transfer-open="balance"><?php esc_html_e('转账', 'aksrt'); ?></button>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="but b-blue-2" data-aksrt-charge-open><?php esc_html_e('充值', 'aksrt'); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($exchange_on) : ?>
|
||||
<button type="button" class="uc-asset-card__link muted-2-color em09" data-aksrt-exchange-open>
|
||||
<?php
|
||||
$rate = (int) ($recharge['exchange']['rate'] ?? 100);
|
||||
printf(esc_html__('积分兑换余额(%d 积分 = 1 元)', 'aksrt'), $rate);
|
||||
?>
|
||||
<i class="fa fa-angle-right em12 ml3" aria-hidden="true"></i>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($card_pass_balance['enabled'])) : ?>
|
||||
@@ -73,20 +90,128 @@ if (class_exists('AKSRT_Charge_Card')) {
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Charge modal -->
|
||||
<div class="uc-modal" id="aksrt-charge-modal" hidden data-aksrt-charge-modal>
|
||||
<div class="uc-modal__overlay" data-aksrt-charge-close></div>
|
||||
<div class="uc-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="aksrt-charge-title">
|
||||
<button type="button" class="uc-modal__close" data-aksrt-charge-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
|
||||
<h3 id="aksrt-charge-title" class="uc-modal__title"><i class="fas fa-wallet mr6" aria-hidden="true"></i><?php esc_html_e('余额充值', 'aksrt'); ?></h3>
|
||||
<?php if (!empty($charge_view['desc'])) : ?>
|
||||
<div class="uc-modal__desc muted-box em09"><?php echo esc_html((string) $charge_view['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<form class="uc-charge-form" data-aksrt-charge-form>
|
||||
<?php if ($packages) : ?>
|
||||
<div class="muted-color mb6"><?php esc_html_e('请选择充值金额', 'aksrt'); ?></div>
|
||||
<div class="uc-charge-packages">
|
||||
<?php foreach ($packages as $idx => $pkg) : ?>
|
||||
<label class="uc-charge-package<?php echo $idx === 0 ? ' is-active' : ''; ?>">
|
||||
<input type="radio" name="balance_package" value="<?php echo esc_attr((string) $pkg['key']); ?>" <?php checked($idx === 0); ?>>
|
||||
<div class="uc-charge-package__credit"><span class="px12">¥</span><?php echo esc_html((string) $pkg['price']); ?></div>
|
||||
<div class="uc-charge-package__pay c-red"><span class="px12">¥</span><?php echo esc_html((string) $pkg['pay_price']); ?>
|
||||
<?php if ((float) $pkg['pay_price'] < (float) $pkg['price']) : ?>
|
||||
<span class="ml6 c-yellow smail"><?php printf(esc_html__('省%s', 'aksrt'), esc_html((string) ((float) $pkg['price'] - (float) $pkg['pay_price']))); ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!empty($pkg['tag'])) : ?>
|
||||
<span class="uc-charge-package__tag"><?php echo esc_html((string) $pkg['tag']); ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($custom_s) : ?>
|
||||
<div class="muted-color mt16 mb6"><?php echo $packages ? esc_html__('自定义充值金额', 'aksrt') : esc_html__('请输入充值金额', 'aksrt'); ?></div>
|
||||
<div class="uc-charge-custom flex ac">
|
||||
<span class="mr10 muted-color">¥</span>
|
||||
<input type="number" class="uc-charge-custom__input" name="custom_price" min="1" max="<?php echo esc_attr((string) $custom_limit); ?>" step="0.01" placeholder="1 ~ <?php echo esc_attr((string) $custom_limit); ?>">
|
||||
</div>
|
||||
<?php if (!$packages) : ?>
|
||||
<input type="hidden" name="balance_package" value="custom">
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php if ($methods) : ?>
|
||||
<div class="muted-color mt16 mb6"><?php esc_html_e('支付方式', 'aksrt'); ?></div>
|
||||
<div class="uc-charge-methods">
|
||||
<?php foreach ($methods as $mi => $m) : ?>
|
||||
<label class="uc-charge-method">
|
||||
<input type="radio" name="payment_method" value="<?php echo esc_attr((string) ($m['id'] ?? '')); ?>" <?php checked($mi === 0); ?>>
|
||||
<span><?php echo esc_html((string) ($m['name'] ?? $m['id'] ?? '')); ?></span>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<p class="uc-modal__tip" data-aksrt-charge-tip></p>
|
||||
<button type="submit" class="but jb-blue btn-block mt10" data-aksrt-charge-submit><?php esc_html_e('立即充值', 'aksrt'); ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Transfer modal (balance) -->
|
||||
<div class="uc-modal" id="aksrt-transfer-modal" hidden data-aksrt-transfer-modal>
|
||||
<div class="uc-modal__overlay" data-aksrt-transfer-close></div>
|
||||
<div class="uc-modal__dialog" role="dialog" aria-modal="true">
|
||||
<button type="button" class="uc-modal__close" data-aksrt-transfer-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
|
||||
<h3 class="uc-modal__title" data-aksrt-transfer-title><?php esc_html_e('余额转账', 'aksrt'); ?></h3>
|
||||
<form data-aksrt-transfer-form>
|
||||
<input type="hidden" name="type" value="balance" data-aksrt-transfer-type>
|
||||
<div class="mb10">
|
||||
<label class="muted-color em09"><?php esc_html_e('收款用户', 'aksrt'); ?></label>
|
||||
<input type="search" class="uc-card-pass__input" data-aksrt-transfer-search placeholder="<?php esc_attr_e('搜索用户名/昵称/邮箱', 'aksrt'); ?>" autocomplete="off">
|
||||
<div class="uc-transfer-results" data-aksrt-transfer-results></div>
|
||||
<input type="hidden" name="recipient" value="" data-aksrt-transfer-recipient>
|
||||
<div class="uc-transfer-selected muted-2-color em09 mt6" data-aksrt-transfer-selected></div>
|
||||
</div>
|
||||
<div class="mb10">
|
||||
<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" data-aksrt-transfer-amount>
|
||||
</div>
|
||||
<?php if (!empty($recharge['transfer']['desc'])) : ?>
|
||||
<div class="muted-box em09 mb10"><?php echo esc_html((string) $recharge['transfer']['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($recharge['transfer']['service_charge'])) : ?>
|
||||
<div class="c-yellow em09 mb10"><?php printf(esc_html__('转账将扣除 %s%% 手续费', 'aksrt'), esc_html((string) (int) $recharge['transfer']['service_charge'])); ?></div>
|
||||
<?php endif; ?>
|
||||
<p class="uc-modal__tip" data-aksrt-transfer-tip></p>
|
||||
<button type="submit" class="but jb-blue btn-block" data-aksrt-transfer-submit><?php esc_html_e('确认转账', 'aksrt'); ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Exchange modal -->
|
||||
<?php if ($exchange_on) : ?>
|
||||
<div class="uc-modal" id="aksrt-exchange-modal" hidden data-aksrt-exchange-modal>
|
||||
<div class="uc-modal__overlay" data-aksrt-exchange-close></div>
|
||||
<div class="uc-modal__dialog" role="dialog" aria-modal="true">
|
||||
<button type="button" class="uc-modal__close" data-aksrt-exchange-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times" aria-hidden="true"></i></button>
|
||||
<h3 class="uc-modal__title"><?php esc_html_e('积分兑换余额', 'aksrt'); ?></h3>
|
||||
<?php if (!empty($recharge['exchange']['desc'])) : ?>
|
||||
<div class="muted-box em09 mb10"><?php echo esc_html((string) $recharge['exchange']['desc']); ?></div>
|
||||
<?php endif; ?>
|
||||
<form data-aksrt-exchange-form>
|
||||
<label class="muted-color em09"><?php esc_html_e('兑换积分数量', 'aksrt'); ?></label>
|
||||
<input type="number" class="uc-card-pass__input" name="points" min="<?php echo esc_attr((string) (int) ($recharge['exchange']['rate'] ?? 100)); ?>" step="1" data-aksrt-exchange-points>
|
||||
<p class="muted-2-color em09 mt6">
|
||||
<?php printf(esc_html__('比例:%d 积分 = 1 元(向下取整)', 'aksrt'), (int) ($recharge['exchange']['rate'] ?? 100)); ?>
|
||||
</p>
|
||||
<p class="uc-modal__tip" data-aksrt-exchange-tip></p>
|
||||
<button type="submit" class="but jb-blue btn-block" data-aksrt-exchange-submit><?php esc_html_e('确认兑换', 'aksrt'); ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="uc-transactions uc-transactions--wallet">
|
||||
<div class="uc-transactions__header">
|
||||
<h3 class="uc-transactions__title">
|
||||
<i class="fas fa-list-ul" aria-hidden="true"></i>
|
||||
<?php esc_html_e('余额明细', 'aksrt'); ?>
|
||||
<?php esc_html_e('余额记录', 'aksrt'); ?>
|
||||
</h3>
|
||||
</div>
|
||||
<?php
|
||||
$wallet_page = max(1, isset($_GET['wallet_page']) ? (int) $_GET['wallet_page'] : 1);
|
||||
if (class_exists('AKSRT_Balance')) {
|
||||
$wlog = AKSRT_Balance::get_log(['user_id' => (int) $user_id, 'page' => $wallet_page, 'per_page' => 10]);
|
||||
} else {
|
||||
$wlog = ['items' => [], 'total' => 0];
|
||||
}
|
||||
$wlog = class_exists('AKSRT_Balance')
|
||||
? AKSRT_Balance::get_log(['user_id' => (int) $user_id, 'page' => $wallet_page, 'per_page' => 10])
|
||||
: ['items' => [], 'total' => 0];
|
||||
if (!empty($wlog['items'])) :
|
||||
?>
|
||||
<div class="uc-transactions__list">
|
||||
@@ -101,35 +226,20 @@ if (class_exists('AKSRT_Charge_Card')) {
|
||||
</div>
|
||||
<div class="uc-transactions__info">
|
||||
<div class="uc-transactions__reason">
|
||||
<?php
|
||||
echo esc_html(
|
||||
class_exists('AKSRT_Balance')
|
||||
? AKSRT_Balance::reason_label((string) $row['reason'])
|
||||
: (string) $row['reason']
|
||||
);
|
||||
?>
|
||||
<?php echo esc_html(class_exists('AKSRT_Balance') ? AKSRT_Balance::reason_label((string) $row['reason']) : (string) $row['reason']); ?>
|
||||
<?php if (!empty($row['remark'])) : ?>
|
||||
<span class="uc-transactions__remark">(<?php echo esc_html((string) $row['remark']); ?>)</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="uc-transactions__time">
|
||||
<?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?>
|
||||
</div>
|
||||
<div class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
|
||||
</div>
|
||||
<div class="uc-transactions__amount">
|
||||
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>">
|
||||
<?php echo esc_html($delta_txt); ?>
|
||||
</span>
|
||||
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>"><?php echo esc_html($delta_txt); ?></span>
|
||||
<span class="uc-transactions__balance">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: wallet balance */
|
||||
esc_html__('余额 %s', 'aksrt'),
|
||||
esc_html(
|
||||
class_exists('AKSRT_Balance')
|
||||
? AKSRT_Balance::format((float) $row['balance_after'])
|
||||
: number_format_i18n((float) $row['balance_after'], 2)
|
||||
)
|
||||
esc_html(class_exists('AKSRT_Balance') ? AKSRT_Balance::format((float) $row['balance_after']) : number_format_i18n((float) $row['balance_after'], 2))
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
@@ -145,9 +255,7 @@ if (class_exists('AKSRT_Charge_Card')) {
|
||||
?>
|
||||
<?php else : ?>
|
||||
<div class="uc-transactions__empty">
|
||||
<div class="uc-transactions__empty-icon">
|
||||
<i class="fas fa-wallet" aria-hidden="true"></i>
|
||||
</div>
|
||||
<div class="uc-transactions__empty-icon"><i class="fas fa-wallet" aria-hidden="true"></i></div>
|
||||
<p><?php esc_html_e('还没有任何余额流水', 'aksrt'); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* User center credits panel orchestrator.
|
||||
* User center assets panel orchestrator (wallet + points).
|
||||
*
|
||||
* Zibll-like dual assets: cash wallet + points, when each is enabled.
|
||||
* Zibll user-tab-balance parity layout.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -13,24 +13,35 @@ $context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
||||
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
||||
|
||||
$dir = __DIR__;
|
||||
|
||||
$show_wallet = !empty($balance_enabled);
|
||||
$show_credits = !empty($credits_enabled);
|
||||
|
||||
if ($show_wallet) {
|
||||
require $dir . '/credits-wallet.php';
|
||||
}
|
||||
// Dual cards row (Zibll row gutters-10).
|
||||
if ($show_wallet || $show_credits) :
|
||||
?>
|
||||
<div class="uc-assets-row<?php echo ($show_wallet && $show_credits) ? ' uc-assets-row--dual' : ''; ?>">
|
||||
<?php if ($show_wallet) : ?>
|
||||
<div class="uc-assets-col">
|
||||
<?php require $dir . '/credits-wallet.php'; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_credits) : ?>
|
||||
<div class="uc-assets-col">
|
||||
<?php
|
||||
// Points card only (ledger rendered once below).
|
||||
require $dir . '/credits-balance.php';
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
// Points block (existing UI) — only when credits system on.
|
||||
if ($show_credits) {
|
||||
// Rename label in balance card is handled inside credits-balance (账户余额 → 积分).
|
||||
require $dir . '/credits-balance.php';
|
||||
if (!empty($show_vip)) {
|
||||
require $dir . '/credits-vip.php';
|
||||
}
|
||||
if ($show_credits) {
|
||||
require $dir . '/credits-signin.php';
|
||||
require $dir . '/credits-transactions.php';
|
||||
} elseif ($show_wallet) {
|
||||
// Wallet-only: still show VIP block if enabled.
|
||||
if (!empty($show_vip)) {
|
||||
require $dir . '/credits-vip.php';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,44 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* User center sidebar: rights / commerce shortcuts.
|
||||
*
|
||||
* Expects extracted $context vars.
|
||||
* User center sidebar: Zibll dual asset mini cards + commerce shortcuts.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (empty($orders_url) && empty($show_vip) && empty($show_credit_tabs) && empty($balance_enabled)) {
|
||||
$show_wallet = !empty($balance_enabled);
|
||||
$show_credits = !empty($show_credit_tabs) || !empty($credits_enabled);
|
||||
$wallet = (float) ($wallet_balance ?? 0.0);
|
||||
$points = (float) ($credit_balance ?? 0.0);
|
||||
$currency = (string) ($currency_name ?? __('积分', 'aksrt'));
|
||||
|
||||
if ($show_wallet || $show_credits) :
|
||||
$assets_url = function_exists('aksrt_get_user_center_tab_url')
|
||||
? aksrt_get_user_center_tab_url('credits')
|
||||
: '#';
|
||||
?>
|
||||
<div class="uc-sidebar__section">
|
||||
<div class="uc-sidebar__title"><?php esc_html_e('我的资产', 'aksrt'); ?></div>
|
||||
<div class="uc-asset-mini flex ab jsb col-ml6">
|
||||
<?php if ($show_wallet) : ?>
|
||||
<a class="uc-asset-mini__card flex1" href="<?php echo esc_url($assets_url); ?>">
|
||||
<div class="uc-asset-mini__label muted-2-color em09"><?php esc_html_e('余额', 'aksrt'); ?><i class="ml6 fa fa-angle-right em12" aria-hidden="true"></i></div>
|
||||
<div class="flex jsb ac">
|
||||
<span class="font-bold c-blue-2"><?php echo esc_html(class_exists('AKSRT_Balance') ? AKSRT_Balance::format($wallet) : number_format_i18n($wallet, 2)); ?></span>
|
||||
<i class="fas fa-wallet em14 c-blue-2" aria-hidden="true"></i>
|
||||
</div>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_credits) : ?>
|
||||
<a class="uc-asset-mini__card flex1" href="<?php echo esc_url($assets_url); ?>">
|
||||
<div class="uc-asset-mini__label muted-2-color em09"><?php echo esc_html($currency); ?><i class="ml6 fa fa-angle-right em12" aria-hidden="true"></i></div>
|
||||
<div class="flex jsb ac">
|
||||
<span class="font-bold c-yellow"><?php echo esc_html(function_exists('aksrt_format_credits') ? aksrt_format_credits((int) $points) : (string) (int) $points); ?></span>
|
||||
<i class="fas fa-coins em14 c-yellow" aria-hidden="true"></i>
|
||||
</div>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if (empty($orders_url) && empty($show_vip) && empty($show_credit_tabs) && empty($balance_enabled) && empty($affiliate_enabled)) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="uc-sidebar__section">
|
||||
<div class="uc-sidebar__title"><?php esc_html_e('权益与消费', 'aksrt'); ?></div>
|
||||
<div class="uc-sidebar__buttons">
|
||||
<?php
|
||||
$revenue_url = function_exists('aksrt_get_revenue_page_url') ? aksrt_get_revenue_page_url() : '';
|
||||
?>
|
||||
<?php if ($orders_url) : ?>
|
||||
<?php $revenue_url = function_exists('aksrt_get_revenue_page_url') ? aksrt_get_revenue_page_url() : ''; ?>
|
||||
<?php if (!empty($orders_url)) : ?>
|
||||
<a href="<?php echo esc_url($orders_url); ?>" class="uc-sidebar__btn">
|
||||
<i class="fas fa-receipt" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('我的订单', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_vip) : ?>
|
||||
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
|
||||
<?php if (!empty($show_vip)) : ?>
|
||||
<a class="uc-sidebar__btn<?php echo (!empty($active_tab) && $active_tab === 'credits') ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
|
||||
<i class="fas fa-crown" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('VIP 会员', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_credit_tabs) : ?>
|
||||
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
|
||||
<i class="fas fa-coins" aria-hidden="true"></i>
|
||||
<span><?php echo esc_html($currency_name); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($affiliate_enabled) && $revenue_url) : ?>
|
||||
<a href="<?php echo esc_url($revenue_url); ?>" class="uc-sidebar__btn">
|
||||
<?php if (!empty($affiliate_enabled) && $revenue_url) : ?>
|
||||
<a href="<?php echo esc_url($revenue_url); ?>" class="uc-sidebar__btn">
|
||||
<i class="fas fa-share-alt" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('推广返佣', 'aksrt'); ?></span>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user