feat(vip): implement layered membership expiry flow
This commit is contained in:
@@ -27,7 +27,7 @@ trait VipServiceMembership {
|
||||
if ($user_id <= 0 || !get_userdata($user_id)) {
|
||||
return new \WP_Error('aksrt_vip_user_missing', __('用户不存在。', 'aksrt'));
|
||||
}
|
||||
if (!in_array($operation, ['set', 'extend', 'disable'], true)) {
|
||||
if (!in_array($operation, ['set', 'extend', 'disable', 'restore'], true)) {
|
||||
return new \WP_Error('aksrt_vip_operation_invalid', __('会员操作无效。', 'aksrt'));
|
||||
}
|
||||
$reason = sanitize_text_field((string) ($context['reason'] ?? ''));
|
||||
@@ -97,6 +97,14 @@ trait VipServiceMembership {
|
||||
|
||||
/** @param array<string,mixed> $before @param array<string,mixed> $payload @return array{level:int,expires:int}|\WP_Error */
|
||||
private function membership_target(array $before, string $operation, array $payload): array|\WP_Error {
|
||||
if ($operation === 'restore') {
|
||||
$level = max(0, min(2, (int) $before['base_level']));
|
||||
$expires = max(0, (int) $before['base_expires']);
|
||||
if ($level <= 0 || ($expires > 0 && $expires <= time())) {
|
||||
return new \WP_Error('aksrt_vip_restore_unavailable', __('没有有效的回退会员可恢复。', 'aksrt'));
|
||||
}
|
||||
return ['level' => $level, 'expires' => $expires];
|
||||
}
|
||||
if ($operation === 'disable') {
|
||||
return ['level' => 0, 'expires' => 0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user