Selaa lähdekoodia

商家小程序登录

FengChaoYu 5 päivää sitten
vanhempi
commit
45fc390ebe

+ 4 - 0
src/main/java/com/gree/mall/contest/config/aop/ApiAspect.java

@@ -70,6 +70,10 @@ public class ApiAspect {
             throw new RemoteServiceException("暂无权限访问,请联系相关人员");
         }
 
+        if (Constant.MINIAPP_API.equals(issuer) && StringUtils.isBlank(CommonUtils.getAPPID())) {
+            throw new RemoteServiceException(ResponseHelper.ResponseCode_AUTH_ERROR, "appid为空,请求不合法");
+        }
+
     }
 
     private Method getSourceMethod(JoinPoint jp) {

+ 29 - 0
src/main/java/com/gree/mall/contest/controller/mini/admin/MiniAdminCompanyWechatOtherController.java

@@ -0,0 +1,29 @@
+package com.gree.mall.contest.controller.mini.admin;
+
+import com.gree.mall.contest.helper.ResponseHelper;
+import com.gree.mall.contest.logic.admin.AdminCompanyWechatOtherLogic;
+import com.gree.mall.contest.plus.entity.AdminCompanyWechatOther;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+@RestController
+@Tag(name = "小程序其他配置", description = "小程序其他配置")
+@RequestMapping(value = "/mini/admin/company/other", produces = "application/json; charset=utf-8")
+@RequiredArgsConstructor
+public class MiniAdminCompanyWechatOtherController {
+    private final AdminCompanyWechatOtherLogic adminCompanyWechatOtherLogic;
+
+
+    @GetMapping("/getOne")
+    @Operation(summary = "获取企业其他配置")
+    public ResponseHelper<AdminCompanyWechatOther> getOne(HttpServletRequest request) {
+
+        return ResponseHelper.success(adminCompanyWechatOtherLogic.getOne(request));
+    }
+}

+ 15 - 0
src/main/java/com/gree/mall/contest/controller/mini/common/MiniCommonController.java

@@ -10,6 +10,7 @@ import com.gree.mall.contest.exception.RemoteServiceException;
 import com.gree.mall.contest.helper.ResponseHelper;
 import com.gree.mall.contest.logic.CarouselMapLogic;
 import com.gree.mall.contest.logic.ExpressLogic;
+import com.gree.mall.contest.logic.SMSLogic;
 import com.gree.mall.contest.logic.common.CommonLogic;
 import com.gree.mall.contest.logic.common.WechatLogic;
 import com.gree.mall.contest.plus.entity.*;
@@ -52,6 +53,7 @@ public class MiniCommonController {
     private final OrderInfoService orderInfoService;
     private final OrderDetailService orderDetailService;
     private final AdminCompanyWechatOtherService adminCompanyWechatOtherService;
+    private final SMSLogic smsLogic;
 
     @PostMapping("/upload")
     @Operation(summary = "文件上传")
@@ -140,6 +142,19 @@ public class MiniCommonController {
         return ResponseHelper.success(map);
     }
 
+    @ApiNotAuth
+    @PostMapping("/sms/send")
+    @Operation(summary = "发送验证码")
+    public ResponseHelper sendSms(
+            @Parameter(description = "手机号码", required = true) @RequestParam String phone,
+            @Parameter(description = "滑动验证key") @RequestParam(required = false) String key,
+            @Parameter(description = "滑动验证数值") @RequestParam(required = false) String vrifyCode,
+            @Parameter(description = "发送类型 LOGIN=手机号登录 RESET=找回密码") @RequestParam(required = false, defaultValue = "LOGIN") String sendType
+    ) throws Exception {
+        smsLogic.sendSms(phone, key, vrifyCode, sendType);
+        return ResponseHelper.success();
+    }
+
     @GetMapping("/config/get")
     @Operation(summary = "获取小程序配置")
     public ResponseHelper<AdminCompanyWechat> getConfig(HttpServletRequest request) {

+ 48 - 4
src/main/java/com/gree/mall/contest/controller/mini/user/MiniUserController.java

@@ -5,12 +5,15 @@ import com.aliyuncs.utils.StringUtils;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.contest.annotation.ApiNotAuth;
+import com.gree.mall.contest.bean.admin.AdminUserBean;
 import com.gree.mall.contest.bean.user.MyProfitBean;
 import com.gree.mall.contest.bean.user.RankBean;
 import com.gree.mall.contest.bean.user.RankItemBean;
 import com.gree.mall.contest.bean.user.UserWxBean;
+import com.gree.mall.contest.constant.Constant;
 import com.gree.mall.contest.exception.RemoteServiceException;
 import com.gree.mall.contest.helper.ResponseHelper;
+import com.gree.mall.contest.logic.admin.AdminUserLogic;
 import com.gree.mall.contest.logic.user.UserLogic;
 import com.gree.mall.contest.plus.entity.OrderShare;
 import com.gree.mall.contest.plus.entity.User;
@@ -19,10 +22,13 @@ import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
 
 @Slf4j
 @RestController
@@ -33,6 +39,8 @@ public class MiniUserController {
 
 
     private final UserLogic userLogic;
+    private final AdminUserLogic adminUserLogic;
+    private final RedisLockRegistry redisLockRegistry;
 
     @PostMapping("/bind")
     @Operation(summary = "绑定业务员")
@@ -72,11 +80,12 @@ public class MiniUserController {
             @Parameter(description = "业务员用户id") @RequestParam(required = false) String serviceId,
             @Parameter(description = "code", required = true) @RequestParam String code,
             @Parameter(description = "公众号openid") @RequestParam(required = false) String mpOpenId,
+            @Parameter(description = "获取验证手机号码code") @RequestParam(required = false) String phoneCode,
             HttpServletRequest request
     ) throws Exception {
         UserWxBean userWxBean;
         log.info("微信授权 code:{} serviceId:{} ", code, serviceId);
-        userWxBean = userLogic.addUser(code, serviceId, mpOpenId, request);
+        userWxBean = userLogic.addUser(code, serviceId, mpOpenId, phoneCode, request);
         userLogic.addVisit(request, userWxBean.getUserId());
         log.info(userWxBean.toString());
         return ResponseHelper.success(userWxBean);
@@ -172,12 +181,47 @@ public class MiniUserController {
         return ResponseHelper.success(user);
     }
 
-    @Operation(summary = "续期token")
     @PostMapping("/renewal")
+    @Operation(summary = "续期token")
     public ResponseHelper<String> renewal(
-            @RequestParam String token
+            @Parameter(description = "小程序 1=用户端 2=商家端", required = true) @RequestParam Integer flag,
+            @Parameter(description = "token", required = true) @RequestParam String token
     ) throws RemoteServiceException {
-        String newToken = userLogic.renewal(token);
+        String newToken = flag == 1 ? userLogic.renewal(token) : adminUserLogic.renewal(token).getToken();
         return ResponseHelper.success(newToken);
     }
+
+    @ApiNotAuth
+    @PostMapping("/login")
+    @Operation(summary = "登录")
+    public ResponseHelper<AdminUserBean> login(
+            @Parameter(description = "帐号", required = true) @RequestParam String userName,
+            @Parameter(description = "密码") @RequestParam(required = false) String password,
+            @Parameter(description = "验证码") @RequestParam(required = false) String code,
+            @Parameter(description = "账号登录 true=是 false=否") @RequestParam Boolean isAccount
+    ) throws RemoteServiceException, InterruptedException {
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_LOGIN + userName);
+        if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
+            throw new RemoteServiceException("系统繁忙请稍后再试");
+        }
+        try {
+            AdminUserBean adminUserBean = adminUserLogic.miniLogin(userName, password, code, isAccount);
+            return ResponseHelper.success(adminUserBean);
+        } finally {
+            obtain.unlock();
+        }
+    }
+
+    @ApiNotAuth
+    @PostMapping("/reset/password/getCode")
+    @Operation(summary = "找回密码-获取验证码")
+    public ResponseHelper miniResetPasswordGetCode(
+            @Parameter(description = "手机号", required = true) @RequestParam String mobile,
+            @Parameter(description = "短信验证码", required = true) @RequestParam String code,
+            @Parameter(description = "密码", required = true) @RequestParam String password
+    ) throws RemoteServiceException {
+        adminUserLogic.miniResetPasswordGetCode(mobile, code, password);
+        return ResponseHelper.success();
+    }
+
 }

+ 1 - 1
src/main/java/com/gree/mall/contest/controller/pc/admin/AdminCompanyWechatOtherController.java

@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletRequest;
 
 @RestController
 @Tag(name = "小程序其他配置", description = "小程序其他配置")
-@RequestMapping(value = "/admin/company/other", produces = "application/json; charset=utf-8")
+@RequestMapping(value = "/pc/admin/company/other", produces = "application/json; charset=utf-8")
 @RequiredArgsConstructor
 public class AdminCompanyWechatOtherController {
     

+ 120 - 27
src/main/java/com/gree/mall/contest/logic/admin/AdminUserLogic.java

@@ -25,6 +25,7 @@ import com.gree.mall.contest.plus.entity.*;
 import com.gree.mall.contest.plus.service.*;
 import com.gree.mall.contest.utils.CommonUtils;
 import com.gree.mall.contest.utils.JwtUtils;
+import com.gree.mall.contest.utils.MD5Utils;
 import com.gree.mall.contest.utils.RedisUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -96,17 +97,17 @@ public class AdminUserLogic {
         }
         //如果是admin操作非admin账号登陆不需要判断密码是否正确
         AdminUserCom adminUser1 = commonLogic.getAdminUser();
-        if(adminUser1 == null || !(adminUser1.getUserName().equals("admin")) && !StringUtils.equals(userName,"admin")) {
+        if (adminUser1 == null || !(adminUser1.getUserName().equals("admin")) && !StringUtils.equals(userName, "admin")) {
 
             String value = (String) redisUtil.get(Constant.RedisPrefix.TOKEN_VERIFICATION + code);
-            if(StringUtils.isBlank(value)){
+            if (StringUtils.isBlank(value)) {
                 throw new RemoteServiceException("验证码过期,请刷新验证码重试");
             }
             if (!value.equals(codeValue)) {
                 throw new RemoteServiceException("验证码错误");
             }
 
-            if(adminUser.getLoginErrNum() >= 3){
+            if (adminUser.getLoginErrNum() >= 3) {
                 throw new RemoteServiceException("登陆失败,您已连续输入错误3次密码,请联系管理人员重置密码");
             }
 
@@ -186,7 +187,7 @@ public class AdminUserLogic {
         if (!StringUtils.isEmpty(adminUser1.getServiceProviderId())
                 && adminUser1.getServiceProviderId().equals(adminUser.getServiceProviderId()) &&
                 (adminUser1.getType().equals(RoleTypeEnum.B.getCode()))
-        ){
+        ) {
             adminUser.setPassword(SecureUtil.md5(password));
             adminUser.setLoginErrNum(0);
             adminUser.updateById();
@@ -199,7 +200,7 @@ public class AdminUserLogic {
             adminUser.setLoginErrNum(0);
             adminUser.updateById();
 
-        }else {
+        } else {
             throw new RemoteServiceException("账号不允许重置别人密码");
         }
     }
@@ -220,7 +221,7 @@ public class AdminUserLogic {
         }
         //当前用户选择的部门
         MerchantWebsit merchantWebsit = merchantWebsitService.getById(adminUser.getAdminWebsitId());
-        if(merchantWebsit == null){
+        if (merchantWebsit == null) {
             throw new RemoteServiceException("请选择部门");
         }
         //需要用户roleId
@@ -234,7 +235,7 @@ public class AdminUserLogic {
         if (adminUser.getRoleName().equals("推单员"))
             throw new RemoteServiceException("推单员需要在推单员列表配置账号");
 
-        if(curAdminUser.getType().equals(RoleTypeEnum.B.getCode())) {
+        if (curAdminUser.getType().equals(RoleTypeEnum.B.getCode())) {
             adminUser.setType(RoleTypeEnum.D.getCode());
             adminUser.setServiceProviderId(curAdminUser.getServiceProviderId());
         }
@@ -259,10 +260,10 @@ public class AdminUserLogic {
         }
         //当前用户选择的部门
         MerchantWebsit merchantWebsit = merchantWebsitService.getById(newUser.getAdminWebsitId());
-        if(merchantWebsit == null){
+        if (merchantWebsit == null) {
             throw new RemoteServiceException("请选择部门");
         }
-        this.setType(admin,oldUser,newUser);
+        this.setType(admin, oldUser, newUser);
 
         newUser.setRoleName(addUserRole.getName());
         newUser.setUserName(null);
@@ -273,26 +274,27 @@ public class AdminUserLogic {
 
     /**
      * 用户类型处理
+     *
      * @param curAdmin
      * @param oldAdmin
      * @param newAdmin
      * @return
      */
-    public AdminUser setType(AdminUserCom curAdmin,AdminUser oldAdmin,AdminUser newAdmin){
-        if(StringUtils.isBlank(newAdmin.getType())){
+    public AdminUser setType(AdminUserCom curAdmin, AdminUser oldAdmin, AdminUser newAdmin) {
+        if (StringUtils.isBlank(newAdmin.getType())) {
             return newAdmin;
         }
         //服务商不可变更服务商信息
-        if(curAdmin.getType().equals(oldAdmin.getType()) && !curAdmin.getUserName().equals("admin")){
+        if (curAdmin.getType().equals(oldAdmin.getType()) && !curAdmin.getUserName().equals("admin")) {
             throw new RemoteServiceException("您暂无权限变更");
         }
         //如果是平台添加帐号则为业务员
         //如果是商家添加账号则为子账号
-        if(oldAdmin.getType().equals(RoleTypeEnum.A.getCode())){
+        if (oldAdmin.getType().equals(RoleTypeEnum.A.getCode())) {
             newAdmin.setType(RoleTypeEnum.A.getCode());
-        }else if(oldAdmin.getType().equals(RoleTypeEnum.B.getCode())){
+        } else if (oldAdmin.getType().equals(RoleTypeEnum.B.getCode())) {
             newAdmin.setType(RoleTypeEnum.D.getCode());
-        }else{
+        } else {
             newAdmin.setType(oldAdmin.getType());
         }
         return newAdmin;
@@ -303,12 +305,12 @@ public class AdminUserLogic {
      *
      * @return
      */
-    public IPage<AdminUser> list(String adminWebsitId,String roleId, Boolean status, String userName, Integer pageNum, Integer pageSize) {
+    public IPage<AdminUser> list(String adminWebsitId, String roleId, Boolean status, String userName, Integer pageNum, Integer pageSize) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
 
         List<String> adminWebsitIds = adminUser.getAdminWebsitIds();
 
-        if(StringUtils.isNotBlank(adminWebsitId)) {
+        if (StringUtils.isNotBlank(adminWebsitId)) {
             List<MerchantWebsit> list = new ArrayList<>();
             list.addAll(commonLogic.queryAllChild(list, adminWebsitId));
             adminWebsitIds = list.stream().map(MerchantWebsit::getWebsitId).collect(Collectors.toList());
@@ -316,11 +318,11 @@ public class AdminUserLogic {
             adminWebsitIds.add(adminWebsitId);
         }
         IPage<AdminUser> page = adminUserService.lambdaQuery()
-                .in(CollectionUtils.isNotEmpty(adminWebsitIds),AdminUser::getAdminWebsitId,adminWebsitIds)
+                .in(CollectionUtils.isNotEmpty(adminWebsitIds), AdminUser::getAdminWebsitId, adminWebsitIds)
                 .eq(StringUtils.isNotBlank(roleId), AdminUser::getRoleId, roleId)
                 .eq(status != null, AdminUser::getStatus, status)
-                .and(StringUtils.isNotBlank(userName),item -> item.like(AdminUser::getUserName, userName)
-                .or().like(AdminUser::getNickName,userName)
+                .and(StringUtils.isNotBlank(userName), item -> item.like(AdminUser::getUserName, userName)
+                        .or().like(AdminUser::getNickName, userName)
                 )
 
                 .orderByDesc(AdminUser::getCreateTime)
@@ -413,7 +415,7 @@ public class AdminUserLogic {
             return list.stream().map(AdminModule::getModuleId).collect(Collectors.toList());
         }
         List<AdminUserModuleRela> list = adminUserModuleRelaService.lambdaQuery()
-                .eq(AdminUserModuleRela::getFlag,1)
+                .eq(AdminUserModuleRela::getFlag, 1)
                 .eq(AdminUserModuleRela::getAdminRoleId, adminRoleId).list();
         if (CollectionUtils.isEmpty(list)) {
             return new ArrayList<>();
@@ -493,16 +495,17 @@ public class AdminUserLogic {
 
     /**
      * 找回密码-获取验证码
+     *
      * @param userName
      * @param mobile
      * @param code
      * @return
      */
-    public AdminUserBean resetPasswordGetCode(String userName,String mobile, String code) {
+    public AdminUserBean resetPasswordGetCode(String userName, String mobile, String code) {
         smsLogic.checkSmsCode(mobile, code, "RESET");
 
         final AdminUser adminUser = adminUserService.lambdaQuery()
-                .eq(AdminUser::getUserName,userName)
+                .eq(AdminUser::getUserName, userName)
                 .eq(AdminUser::getLinkPhone, mobile)
                 .one();
 
@@ -515,12 +518,37 @@ public class AdminUserLogic {
         bean.setUserName(adminUser.getUserName());
         bean.setToken(IdUtil.simpleUUID());
 
-        redisUtil.set(adminUser.getAdminUserId() + ":" + bean.getToken(), bean.getToken(), 5*60);
+        redisUtil.set(adminUser.getAdminUserId() + ":" + bean.getToken(), bean.getToken(), 5 * 60);
         return bean;
     }
 
     /**
+     * 找回密码-获取验证码
+     *
+     * @param mobile
+     * @param code
+     * @param password
+     * @return
+     */
+    public void miniResetPasswordGetCode(String mobile, String code, String password) {
+        if (StringUtils.isBlank(password)) {
+            throw new RemoteServiceException("新密码不能为空");
+        }
+        smsLogic.checkSmsCode(mobile, code, "RESET");
+
+        final boolean update = adminUserService.lambdaUpdate()
+                .set(AdminUser::getPassword, MD5Utils.md5(password))
+                .eq(AdminUser::getLinkPhone, mobile)
+                .update();
+
+        if (!update) {
+            throw new RemoteServiceException("账号不存在");
+        }
+    }
+
+    /**
      * 找回密码-更新密码
+     *
      * @param adminUserId
      * @param token
      * @param newPassword
@@ -532,8 +560,8 @@ public class AdminUserLogic {
             throw new RemoteServiceException("超时操作,请重新找回");
         }
 
-        String value = (String)redisUtil.get(redisKey);
-        if(!StringUtils.equals(value, token)) {
+        String value = (String) redisUtil.get(redisKey);
+        if (!StringUtils.equals(value, token)) {
             throw new RemoteServiceException("修改密码,参数异常");
         }
 
@@ -571,10 +599,75 @@ public class AdminUserLogic {
         AdminUserBean bean = (AdminUserBean) o;
         final AdminUser adminUser = adminUserService.getById(bean.getAdminUserId());
 
-        bean.setToken(JwtUtils.refreshToken(token, Constant.PC_API));
+        final JwtUtils.JwtParseResult result = JwtUtils.parseToken(token);
+
+        bean.setToken(JwtUtils.refreshToken(token, result.getIssuer()));
 
         //存放到redis
         redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + bean.getToken(), adminUser, 2 * 60 * 60 * 1000);
         return bean;
     }
+
+    public AdminUserBean miniLogin(String userName, String password, String code, Boolean isAccount) {
+
+        AdminUser adminUser;
+        if (isAccount) {
+            adminUser = adminUserService.lambdaQuery()
+                    .eq(AdminUser::getUserName, userName)
+                    .one();
+        } else {
+            adminUser = adminUserService.lambdaQuery()
+                    .eq(AdminUser::getLinkPhone, userName)
+                    .last("limit 1")
+                    .one();
+        }
+        if (adminUser == null) {
+            throw new RemoteServiceException("帐号不存在");
+        }
+
+        if (adminUser.getLoginErrNum() >= 3) {
+            throw new RemoteServiceException("登陆失败,账号已锁,请联系管理人员重置密码");
+        }
+
+        if (!isAccount) {
+            smsLogic.checkSmsCode(userName, code, "LOGIN");
+        } else {
+            if (!StringUtils.equals(adminUser.getPassword(), SecureUtil.md5(password))) {
+                adminUser.setLoginErrNum(adminUser.getLoginErrNum() + 1);
+                adminUserService.saveOrUpdate(adminUser);
+                //记录错误次数
+                throw new RemoteServiceException("帐号密码错误");
+            }
+        }
+
+        if (!adminUser.getStatus()) {
+            throw new RemoteServiceException("帐号冻结中,请联系相关管理人员");
+        }
+
+        adminUser.setLoginErrNum(0);
+        adminUser.setLastLoginTime(new Date());
+        adminUser.updateById();
+
+        AdminUserBean adminUserBean = new AdminUserBean();
+        BeanUtils.copyProperties(adminUser, adminUserBean);
+
+        // 注入服务对象
+        if (RoleTypeEnum.isMerchant(adminUser.getType())) {
+            if (StringUtils.isNotBlank(adminUser.getServiceProviderId())) {
+                adminUserBean.setMerchant(merchantService.getById(adminUser.getServiceProviderId()));
+            }
+        }
+
+        // token到期时间
+        final DateTime offset = DateUtil.offset(DateUtil.date(), DateField.MINUTE, Math.toIntExact(expiration));
+        adminUserBean.setExpireTimeToken(offset);
+
+        //不返回密码
+        adminUserBean.setPassword(null);
+        adminUserBean.setToken(JwtUtils.generateToken(adminUser.getAdminUserId(), adminUser.getUserName(), adminUser.getNickName(), adminUser.getType(), Constant.MINIAPP_API));
+        //存放到redis
+        redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + adminUserBean.getToken(), adminUser, expiration * 1000);
+
+        return adminUserBean;
+    }
 }

+ 28 - 19
src/main/java/com/gree/mall/contest/logic/user/UserLogic.java

@@ -762,14 +762,26 @@ public class UserLogic {
      * @param code
      * @param serviceId
      * @param mpOpenId
+     * @param phoneCode
      * @return
      * @throws RemoteServiceException
      * @throws InterruptedException
      */
     @Transactional
-    public UserWxBean addUser(String code, String serviceId, String mpOpenId, HttpServletRequest request) throws RemoteServiceException, InterruptedException {
+    public UserWxBean addUser(String code, String serviceId, String mpOpenId, String phoneCode, HttpServletRequest request) throws RemoteServiceException, InterruptedException {
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
         final WechatOpenBean wechatOpenBean = wechatLogic.authToken(code, currentCompanyWechat.getSubAppId());
+        String openId = wechatOpenBean.getOpenid();
+        String sessionKey = wechatOpenBean.getSessionKey();
+        String unionId = wechatOpenBean.getUnionid();
+
+        log.info("小程序授权openId:{},unionId:{}", openId, unionId);
+        //手机号授权
+        String mobile = "";
+        if (StringUtils.isNotBlank(phoneCode)) {
+            mobile = wechatLogic.authMobile(phoneCode, currentCompanyWechat.getSubAppId());
+            wechatOpenBean.setMobile(mobile);
+        }
 
         log.info("【微信授权】:{}", JSONUtil.toJsonStr(wechatOpenBean));
 
@@ -807,15 +819,18 @@ public class UserLogic {
                 throw new RemoteServiceException("用户已被冻结");
             }
             //判断该手机号是否为业务员
-            user = userToService(user, currentCompanyWechat);
+            if (currentCompanyWechat.getFlag() == 1) {
+                user = userToService(user, currentCompanyWechat);
+                if (StringUtils.isEmpty(user.getServiceId()) && StringUtils.isNotEmpty(serviceId)) {
+                    user.setServiceId(serviceId);
+                    user.setServiceTime(new Date());
+                }
+            }
 
-            user.setUnionId(wechatOpenBean.getUnionid());
-            user.setSessionKey(wechatOpenBean.getSessionKey());
+            user.setUnionId(unionId);
+            user.setSessionKey(sessionKey);
             user.setLastLoginTime(new Date());
-            if (StringUtils.isEmpty(user.getServiceId()) && StringUtils.isNotEmpty(serviceId)) {
-                user.setServiceId(serviceId);
-                user.setServiceTime(new Date());
-            }
+
             user.setOpenId(wechatOpenBean.getOpenid());
             user.updateById();
             return this.supplyUser(user);
@@ -847,6 +862,10 @@ public class UserLogic {
             userWxBean.setWebsitNumber(adminWebsit.getWebsitNumber());
             userWxBean.setWebsitName(adminWebsit.getName());
         }
+        return getUserWxBean(user, userWxBean);
+    }
+
+    private UserWxBean getUserWxBean(User user, UserWxBean userWxBean) {
         if (StringUtils.isNotBlank(user.getServiceId())) {
             final User serviceUser = userService.getById(user.getServiceId());
             ServiceWorkerBean bean = new ServiceWorkerBean();
@@ -954,7 +973,6 @@ public class UserLogic {
                     user.setWorkName(wait.getName());
                     user.setWorkUserId(workUserId);
                     user.setWorkPhone(wait.getMobile());
-//                    user.setWorkQrcode(list.get(0).getQrCode());
                     user.setPosition(wait.getPosition());
                     user.setWebsitId(wait.getWebsitId());
                     user.setWebsitName(wait.getWebsitName());
@@ -996,16 +1014,7 @@ public class UserLogic {
         UserWxBean userWxBean = new UserWxBean();
         BeanUtils.copyProperties(user, userWxBean);
         userWxBean.setShoppingCartNums(shoppingCartLogic.total(userWxBean.getUserId()));
-        if (StringUtils.isNotBlank(user.getServiceId())) {
-            final User serviceUser = userService.getById(user.getServiceId());
-            ServiceWorkerBean bean = new ServiceWorkerBean();
-            if (StringUtils.isNotBlank(serviceUser.getWebsitId())) {
-                bean.setWebsitId(Long.parseLong(serviceUser.getWebsitId()));
-            }
-            bean.setWebsit(serviceUser.getWebsitName());
-            userWxBean.setServiceWorkerBean(bean);
-        }
-        return userWxBean;
+        return getUserWxBean(user, userWxBean);
     }
 
     //保存用户信息