From a923ef8dc2d45dcc3fd0c17f73f06572f4ccfd30 Mon Sep 17 00:00:00 2001 From: lzm <17817447469@163.com> Date: Thu, 24 Nov 2022 16:55:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=8E=88=E6=9D=83:?= =?UTF-8?q?=20=E6=89=8B=E6=9C=BA=E7=BB=91=E5=AE=9A=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../phone/PhoneAuthApplyRecordService.java | 2 + .../service/phone/PhoneAuthRecordService.java | 2 - .../impl/PhoneAuthApplyRecordServiceImpl.java | 66 +++++++++++++------ .../impl/PhoneAuthRecordServiceImpl.java | 7 +- .../phone/PhoneAuthApplyRecordController.java | 13 ++++ .../phone/PhoneAuthRecordController.java | 13 ---- 6 files changed, 63 insertions(+), 40 deletions(-) diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/PhoneAuthApplyRecordService.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/PhoneAuthApplyRecordService.java index 1aa658bf4..622a2f64c 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/PhoneAuthApplyRecordService.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/PhoneAuthApplyRecordService.java @@ -17,4 +17,6 @@ public interface PhoneAuthApplyRecordService extends IService { - - Boolean isBoundPhoneAuthCode(String phone); } \ No newline at end of file diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthApplyRecordServiceImpl.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthApplyRecordServiceImpl.java index eb649d667..6cec8aef4 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthApplyRecordServiceImpl.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthApplyRecordServiceImpl.java @@ -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 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 wrapper = new QueryWrapper<>(); + QueryWrapper 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 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 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); diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthRecordServiceImpl.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthRecordServiceImpl.java index 6c0e3aa2b..2b2dbaf7f 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthRecordServiceImpl.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/phone/impl/PhoneAuthRecordServiceImpl.java @@ -19,10 +19,5 @@ import org.springframework.stereotype.Service; public class PhoneAuthRecordServiceImpl extends ServiceImpl implements PhoneAuthRecordService { - @Override - public Boolean isBoundPhoneAuthCode(String phone) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().eq(PhoneAuthRecord::getPhone, phone).eq(PhoneAuthRecord::getStatus,Constant.GlobalStatus.valid); - return this.getOne(queryWrapper,false) != null; - } + } \ No newline at end of file diff --git a/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthApplyRecordController.java b/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthApplyRecordController.java index 32cecb431..bf495b460 100644 --- a/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthApplyRecordController.java +++ b/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthApplyRecordController.java @@ -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); + } } \ No newline at end of file diff --git a/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthRecordController.java b/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthRecordController.java index f7cff7367..9ed0404e0 100644 --- a/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthRecordController.java +++ b/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/phone/PhoneAuthRecordController.java @@ -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); - } } \ No newline at end of file