فهرست منبع

修改联系人

chao 4 سال پیش
والد
کامیت
92e15c5b5b

+ 21 - 4
src/main/java/com/caimei365/user/controller/BaseApi.java

@@ -1,9 +1,9 @@
 package com.caimei365.user.controller;
 
 import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.dto.MobileDto;
 import com.caimei365.user.model.dto.PasswordDto;
 import com.caimei365.user.service.BaseService;
-import com.caimei365.user.utils.ValidateUtil;
 import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Value;
@@ -55,7 +55,7 @@ public class BaseApi {
      * spi旧接口:/user/activateCodeByReg
      *
      * @param mobile           手机号
-     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册
+     * @param activateCodeType 1:找回密码,2:注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码
      * @param platformType     0:www,1:crm/h5,2:小程序
      * @param isCheckCaptcha   是否检查图片验证码,0:检查,1:不检查
      * @param imgCode          图片验证码
@@ -64,7 +64,7 @@ public class BaseApi {
     @ApiOperation("获取短信验证码")
     @ApiImplicitParams({
         @ApiImplicitParam(required = true, name = "mobile", value = "手机号"),
-        @ApiImplicitParam(required = true, name = "activateCodeType", value = "1:找回密码,2:手机号注册机构,3:供应商注册"),
+        @ApiImplicitParam(required = true, name = "activateCodeType", value = "1:找回密码,2:注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码"),
         @ApiImplicitParam(required = false, name = "platformType", value = "0:www,1:crm/h5,2:小程序"),
         @ApiImplicitParam(required = false, name = "isCheckCaptcha", value = "是否检查图片验证码,0:检查,1:不检查"),
         @ApiImplicitParam(required = false, name = "imgCode", value = "图片验证码"),
@@ -133,9 +133,26 @@ public class BaseApi {
      * }
      */
     @ApiOperation("修改密码(旧:/user/findCompanyPwd)")
-    @PostMapping("/password/update")
+    @PostMapping("/update/password")
     public ResponseJson updatePassword(PasswordDto passwordDto) {
         return baseService.updatePassword(passwordDto);
     }
 
+    /**
+     * 更换手机号
+     *
+     * @param mobileDto {
+     *                      mobile          旧手机号(contractMobile)
+     *                      smsCode         旧手机短信验证码(mobileCode)
+     *                      newMobile       新手机号(contractMobile2)
+     *                      newSmsCode      新手机短信验证码(mobileCode)
+     *                      userId          用户Id
+     * }
+     */
+    @ApiOperation("修改联系人(旧:/club/changeMobile)")
+    @PostMapping("/update/mobile")
+    public ResponseJson changeMobile(MobileDto mobileDto) {
+        return baseService.updateMobile(mobileDto);
+    }
+
 }

+ 18 - 0
src/main/java/com/caimei365/user/mapper/BaseMapper.java

@@ -103,4 +103,22 @@ public interface BaseMapper {
      * @param userId   用户Id
      */
     void updatePasswordByUserId(String password, Integer userId);
+    /**
+     * 根据用户Id修改手机号
+     * @param mobile   手机号
+     * @param userId   用户Id
+     */
+    void updateMobileByUserId(String mobile, Integer userId);
+    /**
+     * 根据供应商Id修改手机号
+     * @param mobile   手机号
+     * @param shopId   用户Id
+     */
+    void updateShopMobileByShopId(String mobile, Integer shopId);
+    /**
+     * 根据机构Id修改手机号
+     * @param mobile   手机号
+     * @param clubId   用户Id
+     */
+    void updateClubMobileByClubId(String mobile, Integer clubId);
 }

+ 48 - 0
src/main/java/com/caimei365/user/model/dto/MobileDto.java

@@ -0,0 +1,48 @@
+package com.caimei365.user.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/4/15
+ */
+@ApiModel("修改手机号")
+@Data
+public class MobileDto implements Serializable {
+    /**
+     * 手机号
+     */
+    @NotNull
+    @ApiModelProperty("旧手机号(contractMobile)")
+    private String mobile;
+    /**
+     * 短信验证码
+     */
+    @NotNull
+    @ApiModelProperty("旧手机短信验证码(mobileCode)")
+    private String smsCode;
+    /**
+     * 新手机号
+     */
+    @NotNull
+    @ApiModelProperty("新手机号(contractMobile2)")
+    private String newMobile;
+    /**
+     * 新短信验证码
+     */
+    @NotNull
+    @ApiModelProperty("新手机短信验证码(newMobileCode)")
+    private String newSmsCode;
+    /**
+     * 用户Id
+     */
+    @ApiModelProperty("用户Id")
+    private Integer userId;
+}

+ 14 - 1
src/main/java/com/caimei365/user/service/BaseService.java

@@ -1,6 +1,7 @@
 package com.caimei365.user.service;
 
 import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.dto.MobileDto;
 import com.caimei365.user.model.dto.PasswordDto;
 
 import java.util.Map;
@@ -34,7 +35,7 @@ public interface BaseService {
      * 获取短信验证码
      *
      * @param mobile           手机号
-     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册
+     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码
      * @param platformType     0:www,1:crm/h5,2:小程序
      * @param isCheckCaptcha   是否检查图片验证码,0:检查,1:不检查
      * @param imgCode          图片验证码
@@ -77,4 +78,16 @@ public interface BaseService {
      */
     ResponseJson updatePassword(PasswordDto passwordDto);
 
+    /**
+     * 更换手机号
+     *
+     * @param mobileDto {
+     *                      mobile          旧手机号(contractMobile)
+     *                      smsCode         旧手机短信验证码(mobileCode)
+     *                      newMobile       新手机号(contractMobile2)
+     *                      newSmsCode      新手机短信验证码(mobileCode)
+     *                      userId          用户Id
+     * }
+     */
+    ResponseJson updateMobile(MobileDto mobileDto);
 }

+ 91 - 5
src/main/java/com/caimei365/user/service/impl/BaseServiceImpl.java

@@ -1,9 +1,16 @@
 package com.caimei365.user.service.impl;
 
+import com.caimei365.user.components.CommonService;
 import com.caimei365.user.mapper.BaseMapper;
+import com.caimei365.user.mapper.LoginMapper;
 import com.caimei365.user.model.ResponseJson;
 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.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.utils.*;
 import lombok.extern.slf4j.Slf4j;
@@ -25,11 +32,14 @@ import java.util.Map;
 @Slf4j
 @Service
 public class BaseServiceImpl implements BaseService {
-
+    @Resource
+    private CommonService commonService;
     @Resource
     private RedisService redisService;
     @Resource
     private BaseMapper baseMapper;
+    @Resource
+    private LoginMapper loginMapper;
     @Value("${spring.cloud.config.profile}")
     private String profile;
 
@@ -94,7 +104,7 @@ public class BaseServiceImpl implements BaseService {
      * 获取短信验证码
      *
      * @param mobile           手机号
-     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册
+     * @param activateCodeType 1:找回密码,2:手机号注册机构,3:供应商注册,4:修改手机号-旧手机验证码,5:修改手机号-新手机验证码
      * @param platformType     0:www,1:crm/h5,2:小程序
      * @param isCheckCaptcha   是否检查图片验证码,0:检查,1:不检查
      * @param imgCode          图片验证码
@@ -119,6 +129,7 @@ public class BaseServiceImpl implements BaseService {
             // 开发 和 测试环境 固定短信验证码 666666
             randomCode = "666666";
         }
+        String codeTypeTxt = "";
         // 根据手机号查询用户Id
         Integer userId = baseMapper.getUserIdByMobile(mobile);
         if (1 == activateCodeType) {
@@ -127,25 +138,41 @@ public class BaseServiceImpl implements BaseService {
             }
             // 找回密码
             sendFlag = AliyunSmsUtil.sendSms(mobile, 1, "{code:" + randomCode + "}");
-        } else {
+            codeTypeTxt = "找回密码";
+        } else if (2 == activateCodeType || 3 == activateCodeType){
             if (null != userId && userId > 0) {
                 return ResponseJson.error("该手机号已被使用");
             }
             if (2 == activateCodeType) {
                 // 机构用户(自主)注册
                 sendFlag = AliyunSmsUtil.sendSms(mobile, 8, "{code:"+ randomCode +"}");
+                codeTypeTxt = "机构(自主)注册";
             } else if (3 == activateCodeType) {
                 // 供应商(自主)注册
                 sendFlag = AliyunSmsUtil.sendSms(mobile, 9, "{code:"+ randomCode +"}");
+                codeTypeTxt = "供应商(自主)注册";
             } else {
                 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) {
             redisService.set("code:"+mobile, randomCode, 1800L);
-            String codeType = activateCodeType == 1 ? "找回密码" : (activateCodeType == 2 ? "注册机构" : "注册供应商");
-            log.info(codeType + ",发送到:" + mobile + "的短信验证码为: " + randomCode);
+            log.info(codeTypeTxt + ",发送到:" + mobile + "的短信验证码为: " + randomCode);
         } else {
+            log.info(codeTypeTxt + ",验证码发送失败!");
             return ResponseJson.error("验证码发送失败!请稍后重试");
         }
         return ResponseJson.success("发送验证码成功");
@@ -335,4 +362,63 @@ public class BaseServiceImpl implements BaseService {
         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();
+    }
+
 }

+ 12 - 0
src/main/resources/mapper/BaseMapper.xml

@@ -5,6 +5,18 @@
         update user set password = #{password}
         where userID = #{userId}
     </update>
+    <update id="updateMobileByUserId">
+        update user set bindMobile = #{mobile}
+        where userID = #{userId}
+    </update>
+    <update id="updateShopMobileByShopId">
+        update shop set contractMobile = #{mobile}, contractMobile1 = #{mobile}
+        where shopID = #{shopId}
+    </update>
+    <update id="updateClubMobileByClubId">
+        update club set contractMobile = #{mobile}, contractMobile1 = #{mobile}
+        where clubID = #{clubId}
+    </update>
     <select id="getUserIdByEmail" resultType="java.lang.Integer">
         select userID from user
         where email = #{email} and userIdentity in (1,2,3,4)