瀏覽代碼

fix seller

he2802 2 年之前
父節點
當前提交
895d447e3a

+ 24 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/distribution/DistributionSellerController.java

@@ -3,11 +3,19 @@ package com.zhongzheng.controller.distribution;
 import java.util.List;
 import java.util.Arrays;
 
+import cn.hutool.core.lang.Validator;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.SellerTokenService;
 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.service.IDistributionSellerService;
 import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
+import com.zhongzheng.modules.user.bo.UserVisitLogAddBo;
+import com.zhongzheng.modules.user.domain.UserWxFollow;
+import com.zhongzheng.modules.user.entity.ClientLoginSeller;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
+import com.zhongzheng.modules.user.vo.UserVo;
 import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,6 +50,8 @@ public class DistributionSellerController extends BaseController {
 
     private final IDistributionSellerService iDistributionSellerService;
 
+    private final SellerTokenService sellerTokenService;
+
     /**
      * 查询分销业务员列表
      */
@@ -87,5 +97,19 @@ public class DistributionSellerController extends BaseController {
         return toAjax(iDistributionSellerService.updateByEditBo(bo) ? 1 : 0);
     }
 
+    /**
+     * 获取用户信息
+     *
+     * @return 用户信息
+     */
+    @ApiOperation("登录业务员用户信息")
+    @GetMapping("getInfo")
+    public AjaxResult<DistributionSellerVo> getInfo(UserVisitLogAddBo bo)
+    {
+        ClientLoginSeller loginUser = sellerTokenService.getLoginUser(ServletUtils.getRequest());
+        DistributionSellerVo vo = iDistributionSellerService.queryById(loginUser.getSeller().getSellerId());
+        vo.setNull();
+        return AjaxResult.success(vo);
+    }
 
 }

+ 8 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/distribution/SellerLoginController.java

@@ -24,7 +24,7 @@ import java.util.Map;
  * @author hjl
  * @date 2021-06-08
  */
-@Api(value = "短信控制器", tags = {"登录控制器"})
+@Api(value = "业务员登录控制器", tags = {"业务员登录控制器"})
 @RequiredArgsConstructor(onConstructor_ = @Autowired)
 @RestController
 @RequestMapping("/app/common/seller")
@@ -47,6 +47,13 @@ public class SellerLoginController extends BaseController {
         return toAjax(iDistributionSellerService.forgetUser(bo) ? 1 : 0);
     }
 
+    @ApiOperation("业务员短信登录")
+    @PostMapping("/sms_login")
+    public AjaxResult sms_login(@RequestBody SellerAppAccountLoginBo bo) {
+        Map<String,Object> map = iDistributionSellerService.smsLogin(bo);
+        return AjaxResult.success(map);
+    }
+
     @ApiOperation("业务员账号登录")
     @PostMapping("/account_login")
     public AjaxResult account_login(@RequestBody SellerAppAccountLoginBo bo) {

+ 30 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/DistributionSellerServiceImpl.java

@@ -96,6 +96,7 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
         inertData.setCreateTime(DateUtils.getNowTime());
         inertData.setUpdateTime(DateUtils.getNowTime());
         inertData.setShareCode(ToolsUtils.getRandomString(8));
+        inertData.setAvatar(bo.getAvatar());
         User userIdCard = iUserService.getOne(new LambdaQueryWrapper<User>()
                 .eq(User::getIdCard,EncryptHandler.encrypt(bo.getIdcard())).last("limit 1"));
         if(Validator.isNotEmpty(userIdCard)){
@@ -229,6 +230,35 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
         return map;
     }
 
+    @Override
+    public Map<String, Object> smsLogin(SellerAppAccountLoginBo bo) {
+        if(bo.getTel()==null){
+            throw new CustomException("手机号不能为空");
+        }
+        String key = Constants.LOGIN_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("该手机号未注册");
+        }
+
+        ClientLoginSeller loginSeller = new ClientLoginSeller();
+        loginSeller.setSeller(seller);
+        Map<String,Object> map = new HashMap<>();
+        map.put(Constants.TOKEN,sellerTokenService.createToken(loginSeller));
+        map.put("user_account",seller.getUserAccount());
+        map.put("full_info",Validator.isEmpty(seller.getIdCard())?false:true); //是否完善身份信息
+        return map;
+    }
+
     @Override
     public DistributionSellerVo queryById(Long sellerId){
         DistributionSeller db = this.baseMapper.selectById(sellerId);

+ 14 - 9
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/SellerTokenService.java

@@ -4,11 +4,15 @@ import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.http.useragent.UserAgent;
 import cn.hutool.http.useragent.UserAgentUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zhongzheng.common.constant.Constants;
 import com.zhongzheng.common.core.redis.RedisCache;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ip.AddressUtils;
 import com.zhongzheng.common.utils.ip.IpUtils;
+import com.zhongzheng.modules.distribution.domain.DistributionSeller;
+import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
+import com.zhongzheng.modules.order.domain.Order;
 import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.entity.ClientLoginSeller;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
@@ -57,7 +61,9 @@ public class SellerTokenService
     private RedisCache redisCache;
 
     @Autowired
-    private IUserService iUserService;
+    private IDistributionSellerService iDistributionSellerService;
+
+
 
     @Resource
     private AuthenticationManager authenticationManager;
@@ -67,11 +73,11 @@ public class SellerTokenService
      *
      * @return 用户信息
      */
-    public ClientLoginUser getLoginUser(HttpServletRequest request)
+    public ClientLoginSeller getLoginUser(HttpServletRequest request)
     {
         //测试用户
         String test_token = request.getHeader("X-Auth-Token");
-        if("test".equals(test_token)){
+        if("test-seller".equals(test_token)){
             return getTestUser();
         }
         // 获取请求携带的令牌
@@ -82,17 +88,16 @@ public class SellerTokenService
             // 解析对应的权限以及用户信息
             String uuid = (String) claims.get(Constants.SELLER_LOGIN_USER_KEY);
             String userKey = getTokenKey(uuid);
-            ClientLoginUser user = redisCache.getCacheObject(userKey);
+            ClientLoginSeller user = redisCache.getCacheObject(userKey);
             return user;
         }
         return null;
     }
 
-    private ClientLoginUser getTestUser(){
-        String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
-        User user = iUserService.queryByUnionId(unionId);
-        ClientLoginUser loginUser = new ClientLoginUser();
-        loginUser.setUser(user);
+    private ClientLoginSeller getTestUser(){
+        DistributionSeller seller = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>().eq(DistributionSeller::getSellerId, 1L));
+        ClientLoginSeller loginUser = new ClientLoginSeller();
+        loginUser.setSeller(seller);
         loginUser.setExpireTime(System.currentTimeMillis()+200);
         return loginUser;
     }

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

@@ -28,4 +28,7 @@ public class SellerAppRegisterBo {
     /** 分享码 */
     @ApiModelProperty("分享码")
     private String shareCode;
+    /** 头像 */
+    @ApiModelProperty("头像")
+    private String avatar;
 }

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

@@ -7,6 +7,7 @@ import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
 import com.zhongzheng.modules.user.bo.UserAppAccountLoginBo;
 import com.zhongzheng.modules.user.bo.UserAppForgetBo;
 import com.zhongzheng.modules.user.bo.UserAppRegisterBo;
+import com.zhongzheng.modules.user.bo.UserAppSmsLoginBo;
 import com.zhongzheng.modules.user.domain.User;
 
 import java.util.Collection;
@@ -61,4 +62,6 @@ public interface IDistributionSellerService extends IService<DistributionSeller>
 	Boolean syncSellerToUser(DistributionSeller seller, User user,Integer type);
 
 	Map<String,Object> accountLogin(SellerAppAccountLoginBo bo);
+
+	Map<String,Object> smsLogin(SellerAppAccountLoginBo bo);
 }

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

@@ -72,4 +72,9 @@ public class DistributionSellerVo {
 	@Excel(name = "分享码")
 	@ApiModelProperty("分享码")
 	private String shareCode;
+
+	public void setNull(){
+		this.setGzhOpenId(null);
+		this.setPassword(null);
+	}
 }