|
@@ -1,9 +1,16 @@
|
|
package com.caimei365.user.service.impl;
|
|
package com.caimei365.user.service.impl;
|
|
|
|
|
|
|
|
+import com.caimei365.user.components.CommonService;
|
|
import com.caimei365.user.mapper.BaseMapper;
|
|
import com.caimei365.user.mapper.BaseMapper;
|
|
|
|
+import com.caimei365.user.mapper.LoginMapper;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.components.RedisService;
|
|
import com.caimei365.user.components.RedisService;
|
|
|
|
+import com.caimei365.user.model.dto.MobileDto;
|
|
import com.caimei365.user.model.dto.PasswordDto;
|
|
import com.caimei365.user.model.dto.PasswordDto;
|
|
|
|
+import com.caimei365.user.model.po.ShopPo;
|
|
|
|
+import com.caimei365.user.model.vo.ShopVo;
|
|
|
|
+import com.caimei365.user.model.vo.UserLoginVo;
|
|
|
|
+import com.caimei365.user.model.vo.UserVo;
|
|
import com.caimei365.user.service.BaseService;
|
|
import com.caimei365.user.service.BaseService;
|
|
import com.caimei365.user.utils.*;
|
|
import com.caimei365.user.utils.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -25,11 +32,14 @@ import java.util.Map;
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class BaseServiceImpl implements BaseService {
|
|
public class BaseServiceImpl implements BaseService {
|
|
-
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private CommonService commonService;
|
|
@Resource
|
|
@Resource
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
@Resource
|
|
@Resource
|
|
private BaseMapper baseMapper;
|
|
private BaseMapper baseMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private LoginMapper loginMapper;
|
|
@Value("${spring.cloud.config.profile}")
|
|
@Value("${spring.cloud.config.profile}")
|
|
private String profile;
|
|
private String profile;
|
|
|
|
|
|
@@ -94,7 +104,7 @@ public class BaseServiceImpl implements BaseService {
|
|
* 获取短信验证码
|
|
* 获取短信验证码
|
|
*
|
|
*
|
|
* @param mobile 手机号
|
|
* @param mobile 手机号
|
|
- * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册
|
|
|
|
|
|
+ * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码
|
|
* @param platformType 0:www,1:crm/h5,2:小程序
|
|
* @param platformType 0:www,1:crm/h5,2:小程序
|
|
* @param isCheckCaptcha 是否检查图片验证码,0:检查,1:不检查
|
|
* @param isCheckCaptcha 是否检查图片验证码,0:检查,1:不检查
|
|
* @param imgCode 图片验证码
|
|
* @param imgCode 图片验证码
|
|
@@ -119,6 +129,7 @@ public class BaseServiceImpl implements BaseService {
|
|
// 开发 和 测试环境 固定短信验证码 666666
|
|
// 开发 和 测试环境 固定短信验证码 666666
|
|
randomCode = "666666";
|
|
randomCode = "666666";
|
|
}
|
|
}
|
|
|
|
+ String codeTypeTxt = "";
|
|
// 根据手机号查询用户Id
|
|
// 根据手机号查询用户Id
|
|
Integer userId = baseMapper.getUserIdByMobile(mobile);
|
|
Integer userId = baseMapper.getUserIdByMobile(mobile);
|
|
if (1 == activateCodeType) {
|
|
if (1 == activateCodeType) {
|
|
@@ -127,25 +138,41 @@ public class BaseServiceImpl implements BaseService {
|
|
}
|
|
}
|
|
// 找回密码
|
|
// 找回密码
|
|
sendFlag = AliyunSmsUtil.sendSms(mobile, 1, "{code:" + randomCode + "}");
|
|
sendFlag = AliyunSmsUtil.sendSms(mobile, 1, "{code:" + randomCode + "}");
|
|
- } else {
|
|
|
|
|
|
+ codeTypeTxt = "找回密码";
|
|
|
|
+ } else if (2 == activateCodeType || 3 == activateCodeType){
|
|
if (null != userId && userId > 0) {
|
|
if (null != userId && userId > 0) {
|
|
return ResponseJson.error("该手机号已被使用");
|
|
return ResponseJson.error("该手机号已被使用");
|
|
}
|
|
}
|
|
if (2 == activateCodeType) {
|
|
if (2 == activateCodeType) {
|
|
// 机构用户(自主)注册
|
|
// 机构用户(自主)注册
|
|
sendFlag = AliyunSmsUtil.sendSms(mobile, 8, "{code:"+ randomCode +"}");
|
|
sendFlag = AliyunSmsUtil.sendSms(mobile, 8, "{code:"+ randomCode +"}");
|
|
|
|
+ codeTypeTxt = "机构(自主)注册";
|
|
} else if (3 == activateCodeType) {
|
|
} else if (3 == activateCodeType) {
|
|
// 供应商(自主)注册
|
|
// 供应商(自主)注册
|
|
sendFlag = AliyunSmsUtil.sendSms(mobile, 9, "{code:"+ randomCode +"}");
|
|
sendFlag = AliyunSmsUtil.sendSms(mobile, 9, "{code:"+ randomCode +"}");
|
|
|
|
+ codeTypeTxt = "供应商(自主)注册";
|
|
} else {
|
|
} else {
|
|
return ResponseJson.error("参数错误:activateCodeType");
|
|
return ResponseJson.error("参数错误:activateCodeType");
|
|
}
|
|
}
|
|
|
|
+ } else if (4 == activateCodeType) {
|
|
|
|
+ // 您正在更换联系人手机号,您的验证码为:${code}。
|
|
|
|
+ sendFlag = AliyunSmsUtil.sendSms(mobile, 13, "{code:"+ randomCode +"}");
|
|
|
|
+ codeTypeTxt = "更换联系人(旧手机号验证码)";
|
|
|
|
+ } else if (5 == activateCodeType) {
|
|
|
|
+ if (null != userId && userId > 0) {
|
|
|
|
+ return ResponseJson.error("该手机号已被使用");
|
|
|
|
+ }
|
|
|
|
+ // 您正在更换联系人手机号,您的验证码为:${code}。
|
|
|
|
+ sendFlag = AliyunSmsUtil.sendSms(mobile, 13, "{code:"+ randomCode +"}");
|
|
|
|
+ codeTypeTxt = "更换联系人(新手机号验证码)";
|
|
|
|
+ } else {
|
|
|
|
+ return ResponseJson.error("参数错误:activateCodeType");
|
|
}
|
|
}
|
|
if (sendFlag) {
|
|
if (sendFlag) {
|
|
redisService.set("code:"+mobile, randomCode, 1800L);
|
|
redisService.set("code:"+mobile, randomCode, 1800L);
|
|
- String codeType = activateCodeType == 1 ? "找回密码" : (activateCodeType == 2 ? "注册机构" : "注册供应商");
|
|
|
|
- log.info(codeType + ",发送到:" + mobile + "的短信验证码为: " + randomCode);
|
|
|
|
|
|
+ log.info(codeTypeTxt + ",发送到:" + mobile + "的短信验证码为: " + randomCode);
|
|
} else {
|
|
} else {
|
|
|
|
+ log.info(codeTypeTxt + ",验证码发送失败!");
|
|
return ResponseJson.error("验证码发送失败!请稍后重试");
|
|
return ResponseJson.error("验证码发送失败!请稍后重试");
|
|
}
|
|
}
|
|
return ResponseJson.success("发送验证码成功");
|
|
return ResponseJson.success("发送验证码成功");
|
|
@@ -335,4 +362,63 @@ public class BaseServiceImpl implements BaseService {
|
|
return ResponseJson.success("密码修改成功", "");
|
|
return ResponseJson.success("密码修改成功", "");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 更换手机号
|
|
|
|
+ *
|
|
|
|
+ * @param mobileDto {
|
|
|
|
+ * mobile 旧手机号(contractMobile)
|
|
|
|
+ * smsCode 旧手机短信验证码(mobileCode)
|
|
|
|
+ * newMobile 新手机号(contractMobile2)
|
|
|
|
+ * newSmsCode 新手机短信验证码(mobileCode)
|
|
|
|
+ * userId 用户Id
|
|
|
|
+ * }
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson updateMobile(MobileDto mobileDto) {
|
|
|
|
+ // 参数校验
|
|
|
|
+ if (StringUtils.isBlank(mobileDto.getMobile())) {
|
|
|
|
+ return ResponseJson.error("参数异常:旧手机号不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(mobileDto.getNewMobile())) {
|
|
|
|
+ return ResponseJson.error("参数异常:新手机号不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(mobileDto.getSmsCode())) {
|
|
|
|
+ return ResponseJson.error("参数异常:旧手机号验证码不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(mobileDto.getNewSmsCode())) {
|
|
|
|
+ return ResponseJson.error("参数异常:新手机号验证码不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if (null == mobileDto.getUserId()) {
|
|
|
|
+ return ResponseJson.error("参数异常:用户Id不能为空!");
|
|
|
|
+ }
|
|
|
|
+ // 旧手机号与验证码校验
|
|
|
|
+ String result = ValidateUtil.validateMobile(mobileDto.getMobile());
|
|
|
|
+ if (result != null) {return ResponseJson.error(result);}
|
|
|
|
+ String smsCode = (String) redisService.get("code:" + mobileDto.getMobile());
|
|
|
|
+ // 开发 和 测试环境 固定短信验证码 666666
|
|
|
|
+ if ("dev".equals(profile) || "beta".equals(profile)){
|
|
|
|
+ smsCode = (null != smsCode && !"null".equals(smsCode) ? smsCode : "666666");
|
|
|
|
+ }
|
|
|
|
+ if (!mobileDto.getSmsCode().equals(smsCode)) {
|
|
|
|
+ return ResponseJson.error("旧手机验证码错误");
|
|
|
|
+ }
|
|
|
|
+ UserLoginVo user = loginMapper.getLoginUserByUserId(mobileDto.getUserId());
|
|
|
|
+ if (null == user) {
|
|
|
|
+ return ResponseJson.error("账户异常");
|
|
|
|
+ }
|
|
|
|
+ //验证新手机号是否可用
|
|
|
|
+ result = commonService.mobileAndCodeValidate(mobileDto.getNewMobile(), mobileDto.getNewSmsCode());
|
|
|
|
+ if (result != null) {return ResponseJson.error(result);}
|
|
|
|
+ // 更新user表手机号
|
|
|
|
+ baseMapper.updateMobileByUserId(mobileDto.getNewMobile(), mobileDto.getUserId());
|
|
|
|
+ if (user.getUserIdentity() == 3) {
|
|
|
|
+ //供应商修改手机号
|
|
|
|
+ baseMapper.updateShopMobileByShopId(mobileDto.getNewMobile(), user.getShopId());
|
|
|
|
+ } else {
|
|
|
|
+ //供应商修改手机号
|
|
|
|
+ baseMapper.updateClubMobileByClubId(mobileDto.getNewMobile(), user.getClubId());
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|