he2802 2 vuotta sitten
vanhempi
commit
cd047573f5

+ 5 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/distribution/SellerLoginController.java

@@ -40,4 +40,9 @@ public class SellerLoginController extends BaseController {
         return toAjax(iDistributionSellerService.registerSeller(bo) ? 1 : 0);
     }
 
+    @ApiOperation("业务员忘记密码")
+    @PostMapping("/register_forget")
+    public AjaxResult<Void> register_forget(@RequestBody SellerAppRegisterBo bo) {
+        return toAjax(iDistributionSellerService.forgetUser(bo) ? 1 : 0);
+    }
 }

+ 14 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ToolsUtils.java

@@ -348,4 +348,18 @@ public class ToolsUtils {
         return TenantId;
     }
 
+    private static int getRandom(int count) {
+        return (int) Math.round(Math.random() * (count));
+    }
+
+    public static String getRandomString(int length){
+        String string = "abcdefghijklmnopqrstuvwxyz";
+        StringBuffer sb = new StringBuffer();
+        int len = string.length();
+        for (int i = 0; i < length; i++) {
+            sb.append(string.charAt(getRandom(len-1)));
+        }
+        return sb.toString();
+    }
+
 }

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/DistributionSellerAddBo.java

@@ -54,4 +54,10 @@ public class DistributionSellerAddBo {
     /** 密码 */
     @ApiModelProperty("密码")
     private String password;
+    /** 父ID */
+    @ApiModelProperty("父ID")
+    private Long parentId;
+    /** 分享码 */
+    @ApiModelProperty("分享码")
+    private String shareCode;
 }

+ 7 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/DistributionSellerEditBo.java

@@ -19,7 +19,7 @@ public class DistributionSellerEditBo {
 
     /** $column.columnComment */
     @ApiModelProperty("$column.columnComment")
-    private Long salerId;
+    private Long sellerId;
 
     /** 真实姓名 */
     @ApiModelProperty("真实姓名")
@@ -65,5 +65,10 @@ public class DistributionSellerEditBo {
     /** 密码 */
     @ApiModelProperty("密码")
     private String password;
-
+    /** 父ID */
+    @ApiModelProperty("父ID")
+    private Long parentId;
+    /** 分享码 */
+    @ApiModelProperty("分享码")
+    private String shareCode;
 }

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/DistributionSellerQueryBo.java

@@ -66,4 +66,10 @@ public class DistributionSellerQueryBo extends BaseEntity {
 	/** 密码 */
 	@ApiModelProperty("密码")
 	private String password;
+	/** 父ID */
+	@ApiModelProperty("父ID")
+	private Long parentId;
+	/** 分享码 */
+	@ApiModelProperty("分享码")
+	private String shareCode;
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/SellerAppRegisterBo.java

@@ -25,4 +25,7 @@ public class SellerAppRegisterBo {
     /** 真实姓名 */
     @ApiModelProperty("真实姓名")
     private String realname;
+    /** 分享码 */
+    @ApiModelProperty("分享码")
+    private String shareCode;
 }

+ 6 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/domain/DistributionSeller.java

@@ -24,8 +24,8 @@ public class DistributionSeller implements Serializable {
 private static final long serialVersionUID=1L;
 
     /** $column.columnComment */
-    @TableId(value = "saler_id")
-    private Long salerId;
+    @TableId(value = "seller_id")
+    private Long sellerId;
     /** 真实姓名 */
     private String realname;
     /** 身份证号 */
@@ -52,4 +52,8 @@ private static final long serialVersionUID=1L;
     private String unionId;
     /** 密码 */
     private String password;
+    /** 父ID */
+    private Long parentId;
+    /** 分享码 */
+    private String shareCode;
 }

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/service/IDistributionSellerService.java

@@ -7,7 +7,9 @@ import com.zhongzheng.modules.distribution.bo.DistributionSellerQueryBo;
 import com.zhongzheng.modules.distribution.bo.SellerAppRegisterBo;
 import com.zhongzheng.modules.distribution.domain.DistributionSeller;
 import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
+import com.zhongzheng.modules.user.bo.UserAppForgetBo;
 import com.zhongzheng.modules.user.bo.UserAppRegisterBo;
+import com.zhongzheng.modules.user.domain.User;
 
 import java.util.Collection;
 import java.util.List;
@@ -54,4 +56,8 @@ public interface IDistributionSellerService extends IService<DistributionSeller>
 
 
 	Boolean registerSeller(SellerAppRegisterBo bo);
+
+	Boolean forgetUser(SellerAppRegisterBo bo);
+
+	Boolean syncSellerToUser(DistributionSeller seller, User user,Integer type);
 }

+ 82 - 3
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/service/impl/DistributionSellerServiceImpl.java

@@ -3,6 +3,7 @@ package com.zhongzheng.modules.distribution.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.zhongzheng.common.constant.Constants;
 import com.zhongzheng.common.core.redis.RedisCache;
@@ -91,14 +92,22 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
         inertData.setRealname(bo.getRealname());
         inertData.setAvatar(Constants.DEFAULT_AVATAR);
         inertData.setPassword(SecurityUtils.encryptPassword(bo.getPwd()));
-        inertData.setCode(ServletUtils.getEncoded(""));
+        inertData.setCode(ServletUtils.getEncoded("YW"));
         inertData.setCreateTime(DateUtils.getNowTime());
         inertData.setUpdateTime(DateUtils.getNowTime());
+        inertData.setShareCode(ToolsUtils.getRandomString(8));
         User userIdCard = iUserService.getOne(new LambdaQueryWrapper<User>()
                 .eq(User::getIdCard,EncryptHandler.encrypt(bo.getIdcard())).last("limit 1"));
         if(Validator.isNotEmpty(userIdCard)){
             inertData.setUserId(userIdCard.getUserId());
         }
+        if(Validator.isNotEmpty(bo.getShareCode())){
+            DistributionSeller sellerShare = getOne(new LambdaQueryWrapper<DistributionSeller>()
+                    .eq(DistributionSeller::getShareCode,bo.getShareCode()).last("limit 1"));
+            if(Validator.isNotEmpty(sellerShare)){
+                inertData.setParentId(sellerShare.getSellerId());
+            }
+        }
         if(!save(inertData)){
             throw new CustomException("注册失败");
         }
@@ -106,8 +115,78 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
     }
 
     @Override
-    public DistributionSellerVo queryById(Long salerId){
-        DistributionSeller db = this.baseMapper.selectById(salerId);
+    public Boolean forgetUser(SellerAppRegisterBo bo) {
+        if(bo.getTel()==null){
+            throw new CustomException("手机号不能为空");
+        }
+        if(bo.getPwd()==null){
+            throw new CustomException("密码不能为空");
+        }
+        String key = Constants.FORGET_SMS + bo.getTel();
+        String code =  redisCache.getCacheObject(key);
+        if(code==null){
+            throw new CustomException("验证码错误");
+        }
+        if(!code.equals(bo.getCode())){
+            throw new CustomException("验证码错误");
+        }
+        redisCache.deleteObject(key);
+        DistributionSeller seller = getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getTelphone,EncryptHandler.encrypt(bo.getTel())).last("limit 1"));
+        if(Validator.isEmpty(seller)){
+            throw new CustomException("该手机号未注册");
+        }
+        seller.setPassword(SecurityUtils.encryptPassword(bo.getPwd()));
+        seller.setUpdateTime(DateUtils.getNowTime());
+
+        DistributionSeller sellerSync = new DistributionSeller();
+        sellerSync.setUserId(seller.getUserId());
+        sellerSync.setPassword(seller.getPassword());
+        syncSellerToUser(sellerSync,null,1);
+        return updateById(seller);
+    }
+
+    /**
+     *
+     * @param seller
+     * @param user
+     * @param type 1业务员更新到用户 2用户更新到业务员
+     * @return
+     */
+    @Override
+    public Boolean syncSellerToUser(DistributionSeller seller, User user, Integer type) {
+        if(type==1){
+            if(Validator.isNotEmpty(seller.getUserId())){
+                iUserService.update(new LambdaUpdateWrapper<User>()
+                        .eq(User::getUserId,seller.getUserId())
+                        .set(User::getUpdateTime,DateUtils.getNowTime())
+                        .set(Validator.isNotEmpty(seller.getTelphone()),User::getTelphone,seller.getTelphone())
+                        .set(Validator.isNotEmpty(seller.getIdCard()),User::getIdCard,seller.getIdCard())
+                        .set(Validator.isNotEmpty(seller.getAvatar()),User::getAvatar,seller.getAvatar())
+                        .set(Validator.isNotEmpty(seller.getRealname()),User::getRealname,seller.getRealname())
+                        .set(Validator.isNotEmpty(seller.getPassword()),User::getPassword,seller.getPassword()));
+            }
+        }
+        else if(type==2){
+            DistributionSeller sellerUser = getOne(new LambdaQueryWrapper<DistributionSeller>()
+                    .eq(DistributionSeller::getUserId,user.getUserId()).last("limit 1"));
+            if(Validator.isNotEmpty(sellerUser)){
+                update(new LambdaUpdateWrapper<DistributionSeller>()
+                        .eq(DistributionSeller::getSellerId,sellerUser.getSellerId())
+                        .set(DistributionSeller::getUpdateTime,DateUtils.getNowTime())
+                        .set(Validator.isNotEmpty(user.getTelphone()),DistributionSeller::getTelphone,user.getTelphone())
+                        .set(Validator.isNotEmpty(user.getIdCard()),DistributionSeller::getIdCard,user.getIdCard())
+                        .set(Validator.isNotEmpty(user.getAvatar()),DistributionSeller::getAvatar,user.getAvatar())
+                        .set(Validator.isNotEmpty(user.getRealname()),DistributionSeller::getRealname,user.getRealname())
+                        .set(Validator.isNotEmpty(user.getPassword()),DistributionSeller::getPassword,user.getPassword()));
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public DistributionSellerVo queryById(Long sellerId){
+        DistributionSeller db = this.baseMapper.selectById(sellerId);
         return BeanUtil.toBean(db, DistributionSellerVo.class);
     }
 

+ 8 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/vo/DistributionSellerVo.java

@@ -64,4 +64,12 @@ public class DistributionSellerVo {
 	@Excel(name = "密码")
 	@ApiModelProperty("密码")
 	private String password;
+	/** 父ID */
+	@Excel(name = "父ID")
+	@ApiModelProperty("父ID")
+	private Long parentId;
+	/** 分享码 */
+	@Excel(name = "分享码")
+	@ApiModelProperty("分享码")
+	private String shareCode;
 }

+ 3 - 1
zhongzheng-system/src/main/resources/mapper/modules/distribution/DistributionSellerMapper.xml

@@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <mapper namespace="com.zhongzheng.system.mapper.DistributionSellerMapper">
 
     <resultMap type="com.zhongzheng.modules.distribution.domain.DistributionSeller" id="DistributionSellerResult">
-        <result property="salerId" column="saler_id"/>
+        <result property="sellerId" column="seller_id"/>
         <result property="realname" column="realname"/>
         <result property="idCard" column="id_card"/>
         <result property="telphone" column="telphone"/>
@@ -18,6 +18,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="gzhOpenId" column="gzh_open_id"/>
         <result property="unionId" column="union_id"/>
         <result property="password" column="password"/>
+        <result property="parentId" column="parent_id"/>
+        <result property="shareCode" column="share_code"/>
     </resultMap>