浏览代码

add seller

he2802 2 年之前
父节点
当前提交
10444504d7

+ 6 - 4
zhongzheng-api/src/main/java/com/zhongzheng/controller/distribution/SellerLoginController.java

@@ -2,6 +2,8 @@ package com.zhongzheng.controller.distribution;
 
 import com.zhongzheng.common.core.controller.BaseController;
 import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.modules.distribution.bo.SellerAppRegisterBo;
+import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
 import com.zhongzheng.modules.user.bo.*;
 import com.zhongzheng.modules.user.service.IUserService;
 import io.swagger.annotations.Api;
@@ -27,15 +29,15 @@ import java.util.Map;
 @RequestMapping("/app/common/seller")
 public class SellerLoginController extends BaseController {
 
-    private final IUserService iUserService;
+    private final IDistributionSellerService iDistributionSellerService;
 
     /**
      * 用户注册
      */
-    @ApiOperation("用户注册")
+    @ApiOperation("业务员客户端注册")
     @PostMapping("/register")
-    public AjaxResult<Void> register(@RequestBody UserAppRegisterBo bo) {
-        return toAjax(iUserService.registerUser(bo) ? 1 : 0);
+    public AjaxResult<Void> register(@RequestBody SellerAppRegisterBo bo) {
+        return toAjax(iDistributionSellerService.registerSeller(bo) ? 1 : 0);
     }
 
 }

+ 1 - 1
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ServletUtils.java

@@ -25,7 +25,7 @@ public class ServletUtils
     public static String getEncoded(String tag)
     {
         String time = String.valueOf(System.currentTimeMillis()/1000);
-        return tag+Integer.valueOf(time.substring(1))+(int)((Math.random()*100));
+        return tag+Integer.valueOf(time.substring(1))+""+(((int)(Math.random() * 90 + 10)));
     }
     //导入生成编号使用
     public static String getImportEncoded(String tag)

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

@@ -0,0 +1,28 @@
+package com.zhongzheng.modules.distribution.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+/**
+ * 客户端用户编辑对象 user
+ *
+ * @author ruoyi
+ * @date 2021-06-08
+ */
+@Data
+@ApiModel("客户端用户注册对象")
+public class SellerAppRegisterBo {
+    @ApiModelProperty("手机号")
+    private String tel;
+    @ApiModelProperty("密码")
+    private String pwd;
+    @ApiModelProperty("验证码")
+    private String code;
+    @ApiModelProperty("身份证")
+    private String idcard;
+    /** 真实姓名 */
+    @ApiModelProperty("真实姓名")
+    private String realname;
+}

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

@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.zhongzheng.modules.distribution.bo.DistributionSellerAddBo;
 import com.zhongzheng.modules.distribution.bo.DistributionSellerEditBo;
 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.UserAppRegisterBo;
 
 import java.util.Collection;
 import java.util.List;
@@ -49,4 +51,7 @@ public interface IDistributionSellerService extends IService<DistributionSeller>
 	 * @return
 	 */
 	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+
+	Boolean registerSeller(SellerAppRegisterBo bo);
 }

+ 77 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/service/impl/DistributionSellerServiceImpl.java

@@ -1,15 +1,29 @@
 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.toolkit.StringUtils;
+import com.zhongzheng.common.constant.Constants;
+import com.zhongzheng.common.core.redis.RedisCache;
+import com.zhongzheng.common.exception.CustomException;
+import com.zhongzheng.common.type.EncryptHandler;
 import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.SecurityUtils;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.common.utils.ToolsUtils;
 import com.zhongzheng.modules.distribution.bo.DistributionSellerAddBo;
 import com.zhongzheng.modules.distribution.bo.DistributionSellerEditBo;
 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.mapper.DistributionSellerMapper;
 import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
 import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
+import com.zhongzheng.modules.user.bo.UserAppRegisterBo;
+import com.zhongzheng.modules.user.domain.User;
+import com.zhongzheng.modules.user.service.IUserService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -30,6 +44,67 @@ import java.util.stream.Collectors;
 @Service
 public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSellerMapper, DistributionSeller> implements IDistributionSellerService {
 
+    @Autowired
+    private RedisCache redisCache;
+
+    @Autowired
+    private IUserService iUserService;
+
+    @Override
+    public Boolean registerSeller(SellerAppRegisterBo bo) {
+        if(StringUtils.isBlank(bo.getIdcard())){
+            throw new CustomException("身份证不能为空");
+        }
+        if(bo.getTel()==null){
+            throw new CustomException("手机号不能为空");
+        }
+        if(bo.getPwd()==null){
+            throw new CustomException("密码不能为空");
+        }
+        if(Validator.isEmpty(bo.getRealname())){
+            throw new CustomException("姓名不能为空");
+        }
+        if(!ToolsUtils.verifPwd(bo.getPwd())){
+            throw new CustomException("密码应由8-16位数字、大小写字母、符号组成");
+        }
+        String key = Constants.REGISTER_SMS + bo.getTel();
+        String code =  redisCache.getCacheObject(key);
+        if(code==null){
+            throw new CustomException("验证码错误");
+        }
+        if(!code.equals(bo.getCode())){
+            throw new CustomException("验证码错误");
+        }
+        DistributionSeller seller = getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getTelphone, EncryptHandler.encrypt(bo.getTel())).last("limit 1"));
+        if(Validator.isNotNull(seller)){
+            throw new CustomException("该手机号已注册");
+        }
+        DistributionSeller sellerIdCard = getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getIdCard,EncryptHandler.encrypt(bo.getIdcard())).last("limit 1"));
+        if(Validator.isNotNull(sellerIdCard)){
+            throw new CustomException("该身份证已注册");
+        }
+        DistributionSeller inertData = new DistributionSeller();
+        inertData.setTelphone(bo.getTel());
+        inertData.setIdCard(bo.getIdcard());
+        inertData.setRealname(bo.getRealname());
+        inertData.setAvatar(Constants.DEFAULT_AVATAR);
+        inertData.setPassword(SecurityUtils.encryptPassword(bo.getPwd()));
+        inertData.setCode(ServletUtils.getEncoded(""));
+        inertData.setCreateTime(DateUtils.getNowTime());
+        inertData.setUpdateTime(DateUtils.getNowTime());
+        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(!save(inertData)){
+            throw new CustomException("注册失败");
+        }
+        return true;
+    }
+
     @Override
     public DistributionSellerVo queryById(Long salerId){
         DistributionSeller db = this.baseMapper.selectById(salerId);
@@ -105,4 +180,6 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
         }
         return this.removeByIds(ids);
     }
+
+
 }