Apply vip_renew discount/reduce to same-level packages, gate renew/upgrade availability, support dedicated vip_upgrade_product line, and show tags/CTAs.
189 lines
7.4 KiB
PHP
189 lines
7.4 KiB
PHP
<?php
|
|
/**
|
|
* User center credits: VIP membership card + purchase packages.
|
|
*
|
|
* Expects extracted $context vars.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$vip_settings = is_array($vip_settings ?? null) ? $vip_settings : [];
|
|
if (empty($vip_settings['enabled'])) {
|
|
return;
|
|
}
|
|
|
|
$user_id = (int) ($user_id ?? get_current_user_id());
|
|
$is_vip_user = function_exists('aksrt_is_vip') && aksrt_is_vip($user_id);
|
|
$vip_level = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level($user_id) : 0;
|
|
$expires = (int) get_user_meta($user_id, 'aksrt_vip_expires', true);
|
|
$expires_label = __('未开通', 'aksrt');
|
|
if ($vip_level > 0) {
|
|
if ($expires <= 0) {
|
|
$expires_label = __('永久有效', 'aksrt');
|
|
} elseif ($expires < time()) {
|
|
$expires_label = __('已过期', 'aksrt');
|
|
} else {
|
|
$expires_label = sprintf(
|
|
/* translators: %s: date */
|
|
__('到期时间:%s', 'aksrt'),
|
|
wp_date('Y-m-d', $expires)
|
|
);
|
|
}
|
|
}
|
|
|
|
$level_name = (string) ($vip_settings['name'] ?? __('VIP会员', 'aksrt'));
|
|
if ($vip_level >= 1 && !empty($vip_settings['levels'][$vip_level]['name'])) {
|
|
$level_name = (string) $vip_settings['levels'][$vip_level]['name'];
|
|
}
|
|
|
|
$packages = [];
|
|
$renew_desc = '';
|
|
$upgrade_desc = '';
|
|
if (class_exists('AKSRT_Vip_Service')) {
|
|
$catalog = AKSRT_Vip_Service::get_instance()->get_catalog($user_id);
|
|
$packages = is_array($catalog['level_packages'] ?? null) ? $catalog['level_packages'] : [];
|
|
$methods = is_array($catalog['payment_methods'] ?? null) ? $catalog['payment_methods'] : [];
|
|
$renew_desc = (string) ($catalog['renew_desc'] ?? '');
|
|
$upgrade_desc = (string) ($catalog['upgrade_desc'] ?? '');
|
|
} else {
|
|
$methods = [['id' => 'balance', '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'] ?? '¥');
|
|
}
|
|
|
|
$shop_title = __('开通会员', 'aksrt');
|
|
if ($vip_level > 0) {
|
|
$shop_title = __('续费 / 升级会员', 'aksrt');
|
|
}
|
|
?>
|
|
<div class="uc-vip-card<?php echo $is_vip_user ? ' uc-vip-card--active' : ''; ?>" data-aksrt-vip-panel>
|
|
<div class="uc-vip-card__bg"></div>
|
|
<div class="uc-vip-card__content">
|
|
<div class="uc-vip-card__header">
|
|
<div class="uc-vip-card__icon">
|
|
<i class="fas fa-crown" aria-hidden="true"></i>
|
|
</div>
|
|
<div class="uc-vip-card__info">
|
|
<span class="uc-vip-card__label"><?php echo esc_html($level_name); ?></span>
|
|
<?php if ($is_vip_user) : ?>
|
|
<span class="uc-vip-card__status uc-vip-card__status--active"><?php echo esc_html($expires_label); ?></span>
|
|
<?php else : ?>
|
|
<span class="uc-vip-card__status"><?php esc_html_e('未开通', 'aksrt'); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="uc-vip-card__benefits">
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-download" aria-hidden="true"></i> <?php esc_html_e('免费下载', 'aksrt'); ?></span>
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-crown" aria-hidden="true"></i> <?php esc_html_e('专属身份', 'aksrt'); ?></span>
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-tag" aria-hidden="true"></i> <?php esc_html_e('会员价优惠', 'aksrt'); ?></span>
|
|
</div>
|
|
<?php if (!empty($vip_settings['desc'])) : ?>
|
|
<p class="uc-vip-card__desc"><?php echo esc_html((string) $vip_settings['desc']); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (!empty($packages)) : ?>
|
|
<div class="uc-vip-shop" data-aksrt-vip-shop>
|
|
<div class="uc-vip-shop__title">
|
|
<i class="fas fa-gem" aria-hidden="true"></i>
|
|
<span><?php echo esc_html($shop_title); ?></span>
|
|
</div>
|
|
|
|
<?php if ($vip_level > 0 && $renew_desc !== '') : ?>
|
|
<p class="uc-vip-shop__note"><?php echo esc_html($renew_desc); ?></p>
|
|
<?php endif; ?>
|
|
<?php if ($vip_level === 1 && $upgrade_desc !== '') : ?>
|
|
<p class="uc-vip-shop__note"><?php echo esc_html($upgrade_desc); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<?php foreach ($packages as $group) :
|
|
$g_level = (int) ($group['level'] ?? 0);
|
|
$g_name = (string) ($group['name'] ?? ('VIP' . $g_level));
|
|
$g_action = (string) ($group['action'] ?? 'pay');
|
|
$items = is_array($group['items'] ?? null) ? $group['items'] : [];
|
|
if ($items === []) {
|
|
continue;
|
|
}
|
|
$group_badge = '';
|
|
if ($g_action === 'renew') {
|
|
$group_badge = __('续费', 'aksrt');
|
|
} elseif ($g_action === 'upgrade') {
|
|
$group_badge = __('升级', 'aksrt');
|
|
} elseif ($vip_level >= $g_level) {
|
|
$group_badge = __('当前档', 'aksrt');
|
|
}
|
|
?>
|
|
<div class="uc-vip-shop__group" data-vip-level="<?php echo esc_attr((string) $g_level); ?>" data-action="<?php echo esc_attr($g_action); ?>">
|
|
<div class="uc-vip-shop__group-title">
|
|
<?php echo esc_html($g_name); ?>
|
|
<?php if ($group_badge !== '') : ?>
|
|
<span class="uc-vip-shop__badge"><?php echo esc_html($group_badge); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="uc-vip-shop__grid">
|
|
<?php foreach ($items as $item) :
|
|
$pid = (int) ($item['package_id'] ?? 0);
|
|
$price_label = (string) ($item['price_label'] ?? ($cash_symbol . ($item['price'] ?? 0)));
|
|
$show_price_label = (string) ($item['show_price_label'] ?? '');
|
|
$discount_tag = (string) ($item['discount_tag'] ?? '');
|
|
$days_label = (string) ($item['days_label'] ?? '');
|
|
$title = (string) ($item['title'] ?? '');
|
|
$cta = (string) ($item['cta_label'] ?? __('立即开通', 'aksrt'));
|
|
?>
|
|
<button
|
|
type="button"
|
|
class="uc-vip-shop__item"
|
|
data-aksrt-vip-buy
|
|
data-package-id="<?php echo esc_attr((string) $pid); ?>"
|
|
data-price-label="<?php echo esc_attr($price_label); ?>"
|
|
data-title="<?php echo esc_attr($title); ?>"
|
|
data-action="<?php echo esc_attr((string) ($item['action'] ?? 'pay')); ?>"
|
|
>
|
|
<?php if ($discount_tag !== '') : ?>
|
|
<span class="uc-vip-shop__item-tag"><?php echo esc_html($discount_tag); ?></span>
|
|
<?php endif; ?>
|
|
<span class="uc-vip-shop__item-title"><?php echo esc_html($title); ?></span>
|
|
<span class="uc-vip-shop__item-days"><?php echo esc_html($days_label); ?></span>
|
|
<span class="uc-vip-shop__item-price">
|
|
<?php echo esc_html($price_label); ?>
|
|
<?php if ($show_price_label !== '') : ?>
|
|
<small class="uc-vip-shop__item-show"><?php echo esc_html($show_price_label); ?></small>
|
|
<?php endif; ?>
|
|
</span>
|
|
<span class="uc-vip-shop__item-cta"><?php echo esc_html($cta); ?></span>
|
|
</button>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if (count($methods) > 1) : ?>
|
|
<div class="uc-vip-shop__methods" data-aksrt-vip-methods>
|
|
<span class="uc-vip-shop__methods-label"><?php esc_html_e('支付方式', 'aksrt'); ?></span>
|
|
<?php foreach ($methods as $i => $m) :
|
|
$mid = (string) ($m['id'] ?? '');
|
|
$mname = (string) ($m['name'] ?? $mid);
|
|
?>
|
|
<label class="uc-vip-shop__method">
|
|
<input type="radio" name="aksrt_vip_pay_method" value="<?php echo esc_attr($mid); ?>" <?php checked($i === 0); ?>>
|
|
<span><?php echo esc_html($mname); ?></span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php elseif (!empty($methods[0]['id'])) : ?>
|
|
<input type="hidden" name="aksrt_vip_pay_method" value="<?php echo esc_attr((string) $methods[0]['id']); ?>" data-aksrt-vip-method-fixed>
|
|
<?php endif; ?>
|
|
|
|
<p class="uc-vip-shop__tip" data-aksrt-vip-tip></p>
|
|
</div>
|
|
<?php elseif (!empty($vip_settings['help_text'])) : ?>
|
|
<p class="uc-vip-shop__empty"><?php echo esc_html((string) $vip_settings['help_text']); ?></p>
|
|
<?php endif; ?>
|