yujian
2019-03-14 4aadf484e193995c23ee1d5bb1971a497d2f9a0d
fanli/src/main/java/com/yeshi/fanli/controller/client/UserAccountController.java
@@ -15,11 +15,13 @@
import com.alipay.api.AlipayApiException;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.BindingAccount;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
import com.yeshi.fanli.entity.bus.user.LoginResult;
import com.yeshi.fanli.entity.bus.user.SMSHistory;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.WeiXinUser;
import com.yeshi.fanli.entity.system.System;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.TBPid;
@@ -28,32 +30,32 @@
import com.yeshi.fanli.exception.AlipayTransferException;
import com.yeshi.fanli.exception.UserAccountException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.InviteGetMoneyService;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.order.LostOrderService;
import com.yeshi.fanli.service.inter.order.OrderItemServcie;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.AccountDetailsService;
import com.yeshi.fanli.service.inter.user.AccountMessageService;
import com.yeshi.fanli.service.inter.user.BindingAccountService;
import com.yeshi.fanli.service.inter.user.ExtractService;
import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
import com.yeshi.fanli.service.inter.user.ShamUserService;
import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserAccountService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.GsonUtil;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.wx.WXLoginUtil;
@@ -75,8 +77,6 @@
   @Resource
   private OrderService orderService;
   @Resource
   private HongBaoService hongBaoService;
   @Resource
   private HongBaoV2Service hongBaoV2Service;
@@ -91,7 +91,7 @@
   private ConfigService configService;
   @Resource
   private SystemService systemService;
   private BusinessSystemService businessSystemService;
   @Resource
   private ShamUserService shamUserService;
@@ -101,12 +101,6 @@
   @Resource
   private LostOrderService lostOrderService;
   @Resource
   private OrderItemServcie orderItemServcie;
   @Resource
   private AccountDetailsService accountDetailsService;
   @Resource
   private AccountMessageService accountMessageService;
@@ -138,6 +132,12 @@
   @Resource
   private UserShareGoodsRecordService userShareGoodsRecordService;
   @Resource
   private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
   @Resource
   private UserSystemCouponService userSystemCouponService;
   private static final String PASSWORD_MAX_ERROR = "password_max_error";
   private static final String EXTRACT_MIN_MONEY = "extract_min_money";
   private static final String EXTRACT_MAX_MONEY = "extract_max_money";
@@ -159,7 +159,7 @@
   public void login(AcceptData acceptData, String code, String vcode, String phone, boolean wxinstall,
         String tbOpenid, String tbNickName, String tbPortrait, String tbSession, int loginType, Boolean first,
         HttpSession session, HttpServletRequest request, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -167,15 +167,21 @@
      if (loginType == 3 && !Constant.IS_TEST)// 验证短信验证码
      {
         String oldVcode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
         if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
            out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
            return;
         // 苹果应用商店上线测试号码
         if ("17316780233".equalsIgnoreCase(phone) && "258168".equalsIgnoreCase(vcode)) {
            ;
         } else {
            String oldVcode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
            if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
               out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
               return;
            }
         }
         redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
      }
      UserInfo tbUserInfo = new UserInfo();
      if (!StringUtil.isNullOrEmpty(tbSession)) {
         try {
            tbSession = DESUtil.decode(tbSession.replace("\n", ""), StringUtil.getBase64String("YeShiFANLI889*+"),
@@ -187,12 +193,14 @@
         tbOpenid = tbs.optString("openId");
         tbNickName = tbs.optString("nick");
         tbPortrait = tbs.optString("avatarUrl");
         // 淘宝ID
         tbUserInfo.setTaoBaoUid(tbs.optString("taobao_user_id"));
      }
      UserInfo tbUserInfo = new UserInfo();
      tbUserInfo.setOpenid(tbOpenid);
      tbUserInfo.setTbName(tbNickName);
      tbUserInfo.setTbPic(tbPortrait);
      try {
         LoginResult result = userAccountService.login(request, first, system.getAppid(), code, phone, tbUserInfo,
               wxinstall, loginType);
@@ -212,6 +220,25 @@
         root.put("type", result.getType());
         root.put("data", data);
         out.print(JsonUtil.loadTrueResult(root));
         final UserInfo uuser =  result.getUser();
         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) {
         try {
            LogHelper.cookieLog("登录出错:" + e.getCode() + "-" + e.getMessage());
@@ -220,6 +247,7 @@
         }
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      }
   }
   /**
@@ -237,7 +265,7 @@
   @RequestMapping(value = "register")
   public void register(AcceptData acceptData, String tbOpenid, String tbNickName, String tbPortrait, String vcode,
         String phone, HttpServletRequest request, HttpSession session, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -297,7 +325,7 @@
    */
   @RequestMapping(value = "connect")
   public void connect(AcceptData acceptData, long mainUid, long lessUid, HttpSession session, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -330,7 +358,7 @@
    */
   @RequestMapping(value = "getuid")
   public void getUid(AcceptData acceptData, String code, String tbOpenid, String phone, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -394,7 +422,7 @@
    */
   @RequestMapping(value = "bindPhone")
   public void bindPhone(AcceptData acceptData, Long uid, String vcode, String phone, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -412,15 +440,32 @@
      String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
      if (!vcode.equalsIgnoreCase(oldVCode)) {
         out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
         return;
      if (Constant.IS_OUTNET) {
         if (!vcode.equalsIgnoreCase(oldVCode)) {
            out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
            return;
         }
         redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
      }
      redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
      try {
         userAccountService.bindPhone(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("user", UserUtil.filterForClientUser(user));
         out.print(JsonUtil.loadTrueResult(data));
@@ -440,7 +485,7 @@
    */
   @RequestMapping(value = "unBindPhone")
   public void unBindPhone(AcceptData acceptData, Long uid, String phone, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -476,11 +521,13 @@
   @RequestMapping(value = "bindTaoBao")
   public void bindTaoBao(AcceptData acceptData, Long uid, String tbOpenid, String tbNickName, String tbPortrait,
         String tbSession, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      String taoBaoUid = "";
      if (!StringUtil.isNullOrEmpty(tbSession)) {
         try {
@@ -493,11 +540,32 @@
         tbOpenid = session.optString("openId");
         tbNickName = session.optString("nick");
         tbPortrait = session.optString("avatarUrl");
         taoBaoUid = session.optString("taobao_user_id");
      }
      try {
         userAccountService.bindTaoBao(uid, tbOpenid, tbNickName, tbPortrait);
         UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
         // 判断taoBaoUid是否已经封禁
         if (!StringUtil.isNullOrEmpty(taoBaoUid)) {
            ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                  .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.taobaoUid, taoBaoUid);
            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("user", UserUtil.filterForClientUser(user));
         out.print(JsonUtil.loadTrueResult(data));
@@ -515,7 +583,7 @@
    */
   @RequestMapping(value = "unBindTaoBao")
   public void unBindTaoBao(AcceptData acceptData, Long uid, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -539,7 +607,7 @@
    */
   @RequestMapping(value = "changeWX")
   public void changeWX(AcceptData acceptData, Long uid, String code, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -553,6 +621,22 @@
      try {
         userAccountService.changeWXBind(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("user", UserUtil.filterForClientUser(user));
         out.print(JsonUtil.loadTrueResult(data));
@@ -570,7 +654,7 @@
    */
   @RequestMapping(value = "getphone")
   public void getPhone(AcceptData acceptData, Long uid, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -590,7 +674,7 @@
   @RequestMapping(value = "verifyvcodeforbind")
   public void verifyVcodeForbind(AcceptData acceptData, Long uid, String vcode, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -635,7 +719,7 @@
    */
   @RequestMapping(value = "bindalipay")
   public void bindAlipay(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -690,7 +774,7 @@
   @RequestMapping(value = "bindalipaywithverify")
   public void bindAlipayWithVerify(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -780,7 +864,7 @@
   @RequestMapping(value = "bindalipaywithverifynew")
   public void bindAlipayWithVerifyNew(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -816,6 +900,23 @@
         return;
      }
      redisManager.cacheCommonString(key, "1", 120);
      // 支付宝绑定
      ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
            .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.alipayAccount, account);
      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;
      }
      // 可以展示给用户看的错误码
      String[] ALIPAY_CODES = new String[] { "SYSTEM_ERROR", "PERMIT_CHECK_PERM_LIMITED", "PERM_AML_NOT_REALNAME_REV",
            "PERM_AML_NOT_REALNAME_REV", "PAYEE_USER_INFO_ERROR", "PAYEE_ACC_OCUPIED",