fix(vip): allow points renewal for existing members

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 16:40:27 +08:00
co-authored by Claude Fable 5
parent df858d04dc
commit ba5638a892
2 changed files with 24 additions and 9 deletions
@@ -145,10 +145,10 @@ foreach ([1, 2] as $lv) {
$cards .= '</div></div>';
}
// Points exchange entry (non-VIP only).
// Points exchange entry (available for guests, ordinary users, and VIP renewals/upgrades).
$points_html = '';
$points_pkgs = is_array($points_exchange['packages'] ?? null) ? $points_exchange['packages'] : [];
if ($level <= 0 && !empty($points_exchange['enabled']) && $points_pkgs !== []) {
if (!empty($points_exchange['enabled']) && $points_pkgs !== []) {
$points_html = '<div class="uc-vip-points-link" data-aksrt-vip-points-modal>'
. '<div class="uc-vip-points-link__icon" aria-hidden="true"><i class="fas fa-coins"></i></div>'
. '<div class="uc-vip-points-link__body">'
+22 -7
View File
@@ -215,8 +215,17 @@ trait VipServicePurchase {
}
$points_packages = [];
if ($points_enabled && $level <= 0) {
if ($points_enabled) {
$points_packages = $this->get_points_exchange_packages($vip, $levels);
if ($level > 0) {
$points_packages = array_values(array_filter(
$points_packages,
static function (array $package) use ($level, $is_permanent): bool {
$target_level = (int) ($package['level'] ?? 0);
return $target_level > $level || (!$is_permanent && $target_level === $level);
}
));
}
}
$points_balance = ($user_id > 0 && class_exists('\AKSRT\Credits\Credits'))
@@ -246,7 +255,7 @@ trait VipServicePurchase {
'upgrade_desc' => (string) ($upgrade['desc'] ?? ''),
'level_packages' => $level_packages,
'points_exchange' => [
'enabled' => $points_enabled && $level <= 0,
'enabled' => $points_enabled,
'desc' => (string) ($points_ex['desc'] ?? ''),
'packages' => $points_packages,
],
@@ -616,7 +625,8 @@ trait VipServicePurchase {
/**
* Points exchange (non-VIP only, zibll pay_vip_points_exchange).
* Points exchange. Ordinary users can open a VIP; existing VIP users can
* renew the same level or upgrade to a higher level with the exchanged term.
*
* @return array|\WP_Error
*/
@@ -636,10 +646,6 @@ trait VipServicePurchase {
return new \WP_Error('aksrt_points_exchange_disabled', __('积分兑换会员未启用', 'aksrt'), ['status' => 400]);
}
if ((int) ($catalog['user_level'] ?? 0) > 0) {
return new \WP_Error('aksrt_already_vip', __('您已是会员,无法使用积分兑换。', 'aksrt'), ['status' => 400]);
}
$match = null;
$packages = is_array($points_ex['packages'] ?? null) ? $points_ex['packages'] : [];
foreach ($packages as $pkg) {
@@ -652,6 +658,15 @@ trait VipServicePurchase {
return new \WP_Error('aksrt_invalid_package', __('兑换套餐不存在', 'aksrt'), ['status' => 400]);
}
if ((int) ($catalog['user_level'] ?? 0) > 0) {
$current_level = (int) ($catalog['user_level'] ?? 0);
$target_level = (int) ($match['level'] ?? 0);
$is_permanent = !empty($catalog['user_is_permanent']);
if ($target_level < $current_level || ($target_level === $current_level && $is_permanent)) {
return new \WP_Error('aksrt_vip_package_unavailable', __('当前会员状态无法兑换该套餐。', 'aksrt'), ['status' => 400]);
}
}
$cost = (int) ($match['points'] ?? 0);
$level = (int) ($match['level'] ?? 1);
$days = (int) ($match['days'] ?? 0);