Browse Source

联合丽格

huangzhiguo 2 years ago
parent
commit
daab9ab126

+ 16 - 0
src/main/java/com/caimei365/user/controller/BaseApi.java

@@ -173,6 +173,22 @@ public class BaseApi {
     public ResponseJson updatePassword(PasswordDto passwordDto) {
         return baseService.updatePassword(passwordDto);
     }
+    /**
+     * 修改密码(找回密码)-- 组织
+     *
+     * @param passwordDto {
+     *                    mobileOrEmail 手机号或邮箱
+     *                    smsCode       短信验证码(旧:activationCode)
+     *                    password      密码
+     *                    confirmPwd    确认密码
+     *                    status        1:手机号找回,2:邮箱找回
+     *                    }
+     */
+    @ApiOperation("修改密码--组织")
+    @PostMapping("/updateOrganize/password")
+    public ResponseJson updateOrganizePassword(PasswordDto passwordDto) {
+        return baseService.updateOrganizePassword(passwordDto);
+    }
 
     /**
      * 更换联系人手机号

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

@@ -35,6 +35,13 @@ public interface BaseMapper {
      * @return 用户Id
      */
     Integer getUserIdByMobile(@Param("mobile") String mobile);
+    /**
+     * 根据手机号获取用户Id -- 组织
+     *
+     * @param mobile 手机号
+     * @return 用户Id
+     */
+    Integer getUserIdOrganizeByMobile(@Param("mobile") String mobile);
 
     /**
      * 获取组织用户userId

+ 7 - 0
src/main/java/com/caimei365/user/mapper/UserCenterMapper.java

@@ -45,4 +45,11 @@ public interface UserCenterMapper {
      * 可用余额
      */
     Double getAbleUserMoney(Integer userId);
+
+    /**
+     * 获取组织id
+     * @param userId
+     * @return
+     */
+    Integer getUserOrganizeId(Integer userId);
 }

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

@@ -46,9 +46,4 @@ public class MobileDto implements Serializable {
      */
     @ApiModelProperty("用户Id")
     private Integer userId;
-    /**
-     * 组织ID 具体对应cm_mall_organize表ID
-     */
-    @ApiModelProperty("组织ID")
-    private Integer organizeId;
 }

+ 12 - 0
src/main/java/com/caimei365/user/service/BaseService.java

@@ -94,6 +94,18 @@ public interface BaseService {
      */
     ResponseJson updatePassword(PasswordDto passwordDto);
 
+    /**
+     * 修改密码(找回密码)
+     *
+     * @param passwordDto {
+     *                    mobileOrEmail 手机号或邮箱
+     *                    smsCode       短信验证码(旧:activationCode)
+     *                    password      密码
+     *                    confirmPwd    确认密码
+     *                    status        1:手机号找回,2:邮箱找回
+     *                    }
+     */
+    ResponseJson updateOrganizePassword(PasswordDto passwordDto);
     /**
      * 更换手机号
      *

+ 70 - 6
src/main/java/com/caimei365/user/service/impl/BaseServiceImpl.java

@@ -7,6 +7,7 @@ import com.caimei365.user.components.RedisService;
 import com.caimei365.user.mapper.BaseMapper;
 import com.caimei365.user.mapper.LoginMapper;
 import com.caimei365.user.mapper.SuperVipMapper;
+import com.caimei365.user.mapper.UserCenterMapper;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.dto.MobileDto;
 import com.caimei365.user.model.dto.PasswordDto;
@@ -55,6 +56,8 @@ public class BaseServiceImpl implements BaseService {
     private String profile;
     @Resource
     private RemoteCallService remoteCallService;
+    @Resource
+    private UserCenterMapper userCenterMapper;
 
     /**
      * 获取图片验证码
@@ -568,6 +571,64 @@ public class BaseServiceImpl implements BaseService {
         return ResponseJson.success("密码修改成功", "");
     }
 
+    /**
+     * 修改密码(找回密码)
+     *
+     * @param passwordDto {
+     *                    mobileOrEmail 手机号或邮箱
+     *                    smsCode       短信验证码(旧:activationCode)
+     *                    password      密码
+     *                    confirmPwd    确认密码
+     *                    status        1:手机号找回,2:邮箱找回
+     *                    }
+     */
+    @Override
+    public ResponseJson updateOrganizePassword(PasswordDto passwordDto) {
+        String mobileOrEmail = passwordDto.getMobileOrEmail();
+        String smsCode = passwordDto.getSmsCode();
+        String passWord = passwordDto.getPassword();
+        String confirmPwd = passwordDto.getPasswordConfirm();
+        Integer status = passwordDto.getStatus();
+        // 验证手机号
+        String result = ValidateUtil.validateMobile(mobileOrEmail);
+        if (result != null) {
+            return ResponseJson.error(result);
+        }
+        if (StringUtils.isEmpty(smsCode)) {
+            return ResponseJson.error("请输入验证码");
+        }
+        String redisSmsCode = (String) redisService.get("code:" + mobileOrEmail);
+        // 开发 和 测试环境 固定短信验证码 666666
+        if ("dev".equals(profile) || "beta".equals(profile)) {
+            redisSmsCode = (null != redisSmsCode && !"null".equals(redisSmsCode) ? redisSmsCode : "666666");
+        }
+        if (!smsCode.equals(redisSmsCode)) {
+            return ResponseJson.error("验证码错误");
+        }
+        // 查找用户表是否存在
+        Integer dbUserId = baseMapper.getUserIdOrganizeByMobile(mobileOrEmail);
+
+        if (dbUserId == null) {
+            return ResponseJson.error("该手机号尚未注册");
+        }
+
+        if (StringUtils.isEmpty(passWord)) {
+            return ResponseJson.error("请输入新密码");
+        }
+        if (StringUtils.isEmpty(confirmPwd)) {
+            return ResponseJson.error("请确认密码");
+        }
+        if (!passWord.equals(confirmPwd)) {
+            return ResponseJson.error("两次输入的密码不一致");
+        }
+        // 设置密码
+        String dbPassword = Md5Util.md5(passWord);
+        baseMapper.updatePasswordByUserId(dbPassword, dbUserId);
+        //重新设置密码后将登录失败表中近30分钟记录置为删除
+        redisService.remove("login-"+dbUserId);
+        return ResponseJson.success("密码修改成功", "");
+    }
+
     /**
      * 更换手机号
      *
@@ -591,18 +652,21 @@ public class BaseServiceImpl implements BaseService {
         if (null == mobileDto.getUserId()) {
             return ResponseJson.error("参数异常:用户Id不能为空!");
         }
-        // 旧手机号与验证码校验
-        String result = ValidateUtil.validateMobile(mobileDto.getMobile());
-        if (result != null) {
-            return ResponseJson.error(result);
-        }
-        if (0 == mobileDto.getOrganizeId()) {
+        // 获取用户组织Id
+        Integer organizeId = userCenterMapper.getUserOrganizeId(mobileDto.getUserId());
+        String result = "";
+        if (0 == organizeId) {
             if (StringUtils.isBlank(mobileDto.getMobile())) {
                 return ResponseJson.error("参数异常:旧手机号不能为空!");
             }
             if (StringUtils.isBlank(mobileDto.getSmsCode())) {
                 return ResponseJson.error("参数异常:旧手机号验证码不能为空!");
             }
+            // 旧手机号与验证码校验
+            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)) {

+ 4 - 0
src/main/java/com/caimei365/user/service/impl/LoginServiceImpl.java

@@ -102,6 +102,7 @@ public class LoginServiceImpl implements LoginService {
         if (null != baseUser) {
             // 绑定微信信息
             Integer operationUser = loginMapper.getOperationUser(mobileOrEmail);
+            log.info("operationUser==="+operationUser);
             if (null == operationUser) {
                 // 绑定微信
                 OperationVo operationVo = new OperationVo();
@@ -116,6 +117,7 @@ public class LoginServiceImpl implements LoginService {
                 operationVo.setBindTime(new Date());
                 operationVo.setDelFlag(0);
                 loginMapper.insertOperation(operationVo);
+                log.info("operationVo***"+operationVo);
             }
             String key = "login-" + baseUser.getUserId();
             boolean exists = redisService.exists(key);
@@ -216,6 +218,7 @@ public class LoginServiceImpl implements LoginService {
                     UserLoginVo baseUser = loginMapper.getLoginUserByMobileOrEmail(mobile);
                     // 绑定微信信息
                     Integer operationUser = loginMapper.getOperationUser(mobile);
+                    log.info("operationUser==="+operationUser);
                     if (null == operationUser) {
                         // 绑定微信
                         OperationVo operationVo = new OperationVo();
@@ -230,6 +233,7 @@ public class LoginServiceImpl implements LoginService {
                         operationVo.setBindTime(new Date());
                         operationVo.setDelFlag(0);
                         loginMapper.insertOperation(operationVo);
+                        log.info("operationVo***"+operationVo);
                     }
                     // 如果前端传入unionId,则存入返回前端
                     baseUser.setUnionId(unionId);

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

@@ -50,6 +50,21 @@
           AND u.userIdentity IN (1, 2, 3, 4)
         LIMIT 1
     </select>
+    <select id="getUserIdOrganizeByMobile" resultType="java.lang.Integer">
+        SELECT u.userID
+        FROM USER u
+                 LEFT JOIN cm_mall_operation_user cu ON cu.userID = u.userID
+        WHERE u.bindMobile = #{mobile} and u.userOrganizeID != 0
+          and u.userIdentity in (1, 2, 3, 4)
+        UNION
+        SELECT u.userID
+        FROM USER u
+                 LEFT JOIN cm_mall_operation_user cu ON cu.userID = u.userID
+        WHERE cu.mobile = #{mobile}
+          AND cu.delFlag != 1
+          AND u.userIdentity IN (1, 2, 3, 4) and u.userOrganizeID != 0
+        LIMIT 1
+    </select>
     <select id="getUserIdByOrganize" resultType="java.lang.Integer">
         SELECT u.userID
         FROM USER u

+ 1 - 1
src/main/resources/mapper/LoginMapper.xml

@@ -84,7 +84,7 @@
     </select>
     <insert id="insertOperation">
         INSERT INTO cm_mall_operation_user (userOrganizeID, userType, userID, clubID, mobile, linkName, STATUS, unionId, bindTime, delFlag)
-        values(#{userOrganizeId}, #{userType}, #{userId}, #{clubId}, #{mobile}, #{linkName}, #{status}, #{unionId}, #{bindTime}, #{delFlag})
+        values(#{organizeId}, #{userType}, #{userId}, #{clubId}, #{mobile}, #{linkName}, #{status}, #{unionId}, #{bindTime}, #{delFlag})
     </insert>
     <select id="getLoginUserByMobile" resultType="com.caimei365.user.model.vo.UserLoginVo">
         select u.userID             as userId,

+ 4 - 1
src/main/resources/mapper/UserCenterMapper.xml

@@ -61,4 +61,7 @@
     <select id="getAbleUserMoney" resultType="java.lang.Double">
         SELECT ableUserMoney FROM user WHERE userID = #{userId}
     </select>
-</mapper>
+    <select id="getUserOrganizeId" resultType="java.lang.Integer">
+        select userOrganizeID from user where userID = #{userId}
+    </select>
+</mapper>