Browse Source

协销登录

chao 4 years ago
parent
commit
6a2ae9a8ad

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

@@ -28,7 +28,7 @@ public class BaseApi {
     @Value(value = "${swagger.enabled}")
     private Boolean swaggerEnabled;
 
-    @GetMapping("/")
+    @GetMapping({"", "/"})
     public String welcome(){
         if (swaggerEnabled){
             return "欢迎使用!<br><a href='http://47.119.112.46:18011/doc.html'>doc接口文档入口(beta)</a><br><a href='http://47.119.112.46:18011/swagger-ui/index.html'>swagger接口文档入口(beta)</a>";

+ 47 - 0
src/main/java/com/caimei365/user/controller/SellerApi.java

@@ -0,0 +1,47 @@
+package com.caimei365.user.controller;
+
+import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.dto.LoginPasswordDto;
+import com.caimei365.user.model.vo.UserLoginVo;
+import com.caimei365.user.service.SellerService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/3/24
+ */
+@Api(tags="协销用户API")
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/user/seller")
+public class SellerApi {
+
+    private final SellerService sellerService;
+
+    /**
+     * 协销登录(手机号,密码)
+     *
+     * spi旧接口:/seller/login
+     *
+     * @param loginPasswordDto {
+     *                           mobileOrEmail 手机号
+     *                           password 密码
+     *                         }
+     * @return UserLoginVo
+     */
+    @ApiOperation("协销登录(手机号,密码)")
+    @PostMapping("/login")
+    public ResponseJson<UserLoginVo> passwordLogin(LoginPasswordDto loginPasswordDto) {
+        String mobile = loginPasswordDto.getMobileOrEmail();
+        String password = loginPasswordDto.getPassword();
+        String unionId = loginPasswordDto.getUnionId();
+        return sellerService.passwordLogin(mobile, password, unionId);
+    }
+}

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

@@ -67,7 +67,7 @@ public class ShopApi {
      *                        faxNumber                 传真号(fax)
      *                        companyNature             传真号(nature)
      *                        turnover                  年营业额
-     *                        medicalPracticeLicenseImg 医疗执业许可证(medicalPracticeLicenseImg1)
+     *                        medicalPracticeLicense    医疗执业许可证(medicalPracticeLicenseImg1)
      *                        shopDesc                  公司介绍(info)
      *                        businessScope             经营范围
      *                        logo                      公司LOGO

+ 28 - 0
src/main/java/com/caimei365/user/mapper/SellerMapper.java

@@ -0,0 +1,28 @@
+package com.caimei365.user.mapper;
+
+import com.caimei365.user.model.vo.UserLoginVo;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/3/24
+ */
+@Mapper
+public interface SellerMapper {
+    /**
+     * 根据手机号获取协销
+     * @param mobile 手机号
+     * @return UserLoginVo
+     */
+    UserLoginVo getLoginSellerByMobile(String mobile);
+
+    /**
+     * 更新协销
+     * @param userId
+     * @param openId
+     * @param unionId
+     */
+    void updateServiceProviderByUserId(Integer userId, String openId, String unionId);
+}

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

@@ -28,4 +28,9 @@ public class LoginPasswordDto implements Serializable {
     @NotNull
     @ApiModelProperty("密码")
     private String password;
+    /**
+     * 微信unionId
+     */
+    @ApiModelProperty("微信unionId")
+    private String unionId;
 }

+ 22 - 0
src/main/java/com/caimei365/user/service/SellerService.java

@@ -0,0 +1,22 @@
+package com.caimei365.user.service;
+
+import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.vo.UserLoginVo;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/3/24
+ */
+public interface SellerService {
+    /**
+     * 协销登录(手机号,密码)
+     *
+     * @param mobile    手机号
+     * @param password  密码
+     * @param unionId   微信unionId
+     * @return UserLoginVo
+     */
+    ResponseJson<UserLoginVo> passwordLogin(String mobile, String password, String unionId);
+}

+ 61 - 0
src/main/java/com/caimei365/user/service/impl/SellerServiceImpl.java

@@ -0,0 +1,61 @@
+package com.caimei365.user.service.impl;
+
+import com.caimei365.user.components.RedisService;
+import com.caimei365.user.mapper.SellerMapper;
+import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.vo.UserLoginVo;
+import com.caimei365.user.service.SellerService;
+import com.caimei365.user.utils.JwtUtil;
+import com.caimei365.user.utils.Md5Util;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Map;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/3/24
+ */
+@Slf4j
+@Service
+public class SellerServiceImpl implements SellerService {
+
+    @Resource
+    private RedisService redisService;
+    @Resource
+    private SellerMapper sellerMapper;
+
+    /**
+     * 协销登录(手机号,密码)
+     *
+     * @param mobile   手机号
+     * @param password 密码
+     * @param unionId  微信unionId
+     * @return UserLoginVo
+     */
+    @Override
+    public ResponseJson<UserLoginVo> passwordLogin(String mobile, String password, String unionId) {
+        if (StringUtils.isBlank(mobile) || StringUtils.isBlank(password)) {
+            return ResponseJson.error("请输入账号密码", null);
+        }
+        if (StringUtils.isBlank(unionId)) {
+            return ResponseJson.error("请输入微信unionId", null);
+        }
+        UserLoginVo seller = sellerMapper.getLoginSellerByMobile(mobile);
+        if (null == seller || !Md5Util.md5(password).equals(seller.getPassword())) {
+            return ResponseJson.error("密码和账户名不匹配" ,null);
+        }
+        String token = JwtUtil.createToken(seller.getUserId());
+        seller.setToken(token);
+        Map<Object, Object> infoData = redisService.getEntries("wxInfo:applets:" + unionId);
+        String openId = (String) infoData.get("openId");
+        sellerMapper.updateServiceProviderByUserId(seller.getUserId(), openId, unionId);
+        log.info("协销账号密码登录openid>>>>" + openId + " ,unionId>>>>>" + unionId);
+        return ResponseJson.success(seller);
+    }
+
+}

+ 27 - 0
src/main/resources/mapper/SellerMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei365.user.mapper.SellerMapper">
+    <select id="getLoginSellerByMobile" resultType="com.caimei365.user.model.vo.UserLoginVo">
+        select u.userID as userId,
+            u.clubID as clubId,
+            u.shopID as shopId,
+            u.userName as userName,
+            u.mobile as mobile,
+            u.bindMobile as bindMobile,
+            u.email as email,
+            u.userPermission as userPermission,
+            u.userIdentity as userIdentity,
+            u.password as password
+        from user u
+        where
+          u.mobile = #{mobile}
+          and u.userIdentity = 1
+          and u.userPermission = 4
+          and u.validFlag = 1
+    </select>
+    <update id="updateServiceProviderByUserId">
+        update serviceprovider
+        set openid = #{openId}, unionId = #{unionId}
+        where userID = #{userId}
+    </update>
+</mapper>

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

@@ -87,7 +87,7 @@
             <if test="turnover != null">
                 turnover = #{turnover},
             </if>
-            <if test="medicalPracticeLicenseImg != null">
+            <if test="medicalPracticeLicense != null">
                 medicalPracticeLicenseImg1 = #{medicalPracticeLicense},
             </if>
             <if test="shopDesc != null">