mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2025-12-12 09:57:20 +00:00
Update RegisterService.php
This commit is contained in:
parent
7eae3e6696
commit
8cd76874c5
@ -39,35 +39,41 @@ class RegisterService extends BaseApiService
|
||||
* 会员公共注册
|
||||
* @param $data
|
||||
*/
|
||||
public function register(string|int $mobile, $data, string $type, bool $is_verify_mobile = true)
|
||||
public function register(string $mobile, $data, string $type, bool $is_verify_mobile = true)
|
||||
{
|
||||
//校验注册方式
|
||||
if(empty(MemberRegisterTypeDict::getType()[$type]))
|
||||
if (empty(MemberRegisterTypeDict::getType()[ $type ]))
|
||||
throw new AuthException('REG_CHANNEL_NOT_EXIST');
|
||||
$data = $this->bindByMobile($mobile, $data, $type, $is_verify_mobile);
|
||||
$member_service = new MemberService();
|
||||
if(!is_array($data)){
|
||||
if (!is_array($data)) {
|
||||
$member_id = $data;
|
||||
} else{
|
||||
if(empty($data['nickname'])){
|
||||
$data['nickname'] = $data['username'] ?? !empty($mobile) ? substr_replace($mobile, '****', 3, 4) : $this->createName();
|
||||
} else {
|
||||
if (empty($data[ 'nickname' ])) {
|
||||
if (!empty($data[ 'username' ])) {
|
||||
$data[ 'nickname' ] = $data[ 'username' ];
|
||||
} elseif (!empty($mobile)) {
|
||||
$data[ 'nickname' ] = substr_replace($mobile, '****', 3, 4);
|
||||
} else {
|
||||
$data[ 'nickname' ] = $this->createName();
|
||||
}
|
||||
$data['register_channel'] = $this->channel;
|
||||
$data['register_type'] = $type;
|
||||
$data['site_id'] = $this->site_id;
|
||||
}
|
||||
$data[ 'register_channel' ] = $this->channel;
|
||||
$data[ 'register_type' ] = $type;
|
||||
$data[ 'site_id' ] = $this->site_id;
|
||||
$pid = $this->request->get('pid');
|
||||
if($pid > 0){
|
||||
$p_member_info = $member_service->findMemberInfo(['member_id' => $pid, 'site_id' => $this->site_id]);
|
||||
if(!$p_member_info->isEmpty()) $data['pid'] = $pid;//设置上级推荐人
|
||||
if ($pid > 0) {
|
||||
$p_member_info = $member_service->findMemberInfo([ 'member_id' => $pid, 'site_id' => $this->site_id ]);
|
||||
if (!$p_member_info->isEmpty()) $data[ 'pid' ] = $pid;//设置上级推荐人
|
||||
}
|
||||
$member_id = (new MemberService())->add($data);
|
||||
$data['member_id'] = $member_id;
|
||||
$member_id = ( new MemberService() )->add($data);
|
||||
$data[ 'member_id' ] = $member_id;
|
||||
event('memberRegister', $data);
|
||||
CoreMemberService::setMemberNo($this->site_id, $member_id);
|
||||
}
|
||||
$member_info = $member_service->findMemberInfo(['member_id' => $member_id, 'site_id' => $this->site_id]);
|
||||
$member_info = $member_service->findMemberInfo([ 'member_id' => $member_id, 'site_id' => $this->site_id ]);
|
||||
if ($member_info->isEmpty()) throw new AuthException('MEMBER_NOT_EXIST');//账号已存在
|
||||
$result = (new LoginService())->login($member_info, $type);
|
||||
$result = ( new LoginService() )->login($member_info, $type);
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -81,12 +87,13 @@ class RegisterService extends BaseApiService
|
||||
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$username = '';
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$username .= $chars[mt_rand(0, strlen($chars))];
|
||||
$username .= $chars[ mt_rand(0, strlen($chars)) ];
|
||||
}
|
||||
|
||||
return $microtime . strtoupper(base_convert(time() - 1420070400, 10, 36)) . $username;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号注册
|
||||
* @param string $username
|
||||
@ -115,40 +122,44 @@ class RegisterService extends BaseApiService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 手机号注册
|
||||
* @param $mobile
|
||||
* @return Member|array|mixed|\think\Model
|
||||
*/
|
||||
public function mobile($mobile){
|
||||
public
|
||||
function mobile($mobile)
|
||||
{
|
||||
//登录注册配置
|
||||
$config = (new MemberConfigService())->getLoginConfig();
|
||||
$is_mobile = $config['is_mobile'];
|
||||
$config = ( new MemberConfigService() )->getLoginConfig();
|
||||
$is_mobile = $config[ 'is_mobile' ];
|
||||
//未开启账号密码登录注册
|
||||
if($is_mobile != 1) throw new AuthException('MEMBER_USERNAME_LOGIN_NOT_OPEN');
|
||||
if ($is_mobile != 1) throw new AuthException('MEMBER_USERNAME_LOGIN_NOT_OPEN');
|
||||
$member_service = new MemberService();
|
||||
$member_info = $member_service->findMemberInfo(['mobile' => $mobile, 'site_id' => $this->site_id]);
|
||||
$member_info = $member_service->findMemberInfo([ 'mobile' => $mobile, 'site_id' => $this->site_id ]);
|
||||
if (!$member_info->isEmpty()) throw new AuthException('MEMBER_IS_EXIST');//账号已存在
|
||||
|
||||
$data = array(
|
||||
$data = array (
|
||||
'mobile' => $mobile,
|
||||
);
|
||||
$result = $this->register($mobile, $data, MemberRegisterTypeDict::MOBILE);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 校验是否启用第三方登录注册
|
||||
* @return true
|
||||
*/
|
||||
public function checkAuth(){
|
||||
$config = (new MemberConfigService())->getLoginConfig();
|
||||
$is_auth_register = $config['is_auth_register'];
|
||||
if($is_auth_register != 1) throw new AuthException('AUTH_LOGIN_NOT_OPEN');//手机号已存在
|
||||
public
|
||||
function checkAuth()
|
||||
{
|
||||
$config = ( new MemberConfigService() )->getLoginConfig();
|
||||
$is_auth_register = $config[ 'is_auth_register' ];
|
||||
if ($is_auth_register != 1) throw new AuthException('AUTH_LOGIN_NOT_OPEN');//手机号已存在
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 通过手机号尝试绑定已存在会员,没有就绑定数据(todo 仅限注册使用)
|
||||
* @param string|int $mobile
|
||||
* @param array $data
|
||||
@ -156,9 +167,10 @@ class RegisterService extends BaseApiService
|
||||
* @param bool $is_verify
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function bindByMobile(string|int $mobile, array $data, string $type, bool $is_verify = true){
|
||||
$config = (new MemberConfigService())->getLoginConfig();
|
||||
$is_bind_mobile = $config['is_bind_mobile'];
|
||||
public
|
||||
function bindByMobile(string|int $mobile, array $data, string $type, bool $is_verify = true){
|
||||
$config = ( new MemberConfigService() )->getLoginConfig();
|
||||
$is_bind_mobile = $config[ 'is_bind_mobile' ];
|
||||
|
||||
$with_field = match($type){
|
||||
MemberLoginTypeDict::USERNAME => 'username',
|
||||
@ -166,21 +178,21 @@ class RegisterService extends BaseApiService
|
||||
MemberLoginTypeDict::WECHAT => 'wx_openid',
|
||||
MemberLoginTypeDict::WEAPP => 'weapp_openid',
|
||||
};
|
||||
if($type == MemberLoginTypeDict::MOBILE || $is_bind_mobile == 1){
|
||||
if(empty($mobile)) throw new AuthException('MOBILE_NEEDED');//必须填写
|
||||
if ($type == MemberLoginTypeDict::MOBILE || $is_bind_mobile == 1) {
|
||||
if (empty($mobile)) throw new AuthException('MOBILE_NEEDED');//必须填写
|
||||
//todo 校验手机号验证码
|
||||
if($is_verify){
|
||||
(new LoginService())->checkMobileCode($mobile);
|
||||
if ($is_verify) {
|
||||
( new LoginService() )->checkMobileCode($mobile);
|
||||
}
|
||||
if($is_bind_mobile == 1){
|
||||
if ($is_bind_mobile == 1) {
|
||||
$member_service = new MemberService();
|
||||
$member = $member_service->findMemberInfo(['mobile' => $mobile, 'site_id' => $this->site_id]);
|
||||
if(!$member->isEmpty()){
|
||||
if($type == MemberLoginTypeDict::MOBILE){
|
||||
$member = $member_service->findMemberInfo([ 'mobile' => $mobile, 'site_id' => $this->site_id ]);
|
||||
if (!$member->isEmpty()) {
|
||||
if ($type == MemberLoginTypeDict::MOBILE) {
|
||||
throw new AuthException('MOBILE_IS_EXIST');//手机号注册时发现手机号已存在账号
|
||||
} else{
|
||||
if($member->$with_field != '') throw new AuthException('MOBILE_IS_EXIST');//手机号已存在
|
||||
foreach($data as $k => $v){
|
||||
} else {
|
||||
if ($member->$with_field != '') throw new AuthException('MOBILE_IS_EXIST');//手机号已存在
|
||||
foreach ($data as $k => $v) {
|
||||
$member->$k = $v;
|
||||
}
|
||||
$member->save();
|
||||
@ -188,7 +200,7 @@ class RegisterService extends BaseApiService
|
||||
}
|
||||
}
|
||||
}
|
||||
$data['mobile'] = $mobile;
|
||||
$data[ 'mobile' ] = $mobile;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user