手机号授权: 手机绑定授权调整
This commit is contained in:
@@ -17,4 +17,6 @@ public interface PhoneAuthApplyRecordService extends IService<PhoneAuthApplyReco
|
||||
void apply(String phone, String code, String phoneAreaCode);
|
||||
|
||||
void boundAuthCode(Long uid, String phone, String authCode, String phoneAreaCode, DeviceInfo deviceInfo);
|
||||
|
||||
Boolean isBoundPhoneAuthCode(String phone, String phoneAreaCode);
|
||||
}
|
@@ -12,6 +12,4 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface PhoneAuthRecordService extends IService<PhoneAuthRecord> {
|
||||
|
||||
|
||||
Boolean isBoundPhoneAuthCode(String phone);
|
||||
}
|
@@ -5,11 +5,11 @@ import com.accompany.business.model.phone.PhoneAuthRecord;
|
||||
import com.accompany.business.mybatismapper.PhoneAuthApplyRecordMapper;
|
||||
import com.accompany.business.service.phone.PhoneAuthApplyRecordService;
|
||||
import com.accompany.business.service.phone.PhoneAuthRecordService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.CommonUtil;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Account;
|
||||
@@ -125,6 +125,12 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
throw new ServiceException("該地區暫不開放使用");
|
||||
}
|
||||
|
||||
String realPhone = phoneAreaCode + phone;
|
||||
Account account = accountService.getAccountByPhone(phone);
|
||||
if (StringUtils.isNotBlank(account.getPhone()) && !realPhone.equals(account.getPhone())) {
|
||||
throw new ServiceException("當前手機已綁定其他用戶");
|
||||
}
|
||||
|
||||
PhoneAuthApplyRecord applyRecord = getAuthApplyRecordByPhone(phone);
|
||||
if (applyRecord == null) {
|
||||
throw new ServiceException("該地區暫不開放使用");
|
||||
@@ -138,21 +144,7 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
throw new ServiceException("授權碼錯誤");
|
||||
}
|
||||
|
||||
String realPhone = phoneAreaCode + phone;
|
||||
Account account = accountService.getAccountByPhone(phone);
|
||||
if (Constant.GlobalStatus.valid.equals(applyRecord.getHasUsed()) && StringUtils.isNotBlank(account.getPhone())
|
||||
&&!realPhone.equals(account.getPhone())) {
|
||||
throw new ServiceException("當前手機已綁定其他用戶");
|
||||
}
|
||||
|
||||
QueryWrapper <PhoneAuthRecord> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(PhoneAuthRecord::getPhone, phone).eq(PhoneAuthRecord::getStatus,Constant.GlobalStatus.valid);
|
||||
PhoneAuthRecord authRecord = phoneAuthRecordService.getOne(queryWrapper, false);
|
||||
if (authRecord != null && !Objects.equals(authRecord.getUid(), uid)) {
|
||||
throw new ServiceException("該手機已被其他用戶使用");
|
||||
}
|
||||
|
||||
QueryWrapper <PhoneAuthRecord> wrapper = new QueryWrapper<>();
|
||||
QueryWrapper<PhoneAuthRecord> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(PhoneAuthRecord::getDeviceId,deviceInfo.getDeviceId());
|
||||
int count = phoneAuthRecordService.count(wrapper);
|
||||
int max = Integer.parseInt(sysConfService.getDefaultSysConfValueById(Constant.SysConfId.divide_id_bound_phone_num, "5"));
|
||||
@@ -160,9 +152,20 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
throw new ServiceException("該設備綁定授權碼過多,無法綁定");
|
||||
}
|
||||
|
||||
// 更新使用狀態
|
||||
applyRecord.setHasUsed(Constant.GlobalStatus.valid);
|
||||
this.saveOrUpdate(applyRecord);
|
||||
// 修改之前的綁定狀態
|
||||
QueryWrapper<PhoneAuthRecord> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(PhoneAuthRecord::getPhone, phone).eq(PhoneAuthRecord::getStatus,Constant.GlobalStatus.valid);
|
||||
PhoneAuthRecord authRecord = phoneAuthRecordService.getOne(queryWrapper, false);
|
||||
if (authRecord != null && !Objects.equals(authRecord.getUid(), uid)) {
|
||||
authRecord.setStatus(Constant.GlobalStatus.in_valid);
|
||||
phoneAuthRecordService.saveOrUpdate(authRecord);
|
||||
}
|
||||
|
||||
// 更新使用邀請碼狀態
|
||||
if (!Constant.GlobalStatus.valid.equals(applyRecord.getHasUsed())) {
|
||||
applyRecord.setHasUsed(Constant.GlobalStatus.valid);
|
||||
this.saveOrUpdate(applyRecord);
|
||||
}
|
||||
// 保存用戶綁定記錄
|
||||
PhoneAuthRecord record = buildPhoneAuthRecord(uid,phone,applyRecord.getId(),phoneAreaCode,deviceInfo.getDeviceId());
|
||||
phoneAuthRecordService.saveOrUpdate(record);
|
||||
@@ -171,6 +174,31 @@ public class PhoneAuthApplyRecordServiceImpl extends ServiceImpl<PhoneAuthApplyR
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isBoundPhoneAuthCode(String phone, String phoneAreaCode) {
|
||||
if (StringUtils.isEmpty(phone) || StringUtils.isEmpty(phoneAreaCode)) {
|
||||
throw new ServiceException(BusiStatus.PHONEINVALID);
|
||||
}
|
||||
if ( !CommonUtil.checkPhoneFormat(phoneAreaCode,phone) ) {
|
||||
throw new ServiceException(BusiStatus.PHONEINVALID);
|
||||
}
|
||||
|
||||
if (!Constant.CHINA_MAINLAND_PHONE_AREA_CODE.equals(phoneAreaCode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QueryWrapper<PhoneAuthApplyRecord> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(PhoneAuthApplyRecord::getPhone, phone);
|
||||
PhoneAuthApplyRecord record = this.getOne(queryWrapper, false);
|
||||
if (record == null) {
|
||||
throw new ServiceException("該地區暫不開放使用");
|
||||
}
|
||||
if (Constant.GlobalStatus.in_valid.equals(record.getHasUsed())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private PhoneAuthRecord buildPhoneAuthRecord(Long uid, String phone, Long authId, String phoneAreaCode, String deviceId) {
|
||||
PhoneAuthRecord record = new PhoneAuthRecord();
|
||||
record.setAuthId(authId);
|
||||
|
@@ -19,10 +19,5 @@ import org.springframework.stereotype.Service;
|
||||
public class PhoneAuthRecordServiceImpl extends ServiceImpl<PhoneAuthRecordMapper, PhoneAuthRecord> implements PhoneAuthRecordService {
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean isBoundPhoneAuthCode(String phone) {
|
||||
QueryWrapper<PhoneAuthRecord> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(PhoneAuthRecord::getPhone, phone).eq(PhoneAuthRecord::getStatus,Constant.GlobalStatus.valid);
|
||||
return this.getOne(queryWrapper,false) != null;
|
||||
}
|
||||
|
||||
}
|
@@ -2,6 +2,7 @@ package com.accompany.business.controller.phone;
|
||||
|
||||
import com.accompany.business.common.BaseController;
|
||||
import com.accompany.business.service.phone.PhoneAuthApplyRecordService;
|
||||
import com.accompany.business.service.phone.PhoneAuthRecordService;
|
||||
import com.accompany.common.annotation.Authorization;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
@@ -9,6 +10,7 @@ import com.accompany.common.status.BusiStatus;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -57,4 +59,15 @@ public class PhoneAuthApplyRecordController extends BaseController {
|
||||
phoneAuthApplyRecordService.boundAuthCode(uid,phone,authCode,phoneAreaCode,deviceInfo);
|
||||
return new BusiResult(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
@ApiOperation("用戶綁定的手機號是否 輸入過對應的授權碼")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "phoneAreaCode", value = "区号", required = true, dataType = "String"),
|
||||
@ApiImplicitParam(name = "phone", value = "手机号 如: 178xxxxxxxx", required = true, dataType = "String"),
|
||||
})
|
||||
@GetMapping("/isBoundPhoneAuthCode")
|
||||
public BusiResult apply(String phone,String phoneAreaCode) {
|
||||
Boolean flag = phoneAuthApplyRecordService.isBoundPhoneAuthCode(phone,phoneAreaCode);
|
||||
return new BusiResult(BusiStatus.SUCCESS,flag);
|
||||
}
|
||||
}
|
@@ -25,18 +25,5 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/phone/auth/record")
|
||||
public class PhoneAuthRecordController extends BaseController {
|
||||
@Autowired
|
||||
private PhoneAuthRecordService phoneAuthRecordService;
|
||||
|
||||
@ApiOperation("手机号申请授权码操作")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "phoneAreaCode", value = "区号", required = true, dataType = "String"),
|
||||
@ApiImplicitParam(name = "phone", value = "区号 + 手机号 如: 86178xxxxxxxx", required = true, dataType = "String"),
|
||||
@ApiImplicitParam(name = "code", value = "验证码", required = true, dataType = "String"),
|
||||
})
|
||||
@GetMapping("/isBoundPhoneAuthCode")
|
||||
public BusiResult apply(String phone) {
|
||||
Boolean flag = phoneAuthRecordService.isBoundPhoneAuthCode(phone);
|
||||
return new BusiResult(BusiStatus.SUCCESS,flag);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user