admin
2020-05-16 7cf44cbaa96948dae87bec1bc2fe2bf80c775caa
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) {// 原先的账号不存在
@@ -450,7 +446,6 @@
         return new LoginResult(LoginResult.TYPE_CREATE, userInfo);
      }
   }
   /**
    * 根据系统与unionid寻找用户
@@ -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);
      }
@@ -1131,9 +1126,6 @@
      bindWeiXin(uid, weiXinUser);
   }
   
   @Transactional(rollbackFor=UserAccountException.class)
   @Override
   public void bindWeiXin(Long uid,WeiXinUser weiXinUser) throws UserAccountException {
@@ -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,6 +1252,21 @@
      if (StringUtil.isNullOrEmpty(portrait))
         portrait = Constant.systemCommonConfig.getDefaultPortrait();
      // 是否需要创建新账户
      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);
@@ -1276,6 +1282,7 @@
      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);
   }
}