|
@@ -2,16 +2,20 @@ package com.cyksj.service.market.task.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
|
|
+import com.cyksj.enums.GatewayApiCode;
|
|
|
import com.cyksj.mapper.PhoneCodeMapper;
|
|
import com.cyksj.mapper.PhoneCodeMapper;
|
|
|
|
|
+import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskTypeMapper;
|
|
import com.cyksj.mapper.market.task.TaskTypeMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.model.entity.PhoneCode;
|
|
import com.cyksj.model.entity.PhoneCode;
|
|
|
import com.cyksj.model.entity.TaskType;
|
|
import com.cyksj.model.entity.TaskType;
|
|
|
|
|
+import com.cyksj.model.entity.User;
|
|
|
import com.cyksj.model.entity.UserBindDetail;
|
|
import com.cyksj.model.entity.UserBindDetail;
|
|
|
import com.cyksj.model.request.UserBindInfoReq;
|
|
import com.cyksj.model.request.UserBindInfoReq;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
@@ -43,9 +47,11 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
|
|
|
|
|
private final PhoneCodeMapper phoneCodeMapper;
|
|
private final PhoneCodeMapper phoneCodeMapper;
|
|
|
|
|
|
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void bindPhone(Long userId, String phone, String code, Boolean isCode) {
|
|
|
|
|
|
|
+ public void bindPhone(Long userId, String phone, String code, Boolean isCheckCode) {
|
|
|
UserBindDetail other = UserBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
UserBindDetail other = UserBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
.eq(UserBindDetail::getPhone, phone).ne(UserBindDetail::getUserId, userId).select(UserBindDetail::getId).last("limit 1"));
|
|
.eq(UserBindDetail::getPhone, phone).ne(UserBindDetail::getUserId, userId).select(UserBindDetail::getId).last("limit 1"));
|
|
|
if (other != null) {
|
|
if (other != null) {
|
|
@@ -56,9 +62,9 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
if (StrUtil.isNotBlank(bindPhone.getPhone())) {
|
|
if (StrUtil.isNotBlank(bindPhone.getPhone())) {
|
|
|
throw BusinessRuntimeException.getInstance("您已绑定手机号");
|
|
throw BusinessRuntimeException.getInstance("您已绑定手机号");
|
|
|
}
|
|
}
|
|
|
- if (isCode) {
|
|
|
|
|
|
|
+ if (isCheckCode) {
|
|
|
//校验
|
|
//校验
|
|
|
- phoneCodeService.checkPhone(phone, code);
|
|
|
|
|
|
|
+ checkPhoneCode(phone, code);
|
|
|
}
|
|
}
|
|
|
bindPhone.setUserId(userId);
|
|
bindPhone.setUserId(userId);
|
|
|
bindPhone.setPhone(phone);
|
|
bindPhone.setPhone(phone);
|
|
@@ -106,13 +112,7 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
if (other != null) {
|
|
if (other != null) {
|
|
|
throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
|
|
throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
|
|
|
}
|
|
}
|
|
|
- String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(email));
|
|
|
|
|
- if (StrUtil.isEmpty(code)) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
|
|
|
|
|
- }
|
|
|
|
|
- if (!StrUtil.equals(inputCode, code)) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ checkEmailCode(email, inputCode);
|
|
|
bindPhone.setEmail(email);
|
|
bindPhone.setEmail(email);
|
|
|
UserBindDetailMapper.updateById(bindPhone);
|
|
UserBindDetailMapper.updateById(bindPhone);
|
|
|
}
|
|
}
|
|
@@ -153,6 +153,28 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(account));
|
|
redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(account));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void bindOtherAccount(UserBindInfoReq request) {
|
|
|
|
|
+ Long userId = request.getUserId();
|
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
|
|
+ if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
|
|
+ String account = request.getAccount();
|
|
|
|
|
+ String code = request.getCode();
|
|
|
|
|
+ if (Validator.isMobile(account)) {
|
|
|
|
|
+ if (StrUtil.isNotBlank(user.getLoginPhone())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您通过手机号登录,无法绑定手机号");
|
|
|
|
|
+ }
|
|
|
|
|
+ bindPhone(userId, account, code, true);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Validator.isEmail(account)) {
|
|
|
|
|
+ if (StrUtil.isNotBlank(user.getEmail())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您通过邮箱登录,无法绑定邮箱");
|
|
|
|
|
+ }
|
|
|
|
|
+ bindEmail(userId, account, code);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void updateBindAccount(UserBindInfoReq request) {
|
|
public void updateBindAccount(UserBindInfoReq request) {
|
|
|
Long userId = request.getUserId();
|
|
Long userId = request.getUserId();
|
|
@@ -162,6 +184,9 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
updateBindPhone(userId, account, code);
|
|
updateBindPhone(userId, account, code);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (Validator.isEmail(account)) {
|
|
|
|
|
+ updateBindEmail(userId, account, code);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|