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:
kate522 committed 2026-07-14 11:52:44 +08:00
1 parent abe2f57417
commit 770205623d
11 files changed
+1142 -170

No files matched your search

+54 -6
View File
@@ -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>
+97 -68
View File
@@ -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')) : ?>