yujian
2019-03-01 9dedfa92c34c92d42230e151766726a8e4a7806f
fanli/src/main/java/com/yeshi/fanli/controller/client/UserAccountController.java
@@ -10,10 +10,13 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.encrypt.DESUtil;
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;
@@ -43,10 +46,13 @@
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.util.Constant;
import com.yeshi.fanli.util.GsonUtil;
import com.yeshi.fanli.util.RedisManager;
@@ -74,7 +80,7 @@
   @Resource
   private HongBaoService hongBaoService;
   @Resource
   private HongBaoV2Service hongBaoV2Service;
@@ -129,6 +135,15 @@
   @Resource
   private TaoBaoUnionConfigService taoBaoUnionConfigService;
   @Resource
   private SpreadUserImgService spreadUserImgService;
   @Resource
   private UserShareGoodsRecordService userShareGoodsRecordService;
   @Resource
   private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
   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";
@@ -143,12 +158,13 @@
    * @param tbOpenid
    * @param tbNickName
    * @param tbPortrait
    * @param tbSession(淘宝session数据,加密)
    * @param out
    */
   @RequestMapping(value = "login")
   public void login(AcceptData acceptData, String code, String vcode, String phone, boolean wxinstall,
         String tbOpenid, String tbNickName, String tbPortrait, int loginType, Boolean first, HttpSession session,
         HttpServletRequest request, PrintWriter out) {
         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());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
@@ -157,19 +173,40 @@
      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*+"),
                  StringUtil.getBase64String("*M#34f?,"));
         } catch (Exception e) {
            e.printStackTrace();
         }
         JSONObject tbs = JSONObject.fromObject(tbSession);
         tbOpenid = tbs.optString("openId");
         tbNickName = tbs.optString("nick");
         tbPortrait = tbs.optString("avatarUrl");
         // 淘宝ID
         tbUserInfo.setTaoBaoUid(tbs.optString("taobao_user_id"));
      }
      tbUserInfo.setOpenid(tbOpenid);
      tbUserInfo.setTbName(tbNickName);
      tbUserInfo.setTbPic(tbPortrait);
      try {
         LoginResult result = userAccountService.login(request, first, system.getAppid(), code, phone, tbUserInfo,
               wxinstall, loginType);
@@ -389,15 +426,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));
@@ -445,21 +499,59 @@
    * @param tbOpenid
    * @param tbNickName
    * @param tbPortrait
    * @param tbSession
    *            -淘宝授权session
    * @param out
    */
   @RequestMapping(value = "bindTaoBao")
   public void bindTaoBao(AcceptData acceptData, Long uid, String tbOpenid, String tbNickName, String tbPortrait,
         PrintWriter out) {
         String tbSession, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      String taoBaoUid = "";
      if (!StringUtil.isNullOrEmpty(tbSession)) {
         try {
            tbSession = DESUtil.decode(tbSession.replace("\n", ""), StringUtil.getBase64String("YeShiFANLI889*+"),
                  StringUtil.getBase64String("*M#34f?,"));
         } catch (Exception e) {
            e.printStackTrace();
         }
         JSONObject session = JSONObject.fromObject(tbSession);
         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,6 +607,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));
@@ -778,6 +886,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",
@@ -839,6 +964,7 @@
    */
   @RequestMapping(value = "getusermoney")
   public void getMoneyDetail(AcceptData acceptData, Long uid, PrintWriter out) {
      UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
      if (user == null) {
         out.print(JsonUtil.loadFalseResult(2, "用户不存在"));
@@ -857,29 +983,39 @@
      BigDecimal unOpenmoney = hongBaoV2Service.getUnRecievedFanLiMoney(uid);
      BigDecimal totalFanMoney = hongBaoV2Service.getTotalFanLiMoney(uid);
      JSONObject data = new JSONObject();
      int spreadImgCount = spreadUserImgService.countUserSpreadImg(uid);
      long shareCount = userShareGoodsRecordService.countShareRecordByUid(uid);
      // IOS端数字按照字符串处理
      if ("ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 33) {
         data.put("moneyToday", moneyToday.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("moneyMonth", moneyMonth.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("moneyLastMonth", moneyLastMonth.toString());
         data.put("money", user.getMyHongBao().toString());
         data.put("unGetMoney", unOpenmoney.toString());
         data.put("totalFanLiMoney", totalFanMoney.toString());// 累计返利
         data.put("totalTiChengMoney", hongBaoV2Service.getTotalTiChengMoney(uid).toString());// 累计提成
         data.put("totalUnGetTiChengMoney", hongBaoV2Service.getUnGetTiChengMoney(uid).toString()); // 未到账提成
         data.put("moneyLastMonth", moneyLastMonth.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("money", user.getMyHongBao().setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("unGetMoney", unOpenmoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("totalFanLiMoney", totalFanMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());// 累计返利
         data.put("totalTiChengMoney",
               hongBaoV2Service.getTotalTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN).toString());// 累计提成
         data.put("totalUnGetTiChengMoney",
               hongBaoV2Service.getUnGetTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN).toString()); // 未到账提成
         // 展示提成数据
         data.put("showTiCheng", hongBaoService.getTotalTiChengCount(uid) > 0);
         if (configService.iosOnLining(Integer.parseInt(acceptData.getVersion())))
            data.put("showTiCheng", false);
         else
            data.put("showTiCheng", spreadImgCount + shareCount > 0);
      } else {
         data.put("moneyToday", moneyToday.setScale(2, BigDecimal.ROUND_DOWN));
         data.put("moneyMonth", moneyMonth.setScale(2, BigDecimal.ROUND_DOWN));
         data.put("moneyLastMonth", moneyLastMonth);
         data.put("money", user.getMyHongBao());
         data.put("unGetMoney", unOpenmoney);
         data.put("totalFanLiMoney", totalFanMoney);// 累计返利
         data.put("totalTiChengMoney", hongBaoV2Service.getTotalTiChengMoney(uid));// 累计提成
         data.put("totalUnGetTiChengMoney", hongBaoV2Service.getUnGetTiChengMoney(uid)); // 未到账提成
         data.put("moneyLastMonth", moneyLastMonth.setScale(2, BigDecimal.ROUND_DOWN));
         data.put("money", user.getMyHongBao().setScale(2, BigDecimal.ROUND_DOWN));
         data.put("unGetMoney", unOpenmoney.setScale(2, BigDecimal.ROUND_DOWN));
         data.put("totalFanLiMoney", totalFanMoney.setScale(2, BigDecimal.ROUND_DOWN));// 累计返利
         data.put("totalTiChengMoney",
               hongBaoV2Service.getTotalTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN));// 累计提成
         data.put("totalUnGetTiChengMoney",
               hongBaoV2Service.getUnGetTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN)); // 未到账提成
         // 展示提成数据
         data.put("showTiCheng", hongBaoV2Service.getTotalTiChengCount(uid) > 0);
         data.put("showTiCheng", spreadImgCount + shareCount > 0);
      }
      user.setNoOpenHongBao(unOpenmoney);