feat: unify invite flow with referral ref
This commit is contained in:
@@ -233,7 +233,7 @@ trait ServicePart1b {
|
||||
/**
|
||||
* 手机号注册
|
||||
*
|
||||
* @param array $post POST 数据 (phone, code, password, invite_code)
|
||||
* @param array $post POST 数据 (phone, code, password, ref)
|
||||
* @return array{success: bool, user_id?: int, error?: string, redirect?: string}
|
||||
*/
|
||||
public static function register_by_phone(array $post): array {
|
||||
@@ -283,9 +283,44 @@ trait ServicePart1b {
|
||||
$suffix++;
|
||||
}
|
||||
|
||||
$ref_service = class_exists('\AKSRT\Payment\ReferralAttribution')
|
||||
? \AKSRT\Payment\ReferralAttribution::get_instance()
|
||||
: null;
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
$registration = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_referral_registration_settings()
|
||||
: ['enabled' => false, 'register_field' => 'hidden', 'reject_invalid' => true];
|
||||
$submitted_ref = sanitize_key((string) ($post['ref'] ?? ''));
|
||||
$field_mode = !empty($registration['enabled'])
|
||||
? (string) ($registration['register_field'] ?? 'hidden')
|
||||
: 'hidden';
|
||||
$accept_submitted = !empty($registration['enabled']) && $field_mode !== 'hidden';
|
||||
$ref_context = $ref_service
|
||||
? $ref_service->prepare_registration($accept_submitted ? $submitted_ref : '')
|
||||
: ['valid' => false, 'submitted_valid' => false, 'conflict' => false, 'source' => 'none'];
|
||||
if ($field_mode === 'required' && empty($ref_context['valid'])) {
|
||||
if ($submitted_ref === '') {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('请填写推广码', 'aksrt')];
|
||||
}
|
||||
if (!empty($registration['reject_invalid'])) {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => __('推广码无效,请检查后重试', 'aksrt')];
|
||||
}
|
||||
}
|
||||
|
||||
// 创建用户
|
||||
$user_id = wp_create_user($username, $pass, $phone . '@sms.aksrt.local');
|
||||
if (is_wp_error($user_id)) {
|
||||
if ($ref_service) {
|
||||
$ref_service->clear_registration_context();
|
||||
}
|
||||
return ['success' => false, 'error' => $user_id->get_error_message()];
|
||||
}
|
||||
|
||||
@@ -296,10 +331,8 @@ trait ServicePart1b {
|
||||
// 邮箱标记为已验证(手机注册等同于已验证)
|
||||
update_user_meta($user_id, 'aksrt_email_verified', '1');
|
||||
|
||||
// 处理邀请码
|
||||
$invite_code = sanitize_key((string) ($post['invite_code'] ?? ''));
|
||||
if ($invite_code !== '' && class_exists('\AKSRT\Credits\Invite')) {
|
||||
\AKSRT\Credits\Invite::get_instance()->handle_registration_invite($user_id, $invite_code);
|
||||
if ($ref_service) {
|
||||
$ref_service->reward_registered_user((int) $user_id);
|
||||
}
|
||||
|
||||
// 自动登录
|
||||
@@ -315,6 +348,7 @@ trait ServicePart1b {
|
||||
'user_id' => $user_id,
|
||||
'redirect' => $redirect,
|
||||
'message' => __('注册成功', 'aksrt'),
|
||||
'notice' => $ref_service ? $ref_service->take_registration_notice() : '',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user