admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -141,8 +141,7 @@
            }
            userInfo = getUserInfoByTaoBaoOpenId(appId, tbUserInfo.getOpenid());
            // 判断用户是否被删除
            if (userInfo != null && userInfo.getState() != null
                  && (userInfo.getState() != UserInfo.STATE_NORMAL))
            if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
               userInfo = null;
            if (userInfo == null) {// 原先的账号不存在
               userInfo = new UserInfo();
@@ -185,9 +184,7 @@
            userInfo = getUserInfoByWXUnionId(appId, weiXinUser.getUnionid());
            // 判断用户是否被删除
            if (userInfo != null && userInfo.getState() != null
                  && (userInfo.getState() != UserInfo.STATE_NORMAL
                     ))
            if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
               userInfo = null;
            // 直接用的微信登录
            if (lastUser == null) {
@@ -324,8 +321,7 @@
            userInfo = getUserInfoByPhone(appId, phone);
            // 判断用户是否被删除
            if (userInfo != null && userInfo.getState() != null
                  && (userInfo.getState() != UserInfo.STATE_NORMAL))
            if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
               userInfo = null;
            if (userInfo == null) {// 原先的账号不存在
@@ -451,7 +447,6 @@
      }
   }
   /**
    * 根据系统与unionid寻找用户
    * 
@@ -524,7 +519,7 @@
      // 剔除被删除掉的用户
      for (int i = 0; i < list.size(); i++) {
         if (list.get(i).getState() !=UserInfo.STATE_NORMAL) {
         if (list.get(i).getState() != UserInfo.STATE_NORMAL) {
            list.remove(i);
            i--;
         }
@@ -856,7 +851,6 @@
      String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, phone);
      redisManager.removeCommonString(key);
      // 采用redis事务防止一个手机号多次注册问题
      String watchKey = StringUtil.Md5("REGISTER:" + phone);
      Jedis jedis = jedisPool.getResource();
@@ -965,8 +959,8 @@
                  InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl());
                  if (asInputStream != null) {
                     FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
                           String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
                                 System.currentTimeMillis() + ""));
                           String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg",
                                 weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
                     if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
                        portrait = result.getUrl();
                  } else {
@@ -1042,7 +1036,8 @@
      UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
      if (userInfo == null) {
         String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()));
         String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey,
               StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()));
         redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(weiXinUser), 60 * 20);
         throw new UserAccountException(101, key);
      }
@@ -1115,7 +1110,7 @@
   }
   @Transactional(rollbackFor=UserAccountException.class)
   @Transactional(rollbackFor = UserAccountException.class)
   @Override
   public void bindWeiXin(AcceptData acceptData, Long uid, String code) throws UserAccountException {
      WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
@@ -1130,18 +1125,15 @@
      }
      bindWeiXin(uid, weiXinUser);
   }
   @Transactional(rollbackFor=UserAccountException.class)
   @Transactional(rollbackFor = UserAccountException.class)
   @Override
   public void bindWeiXin(Long uid,WeiXinUser weiXinUser) throws UserAccountException {
   public void bindWeiXin(Long uid, WeiXinUser weiXinUser) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
      if (user == null) {
         throw new UserAccountException(1, "用户不存在");
      }
      if (weiXinUser == null) {
         throw new UserAccountException(2, "微信帐号授权失败");
      }
@@ -1189,8 +1181,9 @@
         if (asInputStream == null) {
            LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl);
         } else {
            FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String
                  .format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
            FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
                  String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
                        System.currentTimeMillis() + ""));
            if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
               headimgurl = result.getUrl();
            } else {
@@ -1222,9 +1215,6 @@
   @Override
   public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request)
         throws UserAccountException {
      UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone);
      if (phoneUser != null)
         throw new UserAccountException(1, "号码已经被占用");
      // 判断手机号码是否被封禁
      ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService
@@ -1249,8 +1239,9 @@
      if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
         InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl());
         if (asInputStream != null) {
            FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String
                  .format(FilePathEnum.userWXPortrait.getPath() +"%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
            FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
                  String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
                        System.currentTimeMillis() + ""));
            if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
               portrait = result.getUrl();
         } else {
@@ -1261,21 +1252,37 @@
      if (StringUtil.isNullOrEmpty(portrait))
         portrait = Constant.systemCommonConfig.getDefaultPortrait();
      // 创建新账户
      userInfo = new UserInfo();
      userInfo.setPhone(phone);
      userInfo.setPortrait(portrait);
      userInfo.setAppId(appId);
      userInfo.setNickName(weiXinUser.getNickname());
      userInfo.setWxName(weiXinUser.getNickname());
      userInfo.setWxOpenId(weiXinUser.getOpenid());
      userInfo.setWxUnionId(weiXinUser.getUnionid());
      userInfo.setWxPic(weiXinUser.getHeadimgurl());
      userInfo.setLastLoginTime(System.currentTimeMillis());
      userInfo.setLoginType(2);
      userInfo.setLastLoginIp(request.getRemoteHost());
      userInfo.setState(UserInfo.STATE_NORMAL);
      addUser(userInfo);
      // 是否需要创建新账户
      UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone);
      if (phoneUser != null) {
         // 绑定微信
         if (StringUtil.isNullOrEmpty(phoneUser.getWxUnionId())) {
            try {
               bindWeiXin(phoneUser.getId(), weiXinUser);
            } catch (Exception e) {
               throw new UserAccountException(1, "微信绑定失败");
            }
         } else {
            throw new UserAccountException(1, "该微信已被绑定");
         }
         userInfo = userInfoMapper.selectAvailableByPrimaryKey(phoneUser.getId());
      } else {
         // 创建新账户
         userInfo = new UserInfo();
         userInfo.setPhone(phone);
         userInfo.setPortrait(portrait);
         userInfo.setAppId(appId);
         userInfo.setNickName(weiXinUser.getNickname());
         userInfo.setWxName(weiXinUser.getNickname());
         userInfo.setWxOpenId(weiXinUser.getOpenid());
         userInfo.setWxUnionId(weiXinUser.getUnionid());
         userInfo.setWxPic(weiXinUser.getHeadimgurl());
         userInfo.setLastLoginTime(System.currentTimeMillis());
         userInfo.setLoginType(2);
         userInfo.setLastLoginIp(request.getRemoteHost());
         userInfo.setState(UserInfo.STATE_NORMAL);
         addUser(userInfo);
      }
      Long uid = userInfo.getId();
      ThreadUtil.run(new Runnable() {
@@ -1427,6 +1434,5 @@
      // 插入记录
      userInfoDeleteRecordService.addDeleteRecord(uid, UserInfo.STATE_DELETE_OUT_OF_DATE, reason);
   }
}