Browse Source

供应商注册part1

Aslee 4 years ago
parent
commit
6a4141b329

+ 26 - 1
src/main/java/com/caimei365/user/controller/AllApi.java

@@ -1,7 +1,9 @@
 package com.caimei365.user.controller;
 package com.caimei365.user.controller;
 
 
+import com.caimei365.user.idempotent.Idempotent;
 import com.caimei365.user.model.ClubVo;
 import com.caimei365.user.model.ClubVo;
 import com.caimei365.user.model.JsonModel;
 import com.caimei365.user.model.JsonModel;
+import com.caimei365.user.model.OperationVo;
 import com.caimei365.user.utils.ValidateUtil;
 import com.caimei365.user.utils.ValidateUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
@@ -85,7 +87,30 @@ public class AllApi {
         return null;
         return null;
     }
     }
 
 
-
+    /**
+     * 小程序分步供应商注册
+     */
+    @PostMapping("/appletsRegistered")
+    public JsonModel appletsShopRegistered(UserVo user, ShopVo shop, String isAgreed, Integer whichStep) {
+        JsonModel model = JsonModel.newInstance();
+        if (whichStep == 1) {
+            if (StringUtils.isBlank(user.getBindMobile()) || StringUtils.isBlank(user.getPassword()) || StringUtils.isBlank(shop.getMobileCode())) {
+                return model.error("参数异常");
+            }
+            if (!user.getPassword().equals(user.getPassWordConfirm())) {
+                return model.error("两次输入的密码不一致");
+            }
+        } else if (whichStep == 2) {
+            if (StringUtils.isBlank(shop.getName()) || StringUtils.isBlank(shop.getLinkMan())) {
+                return model.error("参数异常");
+            }
+        } else {
+            if (!"1".equals(isAgreed)) {
+                return model.error("请勾选同意协议");
+            }
+        }
+        return supplierService.appletsShopRegistered(user, shop, whichStep);
+    }
 
 
 //club
 //club
     /**
     /**

+ 80 - 0
src/main/java/com/caimei365/user/controller/ShopApi.java

@@ -1,9 +1,15 @@
 package com.caimei365.user.controller;
 package com.caimei365.user.controller;
 
 
+import com.caimei365.user.idempotent.Idempotent;
+import com.caimei365.user.model.BaseUser;
+import com.caimei365.user.model.JsonModel;
 import com.caimei365.user.service.ShopService;
 import com.caimei365.user.service.ShopService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.server.ServerWebExchange;
 
 
 /**
 /**
  * Description
  * Description
@@ -18,5 +24,79 @@ public class ShopApi {
 
 
     private final ShopService shopService;
     private final ShopService shopService;
 
 
+    /**
+     * PC端供应商注册
+     *
+     * spi旧接口:supplier/register
+     *
+     * @param source                注册来源: 0网站 1小程序
+     * @param name                  组织名称
+     * @param sname                 供应商公司简称
+     * @param bindMobile            企业绑定手机号
+     * @param email                 邮箱
+     * @param smsCode               手机验证码(旧:mobileCode)
+     * @param password              密码
+     * @param passWordConfirm       用户确认密码
+     * @param linkMan               联系人
+     * @param provinceID            省
+     * @param cityID                市
+     * @param townID                所在县区Id
+     * @param address               地址
+     * @param socialCreditCode      统一社会信用代码
+     * @param businessLicenseImage  营业执照
+     * @param firstShopType         医疗=1和非医疗=2
+     * @param secondShopType        医疗的二级分类 一类器械=1、二类器械 =2、三类器械=3、其他=4 /// 1和非医疗没有二级分类
+     * @param mainpro               主打项目
+     * @param isAgreed              是否同意勾选同意协议,1是,其他否
+     * @param serverWebExchange     ServerWebExchange
+     */
+    @Idempotent(prefix="idempotent_club", keys={"#baseUser"}, expire=5)
+    @PostMapping("/pc/register")
+    public JsonModel<BaseUser> pcRegister(Integer source,
+                                        String name,
+                                        String sname,
+                                        String bindMobile,
+                                        String email,
+                                        String smsCode,
+                                        String password,
+                                        String passWordConfirm,
+                                        String linkMan,
+                                        Integer provinceID,
+                                        Integer cityID,
+                                        Integer townID,
+                                        String address,
+                                        String socialCreditCode,
+                                        String businessLicenseImage,
+                                        String firstShopType,
+                                        String secondShopType,
+                                        String mainpro,
+                                        Integer isAgreed,
+                                        ServerWebExchange serverWebExchange) {
+        return shopService.pcRegister(source, name, sname, bindMobile, email, smsCode, password, passWordConfirm, linkMan, provinceID, cityID, townID, address, socialCreditCode, businessLicenseImage, firstShopType, secondShopType, mainpro, isAgreed, serverWebExchange);
+    }
 
 
+    /**
+     * 小程序端分步供应商注册
+     */
+    @PostMapping("/applets/register")
+    public JsonModel appletsRegister(UserVo user, ShopVo shop, String isAgreed, Integer whichStep) {
+        JsonModel model = JsonModel.newInstance();
+        if (whichStep == 1) {
+            if (StringUtils.isBlank(user.getBindMobile()) || StringUtils.isBlank(user.getPassword()) || StringUtils.isBlank(shop.getMobileCode())) {
+                return model.error("参数异常");
+            }
+            if (!user.getPassword().equals(user.getPassWordConfirm())) {
+                return model.error("两次输入的密码不一致");
+            }
+        } else if (whichStep == 2) {
+            if (StringUtils.isBlank(shop.getName()) || StringUtils.isBlank(shop.getLinkMan())) {
+                return model.error("参数异常");
+            }
+        } else {
+            if (!"1".equals(isAgreed)) {
+                return model.error("请勾选同意协议");
+            }
+        }
+        return supplierService.appletsShopRegistered(user, shop, whichStep);
+    }
 }
 }

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

@@ -50,4 +50,11 @@ public interface BaseUserDao {
      * @return userId
      * @return userId
      */
      */
     Integer getOperationIdByMobile(String bindMobile);
     Integer getOperationIdByMobile(String bindMobile);
+    /**
+     * 根据邮箱获取用户id
+     *
+     * @param email 邮箱
+     * @return userId
+     */
+    Integer getUserIdByEmail(String email);
 }
 }

+ 30 - 0
src/main/java/com/caimei365/user/service/ShopService.java

@@ -1,5 +1,9 @@
 package com.caimei365.user.service;
 package com.caimei365.user.service;
 
 
+import com.caimei365.user.model.BaseUser;
+import com.caimei365.user.model.JsonModel;
+import org.springframework.web.server.ServerWebExchange;
+
 /**
 /**
  * Description
  * Description
  *
  *
@@ -7,4 +11,30 @@ package com.caimei365.user.service;
  * @date : 2021/3/9
  * @date : 2021/3/9
  */
  */
 public interface ShopService {
 public interface ShopService {
+    /**
+     * PC端供应商注册
+     *
+     * @param source                注册来源: 0网站 1小程序
+     * @param name                  组织名称
+     * @param sname                 供应商公司简称
+     * @param bindMobile            企业绑定手机号
+     * @param email                 邮箱
+     * @param smsCode               手机验证码(旧:mobileCode)
+     * @param password              密码
+     * @param passWordConfirm       用户确认密码
+     * @param linkMan               联系人
+     * @param provinceID            省
+     * @param cityID                市
+     * @param townID                所在县区Id
+     * @param address               地址
+     * @param socialCreditCode      统一社会信用代码
+     * @param businessLicenseImage  营业执照
+     * @param firstShopType         医疗=1和非医疗=2
+     * @param secondShopType        医疗的二级分类 一类器械=1、二类器械 =2、三类器械=3、其他=4 /// 1和非医疗没有二级分类
+     * @param mainpro               主打项目
+     * @param isAgreed              是否同意勾选同意协议,1是,其他否
+     * @param serverWebExchange     ServerWebExchange
+     * @return BaseUser
+     */
+    JsonModel<BaseUser> pcRegister(Integer source, String name, String sname, String bindMobile, String email, String smsCode, String password, String passWordConfirm, String linkMan, Integer provinceID, Integer cityID, Integer townID, String address, String socialCreditCode, String businessLicenseImage, String firstShopType, String secondShopType, String mainpro, Integer isAgreed, ServerWebExchange serverWebExchange);
 }
 }

+ 2 - 3
src/main/java/com/caimei365/user/service/impl/ClubServiceImpl.java

@@ -7,7 +7,7 @@ import com.caimei365.user.service.ClubService;
 import com.caimei365.user.service.RedisService;
 import com.caimei365.user.service.RedisService;
 import com.caimei365.user.utils.AliyunSmsUtil;
 import com.caimei365.user.utils.AliyunSmsUtil;
 import com.caimei365.user.utils.Md5Util;
 import com.caimei365.user.utils.Md5Util;
-import com.caimei365.user.utils.ReduestUtil;
+import com.caimei365.user.utils.RequestUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -17,7 +17,6 @@ import org.springframework.web.server.ServerWebExchange;
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Date;
-import java.util.Map;
 
 
 /**
 /**
  * Description
  * Description
@@ -55,7 +54,7 @@ public class ClubServiceImpl implements ClubService {
     @Transactional
     @Transactional
     public JsonModel<BaseUser> register(Integer source, String userName, String bindMobile, String password, String passWordConfirm, String smsCode, Integer isAgreed, String nickName, String avatarUrl, ServerWebExchange serverWebExchange) {
     public JsonModel<BaseUser> register(Integer source, String userName, String bindMobile, String password, String passWordConfirm, String smsCode, Integer isAgreed, String nickName, String avatarUrl, ServerWebExchange serverWebExchange) {
         // 打印IP
         // 打印IP
-        String ip = ReduestUtil.getIp(serverWebExchange);
+        String ip = RequestUtil.getIp(serverWebExchange);
         log.info("X-Forwarded-For:" + ip);
         log.info("X-Forwarded-For:" + ip);
         // 参数校验
         // 参数校验
         if (StringUtils.isBlank(userName) || StringUtils.isBlank(bindMobile)
         if (StringUtils.isBlank(userName) || StringUtils.isBlank(bindMobile)

+ 103 - 3
src/main/java/com/caimei365/user/service/impl/ShopServiceImpl.java

@@ -2,12 +2,23 @@ package com.caimei365.user.service.impl;
 
 
 import com.caimei365.user.mapper.BaseUserDao;
 import com.caimei365.user.mapper.BaseUserDao;
 import com.caimei365.user.mapper.RegisterUserDao;
 import com.caimei365.user.mapper.RegisterUserDao;
+import com.caimei365.user.model.BaseUser;
+import com.caimei365.user.model.JsonModel;
+import com.caimei365.user.model.OperationVo;
+import com.caimei365.user.model.UserPo;
 import com.caimei365.user.service.RedisService;
 import com.caimei365.user.service.RedisService;
 import com.caimei365.user.service.ShopService;
 import com.caimei365.user.service.ShopService;
+import com.caimei365.user.utils.Md5Util;
+import com.caimei365.user.utils.RequestUtil;
+import com.caimei365.user.utils.ValidateUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.web.server.ServerWebExchange;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 
 /**
 /**
  * Description
  * Description
@@ -26,7 +37,96 @@ public class ShopServiceImpl implements ShopService {
     @Resource
     @Resource
     private RegisterUserDao registerUserDao;
     private RegisterUserDao registerUserDao;
 
 
-
-
-
+    /**
+     * PC端供应商注册
+     *
+     * @param source                注册来源: 0网站 1小程序
+     * @param name                  供应商公司名称
+     * @param sname                 供应商公司简称
+     * @param bindMobile            企业绑定手机号
+     * @param email                 邮箱
+     * @param smsCode               手机验证码(旧:mobileCode)
+     * @param password              密码
+     * @param passWordConfirm       用户确认密码
+     * @param linkMan               联系人
+     * @param provinceID            省
+     * @param cityID                市
+     * @param townID                所在县区Id
+     * @param address               地址
+     * @param socialCreditCode      统一社会信用代码
+     * @param businessLicenseImage  营业执照
+     * @param firstShopType         医疗=1和非医疗=2
+     * @param secondShopType        医疗的二级分类 一类器械=1、二类器械 =2、三类器械=3、其他=4 /// 1和非医疗没有二级分类
+     * @param mainpro               主打项目
+     * @param isAgreed              是否同意勾选同意协议,1是,其他否
+     * @param serverWebExchange     ServerWebExchange(新参数)
+     * @return BaseUser
+     */
+    @Override
+    public JsonModel<BaseUser> pcRegister(Integer source, String name, String sname, String bindMobile, String email, String smsCode, String password, String passWordConfirm, String linkMan, Integer provinceID, Integer cityID, Integer townID, String address, String socialCreditCode, String businessLicenseImage, String firstShopType, String secondShopType, String mainpro, Integer isAgreed, ServerWebExchange serverWebExchange) {
+        // 打印IP
+        String ip = RequestUtil.getIp(serverWebExchange);
+        log.info("X-Forwarded-For:" + ip);
+        // 参数校验
+        if (StringUtils.isBlank(name) || StringUtils.isBlank(bindMobile)
+                || StringUtils.isBlank(password) || StringUtils.isBlank(passWordConfirm)
+                || StringUtils.isBlank(smsCode) || StringUtils.isBlank(linkMan)) {
+            return JsonModel.error("参数异常", null);
+        }
+        JsonModel model = ValidateUtil.validateMobile(bindMobile);
+        if (model.getCode() == -1) {
+            return model;
+        }
+        if (!password.equals(passWordConfirm)) {
+            return JsonModel.error("输入的密码不一致", null);
+        }
+        if (1 != isAgreed) {
+            return JsonModel.error("请勾选同意协议", null);
+        }
+        // 查找用户表是否存在
+        Integer dbUserId = baseUserDao.getUserIdByMobile(bindMobile);
+        if (dbUserId > 0) {
+            return JsonModel.error("该手机号已被使用", null);
+        }
+        // 查找运营人员表是否存在
+        Integer dbOperationId = baseUserDao.getOperationIdByMobile(bindMobile);
+        if (dbOperationId > 0) {
+            return JsonModel.error("您已是机构运营人员,无需再注册机构", null);
+        }
+        String redisSmsCode = (String) redisService.get("code:" + bindMobile);
+        if (redisSmsCode.equals(smsCode)) {
+            return JsonModel.error("手机验证码错误", null);
+        }
+        if (StringUtils.isNotBlank(email)) {
+            dbUserId = baseUserDao.getUserIdByEmail(email);
+            if (dbUserId > 0) {
+                return JsonModel.error("该邮箱已被使用", null);
+            }
+/*            shop.setContractEmail1(user.getEmail());
+            shop.setContractEmail2(user.getEmail());*/
+        }
+        /*
+            组装用户数据 user
+         */
+        UserPo user = new UserPo();
+        // 设置日期时间格式
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String current = dateFormat.format(new Date());
+        // 密码
+        user.setPassword(Md5Util.md5(password));
+        // 注册IP
+        user.setRegisterIp(ip);
+        // 用户类型,供应商1,会员机构3,普通机构4
+        user.setRegisterUserTypeId(1);
+        user.setUserIdentity(3);
+        user.setUserPermission(3);
+        user.setRegisterTime(current);
+        user.setUserName(sname);
+        //待审查资料
+        user.setManufacturerStatus(3);
+        user.setValidFlag(1);
+        user.setAgreeFlag(1);
+        registerUserDao.insertShopUser(user);
+        return null;
+    }
 }
 }

+ 1 - 1
src/main/java/com/caimei365/user/utils/ReduestUtil.java → src/main/java/com/caimei365/user/utils/RequestUtil.java

@@ -12,7 +12,7 @@ import java.util.Objects;
  * @author : Charles
  * @author : Charles
  * @date : 2021/3/8
  * @date : 2021/3/8
  */
  */
-public class ReduestUtil {
+public class RequestUtil {
 
 
     public static String getIp(ServerWebExchange serverWebExchange){
     public static String getIp(ServerWebExchange serverWebExchange){
         ServerHttpRequest request = serverWebExchange.getRequest();
         ServerHttpRequest request = serverWebExchange.getRequest();

+ 5 - 0
src/main/resources/mapper/BaseUserMapper.xml

@@ -59,5 +59,10 @@
         where mobile = #{mobile} and delFlag = '0'
         where mobile = #{mobile} and delFlag = '0'
         limit 1
         limit 1
     </select>
     </select>
+    <select id="getUserIdByEmail" resultType="java.lang.Integer">
+        select userID from user
+        where email = #{mobile} and userIdentity in (1,2,3,4)
+        limit 1
+    </select>
 
 
 </mapper>
 </mapper>