|
@@ -3,11 +3,9 @@ package com.gree.mall.miniapp.logic.user;
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import com.alibaba.excel.util.CollectionUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.gree.mall.miniapp.bean.user.*;
|
|
|
import com.gree.mall.miniapp.commonmapper.*;
|
|
|
import com.gree.mall.miniapp.constant.Constant;
|
|
@@ -18,7 +16,6 @@ import com.gree.mall.miniapp.exception.RemoteServiceException;
|
|
|
import com.gree.mall.miniapp.helper.ResponseHelper;
|
|
|
import com.gree.mall.miniapp.logic.common.CommonLogic;
|
|
|
import com.gree.mall.miniapp.logic.common.WechatLogic;
|
|
|
-import com.gree.mall.miniapp.logic.common.WorkWechatLogic;
|
|
|
import com.gree.mall.miniapp.logic.coupon.CouponLogic;
|
|
|
import com.gree.mall.miniapp.logic.order.ShoppingCartLogic;
|
|
|
import com.gree.mall.miniapp.plus.entity.*;
|
|
@@ -26,23 +23,17 @@ import com.gree.mall.miniapp.plus.service.*;
|
|
|
import com.gree.mall.miniapp.utils.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
-import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
import me.chanjar.weixin.cp.bean.Gender;
|
|
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
|
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
|
|
-import org.apache.commons.codec.binary.Base64;
|
|
|
-import org.apache.commons.lang.StringEscapeUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.xmlbeans.UserType;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.integration.redis.util.RedisLockRegistry;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -68,8 +59,6 @@ public class UserLogic {
|
|
|
@Autowired
|
|
|
CouponLogic couponLogic;
|
|
|
@Autowired
|
|
|
- WorkWechatLogic workWechatLogic;
|
|
|
- @Autowired
|
|
|
RedisLockRegistry redisLockRegistry;
|
|
|
@Autowired
|
|
|
UserService userService;
|
|
@@ -208,139 +197,6 @@ public class UserLogic {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 企业微信里授权的场景
|
|
|
- *
|
|
|
- * @param code
|
|
|
- * @param serviceId
|
|
|
- * @return
|
|
|
- * @throws WxErrorException
|
|
|
- * @throws RemoteServiceException
|
|
|
- * @throws InterruptedException
|
|
|
- */
|
|
|
- @Transactional
|
|
|
- public UserWxBean addWorkUser(String code, String serviceId,HttpServletRequest request) throws RemoteServiceException, InterruptedException {
|
|
|
- CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
- //企业微信里拉取微信授权
|
|
|
- if (StringUtils.isNotEmpty(serviceId)) {
|
|
|
- User user = userService.getById(serviceId);
|
|
|
- Map<String, Object> returnMap = wechatLogic.authToken(code,currentCompanyWechat);
|
|
|
- String openId = (String) returnMap.get("openid");
|
|
|
- String sessionKey = (String) returnMap.get("session_key");
|
|
|
- //删掉可能存在的openid数据
|
|
|
- userService.lambdaUpdate()
|
|
|
- .eq(User::getOpenId, openId)
|
|
|
- .eq(User::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
|
|
|
- .remove();
|
|
|
- //微信授权,二次绑定微信openid
|
|
|
- user.setOpenId(openId);
|
|
|
- user.setSessionKey(sessionKey);
|
|
|
- user.updateById();
|
|
|
- return this.supplyUser(user);
|
|
|
- }
|
|
|
-
|
|
|
- //企业微信进入
|
|
|
- WxCpMaJsCode2SessionResult wxCpMaJsCode2SessionResult = workWechatLogic.jsCode2Session(code,currentCompanyWechat);
|
|
|
-
|
|
|
- String workUserId = wxCpMaJsCode2SessionResult.getUserId();
|
|
|
- String sessionKey = wxCpMaJsCode2SessionResult.getSessionKey();
|
|
|
-
|
|
|
- String key = Constant.RedisPrefix.LOCK_AUTH + ":" + workUserId;
|
|
|
- Lock obtain = redisLockRegistry.obtain(key);
|
|
|
- if (!obtain.tryLock(2, TimeUnit.SECONDS)) {
|
|
|
- log.error("请勿重复授权");
|
|
|
- return null;
|
|
|
- }
|
|
|
- try {
|
|
|
-
|
|
|
- User user = userService.lambdaQuery()
|
|
|
- .eq(User::getWorkUserId, workUserId)
|
|
|
- .eq(User::getStatus,true)
|
|
|
- .eq(User::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
|
|
|
- .one();
|
|
|
- if (user != null) {
|
|
|
- user.setWorkSessionKey(sessionKey);
|
|
|
- user.setLastLoginTime(new Date());
|
|
|
- user.updateById();
|
|
|
- return this.supplyUser(user);
|
|
|
- }
|
|
|
- //获取企业微信个人信息
|
|
|
- WxCpUser wxCpUser = workWechatLogic.getUser(workUserId,currentCompanyWechat);
|
|
|
- if (wxCpUser == null) {
|
|
|
- List<EnterpriseWechatWorker> list = enterpriseWechatWorkerService.lambdaQuery()
|
|
|
- .eq(EnterpriseWechatWorker::getWechatUserId, workUserId)
|
|
|
- .eq(EnterpriseWechatWorker::getCorpId,"").list();
|
|
|
- if (list.size() > 0) {
|
|
|
- EnterpriseWechatWorker enterpriseWechatWorker = list.get(0);
|
|
|
- wxCpUser = new WxCpUser();
|
|
|
- wxCpUser.setMobile(enterpriseWechatWorker.getMobile());
|
|
|
- wxCpUser.setGender(Gender.UNDEFINED);
|
|
|
- wxCpUser.setAvatar(enterpriseWechatWorker.getQrCode());
|
|
|
- wxCpUser.setName(enterpriseWechatWorker.getName());
|
|
|
- wxCpUser.setStatus(1);
|
|
|
- wxCpUser.setQrCode(enterpriseWechatWorker.getQrCode());
|
|
|
- }
|
|
|
- }
|
|
|
- if (wxCpUser == null) {
|
|
|
- log.error("企业微信授权失败,workUserId:{}", workUserId);
|
|
|
- throw new RemoteServiceException("授权失败,请联系相关人员");
|
|
|
- }
|
|
|
-
|
|
|
- //查询是否能根据手机号查询到微信用户
|
|
|
- if(StringUtils.isNotEmpty(wxCpUser.getMobile())){
|
|
|
- user = this.getUserByMobile(wxCpUser.getMobile(),currentCompanyWechat.getCompanyWechatId());
|
|
|
- }
|
|
|
- Integer count = userService.lambdaQuery()
|
|
|
- .eq(User::getWorkUserId, workUserId)
|
|
|
- .eq(User::getType, UserTypeEnum.SERVICE.toString())
|
|
|
- .eq(User::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
|
|
|
- .count();
|
|
|
- if (user == null) {
|
|
|
- user = new User();
|
|
|
- user.setMobile(wxCpUser.getMobile());
|
|
|
- user.setNickName(wxCpUser.getName());
|
|
|
- if(wxCpUser.getGender() != null) {
|
|
|
- user.setSex(wxCpUser.getGender().getGenderName());
|
|
|
- }
|
|
|
- user.setAvatar(wxCpUser.getAvatar());
|
|
|
- user.setStatus(wxCpUser.getStatus() == 1);
|
|
|
-
|
|
|
- if (count < 1) {
|
|
|
- user.setWorkName(wxCpUser.getName());
|
|
|
- user.setWorkPhone(wxCpUser.getMobile());
|
|
|
- user.setWorkUserId(workUserId);
|
|
|
- user.setType(UserTypeEnum.SERVICE.toString());
|
|
|
- user.setPosition(wxCpUser.getPosition());
|
|
|
- user.setWorkQrcode(wxCpUser.getQrCode());
|
|
|
- user.setWorkSessionKey(sessionKey);
|
|
|
- }
|
|
|
- user.setLastLoginTime(new Date());
|
|
|
- user.setCreateTime(new Date());
|
|
|
- user.setCompanyWechatId(currentCompanyWechat.getCompanyWechatId());
|
|
|
- user.setCompanyName(currentCompanyWechat.getCompanyName());
|
|
|
- user.insert();
|
|
|
- } else {
|
|
|
- if (!user.getStatus()) {
|
|
|
- throw new RemoteServiceException("用户已被冻结");
|
|
|
- }
|
|
|
- if (count < 1) {
|
|
|
- user.setWorkUserId(workUserId);
|
|
|
- user.setWorkName(wxCpUser.getName());
|
|
|
- user.setWorkPhone(wxCpUser.getMobile());
|
|
|
- user.setWorkQrcode(wxCpUser.getQrCode());
|
|
|
- user.setType(UserTypeEnum.SERVICE.toString());
|
|
|
- user.setWorkSessionKey(sessionKey);
|
|
|
- }
|
|
|
- user.setLastLoginTime(new Date());
|
|
|
- user.updateById();
|
|
|
- }
|
|
|
- return this.supplyUser(user);
|
|
|
- } finally {
|
|
|
- obtain.unlock();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 返回小程序用户登录需要的信息
|
|
|
*
|
|
|
* @param user
|
|
@@ -700,6 +556,7 @@ public class UserLogic {
|
|
|
userVisit.setVisitTime(new Date());
|
|
|
userVisit.setCompanyWechatId(currentCompanyWechat.getCurrentCompanyWechatId());
|
|
|
userVisit.setCompanyName(currentCompanyWechat.getCurrentCompanyName());
|
|
|
+ userVisit.setWebsitId("");
|
|
|
userVisit.insert();
|
|
|
} catch (Exception e) {
|
|
|
log.error("新增用户访问记录失败", e);
|