admin
2020-07-03 651a15c78f668bef3859d9ed1bb7ad0b669d3600
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -7,12 +7,16 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.util.*;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.SystemUtil;
import org.yeshi.utils.entity.FileUploadResult;
import org.yeshi.utils.entity.ProxyIP;
import org.yeshi.utils.tencentcloud.COSManager;
import com.google.gson.Gson;
@@ -46,12 +50,6 @@
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.factory.msg.MsgAccountDetailFactory;
import com.yeshi.fanli.util.wx.WXLoginUtil;
@@ -66,8 +64,8 @@
   @Resource
   private RedisManager redisManager;
   @Resource
   private UserInfoMapper userInfoMapper;
//    @Resource
//    private UserInfoMapper userInfoMapper;
   @Resource
   private UserInfoService userInfoService;
@@ -139,7 +137,7 @@
                  throw new UserAccountException(Constant.CODE_FORBIDDEN_USER,
                        Constant.FORBIDDEN_USER_REASON_DESC);
            }
            userInfo = getUserInfoByTaoBaoOpenId(appId, tbUserInfo.getOpenid());
                    userInfo = getUserInfoByTaoBaoOpenId(SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()), tbUserInfo.getOpenid());
            // 判断用户是否被删除
            if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
               userInfo = null;
@@ -152,6 +150,7 @@
               userInfo.setNickName(tbUserInfo.getNickName());
               userInfo.setPortrait(tbUserInfo.getPortrait());
               userInfo.setLoginType(loginType);
                        userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
               session.setAttribute("LAST_LOGIN_USER", userInfo);
               // 需要微信登录
               return new LoginResult(LoginResult.TYPE_WX, userInfo);
@@ -182,7 +181,7 @@
            if (identifyCode != null && identifyCode.getEffective() != null && identifyCode.getEffective())
               throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
            userInfo = getUserInfoByWXUnionId(appId, weiXinUser.getUnionid());
                    userInfo = getUserInfoByWXUnionId(SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()), weiXinUser.getUnionid());
            // 判断用户是否被删除
            if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
               userInfo = null;
@@ -204,8 +203,7 @@
                  updateUserInfo.setLastLoginIp(request.getRemoteHost());
                  // 更新openId
                  updateUserInfo.setOpenid(weiXinUser.getOpenid());
                  userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
                            userInfoService.updateByPrimaryKeySelective(updateUserInfo);
                  // 删除邀请图片
                  spreadUserImgService.deleteImgUrl(userInfo.getId());
                  return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
@@ -221,6 +219,7 @@
               userInfo.setLastLoginTime(System.currentTimeMillis());
               userInfo.setLoginType(loginType);
               userInfo.setLastLoginIp(request.getRemoteHost());
                        userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
               addUser(userInfo);
               return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
@@ -264,7 +263,7 @@
                              MsgAccountDetailFactory.TYPE_TB);
                     }
                     updateUserInfo.setLastLoginTime(System.currentTimeMillis());
                     userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
                                userInfoService.updateByPrimaryKeySelective(updateUserInfo);
                     session.removeAttribute("LAST_LOGIN_USER");
                     // 使分销关系生效
@@ -307,6 +306,7 @@
                  userInfo.setLastLoginTime(System.currentTimeMillis());
                  userInfo.setLoginType(loginType);
                  userInfo.setLastLoginIp(request.getRemoteHost());
                            userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
                  addUser(userInfo);
                  session.removeAttribute("LAST_LOGIN_USER");
                  return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
@@ -319,7 +319,7 @@
            if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective())
               throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
            userInfo = getUserInfoByPhone(appId, phone);
                    userInfo = getUserInfoByPhone(SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()), phone);
            // 判断用户是否被删除
            if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
               userInfo = null;
@@ -331,6 +331,7 @@
               userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
               userInfo.setPhone(phone);
               userInfo.setLoginType(loginType);
                        userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
               session.setAttribute("LAST_LOGIN_USER", userInfo);
               // 询问是否绑定微信
               return new LoginResult(LoginResult.TYPE_WX, userInfo);
@@ -381,7 +382,7 @@
            if (identifyCode != null && identifyCode.getEffective() != null && identifyCode.getEffective())
               throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
         }
         userInfo = getUserInfoByTaoBaoOpenId(appId, tbUserInfo.getOpenid());
                userInfo = getUserInfoByTaoBaoOpenId(SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()), tbUserInfo.getOpenid());
         break;
      case 2:// 微信
            // 通过Code换取信息
@@ -397,7 +398,7 @@
         if (identifyCode != null && identifyCode.getEffective() != null && identifyCode.getEffective())
            throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
         userInfo = getUserInfoByWXUnionId(appId, weiXinUser.getUnionid());
                userInfo = getUserInfoByWXUnionId(SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()), weiXinUser.getUnionid());
         break;
      case 3:// 手机号码
            // 判断是否被封禁
@@ -405,7 +406,7 @@
               .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
         if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective())
            throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
         userInfo = getUserInfoByPhone(appId, phone);
                userInfo = getUserInfoByPhone(SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()), phone);
         break;
      }
@@ -416,7 +417,7 @@
      if (userInfo != null) {
         UserInfo updateUserInfo = new UserInfo(userInfo.getId());
         updateUserInfo.setLastLoginTime(System.currentTimeMillis());
         userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
            userInfoService.updateByPrimaryKeySelective(updateUserInfo);
         return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
      } else {// 询问是否创建用户
         userInfo = new UserInfo();
@@ -443,25 +444,27 @@
            userInfo.setPhone(phone);
            break;
         }
            userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
         return new LoginResult(LoginResult.TYPE_CREATE, userInfo);
      }
   }
   /**
    * 根据系统与unionid寻找用户
    *
    * @param appId
     * @param system
    * @param unionId
    * @return
     * @throws UserAccountException
    */
   @Override
   public UserInfo getUserInfoByWXUnionId(String appId, String unionId) throws UserAccountException {
      if (StringUtil.isNullOrEmpty(appId))
         throw new UserAccountException(1, "appId为空");
    public UserInfo getUserInfoByWXUnionId(SystemEnum system, String unionId) throws UserAccountException {
        if (system == null)
            throw new UserAccountException(1, "系统");
      if (StringUtil.isNullOrEmpty(unionId))
         throw new UserAccountException(2, "unionId为空");
      List<UserInfo> list = userInfoMapper.listByAppIdAndWXUnionId(appId, unionId);
        List<UserInfo> list = userInfoService.listBySystemAndWXUnionId(system, unionId);
      // 剔除被删除掉的用户
      for (int i = 0; i < list.size(); i++) {
         if (list.get(i).getState() == UserInfo.STATE_NORMAL) {
@@ -475,19 +478,20 @@
         return null;
   }
   /**
    * 根据系统和淘宝的Openid寻找用户
    *
    * @param appId
     * @param system
    * @param openId
    * @return
     * @throws UserAccountException
    */
   public UserInfo getUserInfoByTaoBaoOpenId(String appId, String openId) throws UserAccountException {
      if (StringUtil.isNullOrEmpty(appId))
         throw new UserAccountException(1, "appId为空");
    public UserInfo getUserInfoByTaoBaoOpenId(SystemEnum system, String openId) throws UserAccountException {
        if (system == null)
            throw new UserAccountException(1, "系统为空");
      if (StringUtil.isNullOrEmpty(openId))
         throw new UserAccountException(2, "openId为空");
      List<UserInfo> list = userInfoMapper.listByAppIdAndTaoBaoOpenId(appId, openId);
        List<UserInfo> list = userInfoService.listBySystemAndTaoBaoOpenId(system, openId);
      // 剔除被删除掉的用户
      for (int i = 0; i < list.size(); i++) {
@@ -505,17 +509,17 @@
   /**
    * 根据系统和电话号码寻找用户
    *
    * @param appId
     * @param system
    * @param phone
    * @return
     * @throws UserAccountException
    */
   public UserInfo getUserInfoByPhone(String appId, String phone) throws UserAccountException {
      if (StringUtil.isNullOrEmpty(appId))
         throw new UserAccountException(1, "appId为空");
    public UserInfo getUserInfoByPhone(SystemEnum system, String phone) throws UserAccountException {
        if (system == null)
            throw new UserAccountException(1, "系统为空");
      if (StringUtil.isNullOrEmpty(phone))
         throw new UserAccountException(2, "phone为空");
      List<UserInfo> list = userInfoMapper.listByAppIdAndPhone(appId, phone);
        List<UserInfo> list = userInfoService.listBySystemAndPhone(system, phone);
      // 剔除被删除掉的用户
      for (int i = 0; i < list.size(); i++) {
@@ -534,26 +538,26 @@
   private void updateLatestLoginTime(Long uid) {
      UserInfo userInfo = new UserInfo(uid);
      userInfo.setLastLoginTime(System.currentTimeMillis());
      userInfoMapper.updateByPrimaryKeySelective(userInfo);
        userInfoService.updateByPrimaryKeySelective(userInfo);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void register(UserInfo userInfo) throws UserAccountException {
      if (!StringUtil.isNullOrEmpty(userInfo.getPhone())) {
         UserInfo user = getUserInfoByPhone(userInfo.getAppId(), userInfo.getPhone());
            UserInfo user = getUserInfoByPhone(userInfo.getSystem(), userInfo.getPhone());
         if (user != null)
            throw new UserAccountException(50001, "电话号码已经被绑定");
      }
      if (!StringUtil.isNullOrEmpty(userInfo.getOpenid())) {
         UserInfo user = getUserInfoByTaoBaoOpenId(userInfo.getAppId(), userInfo.getOpenid());
            UserInfo user = getUserInfoByTaoBaoOpenId(userInfo.getSystem(), userInfo.getOpenid());
         if (user != null)
            throw new UserAccountException(50002, "淘宝号已经被绑定");
      }
      if (!StringUtil.isNullOrEmpty(userInfo.getWxUnionId())) {
         UserInfo user = getUserInfoByWXUnionId(userInfo.getAppId(), userInfo.getWxUnionId());
            UserInfo user = getUserInfoByWXUnionId(userInfo.getSystem(), userInfo.getWxUnionId());
         if (user != null)
            throw new UserAccountException(50003, "微信号已经被注册");
      }
@@ -564,27 +568,16 @@
   @Transactional
   @Override
   public void addUser(UserInfo user) {
      Long maxUid = userInfoMapper.getMaxUid();
      if (maxUid == null)
         maxUid = 100000L;
      long dd = (long) (Math.random() * 100);
      if (dd == 0) {
         dd = 1;
      }
      long uid = maxUid + dd;
      user.setId(uid);
      user.setCreatetime(System.currentTimeMillis());
      user.setRank(0);
      if (StringUtil.isNullOrEmpty(user.getPortrait()))
         user.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
      userInfoMapper.insertSelective(user);
        userInfoService.createUser(user,user.getSystem());
      // 昵称为空时 默认昵称
      if (StringUtil.isNullOrEmpty(user.getNickName())) {
         UserInfo updateUserInfo = new UserInfo(user.getId());
         updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName() + user.getId());
         userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
            userInfoService.updateByPrimaryKeySelective(updateUserInfo);
      }
      try {
@@ -596,33 +589,33 @@
      // 添加账号绑定历史
      if (!StringUtil.isNullOrEmpty(user.getPhone()))
         userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, user.getPhone());
            userInfoModifyRecordService.addModifyRecord(user.getId(), ModifyTypeEnum.bindPhone, user.getPhone());
      if (!StringUtil.isNullOrEmpty(user.getWxUnionId()))
         userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, user.getWxUnionId());
            userInfoModifyRecordService.addModifyRecord(user.getId(), ModifyTypeEnum.bindWeiXin, user.getWxUnionId());
   }
   @Override
   public void updateUserSelective(UserInfo user) {
      userInfoMapper.updateByPrimaryKeySelective(user);
        userInfoService.updateByPrimaryKeySelective(user);
   }
   @Override
   public void bindPhone(Long uid, String phone) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null)
         throw new UserAccountException(4, "用户不存在");
      if (!StringUtil.isNullOrEmpty(user.getPhone()))
         throw new UserAccountException(5, "当前账号已经绑定了手机号,请先解绑");
      UserInfo phoneUser = getUserInfoByPhone(user.getAppId(), phone);
        UserInfo phoneUser = getUserInfoByPhone(user.getSystem(), phone);
      if (phoneUser != null)
         throw new UserAccountException(6, "当前电话号码已经被绑定");
      UserInfo update = new UserInfo(user.getId());
      update.setPhone(phone);
      userInfoMapper.updateByPrimaryKeySelective(update);
        userInfoService.updateByPrimaryKeySelective(update);
      userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
      userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone);
@@ -630,7 +623,7 @@
   @Override
   public void unBindPhone(Long uid, String phone) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null)
         throw new UserAccountException(4, "用户不存在");
@@ -645,14 +638,14 @@
      UserInfo updateUserInfo = new UserInfo(uid);
      updateUserInfo.setPhone("");
      userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        userInfoService.updateByPrimaryKeySelective(updateUserInfo);
      userAccountMsgNotificationService.unBindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
   }
   @Override
   public void bindTaoBao(Long uid, String tbOpenId, String tbNickName, String tbPortrait)
         throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null)
         throw new UserAccountException(4, "用户不存在");
@@ -663,7 +656,7 @@
      if (!StringUtil.isNullOrEmpty(user.getOpenid()) && user.getOpenid().equalsIgnoreCase(tbOpenId))
         return;
      UserInfo taoBaoUser = getUserInfoByTaoBaoOpenId(user.getAppId(), tbOpenId);
        UserInfo taoBaoUser = getUserInfoByTaoBaoOpenId(user.getSystem(), tbOpenId);
      if (taoBaoUser != null)
         throw new UserAccountException(6, "当前淘宝号已经被绑定");
      UserInfo update = new UserInfo(user.getId());
@@ -675,14 +668,14 @@
         update.setNickName(tbNickName);
         update.setPortrait(tbPortrait);
      }
      userInfoMapper.updateByPrimaryKeySelective(update);
        userInfoService.updateByPrimaryKeySelective(update);
      userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_TB);
   }
   @Override
   public void unBindTaoBao(Long uid) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null)
         throw new UserAccountException(4, "用户不存在");
      if (StringUtil.isNullOrEmpty(user.getOpenid()))
@@ -701,7 +694,7 @@
         update.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
      }
      userInfoMapper.updateByPrimaryKeySelective(update);
        userInfoService.updateByPrimaryKeySelective(update);
      userExtraTaoBaoInfoService.unBindUid(uid);
@@ -710,7 +703,7 @@
   @Override
   public void changeWXBind(AcceptData acceptData, Long uid, String code) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null)
         throw new UserAccountException(4, "用户不存在");
      WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
@@ -721,7 +714,7 @@
      if (weiXinUser.getUnionid().equalsIgnoreCase(user.getWxUnionId()))
         throw new UserAccountException(12, "亲,请登录其它微信号进行更换绑定");
      UserInfo newUser = getUserInfoByWXUnionId(user.getAppId(), weiXinUser.getUnionid());
        UserInfo newUser = getUserInfoByWXUnionId(user.getSystem(), weiXinUser.getUnionid());
      if (newUser != null)
         throw new UserAccountException(13, "该微信号已被其他账号绑定");
@@ -747,7 +740,7 @@
         updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
      }
      userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        userInfoService.updateByPrimaryKeySelective(updateUserInfo);
      userAccountMsgNotificationService.changeBindingSuccess(uid, MsgAccountDetailFactory.TYPE_WX);
@@ -758,7 +751,7 @@
   public void clearUserPortrait(Long uid) {
      if (uid == null)
         return;
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      String prefix = String.format("/portrait/wx/%s_", user.getWxUnionId());
      ObjectListing list = COSManager.getInstance().getObjectList(prefix, null, 30);
      if (list != null && list.getObjectSummaries() != null)
@@ -773,7 +766,7 @@
   public String repairPortrait(Long uid) {
      if (uid == null)
         return null;
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null)
         return null;
      String prefix = String.format("/portrait/wx/%s_", user.getWxUnionId());
@@ -794,7 +787,7 @@
         if (!StringUtil.isNullOrEmpty(portrait)) {
            UserInfo updateUser = new UserInfo(uid);
            updateUser.setPortrait(portrait);
            userInfoMapper.updateByPrimaryKeySelective(updateUser);
                userInfoService.updateByPrimaryKeySelective(updateUser);
            return portrait;
         }
      }
@@ -804,7 +797,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public UserInfo loginPhone(HttpServletRequest request, int loginType, String vcode, String phone, String appId)
    public UserInfo loginPhone(ProxyIP ipInfo, AcceptData acceptData, int loginType, String vcode, String phone, String appId)
         throws UserAccountException {
      // 空额清理
@@ -866,10 +859,10 @@
         } else {
            // 查询是否存在该电话历史用户
            UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByPhone(phone);
                UserInfo userInfo = userInfoService.getEffectiveUserInfoByPhone(phone, SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()));
            if (userInfo != null) {
               // 更新账户登录信息
               updateLonginInfo(userInfo, loginType, request);
                    updateLonginInfo(userInfo, loginType, ipInfo);
            } else {
               userInfo = new UserInfo();
               userInfo.setAppId(appId);
@@ -878,6 +871,7 @@
               userInfo.setPhone(phone);
               userInfo.setLoginType(loginType);
               userInfo.setState(UserInfo.STATE_NORMAL);
                    userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
               // 创建用户
               addUser(userInfo);
@@ -904,7 +898,7 @@
   
   @Transactional(rollbackFor = Exception.class)
   @Override
   public UserInfo loginPhoneNew(HttpServletRequest request, int loginType, String vcode, String phone, String appId)
    public UserInfo loginPhoneNew(ProxyIP ipInfo, AcceptData acceptData, int loginType, String vcode, String phone, String appId)
         throws UserAccountException {
      // 空额清理
      if (phone == null || phone.trim().length() == 0) {
@@ -961,12 +955,11 @@
         if (exec == null || exec.size() == 0) {
            throw new UserAccountException(10, "请稍后再试");
         } else {
            // 查询是否存在该电话历史用户
            UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByPhone(phone);
                UserInfo userInfo = userInfoService.getEffectiveUserInfoByPhone(phone, SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()));
            if (userInfo != null) {
               // 更新账户登录信息
               updateLonginInfo(userInfo, loginType, request);
                    updateLonginInfo(userInfo, loginType, ipInfo);
            } else {
               // 绑定微信
               String keylogin = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("phoneLogin:" + phone));
@@ -986,10 +979,9 @@
   }
   
   @Transactional(rollbackFor = Exception.class)
   @Override
   public UserInfo loginWinXin(HttpServletRequest request, AcceptData acceptData, int loginType, String code,
    public UserInfo loginWinXin(ProxyIP ipInfo, AcceptData acceptData, int loginType, String code,
         String appId) throws UserAccountException {
      // 日志信息
      JSONObject logInfo = new JSONObject();
@@ -1026,13 +1018,12 @@
         if (exec == null || exec.size() == 0) {
            throw new UserAccountException(10, "请稍后再试");
         } else {
            UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
                UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()));
            // 直接用的微信登录
            if (userInfo != null) {
               LogHelper.test("微信unionID存在:" + weiXinUser.getUnionid());
               // 更新账户登录信息
               updateLonginInfo(userInfo, loginType, request);
                    updateLonginInfo(userInfo, loginType,ipInfo );
               // 删除邀请分享图
               spreadUserImgService.deleteImgUrl(userInfo.getId());
            } else {
@@ -1066,8 +1057,9 @@
               userInfo.setWxPic(weiXinUser.getHeadimgurl());
               userInfo.setLastLoginTime(System.currentTimeMillis());
               userInfo.setLoginType(loginType);
               userInfo.setLastLoginIp(request.getRemoteHost());
                    userInfo.setLastLoginIp(ipInfo.getIp());
               userInfo.setState(UserInfo.STATE_NORMAL);
                    userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
               addUser(userInfo);
               try {
@@ -1094,7 +1086,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode,
    public UserInfo loginWeiXinNew(ProxyIP ipInfo, AcceptData acceptData, int loginType, String wxCode,
         String appId) throws UserAccountException {
      // 日志信息
      JSONObject logInfo = new JSONObject();
@@ -1118,7 +1110,7 @@
         throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
      }
      UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
        UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), SystemInfoUtil.getSystem(acceptData));
      if (userInfo == null) {
         String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey,
               StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()));
@@ -1126,7 +1118,7 @@
         throw new UserAccountException(101, key);
      }
      // 更新账户登录信息
      updateLonginInfo(userInfo, loginType, request);
        updateLonginInfo(userInfo, loginType, ipInfo);
      Long uid = userInfo.getId();
      ThreadUtil.run(new Runnable() {
         public void run() {
@@ -1142,20 +1134,20 @@
    * 
    * @param userInfo
    * @param loginType
    * @param request
     * @param ipInfo
    */
   public void updateLonginInfo(UserInfo userInfo, int loginType, HttpServletRequest request) {
    private void updateLonginInfo(UserInfo userInfo, int loginType, ProxyIP ipInfo) {
      // 设置登录时间与登录类型
      UserInfo updateUserInfo = new UserInfo(userInfo.getId());
      updateUserInfo.setLastLoginTime(System.currentTimeMillis());
      updateUserInfo.setLoginType(loginType);
      updateUserInfo.setLastLoginIp(request.getRemoteHost());
      userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        updateUserInfo.setLastLoginIp(ipInfo.getIp());
        userInfoService.updateByPrimaryKeySelective(updateUserInfo);
   }
   @Override
   public void bindPhoneNew(Long uid, String phone) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null) {
         throw new UserAccountException(1, "用户不存在");
      }
@@ -1165,7 +1157,7 @@
         throw new UserAccountException(2, "您已经绑定了该电话号码");
      }
      UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone);
        UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone,user.getSystem());
      if (phoneUser != null) {
         throw new UserAccountException(2, "号码已经被占用");
      }
@@ -1173,7 +1165,7 @@
      // 更新电话号码
      UserInfo update = new UserInfo(user.getId());
      update.setPhone(phone);
      userInfoMapper.updateByPrimaryKeySelective(update);
        userInfoService.updateByPrimaryKeySelective(update);
      // 加入绑定记录
      UserAccountBindingHistory history = new UserAccountBindingHistory();
      history.setContent(phone);
@@ -1213,7 +1205,7 @@
   @Transactional(rollbackFor = UserAccountException.class)
   @Override
   public void bindWeiXin(Long uid, WeiXinUser weiXinUser) throws UserAccountException {
      UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
      if (user == null) {
         throw new UserAccountException(1, "用户不存在");
      }
@@ -1229,7 +1221,7 @@
      String wxUnionIdExist = user.getWxUnionId();
      if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
         UserInfo newUser = userInfoMapper.getEffectiveUserInfoByWXUnionId(wxUnionId);
            UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId, user.getSystem());
         if (newUser != null) {
            throw new UserAccountException(4, "该微信号已被其他帐号绑定");
         }
@@ -1276,7 +1268,7 @@
         }
         updateUserInfo.setPortrait(headimgurl);
      }
      userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        userInfoService.updateByPrimaryKeySelective(updateUserInfo);
      // 加入绑定记录
      UserAccountBindingHistory history = new UserAccountBindingHistory();
@@ -1297,7 +1289,7 @@
   }
   @Override
   public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request)
    public UserInfo bindPhoneToLogin(ProxyIP ipinfo, AcceptData acceptData, String phone, String key)
         throws UserAccountException {
      // 判断手机号码是否被封禁
@@ -1314,7 +1306,9 @@
      if (weiXinUser == null)
         throw new UserAccountException(1, "微信授权失效,请使用微信重新登录");
      UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
        SystemEnum system = SystemInfoUtil.getSystem(acceptData);
        UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), system);
      // 直接用的微信登录
      if (userInfo != null)
         throw new UserAccountException(10, "该微信号已被占用");
@@ -1337,7 +1331,7 @@
         portrait = Constant.systemCommonConfig.getDefaultPortrait();
      // 是否需要创建新账户
      UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone);
        UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone, system);
      if (phoneUser != null) {
         // 绑定微信
         if (StringUtil.isNullOrEmpty(phoneUser.getWxUnionId())) {
@@ -1349,13 +1343,13 @@
         } else {
            throw new UserAccountException(1, "该微信已被绑定");
         }
         userInfo = userInfoMapper.selectAvailableByPrimaryKey(phoneUser.getId());
            userInfo = userInfoService.selectAvailableByPrimaryKey(phoneUser.getId());
      } else {
         // 创建新账户
         userInfo = new UserInfo();
         userInfo.setPhone(phone);
         userInfo.setPortrait(portrait);
         userInfo.setAppId(appId);
            userInfo.setAppId(null);
         userInfo.setNickName(weiXinUser.getNickname());
         userInfo.setWxName(weiXinUser.getNickname());
         userInfo.setWxOpenId(weiXinUser.getOpenid());
@@ -1363,8 +1357,9 @@
         userInfo.setWxPic(weiXinUser.getHeadimgurl());
         userInfo.setLastLoginTime(System.currentTimeMillis());
         userInfo.setLoginType(2);
         userInfo.setLastLoginIp(request.getRemoteHost());
            userInfo.setLastLoginIp(ipinfo.getIp());
         userInfo.setState(UserInfo.STATE_NORMAL);
            userInfo.setSystem(system);
         addUser(userInfo);
      }
@@ -1398,13 +1393,15 @@
   
   
   @Override
   public UserInfo bindWXToLogin(HttpServletRequest request, AcceptData acceptData, String code, String appId, String key) throws UserAccountException {
    public UserInfo bindWXToLogin(ProxyIP ipInfo, AcceptData acceptData, String code, String appId, String key) throws UserAccountException {
      // 日志信息
      JSONObject logInfo = new JSONObject();
      logInfo.put("appId", appId);
      logInfo.put("code", code);
      logInfo.put("loginType", 2);
      LogHelper.lgoinInfo(logInfo.toString());
        SystemEnum system = SystemInfoUtil.getSystem(acceptData);
      // 通过Code换取信息
      WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
@@ -1439,7 +1436,7 @@
            throw new UserAccountException(10, "请稍后再试");
         } else {
            UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
                UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), system);
            // 直接用的微信登录
            if (userInfo != null) {
               // 绑定微信
@@ -1480,8 +1477,9 @@
               userInfo.setWxPic(weiXinUser.getHeadimgurl());
               userInfo.setLastLoginTime(System.currentTimeMillis());
               userInfo.setLoginType(2);
               userInfo.setLastLoginIp(request.getRemoteHost());
                    userInfo.setLastLoginIp(ipInfo.getIp());
               userInfo.setState(UserInfo.STATE_NORMAL);
                    userInfo.setSystem(system);
               addUser(userInfo);
               Long uid = userInfo.getId();