feat(pay): wire VIP-tier pricing into cost, gates, and download box
Resolve user-facing pay amounts via aksrt_get_user_pay_price (cash/points + VIP1/2 tiers), surface pay_modo/pay_limit through download meta and REST policy, and tighten content-visibility / download-box UX for member-only and purchase gates while improving local stream throttle math.
This commit is contained in:
1 parent
1c8e4d3919
commit
abe2f57417
5 files changed
+459
-127
No files matched your search
@@ -47,6 +47,15 @@ $paid_settings = class_exists('AKSRT_Settings')
|
||||
|
||||
$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;
|
||||
}
|
||||
$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;
|
||||
@@ -55,58 +64,83 @@ $balance = (int) ($gate_data['balance'] ?? 0);
|
||||
$login_url = (string) ($gate_data['login_url'] ?? wp_login_url(get_permalink($post_id)));
|
||||
|
||||
$is_need_login = $gate_blocked && $gate_code === 'aksrt_need_login';
|
||||
$is_low_credit = $gate_blocked && $gate_code === 'aksrt_credits_insufficient';
|
||||
$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';
|
||||
|
||||
// Zibll pay_free_logged_show: free downloads still require login.
|
||||
$free_logged_show = !empty($paid_settings['free_logged_show']);
|
||||
$price_amount = (float) ($meta['price'] ?? 0);
|
||||
if ($price_amount <= 0 && $free_logged_show && !is_user_logged_in()) {
|
||||
$is_need_login = true;
|
||||
$gate_blocked = true;
|
||||
}
|
||||
// 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);
|
||||
if ($price_amount <= 0 && $free_logged_show && !is_user_logged_in()) {
|
||||
$is_need_login = true;
|
||||
$gate_blocked = true;
|
||||
}
|
||||
|
||||
// Zibll down_alone_page: single entry to independent download page.
|
||||
$alone_page = !empty($paid_settings['down_alone_page']) || !empty($paid_settings['download']['alone_page']);
|
||||
$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;
|
||||
if (!empty($GLOBALS['aksrt_on_download_file_page'])) {
|
||||
$use_alone_entry = false;
|
||||
}
|
||||
// Zibll down_alone_page: single entry to independent download page.
|
||||
$alone_page = !empty($paid_settings['down_alone_page']) || !empty($paid_settings['download']['alone_page']);
|
||||
$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;
|
||||
if (!empty($GLOBALS['aksrt_on_download_file_page'])) {
|
||||
$use_alone_entry = false;
|
||||
}
|
||||
|
||||
// 缩略图
|
||||
$thumbnail = get_the_post_thumbnail_url($post_id, 'medium') ?: '';
|
||||
$has_thumbnail = $thumbnail !== '';
|
||||
|
||||
// 原价 & VIP 价
|
||||
// 原价 & VIP 价(按 pay_modo 切换现金/积分档)
|
||||
$original_price = (float) ($meta['original_price'] ?? 0);
|
||||
$vip1_price = (float) ($meta['vip1_price'] ?? 0);
|
||||
$vip2_price = (float) ($meta['vip2_price'] ?? 0);
|
||||
$has_original = $original_price > 0 && $original_price > (float) ($meta['price'] ?? 0);
|
||||
$has_vip = $vip1_price > 0 || $vip2_price > 0;
|
||||
if ($pay_modo === 'points') {
|
||||
$vip1_price = (float) ($meta['vip1_points'] ?? 0);
|
||||
$vip2_price = (float) ($meta['vip2_points'] ?? 0);
|
||||
$base_price = (float) ($meta['points_price'] ?? $meta['price'] ?? 0);
|
||||
} else {
|
||||
$vip1_price = (float) ($meta['vip1_price'] ?? 0);
|
||||
$vip2_price = (float) ($meta['vip2_price'] ?? 0);
|
||||
$base_price = (float) ($meta['price'] ?? 0);
|
||||
}
|
||||
$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);
|
||||
|
||||
// 销量
|
||||
$download_count = (int) ($meta['download_count'] ?? 0);
|
||||
$sales_count = (int) ($meta['sales_count'] ?? 0);
|
||||
$display_count = max($download_count, $sales_count);
|
||||
$show_sales = !isset($meta['show_sales']) || !empty($meta['show_sales']);
|
||||
|
||||
// 付费类型徽章
|
||||
$pay_type_badge = function_exists('aksrt_get_pay_type_badge') ? aksrt_get_pay_type_badge($pay_type) : '';
|
||||
|
||||
// 货币名称
|
||||
$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'] ?? '¥');
|
||||
}
|
||||
$format_vip = static function (float $amount) use ($pay_modo, $currency, $cash_symbol): string {
|
||||
if ($amount <= 0) {
|
||||
return (string) __('免费', 'aksrt');
|
||||
}
|
||||
$n = function_exists('aksrt_format_price') ? aksrt_format_price($amount) : (string) $amount;
|
||||
return $pay_modo === 'points' ? ($n . ' ' . $currency) : ($cash_symbol . $n);
|
||||
};
|
||||
?>
|
||||
|
||||
<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); ?>"
|
||||
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-price="<?php echo esc_attr((string) ($meta['price'] ?? 0)); ?>"
|
||||
data-price="<?php echo esc_attr((string) $base_price); ?>"
|
||||
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-captcha="<?php echo $captcha_active ? '1' : '0'; ?>"
|
||||
aria-label="<?php esc_attr_e('下载区', 'aksrt'); ?>">
|
||||
|
||||
<?php if ($display_count > 0) : ?>
|
||||
<?php if ($show_sales && $display_count > 0) : ?>
|
||||
<span class="resource-download-box__sales-badge">
|
||||
<i class="fas fa-fire" aria-hidden="true"></i>
|
||||
<?php
|
||||
@@ -144,31 +178,37 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
|
||||
<span class="resource-download-box__price<?php echo !empty($price_label['free']) ? ' is-free' : ''; ?>">
|
||||
<?php echo esc_html((string) ($price_label['text'] ?? '')); ?>
|
||||
</span>
|
||||
<?php if ($has_original) : ?>
|
||||
<?php if ($has_original && $pay_limit <= 0) : ?>
|
||||
<span class="resource-download-box__original-price">
|
||||
<?php echo esc_html(aksrt_format_price($original_price) . ' ' . $currency); ?>
|
||||
<?php
|
||||
echo esc_html(
|
||||
$pay_modo === 'points'
|
||||
? (aksrt_format_price($original_price) . ' ' . $currency)
|
||||
: ($cash_symbol . aksrt_format_price($original_price))
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php echo $pay_type_badge && !$has_thumbnail ? $pay_type_badge : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
|
||||
<?php if ($has_vip) : ?>
|
||||
<?php if ($has_vip && $pay_limit <= 0) : ?>
|
||||
<div class="resource-download-box__vip-pricing">
|
||||
<?php if ($vip1_price > 0) : ?>
|
||||
<?php if ($vip1_price > 0 && $vip1_price < $base_price) : ?>
|
||||
<span class="resource-download-box__vip-badge resource-download-box__vip-badge--1">
|
||||
<i class="fas fa-crown" aria-hidden="true"></i>
|
||||
<?php
|
||||
/* translators: %s: VIP1 价格 */
|
||||
printf(esc_html__('VIP1 %s', 'aksrt'), aksrt_format_price($vip1_price));
|
||||
printf(esc_html__('VIP1 %s', 'aksrt'), $format_vip($vip1_price));
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($vip2_price > 0) : ?>
|
||||
<?php if ($vip2_price > 0 && $vip2_price < $base_price) : ?>
|
||||
<span class="resource-download-box__vip-badge resource-download-box__vip-badge--2">
|
||||
<i class="fas fa-gem" aria-hidden="true"></i>
|
||||
<?php
|
||||
/* translators: %s: VIP2 价格 */
|
||||
printf(esc_html__('VIP2 %s', 'aksrt'), aksrt_format_price($vip2_price));
|
||||
printf(esc_html__('VIP2 %s', 'aksrt'), $format_vip($vip2_price));
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
@@ -179,7 +219,19 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
|
||||
<p class="resource-download-box__catalog-note"><?php echo esc_html((string) $paid_settings['catalog_note']); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($use_alone_entry)) : ?>
|
||||
<?php if ($is_need_vip) : ?>
|
||||
<div class="mt10 resource-download-box__vip-gate">
|
||||
<span class="resource-download-box__btn btn-primary resource-download-box__btn--vip is-disabled">
|
||||
<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>
|
||||
<?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 (!empty($use_alone_entry)) : ?>
|
||||
<div class="mt10 resource-download-box__alone">
|
||||
<a target="_blank" rel="nofollow" href="<?php echo esc_url($alone_url); ?>" class="resource-download-box__btn btn-primary resource-download-box__btn--alone">
|
||||
<i class="fas fa-download" aria-hidden="true"></i>
|
||||
@@ -220,6 +272,11 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
|
||||
$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);
|
||||
@@ -256,7 +313,7 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
|
||||
<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' : 'aksrt-download'; ?>"
|
||||
data-action="<?php echo $is_low_credit ? 'aksrt-need-credits' : ($is_need_purchase ? 'aksrt-need-purchase' : 'aksrt-download'); ?>"
|
||||
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'; ?>"
|
||||
@@ -282,42 +339,52 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if (is_user_logged_in() && $cost <= 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;
|
||||
$dl_surplus = max(0, $dl_limit - $dl_used);
|
||||
$vip_lv = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level() : 0;
|
||||
if ($dl_surplus <= 0) {
|
||||
echo '<div class="resource-download-box__quota-notice"><span class="badg c-red btn-block">' . esc_html__('您今日下载免费资源个数已超限,请明日再下载。', 'aksrt') . '</span></div>';
|
||||
} else {
|
||||
$who = $vip_lv > 0 ? esc_html__('您是尊贵的会员,', 'aksrt') : esc_html__('您', 'aksrt');
|
||||
echo '<div class="resource-download-box__quota-notice"><span class="badg c-red btn-block">' . $who . esc_html(sprintf(__('今日还可下载 %s 个免费资源', 'aksrt'), number_format_i18n($dl_surplus))) . '</span></div>';
|
||||
}
|
||||
<?php
|
||||
if (is_user_logged_in() && $cost <= 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;
|
||||
$dl_surplus = max(0, $dl_limit - $dl_used);
|
||||
$vip_lv = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level() : 0;
|
||||
if ($dl_surplus <= 0) {
|
||||
echo '<div class="resource-download-box__quota-notice"><span class="badg c-red btn-block">' . esc_html__('您今日下载免费资源个数已超限,请明日再下载。', 'aksrt') . '</span></div>';
|
||||
} else {
|
||||
$who = $vip_lv > 0 ? esc_html__('您是尊贵的会员,', 'aksrt') : esc_html__('您', 'aksrt');
|
||||
echo '<div class="resource-download-box__quota-notice"><span class="badg c-red btn-block">' . $who . esc_html(sprintf(__('今日还可下载 %s 个免费资源', 'aksrt'), number_format_i18n($dl_surplus))) . '</span></div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="resource-download-box__guarantees">
|
||||
<?php
|
||||
if (function_exists('aksrt_get_pay_service_html')) {
|
||||
echo aksrt_get_pay_service_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
?>
|
||||
<span class="resource-download-box__guarantee"><i class="fas fa-shield-alt" aria-hidden="true"></i> <?php esc_html_e('安全检测', 'aksrt'); ?></span>
|
||||
<span class="resource-download-box__guarantee"><i class="fas fa-crown" aria-hidden="true"></i> <?php esc_html_e('支持 VIP 权益', 'aksrt'); ?></span>
|
||||
<span class="resource-download-box__guarantee"><i class="fas fa-coins" aria-hidden="true"></i> <?php esc_html_e('支持积分结算', 'aksrt'); ?></span>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="resource-download-box__guarantees">
|
||||
<?php
|
||||
if (function_exists('aksrt_get_pay_service_html')) {
|
||||
echo aksrt_get_pay_service_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
?>
|
||||
</div>
|
||||
<span class="resource-download-box__guarantee"><i class="fas fa-shield-alt" aria-hidden="true"></i> <?php esc_html_e('安全检测', 'aksrt'); ?></span>
|
||||
<span class="resource-download-box__guarantee"><i class="fas fa-crown" aria-hidden="true"></i> <?php esc_html_e('支持 VIP 权益', 'aksrt'); ?></span>
|
||||
<span class="resource-download-box__guarantee"><i class="fas fa-coins" aria-hidden="true"></i> <?php esc_html_e('支持积分结算', 'aksrt'); ?></span>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($is_need_login) : ?>
|
||||
<p class="resource-download-box__hint resource-download-box__hint--login">
|
||||
<i class="fas fa-info-circle" aria-hidden="true"></i>
|
||||
<?php echo (isset($price_amount) && $price_amount <= 0) ? esc_html__('免费资源,请登录后下载。', 'aksrt') : esc_html__('登录后可解锁并下载该内容。', 'aksrt'); ?>
|
||||
<?php echo ($price_amount <= 0) ? esc_html__('免费资源,请登录后下载。', 'aksrt') : esc_html__('登录后可解锁并下载该内容。', 'aksrt'); ?>
|
||||
</p>
|
||||
<?php elseif ($is_need_vip) : ?>
|
||||
<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')); ?>
|
||||
</p>
|
||||
<?php elseif ($is_need_purchase) : ?>
|
||||
<p class="resource-download-box__hint resource-download-box__hint--purchase">
|
||||
<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">
|
||||
|
||||
Reference in new issue
Block a user