yujian
2019-04-08 1da17d215d48e3e3aa9e8d7a3ef526904764f408
fanli/src/main/java/com/yeshi/fanli/controller/client/UserAccountController.java
@@ -9,6 +9,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.encrypt.DESUtil;
@@ -1104,4 +1105,212 @@
         deviceTokenHWService.unBindDeviceToken(acceptData.getDevice());
      out.print(JsonUtil.loadTrueResult(""));
   }
   /**
    *   新版登录  V1.5.3
    * @param acceptData
    * @param vcode
    * @param phone
    * @param code
    * @param loginType 登录方式:  1-手机登录   2-微信登录
    * @param request
    * @param out
    */
   @RequestMapping(value = "loginNew", method = RequestMethod.POST)
   public void loginNew(AcceptData acceptData, String vcode, String phone, String code,
         int loginType, HttpServletRequest request, PrintWriter out) {
      try {
         BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
               acceptData.getPackages());
         if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
         }
         UserInfo userInfo = null;
         // 手机登录
         if (loginType == 1) {
            userInfo = userAccountService.loginPhone(request, loginType, vcode, phone, system.getAppid());
         }
         // 微信登录
         if (loginType == 2) {
            userInfo = userAccountService.loginWinXin(request,loginType, code, system.getAppid());
         }
         if (userInfo == null) {
            out.print(JsonUtil.loadFalseResult("登录失败"));
         } else {
            JSONObject data = new JSONObject();
            data.put("userInfo", UserUtil.filterForClientUser(userInfo));
            out.print(JsonUtil.loadTrueResult(data));
            /* 同步未登录之前设备抽奖数据  */
            final UserInfo uuser = userInfo;
            ThreadUtil.run(new Runnable() {
               public void run() {
                  try {
                     int platformType = 0;
                     String platform = acceptData.getPlatform();
                     if ("android".equals(platform)) {
                        platformType = 1;
                     } else if ("ios".equals(platform)) {
                        platformType = 2;
                     }
                     userSystemCouponService.copyLotteryPrize(uuser.getId(), platformType, acceptData.getDevice());
                  } catch (Exception e) {
                     e.printStackTrace();
                  }
               }
            });
         }
      } catch (UserAccountException e) {
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
         try {
            LogHelper.cookieLog("登录出错:" + e.getCode() + "-" + e.getMessage());
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("登录失败"));
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
   }
   /**
    *   绑定电话号码  V1.5.3
    *
    * @param acceptData
    * @param vcode
    * @param phone
    * @param out
    */
   @RequestMapping(value = "bindPhoneNew")
   public void bindPhoneNew(AcceptData acceptData, Long uid, String vcode, String phone, PrintWriter out) {
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      if (StringUtil.isNullOrEmpty(vcode)) {
         out.print(JsonUtil.loadFalseResult("验证码不能为空"));
         return;
      }
      if (StringUtil.isNullOrEmpty(phone)) {
         out.print(JsonUtil.loadFalseResult("电话号码不能为空"));
         return;
      }
      phone = phone.replaceAll(" ", "");
      String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_BIND);
      if (Constant.IS_OUTNET) {
         if (!vcode.equalsIgnoreCase(oldVCode)) {
            out.print(JsonUtil.loadFalseResult(9001, "验证码错误,重新输入"));
            return;
         }
         redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_BIND);
      }
      try {
         // 绑定用户
         userAccountService.bindPhoneNew(uid, phone);
         UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
         // 判断电话号码是否已经封禁
         ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
               .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
         if (ic != null && ic.getEffective() != null && ic.getEffective()) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            // 封禁用户
            // 封禁绑定的正常用户
            if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
               UserInfo update = new UserInfo(uid);
               update.setState(UserInfo.STATE_FORBIDDEN);
               update.setStateDesc("绑定被封禁的电话号码被封禁");
               userInfoService.updateByPrimaryKeySelective(update);
            }
            return;
         }
         JSONObject data = new JSONObject();
         data.put("userInfo", UserUtil.filterForClientUser(user));
         out.print(JsonUtil.loadTrueResult(data));
      } catch (UserAccountException e) {
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult(1, "绑定失败"));
      }
   }
   /**
    * 更改微信
    *
    * @param acceptData
    * @param uid
    * @param code
    * @param out
    */
   @RequestMapping(value = "bindWeiXin")
   public void bindWeiXin(AcceptData acceptData, Long uid, String code, PrintWriter out) {
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      if (StringUtil.isNullOrEmpty(code)) {
         out.print(JsonUtil.loadFalseResult("请上传code"));
         return;
      }
      try {
         userAccountService.bindWeiXin(uid, code);
         UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
         // 判断taoBaoUid是否已经封禁
         ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
               .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, user.getWxUnionId());
         if (ic != null && ic.getEffective() != null && ic.getEffective()) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            // 封禁用户
            // 封禁绑定的正常用户
            if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
               UserInfo update = new UserInfo(uid);
               update.setState(UserInfo.STATE_FORBIDDEN);
               update.setStateDesc("绑定被封禁的微信号被封禁");
               userInfoService.updateByPrimaryKeySelective(update);
            }
            return;
         }
         JSONObject data = new JSONObject();
         data.put("userInfo", UserUtil.filterForClientUser(user));
         out.print(JsonUtil.loadTrueResult(data));
      } catch (UserAccountException e) {
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      }
   }
}