feat(pay): content cashier, resource orders at VIP price, purchase/download JS loop
Wire zibll-style one-shot points/cash cashier for post+_aksrt_pay downloads: server amount from aksrt_get_user_pay_price, ORDER_PRODUCT_RESOURCE unlock, frontend need-purchase opens modal, download box purchased/VIP/purchase CTAs.
This commit is contained in:
+249
-3
@@ -140,13 +140,29 @@
|
||||
title = tt('need_login', '请先登录');
|
||||
msg = tt('login_hint', '登录后即可继续下载,访客不可使用此资源。');
|
||||
extra = '<a class="btn-primary btn-sm" href="' + data.login_url + '">' + tt('go_login', '前往登录') + '</a>';
|
||||
} else if (code === 'aksrt_credits_insufficient') {
|
||||
} else if (code === 'aksrt_need_purchase') {
|
||||
title = tt('need_purchase', '请先购买');
|
||||
msg = msg || tt('purchase_hint', '请先完成购买后再下载该资源。');
|
||||
extra = '<button type="button" class="btn-primary btn-sm" data-aksrt-open-cashier="' + escapeAttr((data && data.post_id) || '') + '">' + tt('go_buy', '去购买') + '</button>';
|
||||
} else if (code === 'aksrt_need_vip') {
|
||||
title = tt('need_vip', '会员专属');
|
||||
msg = msg || tt('vip_hint', '该资源仅限会员购买/下载。');
|
||||
if (data && data.vip_url) {
|
||||
extra = '<a class="btn-primary btn-sm" href="' + escapeAttr(data.vip_url) + '">' + tt('go_vip', '开通会员') + '</a>';
|
||||
}
|
||||
} else if (code === 'aksrt_credits_insufficient' || code === 'aksrt_balance_insufficient') {
|
||||
title = tt('credit_low', '积分不够');
|
||||
const balance = typeof (data && data.balance) === 'number' ? data.balance : 0;
|
||||
const cost = typeof (data && data.cost) === 'number' ? data.cost : 0;
|
||||
msg = tt('credit_hint',
|
||||
'当前余额 ' + balance + ' 积分,需要 ' + cost + ' 积分。可通过签到、阅读、邀请好友等方式获取积分。'
|
||||
);
|
||||
if (data && data.credits_url) {
|
||||
extra = '<a class="btn-primary btn-sm" href="' + escapeAttr(data.credits_url) + '">' + tt('my_points', '我的积分') + '</a>';
|
||||
}
|
||||
} else if (code === 'aksrt_captcha_failed') {
|
||||
title = tt('captcha_fail', '验证失败');
|
||||
msg = msg || tt('captcha_retry', '人机验证失败,请重试。');
|
||||
} else if (data && data.login_url) {
|
||||
extra = '<a class="btn-primary btn-sm" href="' + data.login_url + '">' + tt('go_login', '前往登录') + '</a>';
|
||||
}
|
||||
@@ -157,6 +173,15 @@
|
||||
(extra ? '<div class="aksrt-dl-modal__actions">' + extra + '</div>' : ''),
|
||||
returnFocusEl
|
||||
);
|
||||
|
||||
const openCashierBtn = document.querySelector('[data-aksrt-open-cashier]');
|
||||
if (openCashierBtn) {
|
||||
openCashierBtn.addEventListener('click', function () {
|
||||
const pid = parseInt(openCashierBtn.getAttribute('data-aksrt-open-cashier'), 10) || 0;
|
||||
close();
|
||||
if (pid) openCashier(pid, returnFocusEl);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 成功渲染 =====
|
||||
@@ -303,6 +328,189 @@
|
||||
renderError('', { balance: balance, cost: cost }, button, 'aksrt_credits_insufficient');
|
||||
}
|
||||
|
||||
// ===== 收银台(内容购买) =====
|
||||
function restHeaders() {
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
'X-WP-Nonce': window.aksrtData.restNonce || '',
|
||||
};
|
||||
}
|
||||
|
||||
function openCashier(postId, returnFocusEl) {
|
||||
if (!postId) return;
|
||||
open(
|
||||
'<h3 class="aksrt-dl-modal__title">' + tt('cashier_loading', '确认购买') + '</h3>' +
|
||||
'<p class="aksrt-dl-modal__msg">' + tt('loading', '加载中…') + '</p>',
|
||||
returnFocusEl
|
||||
);
|
||||
|
||||
fetch(REST_BASE + '/pay/content/' + postId, {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
headers: restHeaders(),
|
||||
})
|
||||
.then(function (resp) { return resp.json().then(function (j) { return { ok: resp.ok, status: resp.status, json: j }; }); })
|
||||
.then(function (r) {
|
||||
if (!r.ok || (r.json && r.json.code)) {
|
||||
const code = r.json && r.json.code ? r.json.code : '';
|
||||
const data = (r.json && r.json.data) || {};
|
||||
if (code === 'aksrt_need_login' || r.status === 401) {
|
||||
renderError(r.json.message || '', data, returnFocusEl, 'aksrt_need_login');
|
||||
return;
|
||||
}
|
||||
if (code === 'aksrt_need_vip') {
|
||||
renderError(r.json.message || '', data, returnFocusEl, 'aksrt_need_vip');
|
||||
return;
|
||||
}
|
||||
if (code === 'aksrt_already_paid') {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
renderError((r.json && r.json.message) || tt('default_err', '请稍后重试'), data, returnFocusEl, code);
|
||||
return;
|
||||
}
|
||||
renderCashier(r.json, returnFocusEl);
|
||||
})
|
||||
.catch(function () {
|
||||
renderError(tt('network_err', '网络错误,请稍后重试'), {}, returnFocusEl);
|
||||
});
|
||||
}
|
||||
|
||||
function renderCashier(preview, returnFocusEl) {
|
||||
if (!preview) return;
|
||||
if (preview.need_login) {
|
||||
renderError('', { login_url: preview.login_url }, returnFocusEl, 'aksrt_need_login');
|
||||
return;
|
||||
}
|
||||
if (preview.need_vip) {
|
||||
renderError('', { vip_url: preview.vip_url }, returnFocusEl, 'aksrt_need_vip');
|
||||
return;
|
||||
}
|
||||
if (preview.has_paid_access || preview.is_free) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
const isPoints = preview.pay_modo === 'points';
|
||||
const amountLabel = escapeHtml(preview.amount_label || '');
|
||||
const baseLabel = escapeHtml(preview.base_label || '');
|
||||
const title = escapeHtml(preview.title || '');
|
||||
const typeLabel = escapeHtml(preview.pay_type_label || '');
|
||||
const balance = typeof preview.balance === 'number' ? preview.balance : 0;
|
||||
const methods = Array.isArray(preview.payment_methods) ? preview.payment_methods : [];
|
||||
|
||||
let priceRows = '';
|
||||
if (!preview.pay_limit) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('price', '价格') + '</span><b>' + baseLabel + '</b></div>';
|
||||
}
|
||||
if (preview.amount !== preview.base) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('vip_price', '会员价') + '</span><b class="is-sale">' + amountLabel + '</b></div>';
|
||||
}
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('pay_amount', '支付金额') + '</span><b class="is-sale">' + amountLabel + '</b></div>';
|
||||
|
||||
let body = '';
|
||||
body += '<div class="aksrt-cashier__product"><span class="aksrt-cashier__tag">' + typeLabel + '</span><span>' + title + '</span></div>';
|
||||
body += '<div class="aksrt-cashier__box">' + priceRows + '</div>';
|
||||
|
||||
if (isPoints) {
|
||||
body += '<div class="aksrt-cashier__box"><div class="aksrt-cashier__row"><span>' + tt('my_points', '我的积分') + '</span><b class="is-ok">' + balance + '</b></div></div>';
|
||||
if (!preview.balance_enough) {
|
||||
body += '<div class="aksrt-cashier__warn">' + tt('points_short', '抱歉,您的积分不足,暂时无法支付') + '</div>';
|
||||
body += '<div class="aksrt-dl-modal__actions">';
|
||||
if (preview.credits_url) {
|
||||
body += '<a class="btn-primary btn-sm" href="' + escapeAttr(preview.credits_url) + '">' + tt('my_points', '我的积分') + '</a>';
|
||||
}
|
||||
body += '</div>';
|
||||
open('<h3 class="aksrt-dl-modal__title">' + tt('confirm_buy', '确认购买') + '</h3>' + body, returnFocusEl);
|
||||
return;
|
||||
}
|
||||
body += '<div class="aksrt-dl-modal__actions">';
|
||||
body += '<button type="button" class="btn-primary aksrt-dl-modal__download" data-aksrt-pay-submit data-mode="points">' + tt('pay_now', '立即支付') + ' ' + amountLabel + '</button>';
|
||||
body += '</div>';
|
||||
} else {
|
||||
let methodHtml = '';
|
||||
methods.forEach(function (m, idx) {
|
||||
const id = escapeAttr(m.id || '');
|
||||
const name = escapeHtml(m.name || id);
|
||||
methodHtml += '<label class="aksrt-cashier__method"><input type="radio" name="aksrt_pay_method" value="' + id + '"' + (idx === 0 ? ' checked' : '') + '> <span>' + name + '</span></label>';
|
||||
});
|
||||
if (methodHtml) {
|
||||
body += '<div class="aksrt-cashier__methods"><div class="aksrt-cashier__methods-title">' + tt('pay_method', '支付方式') + '</div>' + methodHtml + '</div>';
|
||||
}
|
||||
body += '<div class="aksrt-dl-modal__actions">';
|
||||
body += '<button type="button" class="btn-primary aksrt-dl-modal__download" data-aksrt-pay-submit data-mode="cash">' + tt('pay_now', '立即支付') + ' ' + amountLabel + '</button>';
|
||||
body += '</div>';
|
||||
}
|
||||
|
||||
open('<h3 class="aksrt-dl-modal__title">' + tt('confirm_buy', '确认购买') + '</h3>' + body, returnFocusEl);
|
||||
|
||||
const submitBtn = document.querySelector('[data-aksrt-pay-submit]');
|
||||
if (submitBtn) {
|
||||
submitBtn.addEventListener('click', function () {
|
||||
const mode = submitBtn.getAttribute('data-mode') || (isPoints ? 'points' : 'cash');
|
||||
let paymentMethod = 'balance';
|
||||
const checked = document.querySelector('input[name="aksrt_pay_method"]:checked');
|
||||
if (checked) paymentMethod = checked.value;
|
||||
submitPurchase(preview.post_id, mode, paymentMethod, submitBtn, returnFocusEl);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function submitPurchase(postId, mode, paymentMethod, button, returnFocusEl) {
|
||||
if (!postId) return;
|
||||
const original = button.innerHTML;
|
||||
button.disabled = true;
|
||||
button.innerHTML = tt('processing', '处理中…');
|
||||
|
||||
const payload = { mode: mode };
|
||||
if (mode === 'cash') payload.payment_method = paymentMethod || 'balance';
|
||||
|
||||
fetch(REST_BASE + '/pay/content/' + postId, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: restHeaders(),
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
.then(function (resp) { return resp.json().then(function (j) { return { ok: resp.ok, status: resp.status, json: j }; }); })
|
||||
.then(function (r) {
|
||||
button.disabled = false;
|
||||
button.innerHTML = original;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
const code = r.json && r.json.code ? r.json.code : '';
|
||||
const data = (r.json && r.json.data) || {};
|
||||
if (code === 'aksrt_already_paid') {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
renderError((r.json && r.json.message) || tt('default_err', '请稍后重试'), data, returnFocusEl, code);
|
||||
return;
|
||||
}
|
||||
const 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.location.href = data.payment_url;
|
||||
return;
|
||||
}
|
||||
open(
|
||||
'<h3 class="aksrt-dl-modal__title">' + tt('scan_pay', '扫码支付') + '</h3>' +
|
||||
'<p class="aksrt-dl-modal__msg">' + escapeHtml(data.message || tt('scan_hint', '请使用手机扫码完成支付,支付后刷新页面。')) + '</p>' +
|
||||
'<p class="aksrt-dl-modal__msg"><code>' + escapeHtml(data.qr_content || '') + '</code></p>' +
|
||||
'<div class="aksrt-dl-modal__actions"><button type="button" class="btn-primary btn-sm" data-aksrt-reload>' + tt('paid_refresh', '我已支付') + '</button></div>',
|
||||
returnFocusEl
|
||||
);
|
||||
const reloadBtn = document.querySelector('[data-aksrt-reload]');
|
||||
if (reloadBtn) reloadBtn.addEventListener('click', function () { window.location.reload(); });
|
||||
return;
|
||||
}
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function () {
|
||||
button.disabled = false;
|
||||
button.innerHTML = original;
|
||||
renderError(tt('network_err', '网络错误,请稍后重试'), {}, returnFocusEl);
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 事件绑定 =====
|
||||
document.addEventListener('click', function (e) {
|
||||
const lowBtn = e.target.closest('[data-action="aksrt-need-credits"]');
|
||||
@@ -312,6 +520,28 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const buyBtn = e.target.closest('[data-action="aksrt-need-purchase"], [data-aksrt-pay-content]');
|
||||
if (buyBtn) {
|
||||
e.preventDefault();
|
||||
const postId = parseInt(
|
||||
buyBtn.getAttribute('data-aksrt-pay-content') ||
|
||||
buyBtn.getAttribute('data-post-id') ||
|
||||
(buyBtn.closest('[data-post-id]') && buyBtn.closest('[data-post-id]').getAttribute('data-post-id')) ||
|
||||
'0',
|
||||
10
|
||||
);
|
||||
if (postId) openCashier(postId, buyBtn);
|
||||
return;
|
||||
}
|
||||
|
||||
const cashierLink = e.target.closest('.cashier-link');
|
||||
if (cashierLink && cashierLink.hasAttribute('data-aksrt-pay-content')) {
|
||||
e.preventDefault();
|
||||
const postId = parseInt(cashierLink.getAttribute('data-aksrt-pay-content') || '0', 10);
|
||||
if (postId) openCashier(postId, cashierLink);
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = e.target.closest('[data-action="aksrt-download"]');
|
||||
if (!btn) return;
|
||||
if (btn.disabled || btn.getAttribute('aria-disabled') === 'true') return;
|
||||
@@ -338,9 +568,25 @@
|
||||
'.aksrt-dl-modal__copy:hover{background:#dbeafe!important;border-color:#93c5fd!important;color:#1d4ed8!important;-webkit-text-fill-color:#1d4ed8!important;}' +
|
||||
'.aksrt-dl-modal__copy-text{display:inline-flex!important;align-items:center!important;justify-content:center!important;position:relative!important;z-index:2!important;color:#2563eb!important;-webkit-text-fill-color:#2563eb!important;font-size:13px!important;font-weight:700!important;line-height:1!important;font-family:inherit!important;text-indent:0!important;opacity:1!important;visibility:visible!important;white-space:nowrap!important;}' +
|
||||
'.aksrt-dl-modal__copy:hover .aksrt-dl-modal__copy-text{color:#1d4ed8!important;-webkit-text-fill-color:#1d4ed8!important;}' +
|
||||
'.aksrt-dl-modal__actions{display:flex;align-items:center;gap:12px;padding-top:4px;}' +
|
||||
'.aksrt-dl-modal__download{min-height:40px;padding:0 18px;border-radius:9px;display:inline-flex;align-items:center;justify-content:center;text-decoration:none;}' +
|
||||
'.aksrt-dl-modal__actions{display:flex;align-items:center;gap:12px;padding-top:4px;flex-wrap:wrap;}' +
|
||||
'.aksrt-dl-modal__download{min-height:40px;padding:0 18px;border-radius:9px;display:inline-flex;align-items:center;justify-content:center;text-decoration:none;border:0;cursor:pointer;}' +
|
||||
'.aksrt-dl-modal__balance{font-size:13px;color:#6b7280;margin-left:auto;white-space:nowrap;}' +
|
||||
'.aksrt-cashier__product{margin:0 0 12px;font-size:14px;line-height:1.5;}' +
|
||||
'.aksrt-cashier__tag{display:inline-block;margin-right:8px;padding:2px 8px;border-radius:6px;background:#eff6ff;color:#1d4ed8;font-size:12px;font-weight:700;}' +
|
||||
'.aksrt-cashier__box{background:#f8fafc;border:1px solid #e5e7eb;border-radius:10px;padding:10px 12px;margin:0 0 12px;}' +
|
||||
'.aksrt-cashier__row{display:flex;justify-content:space-between;align-items:center;gap:12px;font-size:13px;color:#6b7280;padding:4px 0;}' +
|
||||
'.aksrt-cashier__row b{color:#111827;font-size:15px;}' +
|
||||
'.aksrt-cashier__row b.is-sale{color:#dc2626;}' +
|
||||
'.aksrt-cashier__row b.is-ok{color:#059669;}' +
|
||||
'.aksrt-cashier__warn{background:#fef2f2;color:#b91c1c;border-radius:8px;padding:10px 12px;margin:0 0 12px;font-size:13px;}' +
|
||||
'.aksrt-cashier__methods{margin:0 0 14px;}' +
|
||||
'.aksrt-cashier__methods-title{font-size:13px;font-weight:600;color:#374151;margin:0 0 8px;}' +
|
||||
'.aksrt-cashier__method{display:flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid #e5e7eb;border-radius:8px;margin:0 0 6px;cursor:pointer;font-size:13px;}' +
|
||||
'.resource-download-box__attrs{list-style:none;margin:10px 0 0;padding:0;display:grid;gap:6px;}' +
|
||||
'.resource-download-box__attrs-item{display:flex;justify-content:space-between;gap:12px;font-size:12px;color:#6b7280;}' +
|
||||
'.resource-download-box__attrs-name{flex:0 0 auto;}' +
|
||||
'.resource-download-box__attrs-value{color:#111827;text-align:right;}' +
|
||||
'.resource-download-box__paid-badge{background:#ecfdf5!important;color:#047857!important;}' +
|
||||
'@media(max-width:480px){.aksrt-dl-modal__panel{padding:24px 20px 22px;}.aksrt-dl-modal__row{grid-template-columns:1fr 72px;gap:8px 12px;}.aksrt-dl-modal__label{grid-column:1 / -1;}.aksrt-dl-modal__code{font-size:17px;}.aksrt-dl-modal__actions{align-items:flex-start;flex-direction:column;}.aksrt-dl-modal__download{width:100%;}.aksrt-dl-modal__balance{margin-left:0;}}' +
|
||||
'body.aksrt-dl-modal-open{overflow:hidden;}';
|
||||
document.head.appendChild(style);
|
||||
|
||||
@@ -174,6 +174,9 @@ if (class_exists('AKSRT_Creator_Revenue')) {
|
||||
if (class_exists('AKSRT_Download')) {
|
||||
AKSRT_Download::get_instance()->init();
|
||||
}
|
||||
if (class_exists('AKSRT_Content_Pay')) {
|
||||
AKSRT_Content_Pay::get_instance()->init();
|
||||
}
|
||||
// Download State & Docs Presenter are pure service singletons (no hooks)
|
||||
if (class_exists('AKSRT_Download_State')) {
|
||||
AKSRT_Download_State::get_instance();
|
||||
|
||||
@@ -217,6 +217,9 @@ require_once AKSRT_DIR . '/inc/classes/class-aksrt-invite.php';
|
||||
// 加载下载服务(CMS / 资源 token 流程)
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-download.php';
|
||||
|
||||
// 付费内容收银台(post/_aksrt_pay → resource 订单)
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-content-pay.php';
|
||||
|
||||
// 下载状态统一解析器
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-download-state.php';
|
||||
|
||||
|
||||
@@ -0,0 +1,582 @@
|
||||
<?php
|
||||
/**
|
||||
* AKSRT Content Pay — post/_aksrt_pay cashier + resource orders.
|
||||
*
|
||||
* Server-side amount always from aksrt_get_user_pay_price().
|
||||
* product_type = ORDER_PRODUCT_RESOURCE (post_id).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_Content_Pay {
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
public function register_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/pay/content/(?P<id>\\d+)', [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'rest_preview'],
|
||||
'permission_callback' => [$this, 'check_rest_nonce'],
|
||||
],
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'rest_purchase'],
|
||||
'permission_callback' => [$this, 'check_rest_nonce'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* REST nonce for logged-in users (wp_rest). Guests get 401 on purchase paths.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @return true|WP_Error
|
||||
*/
|
||||
public function check_rest_nonce(WP_REST_Request $request) {
|
||||
$nonce = $request->get_header('x-wp-nonce');
|
||||
if (!$nonce) {
|
||||
return new WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
if (!wp_verify_nonce($nonce, 'wp_rest')) {
|
||||
return new WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /pay/content/{id}
|
||||
*/
|
||||
public function rest_preview(WP_REST_Request $request) {
|
||||
$post_id = (int) $request['id'];
|
||||
$uid = get_current_user_id();
|
||||
$preview = $this->preview($post_id, $uid);
|
||||
if (is_wp_error($preview)) {
|
||||
return $preview;
|
||||
}
|
||||
return new WP_REST_Response($preview, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /pay/content/{id}
|
||||
* body: { mode?: points|cash, payment_method?: balance|alipay|... }
|
||||
*/
|
||||
public function rest_purchase(WP_REST_Request $request) {
|
||||
$post_id = (int) $request['id'];
|
||||
$uid = get_current_user_id();
|
||||
if ($uid <= 0) {
|
||||
$post = get_post($post_id);
|
||||
return new WP_Error('aksrt_need_login', __('请先登录后再购买。', 'aksrt'), [
|
||||
'status' => 401,
|
||||
'login_url' => wp_login_url($post ? get_permalink($post) : home_url('/')),
|
||||
]);
|
||||
}
|
||||
|
||||
$params = $request->get_json_params();
|
||||
if (!is_array($params)) {
|
||||
$params = $request->get_params();
|
||||
}
|
||||
|
||||
$gate = $this->assert_purchasable($post_id, $uid);
|
||||
if (is_wp_error($gate)) {
|
||||
return $gate;
|
||||
}
|
||||
|
||||
$priced = $gate['priced'];
|
||||
$pay_modo = (($priced['modo'] ?? '0') === 'points') ? 'points' : '0';
|
||||
|
||||
$mode = sanitize_key((string) ($params['mode'] ?? ''));
|
||||
if ($mode === '') {
|
||||
$mode = $pay_modo === 'points' ? 'points' : 'cash';
|
||||
}
|
||||
if ($mode === 'points' || $pay_modo === 'points') {
|
||||
return $this->rest_wrap_result($this->create_and_pay_points($post_id, $uid));
|
||||
}
|
||||
|
||||
$payment_method = sanitize_key((string) ($params['payment_method'] ?? 'balance'));
|
||||
if ($payment_method === '' || $payment_method === 'cash') {
|
||||
$payment_method = 'balance';
|
||||
}
|
||||
return $this->rest_wrap_result($this->create_cash_order($post_id, $uid, $payment_method));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|WP_Error $result
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
private function rest_wrap_result($result) {
|
||||
if (is_wp_error($result)) {
|
||||
return $result;
|
||||
}
|
||||
if (empty($result['success'])) {
|
||||
$code = sanitize_key((string) ($result['code'] ?? 'aksrt_pay_failed'));
|
||||
$status = (int) ($result['status'] ?? 400);
|
||||
return new WP_Error($code !== '' ? $code : 'aksrt_pay_failed', (string) ($result['message'] ?? __('支付失败', 'aksrt')), array_merge(
|
||||
['status' => $status > 0 ? $status : 400],
|
||||
is_array($result['data'] ?? null) ? $result['data'] : []
|
||||
));
|
||||
}
|
||||
return new WP_REST_Response($result, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cashier preview payload.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function preview(int $post_id, int $user_id = 0) {
|
||||
$post = get_post($post_id);
|
||||
if (!($post instanceof WP_Post) || $post->post_status !== 'publish') {
|
||||
return new WP_Error('aksrt_invalid', __('内容不存在', 'aksrt'), ['status' => 404]);
|
||||
}
|
||||
|
||||
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
|
||||
$pay_type = AKSRT_Domain_Model::normalize_pay_type((string) ($meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
|
||||
if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_NO) {
|
||||
return new WP_Error('aksrt_not_paid', __('该内容无需购买', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$uid = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
$priced = function_exists('aksrt_get_user_pay_price')
|
||||
? aksrt_get_user_pay_price($post, $uid)
|
||||
: ['amount' => 0.0, 'base' => 0.0, 'modo' => '0', 'currency' => '¥', 'is_free' => true, 'pay_limit' => 0, 'vip_level' => 0, 'original' => 0.0, 'vip1' => 0.0, 'vip2' => 0.0];
|
||||
|
||||
$pay_modo = (($priced['modo'] ?? '0') === 'points') ? 'points' : '0';
|
||||
$pay_limit = (int) ($priced['pay_limit'] ?? 0);
|
||||
$vip_level = (int) ($priced['vip_level'] ?? 0);
|
||||
$amount = (float) ($priced['amount'] ?? 0);
|
||||
$base = (float) ($priced['base'] ?? $amount);
|
||||
|
||||
$has_paid = false;
|
||||
if ($uid > 0 && class_exists('AKSRT_Order')) {
|
||||
$has_paid = AKSRT_Order::get_instance()->has_paid_access(
|
||||
$uid,
|
||||
AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
|
||||
$post_id
|
||||
);
|
||||
}
|
||||
|
||||
$need_vip = $pay_limit > 0 && $vip_level < $pay_limit;
|
||||
$currency = (string) ($priced['currency'] ?? ($pay_modo === 'points'
|
||||
? (class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt'))
|
||||
: '¥'));
|
||||
|
||||
$balance = ($uid > 0 && class_exists('AKSRT_Credits')) ? AKSRT_Credits::balance($uid) : 0;
|
||||
$methods = $this->available_payment_methods($pay_modo);
|
||||
|
||||
$amount_label = $this->format_amount_label($amount, $pay_modo, $currency);
|
||||
$base_label = $this->format_amount_label($base, $pay_modo, $currency);
|
||||
|
||||
$vip_page = function_exists('aksrt_get_user_center_url')
|
||||
? aksrt_get_user_center_url()
|
||||
: home_url('/');
|
||||
|
||||
return [
|
||||
'post_id' => $post_id,
|
||||
'title' => get_the_title($post),
|
||||
'permalink' => get_permalink($post),
|
||||
'pay_type' => $pay_type,
|
||||
'pay_type_label' => AKSRT_Domain_Model::pay_type_labels()[$pay_type] ?? $pay_type,
|
||||
'pay_modo' => $pay_modo,
|
||||
'pay_limit' => $pay_limit,
|
||||
'vip_level' => $vip_level,
|
||||
'amount' => $pay_modo === 'points' ? (int) ceil($amount) : round($amount, 2),
|
||||
'base' => $pay_modo === 'points' ? (int) ceil($base) : round($base, 2),
|
||||
'original' => (float) ($priced['original'] ?? 0),
|
||||
'vip1' => (float) ($priced['vip1'] ?? 0),
|
||||
'vip2' => (float) ($priced['vip2'] ?? 0),
|
||||
'currency' => $currency,
|
||||
'amount_label' => $amount_label,
|
||||
'base_label' => $base_label,
|
||||
'is_free' => !empty($priced['is_free']) || $amount <= 0,
|
||||
'has_paid_access' => $has_paid,
|
||||
'need_login' => $uid <= 0,
|
||||
'need_vip' => $need_vip,
|
||||
'need_purchase' => !$has_paid && !$need_vip && $amount > 0,
|
||||
'logged_in' => $uid > 0,
|
||||
'balance' => $balance,
|
||||
'balance_enough' => $pay_modo !== 'points' || $balance >= (int) ceil($amount),
|
||||
'payment_methods' => $methods,
|
||||
'login_url' => wp_login_url(get_permalink($post)),
|
||||
'vip_url' => $vip_page,
|
||||
'credits_url' => $vip_page,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Points one-shot purchase → permanent resource order.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function create_and_pay_points(int $post_id, int $user_id) {
|
||||
$assert = $this->assert_purchasable($post_id, $user_id);
|
||||
if (is_wp_error($assert)) {
|
||||
return $assert;
|
||||
}
|
||||
|
||||
$priced = $assert['priced'];
|
||||
if ((($priced['modo'] ?? '0') !== 'points')) {
|
||||
return new WP_Error('aksrt_wrong_modo', __('该内容不支持积分支付。', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$amount = (int) ceil((float) ($priced['amount'] ?? 0));
|
||||
if ($amount <= 0) {
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'free' => true,
|
||||
'message' => __('无需支付,已可访问。', 'aksrt'),
|
||||
'reload' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Credits')) {
|
||||
return new WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
|
||||
$balance = AKSRT_Credits::balance($user_id);
|
||||
if ($balance < $amount) {
|
||||
return new WP_Error('aksrt_credits_insufficient', __('积分不足,暂时无法支付。', 'aksrt'), [
|
||||
'status' => 402,
|
||||
'balance' => $balance,
|
||||
'cost' => $amount,
|
||||
]);
|
||||
}
|
||||
|
||||
$note = wp_json_encode([
|
||||
'content_pay' => 1,
|
||||
'pay_modo' => 'points',
|
||||
'post_id' => $post_id,
|
||||
'vip_level' => (int) ($priced['vip_level'] ?? 0),
|
||||
'base' => (float) ($priced['base'] ?? $amount),
|
||||
'amount' => $amount,
|
||||
], 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_RESOURCE,
|
||||
'product_id' => $post_id,
|
||||
'amount' => (float) $amount,
|
||||
'currency' => 'points',
|
||||
'status' => AKSRT_Order::STATUS_PENDING,
|
||||
'payment_method' => 'points',
|
||||
'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]);
|
||||
}
|
||||
|
||||
$deducted = AKSRT_Credits::deduct(
|
||||
$user_id,
|
||||
$amount,
|
||||
'content_points_pay',
|
||||
['type' => 'post', 'id' => $post_id, 'order' => $order_number],
|
||||
sprintf(__('积分购买《%s》', 'aksrt'), get_the_title($post_id))
|
||||
);
|
||||
|
||||
if (is_wp_error($deducted) || $deducted === false) {
|
||||
AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_CANCELLED, [
|
||||
'note' => __('积分扣除失败,自动取消', 'aksrt'),
|
||||
]);
|
||||
$msg = is_wp_error($deducted) ? $deducted->get_error_message() : __('积分扣除失败。', 'aksrt');
|
||||
return new WP_Error('aksrt_credits_deduct_failed', $msg ?: __('积分扣除失败。', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
|
||||
'payment_method' => 'points',
|
||||
'payment_transaction_id' => 'points_' . $order_number,
|
||||
'note' => sprintf(__('积分支付 %d 积分。', 'aksrt'), $amount),
|
||||
]);
|
||||
|
||||
if (!$paid) {
|
||||
AKSRT_Credits::add(
|
||||
$user_id,
|
||||
$amount,
|
||||
'content_points_pay_refund',
|
||||
['type' => 'post', 'id' => $post_id, 'order' => $order_number],
|
||||
sprintf(__('购买失败退款:%s', 'aksrt'), get_the_title($post_id))
|
||||
);
|
||||
return new WP_Error('aksrt_order_confirm_failed', __('订单确认失败,已尝试退回积分。', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'order_number' => $order_number,
|
||||
'amount' => $amount,
|
||||
'pay_modo' => 'points',
|
||||
'balance' => AKSRT_Credits::balance($user_id),
|
||||
'message' => __('支付成功', 'aksrt'),
|
||||
'reload' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Cash order create + balance/gateway pay.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function create_cash_order(int $post_id, int $user_id, string $payment_method = 'balance') {
|
||||
$assert = $this->assert_purchasable($post_id, $user_id);
|
||||
if (is_wp_error($assert)) {
|
||||
return $assert;
|
||||
}
|
||||
|
||||
$priced = $assert['priced'];
|
||||
if ((($priced['modo'] ?? '0') === 'points')) {
|
||||
return new WP_Error('aksrt_wrong_modo', __('该内容仅支持积分支付。', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$amount = round((float) ($priced['amount'] ?? 0), 2);
|
||||
if ($amount <= 0) {
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'free' => true,
|
||||
'message' => __('无需支付,已可访问。', 'aksrt'),
|
||||
'reload' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Order_Repository')) {
|
||||
return new WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
|
||||
$payment_method = sanitize_key($payment_method);
|
||||
if ($payment_method === '') {
|
||||
$payment_method = 'balance';
|
||||
}
|
||||
|
||||
$note = wp_json_encode([
|
||||
'content_pay' => 1,
|
||||
'pay_modo' => '0',
|
||||
'post_id' => $post_id,
|
||||
'vip_level' => (int) ($priced['vip_level'] ?? 0),
|
||||
'base' => (float) ($priced['base'] ?? $amount),
|
||||
'amount' => $amount,
|
||||
], 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_RESOURCE,
|
||||
'product_id' => $post_id,
|
||||
'amount' => $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'] = sprintf(
|
||||
/* translators: %s: post title */
|
||||
__('购买《%s》', 'aksrt'),
|
||||
get_the_title($post_id)
|
||||
);
|
||||
|
||||
if (!class_exists('AKSRT_Payment_Gateway')) {
|
||||
return new WP_Error('aksrt_pay_unavailable', __('支付网关不可用。', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
|
||||
$gateway_manager = AKSRT_Payment_Gateway::get_instance();
|
||||
$gateway = $gateway_manager->get_gateway($payment_method);
|
||||
if (!$gateway) {
|
||||
AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_CANCELLED, [
|
||||
'note' => __('支付方式不可用,自动取消', 'aksrt'),
|
||||
]);
|
||||
return new WP_Error('aksrt_gateway_unavailable', __('当前支付方式不可用。', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if (method_exists($gateway, 'is_configured') && !$gateway->is_configured()) {
|
||||
AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_CANCELLED, [
|
||||
'note' => __('支付方式未配置,自动取消', 'aksrt'),
|
||||
]);
|
||||
return new WP_Error('aksrt_gateway_unconfigured', __('该支付方式尚未配置,请联系站长。', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
|
||||
$payment_result = $gateway->create_payment($order);
|
||||
if (empty($payment_result['success'])) {
|
||||
AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_CANCELLED, [
|
||||
'note' => (string) ($payment_result['message'] ?? __('支付失败,自动取消', 'aksrt')),
|
||||
]);
|
||||
$msg = (string) ($payment_result['message'] ?? __('支付失败。', 'aksrt'));
|
||||
$code = ($payment_method === 'balance' && str_contains($msg, '余额'))
|
||||
? 'aksrt_balance_insufficient'
|
||||
: 'aksrt_pay_failed';
|
||||
return new WP_Error($code, $msg, [
|
||||
'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 [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'redirect' => true,
|
||||
'payment_url' => $payment_url,
|
||||
'qr_content' => $code_url,
|
||||
'order_number' => $order_number,
|
||||
'amount' => $amount,
|
||||
'pay_modo' => '0',
|
||||
'message' => $payment_result['message'] ?? __('请在新页面完成支付。', 'aksrt'),
|
||||
'reload' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Sync gateway (balance): mark paid.
|
||||
$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]);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'order_number' => $order_number,
|
||||
'amount' => $amount,
|
||||
'pay_modo' => '0',
|
||||
'message' => $payment_result['message'] ?? __('支付成功', 'aksrt'),
|
||||
'reload' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{post:WP_Post,meta:array,priced:array}|WP_Error
|
||||
*/
|
||||
private function assert_purchasable(int $post_id, int $user_id) {
|
||||
$post = get_post($post_id);
|
||||
if (!($post instanceof WP_Post) || $post->post_status !== 'publish') {
|
||||
return new WP_Error('aksrt_invalid', __('内容不存在', 'aksrt'), ['status' => 404]);
|
||||
}
|
||||
if ($user_id <= 0) {
|
||||
return new WP_Error('aksrt_need_login', __('请先登录后再购买。', 'aksrt'), [
|
||||
'status' => 401,
|
||||
'login_url' => wp_login_url(get_permalink($post)),
|
||||
]);
|
||||
}
|
||||
|
||||
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
|
||||
$pay_type = AKSRT_Domain_Model::normalize_pay_type((string) ($meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
|
||||
if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_NO) {
|
||||
return new WP_Error('aksrt_not_paid', __('该内容无需购买', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_VIP) {
|
||||
return new WP_Error('aksrt_need_vip', __('该内容为 VIP 专属,请开通会员。', 'aksrt'), ['status' => 403]);
|
||||
}
|
||||
|
||||
$priced = function_exists('aksrt_get_user_pay_price')
|
||||
? aksrt_get_user_pay_price($post, $user_id)
|
||||
: ['amount' => 0.0, 'modo' => '0', 'pay_limit' => 0, 'vip_level' => 0, 'is_free' => true, 'base' => 0.0];
|
||||
|
||||
$pay_limit = (int) ($priced['pay_limit'] ?? 0);
|
||||
$vip_level = (int) ($priced['vip_level'] ?? 0);
|
||||
if ($pay_limit > 0 && $vip_level < $pay_limit) {
|
||||
return new WP_Error('aksrt_need_vip', sprintf(
|
||||
/* translators: %d: required VIP level */
|
||||
__('该资源仅限 VIP%s 及以上会员购买/下载。', 'aksrt'),
|
||||
max(1, $pay_limit)
|
||||
), [
|
||||
'status' => 403,
|
||||
'pay_limit' => $pay_limit,
|
||||
]);
|
||||
}
|
||||
|
||||
if (class_exists('AKSRT_Order') && AKSRT_Order::get_instance()->has_paid_access(
|
||||
$user_id,
|
||||
AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
|
||||
$post_id
|
||||
)) {
|
||||
return new WP_Error('aksrt_already_paid', __('您已购买该内容。', 'aksrt'), [
|
||||
'status' => 200,
|
||||
'has_paid_access' => true,
|
||||
'reload' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'post' => $post,
|
||||
'meta' => $meta,
|
||||
'priced' => $priced,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id:string,name:string}>
|
||||
*/
|
||||
private function available_payment_methods(string $pay_modo): array {
|
||||
if ($pay_modo === 'points') {
|
||||
return [
|
||||
['id' => 'points', 'name' => __('积分支付', 'aksrt')],
|
||||
];
|
||||
}
|
||||
|
||||
$methods = [];
|
||||
if (!class_exists('AKSRT_Payment_Gateway')) {
|
||||
return [['id' => 'balance', 'name' => __('站内余额', 'aksrt')]];
|
||||
}
|
||||
$gw = AKSRT_Payment_Gateway::get_instance();
|
||||
foreach (['balance', 'alipay', 'wechatpay', 'paypal', 'stripe'] as $id) {
|
||||
$g = $gw->get_gateway($id);
|
||||
if (!$g) {
|
||||
continue;
|
||||
}
|
||||
if (method_exists($g, 'is_configured') && !$g->is_configured()) {
|
||||
continue;
|
||||
}
|
||||
$methods[] = [
|
||||
'id' => $id,
|
||||
'name' => method_exists($g, 'get_name') ? (string) $g->get_name() : $id,
|
||||
];
|
||||
}
|
||||
if ($methods === []) {
|
||||
$methods[] = ['id' => 'balance', 'name' => __('站内余额', 'aksrt')];
|
||||
}
|
||||
return $methods;
|
||||
}
|
||||
|
||||
private function format_amount_label(float $amount, string $pay_modo, string $currency): string {
|
||||
if ($amount <= 0) {
|
||||
return (string) __('免费', 'aksrt');
|
||||
}
|
||||
$n = function_exists('aksrt_format_price') ? aksrt_format_price($amount) : (string) $amount;
|
||||
if ($pay_modo === 'points') {
|
||||
return $n . ' ' . $currency;
|
||||
}
|
||||
return $currency . $n;
|
||||
}
|
||||
}
|
||||
@@ -121,38 +121,41 @@ class AKSRT_Content_Visibility {
|
||||
|
||||
// Member-only purchase restriction (Zibll pay_limit).
|
||||
if ($pay_limit > 0 && $pay_type !== AKSRT_Domain_Model::PAY_TYPE_NO) {
|
||||
$state['need_vip'] = true;
|
||||
$state['need_vip'] = $uid <= 0 || $user_vip_level < $pay_limit;
|
||||
$allowed_member = $uid > 0 && $user_vip_level >= $pay_limit;
|
||||
if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
|
||||
$download_cost = function_exists('aksrt_resource_download_cost')
|
||||
? (int) aksrt_resource_download_cost($resource_post)
|
||||
: (int) ceil($price);
|
||||
// If member is free via VIP price, cost is 0.
|
||||
// Cash: order gate only. Points: cashier once → paid order zeros cost.
|
||||
$download_cost = 0;
|
||||
if ($pay_modo === 'points' && $price > 0 && !$has_paid_order) {
|
||||
$download_cost = (int) ceil($price);
|
||||
}
|
||||
if ($allowed_member && $price <= 0) {
|
||||
$download_cost = 0;
|
||||
}
|
||||
$state['download_cost'] = max(0, $download_cost);
|
||||
$state['need_login'] = $uid <= 0;
|
||||
$state['need_purchase'] = $allowed_member && $state['download_cost'] > 0 && !$has_paid_order;
|
||||
$state['has_paid_access'] = $allowed_member && ($has_paid_order || $state['download_cost'] <= 0);
|
||||
$state['need_purchase'] = $allowed_member && $price > 0 && !$has_paid_order;
|
||||
$state['has_paid_access'] = $allowed_member && ($has_paid_order || $price <= 0);
|
||||
$state['can_view'] = true;
|
||||
$state['can_download'] = $allowed_member && ($uid > 0) && ($has_paid_order || $state['download_cost'] <= 0);
|
||||
$state['can_download'] = $allowed_member && ($uid > 0) && ($has_paid_order || $price <= 0);
|
||||
if (!$allowed_member) {
|
||||
$state['can_download'] = false;
|
||||
$state['has_paid_access'] = false;
|
||||
$state['need_purchase'] = false;
|
||||
$state['need_vip'] = true;
|
||||
}
|
||||
return $state;
|
||||
}
|
||||
|
||||
$state['has_paid_access'] = ($allowed_member && $price <= 0) || $has_paid_order || ($allowed_member && $has_vip_access && $pay_type === AKSRT_Domain_Model::PAY_TYPE_VIP);
|
||||
// For reading/gallery/video with pay_limit: members still need to purchase unless free.
|
||||
// reading/gallery/video with pay_limit
|
||||
if ($allowed_member) {
|
||||
$state['has_paid_access'] = $has_paid_order || $price <= 0;
|
||||
$state['need_purchase'] = !$state['has_paid_access'];
|
||||
$state['need_vip'] = false;
|
||||
} else {
|
||||
$state['has_paid_access'] = false;
|
||||
$state['need_purchase'] = false;
|
||||
$state['need_vip'] = true;
|
||||
}
|
||||
$state['can_view'] = $state['has_paid_access'];
|
||||
$state['can_download'] = false;
|
||||
@@ -160,34 +163,23 @@ class AKSRT_Content_Visibility {
|
||||
}
|
||||
|
||||
if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
|
||||
$download_cost = function_exists('aksrt_resource_download_cost')
|
||||
? (int) aksrt_resource_download_cost($resource_post)
|
||||
: (int) ceil($price);
|
||||
|
||||
// Zibll: cash = order unlock; points = one-shot cashier order (not per-download deduct).
|
||||
$download_cost = 0;
|
||||
if ($pay_modo === 'points' && $price > 0 && !$has_paid_order) {
|
||||
$download_cost = (int) ceil($price);
|
||||
}
|
||||
$state['download_cost'] = max(0, $download_cost);
|
||||
// Zibll pay_free_logged_show: free download still requires login.
|
||||
|
||||
$free_logged_show = !empty($paid_settings['free_logged_show']);
|
||||
$state['need_login'] = !empty($paid_settings['download_login'])
|
||||
|| !empty($pay_meta['require_login'])
|
||||
|| ($free_logged_show && $state['download_cost'] <= 0);
|
||||
|| ($free_logged_show && $price <= 0);
|
||||
$state['require_captcha'] = !empty($paid_settings['download_captcha']) || !empty($pay_meta['require_captcha']);
|
||||
// Cash mode with cost handled by orders: need purchase when no order and base price > 0.
|
||||
$needs_pay = $state['download_cost'] > 0 || ($pay_modo === '0' && $price > 0 && !$has_paid_order && empty($paid_settings['download_credit']));
|
||||
if ($pay_modo === '0' && $price > 0 && empty($paid_settings['download_credit'])) {
|
||||
$state['need_purchase'] = !$has_paid_order && !($has_vip_access && $price <= 0);
|
||||
$state['has_paid_access'] = $has_paid_order || $price <= 0;
|
||||
// Download still gated by login/credit path for token; cash unlock is order-based.
|
||||
$state['can_view'] = true;
|
||||
$state['can_download'] = ($has_paid_order || $price <= 0) && (!$state['need_login'] || $uid > 0);
|
||||
return $state;
|
||||
}
|
||||
|
||||
$state['need_purchase'] = !$has_paid_order && $state['download_cost'] > 0 && !$has_free_access;
|
||||
// VIP with free tier amount already reflected in download_cost.
|
||||
$state['has_paid_access'] = $has_paid_order || $state['download_cost'] <= 0 || $has_free_access;
|
||||
$state['need_purchase'] = !$has_paid_order && $price > 0;
|
||||
$state['has_paid_access'] = $has_paid_order || $price <= 0 || $has_free_access;
|
||||
$state['can_view'] = true;
|
||||
$state['can_download'] = (!$state['need_login'] || $uid > 0) && ($has_paid_order || $state['download_cost'] <= 0 || true);
|
||||
// can_download true only means "may request token"; rest_request still deducts credits.
|
||||
$state['can_download'] = (!$state['need_login'] || $uid > 0) && ($has_paid_order || $price <= 0);
|
||||
|
||||
return $state;
|
||||
}
|
||||
@@ -270,14 +262,19 @@ class AKSRT_Content_Visibility {
|
||||
]);
|
||||
}
|
||||
|
||||
// Cash purchase required (order path).
|
||||
if (!empty($state['need_purchase']) && empty($state['has_paid_access']) && $cost <= 0 && (($state['pay_modo'] ?? '0') === '0')) {
|
||||
// Cash or points: require cashier purchase (resource order) before download token.
|
||||
if (!empty($state['need_purchase']) && empty($state['has_paid_access'])) {
|
||||
$pay_modo = (string) ($state['pay_modo'] ?? '0');
|
||||
$price = (float) ($state['price'] ?? 0);
|
||||
return new WP_Error('aksrt_need_purchase', __('请先购买后再下载。', 'aksrt'), [
|
||||
'status' => 402,
|
||||
'pay_modo' => $pay_modo,
|
||||
'amount' => $pay_modo === 'points' ? (int) ceil($price) : $price,
|
||||
'post_id' => (int) ($state['post_id'] ?? 0),
|
||||
]);
|
||||
}
|
||||
|
||||
// Zibll daily free-download quota.
|
||||
// Zibll daily free-download quota (only when free / already unlocked).
|
||||
if ($cost <= 0 && function_exists('aksrt_check_free_download_quota')) {
|
||||
$quota = aksrt_check_free_download_quota($uid, $cost);
|
||||
if (is_wp_error($quota)) {
|
||||
@@ -285,22 +282,6 @@ class AKSRT_Content_Visibility {
|
||||
}
|
||||
}
|
||||
|
||||
$pay_modo = (string) ($state['pay_modo'] ?? '0');
|
||||
$need_credit_check = $cost > 0 && (
|
||||
$pay_modo === 'points'
|
||||
|| !empty($paid_settings['download_credit'])
|
||||
);
|
||||
if ($need_credit_check) {
|
||||
$balance = class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0;
|
||||
if ($balance < $cost) {
|
||||
return new WP_Error('aksrt_credits_insufficient', __('积分不足,无法下载。', 'aksrt'), [
|
||||
'status' => 402,
|
||||
'balance' => $balance,
|
||||
'cost' => $cost,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,26 +120,37 @@ class AKSRT_Download {
|
||||
: ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
|
||||
$display_price = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
|
||||
|
||||
$access = class_exists('AKSRT_Content_Visibility')
|
||||
? AKSRT_Content_Visibility::get_post_access_state($post, $uid)
|
||||
: [];
|
||||
|
||||
$need_captcha = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
|
||||
if ($need_captcha && function_exists('aksrt_is_captcha_enabled_for') && !aksrt_is_captcha_enabled_for('download')) {
|
||||
$need_captcha = false;
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
'post_id' => $post_id,
|
||||
'price' => $display_price,
|
||||
'base_price' => is_array($priced) ? (float) ($priced['base'] ?? $display_price) : (float) ($meta['price'] ?? 0),
|
||||
'pay_modo' => $pay_modo,
|
||||
'pay_limit' => (int) ($meta['pay_limit'] ?? 0),
|
||||
'cost' => $cost,
|
||||
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']) || (!empty($paid_settings['free_logged_show']) && $cost <= 0),
|
||||
'require_captcha' => $need_captcha,
|
||||
'logged_in' => $uid > 0,
|
||||
'balance' => $uid > 0 && class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0,
|
||||
'free_limit' => $uid > 0 && function_exists('aksrt_get_user_free_download_limit') ? aksrt_get_user_free_download_limit($uid) : 0,
|
||||
'free_used' => $uid > 0 && function_exists('aksrt_get_user_free_downloaded_number') ? aksrt_get_user_free_downloaded_number($uid) : 0,
|
||||
'free_surplus' => $uid > 0 && function_exists('aksrt_get_free_download_surplus') ? aksrt_get_free_download_surplus($uid) : null,
|
||||
'sources' => array_map(function ($row, $idx) {
|
||||
'post_id' => $post_id,
|
||||
'price' => $display_price,
|
||||
'base_price' => is_array($priced) ? (float) ($priced['base'] ?? $display_price) : (float) ($meta['price'] ?? 0),
|
||||
'pay_modo' => $pay_modo,
|
||||
'pay_limit' => (int) ($meta['pay_limit'] ?? 0),
|
||||
'cost' => $cost,
|
||||
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']) || (!empty($paid_settings['free_logged_show']) && $cost <= 0 && $display_price <= 0),
|
||||
'require_captcha' => $need_captcha,
|
||||
'logged_in' => $uid > 0,
|
||||
'balance' => $uid > 0 && class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0,
|
||||
'has_paid_access' => !empty($access['has_paid_access']),
|
||||
'need_purchase' => !empty($access['need_purchase']),
|
||||
'need_vip' => !empty($access['need_vip']),
|
||||
'need_login' => !empty($access['need_login']) && $uid <= 0,
|
||||
'can_download' => !empty($access['can_download']),
|
||||
'login_url' => wp_login_url(get_permalink($post)),
|
||||
'vip_level' => (int) ($access['user_vip_level'] ?? 0),
|
||||
'free_limit' => $uid > 0 && function_exists('aksrt_get_user_free_download_limit') ? aksrt_get_user_free_download_limit($uid) : 0,
|
||||
'free_used' => $uid > 0 && function_exists('aksrt_get_user_free_downloaded_number') ? aksrt_get_user_free_downloaded_number($uid) : 0,
|
||||
'free_surplus' => $uid > 0 && function_exists('aksrt_get_free_download_surplus') ? aksrt_get_free_download_surplus($uid) : null,
|
||||
'sources' => array_map(function ($row, $idx) {
|
||||
$extract_code = trim((string) ($row['extract_code'] ?? ''));
|
||||
return [
|
||||
'index' => $idx,
|
||||
@@ -198,16 +209,9 @@ class AKSRT_Download {
|
||||
}
|
||||
}
|
||||
|
||||
if ($cost > 0 && $uid > 0 && class_exists('AKSRT_Credits')) {
|
||||
$deducted = AKSRT_Credits::deduct($uid, $cost, 'download', ['type' => 'post', 'id' => $post_id]);
|
||||
if (is_wp_error($deducted)) return $deducted;
|
||||
}
|
||||
|
||||
$token = $this->issue_token($uid, $post_id, $source_index, $cost);
|
||||
// Purchase is one-shot via cashier (resource order). Token issue does not re-deduct.
|
||||
$token = $this->issue_token($uid, $post_id, $source_index, 0);
|
||||
if (is_wp_error($token)) {
|
||||
if ($cost > 0 && $uid > 0 && class_exists('AKSRT_Credits')) {
|
||||
AKSRT_Credits::add($uid, $cost, 'refund', ['type' => 'post', 'id' => $post_id]);
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,24 @@ trait AKSRT_Scripts_Part_1b {
|
||||
$is_single_resource = (function_exists('aksrt_is_resource_post') && is_singular() && aksrt_is_resource_post(get_queried_object_id()));
|
||||
// 普通博客 single(排除资源型 post)
|
||||
$is_single_post = is_singular('post') && !$is_single_resource;
|
||||
// 付费下载/付费墙:任意 singular 需收银台/下载脚本
|
||||
$is_paid_content_single = false;
|
||||
if (is_singular()) {
|
||||
$qid = (int) get_queried_object_id();
|
||||
if ($qid > 0) {
|
||||
if (function_exists('aksrt_is_downloadable_content') && aksrt_is_downloadable_content($qid)) {
|
||||
$is_paid_content_single = true;
|
||||
} elseif (function_exists('aksrt_is_paid_post') && aksrt_is_paid_post($qid)) {
|
||||
$is_paid_content_single = true;
|
||||
} elseif (function_exists('aksrt_get_pay_meta')) {
|
||||
$pm = aksrt_get_pay_meta($qid);
|
||||
$pt = (string) ($pm['pay_type'] ?? 'no');
|
||||
$is_paid_content_single = ($pt !== '' && $pt !== 'no');
|
||||
}
|
||||
}
|
||||
}
|
||||
// 独立下载页模板
|
||||
$is_download_file_page = is_page_template('templates/pages/page-download-file.php');
|
||||
// 资源虚拟列表 /resources/
|
||||
$is_resource_archive = function_exists('aksrt_is_resource_archive') && aksrt_is_resource_archive();
|
||||
// /user/{nicename}/ 自定义重写路由(class-aksrt-user.php 注册)
|
||||
@@ -643,13 +661,13 @@ trait AKSRT_Scripts_Part_1b {
|
||||
$enqueue_module('resource-archive');
|
||||
}
|
||||
|
||||
// 单篇资源:下载脚本
|
||||
if ($is_single_resource) {
|
||||
// 单篇资源 / 付费内容 / 独立下载页:下载 + 收银台脚本
|
||||
if ($is_single_resource || $is_paid_content_single || $is_download_file_page) {
|
||||
$cms_download_js_path = get_template_directory() . '/assets/js/cms-download.js';
|
||||
wp_enqueue_script(
|
||||
'aksrt-cms-download',
|
||||
$base_uri . '/assets/js/cms-download.js',
|
||||
['aksrt-script'],
|
||||
['aksrt-script', 'aksrt-runtime'],
|
||||
file_exists($cms_download_js_path) ? (string) filemtime($cms_download_js_path) : $version,
|
||||
true
|
||||
);
|
||||
|
||||
@@ -481,6 +481,7 @@ if (!function_exists('aksrt_get_pay_price_label')) {
|
||||
$pay_limit = is_array($priced)
|
||||
? (int) ($priced['pay_limit'] ?? 0)
|
||||
: (int) ($meta['pay_limit'] ?? 0);
|
||||
$vip_level = is_array($priced) ? (int) ($priced['vip_level'] ?? 0) : 0;
|
||||
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
|
||||
$cash_symbol = '¥';
|
||||
if (class_exists('AKSRT_Settings')) {
|
||||
@@ -488,7 +489,10 @@ if (!function_exists('aksrt_get_pay_price_label')) {
|
||||
$cash_symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
|
||||
}
|
||||
|
||||
if ($meta['pay_type'] === AKSRT_PAY_TYPE_VIP || $pay_limit > 0) {
|
||||
// pay_type VIP-only or pay_limit not met → member-exclusive badge.
|
||||
$member_blocked = ($meta['pay_type'] === AKSRT_PAY_TYPE_VIP)
|
||||
|| ($pay_limit > 0 && $vip_level < $pay_limit);
|
||||
if ($member_blocked) {
|
||||
return [
|
||||
'text' => __('会员专属', 'aksrt'),
|
||||
'free' => false,
|
||||
@@ -511,7 +515,7 @@ if (!function_exists('aksrt_get_pay_price_label')) {
|
||||
'amount' => 0,
|
||||
'base' => $base,
|
||||
'modo' => $pay_modo,
|
||||
'pay_limit' => 0,
|
||||
'pay_limit' => $pay_limit,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -522,7 +526,7 @@ if (!function_exists('aksrt_get_pay_price_label')) {
|
||||
'amount' => $price,
|
||||
'base' => $base,
|
||||
'modo' => 'points',
|
||||
'pay_limit' => 0,
|
||||
'pay_limit' => $pay_limit,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -532,7 +536,7 @@ if (!function_exists('aksrt_get_pay_price_label')) {
|
||||
'amount' => $price,
|
||||
'base' => $base,
|
||||
'modo' => '0',
|
||||
'pay_limit' => 0,
|
||||
'pay_limit' => $pay_limit,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -646,6 +650,57 @@ if (!function_exists('aksrt_get_demo_link_html')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Product attributes row (Zibll zibpay_get_product_attributes).
|
||||
*/
|
||||
if (!function_exists('aksrt_get_pay_attributes_html')) {
|
||||
function aksrt_get_pay_attributes_html($post = null, string $class = 'resource-download-box__attrs'): string {
|
||||
$p = get_post($post);
|
||||
if (!($p instanceof WP_Post)) {
|
||||
return '';
|
||||
}
|
||||
$meta = aksrt_get_pay_meta($p);
|
||||
$attrs = is_array($meta['attributes'] ?? null) ? $meta['attributes'] : [];
|
||||
// Built-in version/size/license/compat as attributes when set.
|
||||
$builtin = [
|
||||
'version' => __('版本', 'aksrt'),
|
||||
'size' => __('大小', 'aksrt'),
|
||||
'license' => __('授权', 'aksrt'),
|
||||
'compat' => __('兼容', 'aksrt'),
|
||||
];
|
||||
$rows = [];
|
||||
foreach ($builtin as $key => $label) {
|
||||
$val = trim((string) ($meta[$key] ?? ''));
|
||||
if ($val !== '') {
|
||||
$rows[] = ['name' => $label, 'value' => $val];
|
||||
}
|
||||
}
|
||||
foreach ($attrs as $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
$name = trim((string) ($row['name'] ?? $row['key'] ?? $row['label'] ?? ''));
|
||||
$value = trim((string) ($row['value'] ?? $row['val'] ?? ''));
|
||||
if ($name === '' || $value === '') {
|
||||
continue;
|
||||
}
|
||||
$rows[] = ['name' => $name, 'value' => $value];
|
||||
}
|
||||
if ($rows === []) {
|
||||
return '';
|
||||
}
|
||||
$html = '<ul class="' . esc_attr($class) . '">';
|
||||
foreach ($rows as $row) {
|
||||
$html .= '<li class="' . esc_attr($class) . '-item">';
|
||||
$html .= '<span class="' . esc_attr($class) . '-name">' . esc_html($row['name']) . '</span>';
|
||||
$html .= '<span class="' . esc_attr($class) . '-value">' . esc_html($row['value']) . '</span>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 付费墙 HTML
|
||||
// ============================================================
|
||||
@@ -657,6 +712,7 @@ if (!function_exists('aksrt_get_paywall_html')) {
|
||||
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post) : null;
|
||||
$pay_modo = is_array($priced) ? ((($priced['modo'] ?? '0') === 'points') ? 'points' : '0') : ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
|
||||
$price = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
|
||||
$vip_level = is_array($priced) ? (int) ($priced['vip_level'] ?? 0) : 0;
|
||||
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
|
||||
$cash_symbol = '¥';
|
||||
if (class_exists('AKSRT_Settings')) {
|
||||
@@ -679,6 +735,8 @@ if (!function_exists('aksrt_get_paywall_html')) {
|
||||
$original_price = (float) ($meta['original_price'] ?? 0);
|
||||
$has_original = $original_price > 0 && $original_price > $price;
|
||||
$pay_limit = (int) ($meta['pay_limit'] ?? 0);
|
||||
$member_blocked = $pay_limit > 0 && $vip_level < $pay_limit;
|
||||
$vip_url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/');
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
@@ -692,7 +750,7 @@ if (!function_exists('aksrt_get_paywall_html')) {
|
||||
<h3 class="aksrt-paywall__title"><?php echo esc_html($type_info['label']); ?></h3>
|
||||
<p class="aksrt-paywall__desc"><?php echo esc_html($type_info['desc']); ?></p>
|
||||
<div class="aksrt-paywall__price">
|
||||
<?php if ($pay_limit > 0) : ?>
|
||||
<?php if ($member_blocked) : ?>
|
||||
<span class="aksrt-paywall__price-member"><?php esc_html_e('会员专属', 'aksrt'); ?></span>
|
||||
<?php elseif ($price > 0) : ?>
|
||||
<span class="aksrt-paywall__price-amount"><?php echo esc_html($price_text); ?></span>
|
||||
@@ -704,13 +762,13 @@ if (!function_exists('aksrt_get_paywall_html')) {
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!$is_logged_in) : ?>
|
||||
<a href="<?php echo esc_url($login_url); ?>" class="but jb-red padding-lg cashier-link aksrt-paywall__btn">
|
||||
<a href="<?php echo esc_url($login_url); ?>" class="but jb-red padding-lg aksrt-paywall__btn">
|
||||
<i class="fa fa-sign-in" aria-hidden="true"></i> <?php esc_html_e('登录后购买', 'aksrt'); ?>
|
||||
</a>
|
||||
<?php elseif ($pay_limit > 0) : ?>
|
||||
<span class="but jb-vip padding-lg aksrt-paywall__btn is-disabled">
|
||||
<?php elseif ($member_blocked) : ?>
|
||||
<a href="<?php echo esc_url($vip_url); ?>" class="but jb-vip padding-lg aksrt-paywall__btn">
|
||||
<i class="fas fa-crown" aria-hidden="true"></i> <?php esc_html_e('开通会员后可查看', 'aksrt'); ?>
|
||||
</span>
|
||||
</a>
|
||||
<?php elseif ($price > 0) : ?>
|
||||
<button type="button" class="but <?php echo $pay_modo === 'points' ? 'jb-yellow' : 'jb-red'; ?> padding-lg cashier-link aksrt-paywall__btn" data-aksrt-pay-content="<?php echo esc_attr((string) $post->ID); ?>">
|
||||
<i class="fa fa-shopping-cart" aria-hidden="true"></i> <?php printf(esc_html__('立即购买(%s)', 'aksrt'), $price_text); ?>
|
||||
|
||||
@@ -486,8 +486,8 @@ if (!function_exists('aksrt_resource_download_cost')) {
|
||||
$pay_modo = (($pay['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
|
||||
}
|
||||
|
||||
// Cash mode: order/checkout path unless legacy download_credit is on.
|
||||
if ($pay_modo !== 'points' && empty($paid_settings['download_credit'])) {
|
||||
// Cash mode always unlocks via resource order (cashier), never per-download credits.
|
||||
if ($pay_modo !== 'points') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -495,6 +495,10 @@ if (!function_exists('aksrt_resource_download_cost')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Points mode: one-time purchase via cashier. Unpaid amount is not deducted here —
|
||||
// can_download returns need_purchase; after order, has_paid_access zeros cost above.
|
||||
// Return display/gate cost only for free-tier (0) detection; unpaid still shows amount
|
||||
// but rest_request must not deduct without paid order (see Content_Visibility).
|
||||
if (is_array($priced)) {
|
||||
$price = (float) ($priced['amount'] ?? 0);
|
||||
if ($price > 0) {
|
||||
@@ -505,15 +509,11 @@ if (!function_exists('aksrt_resource_download_cost')) {
|
||||
|
||||
// Fallback without helper.
|
||||
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : aksrt_get_resource_meta($post);
|
||||
if ($pay_modo === 'points') {
|
||||
$price = (float) ($meta['points_price'] ?? $meta['price'] ?? 0);
|
||||
} else {
|
||||
$price = (float) ($meta['price'] ?? 0);
|
||||
}
|
||||
$price = (float) ($meta['points_price'] ?? $meta['price'] ?? 0);
|
||||
if ($price > 0) {
|
||||
return (int) ceil($price);
|
||||
}
|
||||
return max(0, (int) ($paid_settings['default_cost'] ?? 0));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,14 @@ if (function_exists('get_the_subtitle')) {
|
||||
$has_access = function_exists('aksrt_has_paid_access') ? aksrt_has_paid_access($post) : false;
|
||||
$gate = function_exists('aksrt_can_download') ? aksrt_can_download($post) : true;
|
||||
$can_dl = $gate === true;
|
||||
$need_login = is_wp_error($gate) && $gate->get_error_code() === 'aksrt_need_login';
|
||||
$gate_code = is_wp_error($gate) ? $gate->get_error_code() : '';
|
||||
$need_login = $gate_code === 'aksrt_need_login';
|
||||
$need_purchase = $gate_code === 'aksrt_need_purchase';
|
||||
$need_vip = $gate_code === 'aksrt_need_vip';
|
||||
|
||||
// Free download + login required (Zibll pay_free_logged_show).
|
||||
$price = (float) ($pay_meta['price'] ?? 0);
|
||||
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post) : null;
|
||||
$price = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($pay_meta['price'] ?? 0);
|
||||
$pay_modo = is_array($priced) ? ((($priced['modo'] ?? '0') === 'points') ? 'points' : '0') : ((($pay_meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
|
||||
$order_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_order_settings() : [];
|
||||
$free_logged_show = !empty($order_settings['free_logged_show']);
|
||||
if ($price <= 0 && $free_logged_show && !is_user_logged_in()) {
|
||||
@@ -60,6 +64,20 @@ if ($price <= 0 && $free_logged_show && !is_user_logged_in()) {
|
||||
$has_access = true; // free "access" but must login to download
|
||||
}
|
||||
|
||||
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
|
||||
$cash_symbol = '¥';
|
||||
if (class_exists('AKSRT_Settings')) {
|
||||
$paid_display = AKSRT_Settings::get_paid_content_settings();
|
||||
$cash_symbol = (string) ($paid_display['display']['currency_symbol'] ?? '¥');
|
||||
}
|
||||
$price_text = $price <= 0
|
||||
? __('免费', 'aksrt')
|
||||
: ($pay_modo === 'points'
|
||||
? (function_exists('aksrt_format_price') ? aksrt_format_price($price) : (string) $price) . ' ' . $currency
|
||||
: $cash_symbol . (function_exists('aksrt_format_price') ? aksrt_format_price($price) : (string) $price));
|
||||
$login_url = wp_login_url(add_query_arg('post', $post_id, get_permalink()));
|
||||
$vip_url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/');
|
||||
|
||||
$paid_name = '';
|
||||
if ($has_access || $can_dl) {
|
||||
if ($price <= 0) {
|
||||
@@ -120,11 +138,10 @@ get_header();
|
||||
</div>
|
||||
<?php elseif ($need_login) : ?>
|
||||
<div class="alert jb-yellow em12" style="margin:2em;">
|
||||
<b><?php esc_html_e('免费资源,请登录后下载', 'aksrt'); ?></b>
|
||||
<b><?php echo ($price <= 0) ? esc_html__('免费资源,请登录后下载', 'aksrt') : esc_html__('请先登录后再下载', 'aksrt'); ?></b>
|
||||
</div>
|
||||
<div class="pay-extra-hide">
|
||||
<?php
|
||||
$login_url = wp_login_url(add_query_arg('post', $post_id, get_permalink()));
|
||||
printf(
|
||||
/* translators: %s: login url */
|
||||
wp_kses_post(__('Hi!请先 <a href="%s">登录</a> 后再下载。', 'aksrt')),
|
||||
@@ -132,13 +149,44 @@ get_header();
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<a style="margin-bottom:2em;" href="<?php echo esc_url($login_url); ?>" class="but jb-red padding-lg">
|
||||
<i class="fa fa-sign-in" aria-hidden="true"></i>
|
||||
<span class="ml10"><?php esc_html_e('前往登录', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php elseif ($need_vip) : ?>
|
||||
<div class="alert jb-yellow em12" style="margin:2em;">
|
||||
<b><?php echo esc_html(is_wp_error($gate) ? $gate->get_error_message() : __('该资源仅限会员购买/下载。', 'aksrt')); ?></b>
|
||||
</div>
|
||||
<a style="margin-bottom:1em;" href="<?php echo esc_url($vip_url); ?>" class="but jb-vip padding-lg">
|
||||
<i class="fa fa-crown" aria-hidden="true"></i>
|
||||
<span class="ml10"><?php esc_html_e('开通会员', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<a style="margin-bottom:2em;" href="<?php echo esc_url($article_url); ?>" class="but jb-yellow padding-lg">
|
||||
<i class="fa fa-long-arrow-left" aria-hidden="true"></i>
|
||||
<span class="ml10"><?php esc_html_e('返回文章', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php elseif ($need_purchase) : ?>
|
||||
<div class="alert jb-red em12" style="margin:2em;">
|
||||
<b><?php esc_html_e('请先购买后再下载', 'aksrt'); ?></b>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="but <?php echo $pay_modo === 'points' ? 'jb-yellow' : 'jb-red'; ?> padding-lg cashier-link"
|
||||
data-action="aksrt-need-purchase"
|
||||
data-aksrt-pay-content="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
|
||||
style="margin-bottom:1em;"
|
||||
>
|
||||
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
|
||||
<span class="ml10"><?php printf(esc_html__('立即购买(%s)', 'aksrt'), $price_text); ?></span>
|
||||
</button>
|
||||
<a style="margin-bottom:2em;" href="<?php echo esc_url($article_url); ?>" class="but jb-yellow padding-lg">
|
||||
<i class="fa fa-long-arrow-left" aria-hidden="true"></i>
|
||||
<span class="ml10"><?php esc_html_e('返回文章', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php else : ?>
|
||||
<div class="alert jb-red em12" style="margin:2em;">
|
||||
<b><?php esc_html_e('暂无下载权限', 'aksrt'); ?></b>
|
||||
<b><?php echo esc_html(is_wp_error($gate) ? $gate->get_error_message() : __('暂无下载权限', 'aksrt')); ?></b>
|
||||
</div>
|
||||
<a style="margin-bottom:2em;" href="<?php echo esc_url($article_url); ?>" class="but jb-yellow padding-lg">
|
||||
<i class="fa fa-long-arrow-left" aria-hidden="true"></i>
|
||||
|
||||
@@ -45,32 +45,34 @@ $paid_settings = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::get_paid_content_settings()
|
||||
: ['download_credit' => true, 'download_captcha' => false];
|
||||
|
||||
$cost = function_exists('aksrt_get_download_cost') ? aksrt_get_download_cost($post_id) : (int) ceil((float) ($meta['price'] ?? 0));
|
||||
$credit_active = !empty($paid_settings['download_credit']) && $cost > 0;
|
||||
$pay_modo = (($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
|
||||
if (function_exists('aksrt_get_user_pay_price')) {
|
||||
$priced = aksrt_get_user_pay_price($post_id);
|
||||
$pay_modo = (($priced['modo'] ?? $pay_modo) === 'points') ? 'points' : '0';
|
||||
}
|
||||
// Points mode always uses credit deduct path when cost > 0.
|
||||
if ($pay_modo === 'points' && $cost > 0) {
|
||||
$credit_active = true;
|
||||
}
|
||||
$access = class_exists('AKSRT_Content_Visibility')
|
||||
? AKSRT_Content_Visibility::get_post_access_state($post_id)
|
||||
: [];
|
||||
$has_paid_access = !empty($access['has_paid_access']);
|
||||
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post_id) : null;
|
||||
$pay_modo = is_array($priced)
|
||||
? ((($priced['modo'] ?? '0') === 'points') ? 'points' : '0')
|
||||
: ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
|
||||
$user_amount = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
|
||||
$cost = function_exists('aksrt_resource_download_cost') ? (int) aksrt_resource_download_cost($post_id) : 0;
|
||||
|
||||
$captcha_active = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
|
||||
if ($captcha_active && function_exists('aksrt_is_captcha_enabled_for') && !aksrt_is_captcha_enabled_for('download')) {
|
||||
$captcha_active = false;
|
||||
}
|
||||
$balance = (int) ($gate_data['balance'] ?? 0);
|
||||
$balance = (int) ($gate_data['balance'] ?? (is_user_logged_in() && class_exists('AKSRT_Credits') ? AKSRT_Credits::balance(get_current_user_id()) : 0));
|
||||
$login_url = (string) ($gate_data['login_url'] ?? wp_login_url(get_permalink($post_id)));
|
||||
$vip_url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/');
|
||||
|
||||
$is_need_login = $gate_blocked && $gate_code === 'aksrt_need_login';
|
||||
$is_low_credit = $gate_blocked && $gate_code === 'aksrt_credits_insufficient';
|
||||
$is_need_vip = $gate_blocked && $gate_code === 'aksrt_need_vip';
|
||||
$is_need_purchase = $gate_blocked && $gate_code === 'aksrt_need_purchase';
|
||||
// Points unpaid may also surface as need_purchase; treat low balance only after cashier.
|
||||
$is_low_credit = false;
|
||||
|
||||
// Zibll pay_free_logged_show: free downloads still require login.
|
||||
$free_logged_show = !empty($paid_settings['free_logged_show']);
|
||||
$price_amount = (float) ($price_label['amount'] ?? $meta['price'] ?? 0);
|
||||
$price_amount = (float) ($price_label['amount'] ?? $user_amount);
|
||||
if ($price_amount <= 0 && $free_logged_show && !is_user_logged_in()) {
|
||||
$is_need_login = true;
|
||||
$gate_blocked = true;
|
||||
@@ -82,7 +84,7 @@ $alone_url = '';
|
||||
if ($alone_page && function_exists('aksrt_get_single_download_page_url')) {
|
||||
$alone_url = aksrt_get_single_download_page_url($post_id);
|
||||
}
|
||||
$use_alone_entry = $alone_page && $alone_url !== '' && !$is_need_login && !$is_low_credit && !$is_need_vip && !$is_need_purchase;
|
||||
$use_alone_entry = $alone_page && $alone_url !== '' && !$is_need_login && !$is_need_vip && !$is_need_purchase && !$gate_blocked;
|
||||
if (!empty($GLOBALS['aksrt_on_download_file_page'])) {
|
||||
$use_alone_entry = false;
|
||||
}
|
||||
@@ -105,6 +107,8 @@ if ($pay_modo === 'points') {
|
||||
$has_original = $original_price > 0 && $original_price > $base_price;
|
||||
$has_vip = ($vip1_price > 0 && $vip1_price < $base_price) || ($vip2_price > 0 && $vip2_price < $base_price);
|
||||
$pay_limit = (int) ($meta['pay_limit'] ?? 0);
|
||||
$user_vip_level = is_array($priced) ? (int) ($priced['vip_level'] ?? 0) : 0;
|
||||
$member_blocked = $pay_limit > 0 && $user_vip_level < $pay_limit;
|
||||
|
||||
// 销量
|
||||
$download_count = (int) ($meta['download_count'] ?? 0);
|
||||
@@ -129,18 +133,34 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
$n = function_exists('aksrt_format_price') ? aksrt_format_price($amount) : (string) $amount;
|
||||
return $pay_modo === 'points' ? ($n . ' ' . $currency) : ($cash_symbol . $n);
|
||||
};
|
||||
|
||||
$purchase_label = '';
|
||||
if ($is_need_purchase && $user_amount > 0) {
|
||||
$purchase_label = $pay_modo === 'points'
|
||||
? sprintf(__('立即购买(%s %s)', 'aksrt'), aksrt_format_price($user_amount), $currency)
|
||||
: sprintf(__('立即购买(%s%s)', 'aksrt'), $cash_symbol, aksrt_format_price($user_amount));
|
||||
} elseif ($is_need_purchase) {
|
||||
$purchase_label = __('购买后下载', 'aksrt');
|
||||
}
|
||||
?>
|
||||
|
||||
<section class="widget resource-download-box resource-download-box--v2<?php echo $gate_blocked ? ' is-blocked' : ''; ?> resource-download-box--<?php echo esc_attr($context_variant); ?>"
|
||||
<section class="widget resource-download-box resource-download-box--v2<?php echo $gate_blocked ? ' is-blocked' : ''; ?><?php echo $has_paid_access ? ' is-purchased' : ''; ?> resource-download-box--<?php echo esc_attr($context_variant); ?>"
|
||||
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-price="<?php echo esc_attr((string) $base_price); ?>"
|
||||
data-amount="<?php echo esc_attr((string) $user_amount); ?>"
|
||||
data-pay-modo="<?php echo esc_attr($pay_modo); ?>"
|
||||
data-pay-limit="<?php echo esc_attr((string) $pay_limit); ?>"
|
||||
data-credit="<?php echo $credit_active ? '1' : '0'; ?>"
|
||||
data-has-paid="<?php echo $has_paid_access ? '1' : '0'; ?>"
|
||||
data-credit="0"
|
||||
data-captcha="<?php echo $captcha_active ? '1' : '0'; ?>"
|
||||
aria-label="<?php esc_attr_e('下载区', 'aksrt'); ?>">
|
||||
|
||||
<?php if ($show_sales && $display_count > 0) : ?>
|
||||
<?php if ($has_paid_access && $user_amount > 0) : ?>
|
||||
<span class="resource-download-box__sales-badge resource-download-box__paid-badge">
|
||||
<i class="fas fa-check-circle" aria-hidden="true"></i>
|
||||
<?php esc_html_e('已购买', 'aksrt'); ?>
|
||||
</span>
|
||||
<?php elseif ($show_sales && $display_count > 0) : ?>
|
||||
<span class="resource-download-box__sales-badge">
|
||||
<i class="fas fa-fire" aria-hidden="true"></i>
|
||||
<?php
|
||||
@@ -166,7 +186,7 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
<p class="resource-download-box__eyebrow"><?php echo esc_html(sprintf(__('%s付费 / 下载能力', 'aksrt'), $subject_label)); ?></p>
|
||||
<h2 class="resource-download-box__title">
|
||||
<i class="fas fa-cloud-download-alt" aria-hidden="true"></i>
|
||||
<?php esc_html_e('解锁下载', 'aksrt'); ?>
|
||||
<?php echo $has_paid_access ? esc_html__('资源下载', 'aksrt') : esc_html__('解锁下载', 'aksrt'); ?>
|
||||
</h2>
|
||||
</div>
|
||||
<span class="resource-download-box__count">
|
||||
@@ -175,10 +195,16 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
</header>
|
||||
|
||||
<div class="resource-download-box__pricing">
|
||||
<span class="resource-download-box__price<?php echo !empty($price_label['free']) ? ' is-free' : ''; ?>">
|
||||
<?php echo esc_html((string) ($price_label['text'] ?? '')); ?>
|
||||
<span class="resource-download-box__price<?php echo !empty($price_label['free']) || $has_paid_access ? ' is-free' : ''; ?>">
|
||||
<?php
|
||||
if ($has_paid_access && $user_amount > 0) {
|
||||
esc_html_e('已解锁', 'aksrt');
|
||||
} else {
|
||||
echo esc_html((string) ($price_label['text'] ?? ''));
|
||||
}
|
||||
?>
|
||||
</span>
|
||||
<?php if ($has_original && $pay_limit <= 0) : ?>
|
||||
<?php if ($has_original && !$member_blocked && !$has_paid_access) : ?>
|
||||
<span class="resource-download-box__original-price">
|
||||
<?php
|
||||
echo esc_html(
|
||||
@@ -192,7 +218,7 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
<?php echo $pay_type_badge && !$has_thumbnail ? $pay_type_badge : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
|
||||
<?php if ($has_vip && $pay_limit <= 0) : ?>
|
||||
<?php if ($has_vip && !$member_blocked && !$has_paid_access) : ?>
|
||||
<div class="resource-download-box__vip-pricing">
|
||||
<?php if ($vip1_price > 0 && $vip1_price < $base_price) : ?>
|
||||
<span class="resource-download-box__vip-badge resource-download-box__vip-badge--1">
|
||||
@@ -215,16 +241,42 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if (function_exists('aksrt_get_pay_attributes_html')) {
|
||||
echo aksrt_get_pay_attributes_html($post_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (!empty($paid_settings['catalog_note'])) : ?>
|
||||
<p class="resource-download-box__catalog-note"><?php echo esc_html((string) $paid_settings['catalog_note']); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($is_need_vip) : ?>
|
||||
<?php if ($is_need_vip || $member_blocked) : ?>
|
||||
<div class="mt10 resource-download-box__vip-gate">
|
||||
<span class="resource-download-box__btn btn-primary resource-download-box__btn--vip is-disabled">
|
||||
<a href="<?php echo esc_url($vip_url); ?>" class="resource-download-box__btn btn-primary resource-download-box__btn--vip">
|
||||
<i class="fas fa-crown" aria-hidden="true"></i>
|
||||
<span><?php echo esc_html($gate instanceof WP_Error ? $gate->get_error_message() : __('会员专属资源', 'aksrt')); ?></span>
|
||||
</span>
|
||||
<span><?php echo esc_html($gate instanceof WP_Error ? $gate->get_error_message() : __('开通会员后下载', 'aksrt')); ?></span>
|
||||
</a>
|
||||
<?php
|
||||
if (function_exists('aksrt_get_demo_link_html')) {
|
||||
echo aksrt_get_demo_link_html($post_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php elseif ($is_need_purchase) : ?>
|
||||
<div class="mt10 resource-download-box__purchase-gate">
|
||||
<button
|
||||
type="button"
|
||||
class="resource-download-box__btn btn-primary resource-download-box__btn--purchase cashier-link <?php echo $pay_modo === 'points' ? 'is-points' : 'is-cash'; ?>"
|
||||
data-action="aksrt-need-purchase"
|
||||
data-aksrt-pay-content="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-pay-modo="<?php echo esc_attr($pay_modo); ?>"
|
||||
data-amount="<?php echo esc_attr((string) $user_amount); ?>"
|
||||
>
|
||||
<i class="fas fa-shopping-cart" aria-hidden="true"></i>
|
||||
<span><?php echo esc_html($purchase_label); ?></span>
|
||||
</button>
|
||||
<?php
|
||||
if (function_exists('aksrt_get_demo_link_html')) {
|
||||
echo aksrt_get_demo_link_html($post_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
@@ -240,13 +292,6 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
<?php
|
||||
if (function_exists('aksrt_get_demo_link_html')) {
|
||||
echo aksrt_get_demo_link_html($post_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} elseif (!empty($meta['demo_url'])) {
|
||||
?>
|
||||
<a target="_blank" rel="nofollow" href="<?php echo esc_url((string) $meta['demo_url']); ?>" class="resource-download-box__btn btn-outline resource-download-box__btn--demo">
|
||||
<i class="fas fa-external-link-alt" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('查看演示', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
@@ -272,26 +317,13 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
$btn_text = __('登录后下载', 'aksrt');
|
||||
$btn_icon = 'fa-sign-in-alt';
|
||||
$btn_modifier = ' resource-download-box__btn--login';
|
||||
} elseif ($is_need_purchase) {
|
||||
$btn_tag = 'button';
|
||||
$btn_text = __('购买后下载', 'aksrt');
|
||||
$btn_icon = 'fa-shopping-cart';
|
||||
$btn_modifier = ' resource-download-box__btn--purchase';
|
||||
} elseif ($is_low_credit) {
|
||||
$btn_tag = 'button';
|
||||
$btn_text = sprintf(__('解锁下载(%d 积分)', 'aksrt'), $cost);
|
||||
$btn_icon = 'fa-coins';
|
||||
$btn_modifier = ' resource-download-box__btn--credit-low';
|
||||
} elseif ($credit_active && $cost > 0) {
|
||||
$btn_tag = 'button';
|
||||
$btn_text = sprintf(__('下载(%d 积分)', 'aksrt'), $cost);
|
||||
$btn_icon = 'fa-download';
|
||||
$btn_modifier = ' resource-download-box__btn--paid';
|
||||
$btn_action = '';
|
||||
} else {
|
||||
$btn_tag = 'button';
|
||||
$btn_text = __('立即下载', 'aksrt');
|
||||
$btn_icon = 'fa-download';
|
||||
$btn_modifier = '';
|
||||
$btn_modifier = $has_paid_access ? ' resource-download-box__btn--owned' : '';
|
||||
$btn_action = 'aksrt-download';
|
||||
}
|
||||
?>
|
||||
<li class="resource-download-box__item">
|
||||
@@ -313,7 +345,7 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
<button
|
||||
type="button"
|
||||
class="resource-download-box__btn btn-primary resource-download-box__btn--service-<?php echo esc_attr($service['key']); ?><?php echo esc_attr($btn_modifier); ?>"
|
||||
data-action="<?php echo $is_low_credit ? 'aksrt-need-credits' : ($is_need_purchase ? 'aksrt-need-purchase' : 'aksrt-download'); ?>"
|
||||
data-action="<?php echo esc_attr($btn_action); ?>"
|
||||
data-source-index="<?php echo esc_attr((string) $idx); ?>"
|
||||
data-source-type="<?php echo esc_attr($type); ?>"
|
||||
data-has-extract="<?php echo $has_extract ? '1' : '0'; ?>"
|
||||
@@ -323,24 +355,26 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
>
|
||||
<i class="fas <?php echo esc_attr($btn_icon); ?>" aria-hidden="true"></i>
|
||||
<span><?php echo esc_html($btn_text); ?></span>
|
||||
<?php if ($is_low_credit) : ?>
|
||||
<small class="resource-download-box__btn-sub">
|
||||
<?php printf(esc_html__('当前余额 %d', 'aksrt'), $balance); ?>
|
||||
</small>
|
||||
<?php else : ?>
|
||||
<span class="resource-download-box__service-badge" style="background: <?php echo esc_attr($service['color']); ?>">
|
||||
<?php echo esc_html($service['name']); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<span class="resource-download-box__service-badge" style="background: <?php echo esc_attr($service['color']); ?>">
|
||||
<?php echo esc_html($service['name']); ?>
|
||||
</span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</ul>
|
||||
<?php
|
||||
if (function_exists('aksrt_get_demo_link_html')) {
|
||||
$demo = aksrt_get_demo_link_html($post_id);
|
||||
if ($demo !== '') {
|
||||
echo '<div class="mt10 resource-download-box__demo-row">' . $demo . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if (is_user_logged_in() && $cost <= 0 && function_exists('aksrt_get_user_free_download_limit')) {
|
||||
if (is_user_logged_in() && $user_amount <= 0 && function_exists('aksrt_get_user_free_download_limit')) {
|
||||
$dl_limit = aksrt_get_user_free_download_limit();
|
||||
if ($dl_limit > 0) {
|
||||
$dl_used = function_exists('aksrt_get_user_free_downloaded_number') ? aksrt_get_user_free_downloaded_number() : 0;
|
||||
@@ -376,7 +410,7 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
<i class="fas fa-info-circle" aria-hidden="true"></i>
|
||||
<?php echo ($price_amount <= 0) ? esc_html__('免费资源,请登录后下载。', 'aksrt') : esc_html__('登录后可解锁并下载该内容。', 'aksrt'); ?>
|
||||
</p>
|
||||
<?php elseif ($is_need_vip) : ?>
|
||||
<?php elseif ($is_need_vip || $member_blocked) : ?>
|
||||
<p class="resource-download-box__hint resource-download-box__hint--vip">
|
||||
<i class="fas fa-info-circle" aria-hidden="true"></i>
|
||||
<?php echo esc_html($gate instanceof WP_Error ? $gate->get_error_message() : __('该资源仅限会员购买/下载。', 'aksrt')); ?>
|
||||
@@ -386,11 +420,6 @@ $format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_s
|
||||
<i class="fas fa-info-circle" aria-hidden="true"></i>
|
||||
<?php esc_html_e('请先完成购买后再下载该资源。', 'aksrt'); ?>
|
||||
</p>
|
||||
<?php elseif ($is_low_credit) : ?>
|
||||
<p class="resource-download-box__hint resource-download-box__hint--credit">
|
||||
<i class="fas fa-info-circle" aria-hidden="true"></i>
|
||||
<?php printf(esc_html__('当前余额 %1$d 积分,需要 %2$d 积分。可通过签到、阅读、邀请好友等方式获取积分。', 'aksrt'), $balance, $cost); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($captcha_active && function_exists('aksrt_render_captcha')) : ?>
|
||||
|
||||
Reference in New Issue
Block a user