admin
2019-01-15 3b46a3cf795784fd9e4ca8f168da4c75ad871ba7
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.yeshi.utils.JsonUtil;
import com.alipay.api.AlipayApiException;
import com.yeshi.fanli.entity.accept.AcceptData;
@@ -29,10 +30,10 @@
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.goods.CollectionGoodsService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoMessageService;
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;
@@ -43,19 +44,18 @@
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.MoneyRecordService;
import com.yeshi.fanli.service.inter.user.PassWordErrorRecordService;
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.WxDownService;
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;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.wx.WXLoginUtil;
import org.yeshi.utils.JsonUtil;
import net.sf.json.JSONObject;
@@ -79,7 +79,7 @@
   private HongBaoService hongBaoService;
   @Resource
   private MoneyRecordService moneyRecordService;
   private HongBaoV2Service hongBaoV2Service;
   @Resource
   private BindingAccountService bindingAccountService;
@@ -88,16 +88,10 @@
   private ExtractService extractService;
   @Resource
   private PassWordErrorRecordService passWordErrorRecordService;
   @Resource
   private ConfigService configService;
   @Resource
   private SystemService systemService;
   @Resource
   private HongBaoMessageService hongBaoMessageService;
   @Resource
   private ShamUserService shamUserService;
@@ -118,12 +112,7 @@
   private AccountMessageService accountMessageService;
   @Resource
   private CollectionGoodsService collectionGoodsService;
   @Resource
   private HongBaoManageService hongBaoManageService;
   @Resource
   private WxDownService wxDownService;
   @Resource
   private UserAccountService userAccountService;
@@ -142,6 +131,12 @@
   @Resource
   private TaoBaoUnionConfigService taoBaoUnionConfigService;
   @Resource
   private SpreadUserImgService spreadUserImgService;
   @Resource
   private UserShareGoodsRecordService userShareGoodsRecordService;
   private static final String PASSWORD_MAX_ERROR = "password_max_error";
   private static final String EXTRACT_MIN_MONEY = "extract_min_money";
@@ -162,14 +157,14 @@
   @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,
         PrintWriter out) {
         HttpServletRequest request, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      if (loginType == 3)// 验证短信验证码
      if (loginType == 3 && !Constant.IS_TEST)// 验证短信验证码
      {
         String oldVcode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
         if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
@@ -185,7 +180,7 @@
      tbUserInfo.setTbName(tbNickName);
      tbUserInfo.setTbPic(tbPortrait);
      try {
         LoginResult result = userAccountService.login(session, first, system.getAppid(), code, phone, tbUserInfo,
         LoginResult result = userAccountService.login(request, first, system.getAppid(), code, phone, tbUserInfo,
               wxinstall, loginType);
         if (result == null)
            LogHelper.error("login-result为空值");
@@ -204,6 +199,11 @@
         root.put("data", data);
         out.print(JsonUtil.loadTrueResult(root));
      } catch (UserAccountException e) {
         try {
            LogHelper.cookieLog("登录出错:" + e.getCode() + "-" + e.getMessage());
         } catch (Exception e1) {
            e1.printStackTrace();
         }
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
      }
   }
@@ -328,11 +328,35 @@
            out.print(JsonUtil.loadFalseResult(1, "获取微信用户信息失败"));
            return;
         }
         user = userAccountService.getUserInfoByWXUnionId(system.getAppid(), weiXinUser.getUnionid());
         try {
            user = userAccountService.getUserInfoByWXUnionId(system.getAppid(), weiXinUser.getUnionid());
         } catch (UserAccountException e) {
            try {
               LogHelper.errorDetailInfo(e, null, "获取用户信息出错");
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
      } else if (!StringUtil.isNullOrEmpty(tbOpenid)) {
         user = userAccountService.getUserInfoByTaoBaoOpenId(system.getAppid(), tbOpenid);
         try {
            user = userAccountService.getUserInfoByTaoBaoOpenId(system.getAppid(), tbOpenid);
         } catch (UserAccountException e) {
            try {
               LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
      } else if (!StringUtil.isNullOrEmpty(phone)) {
         user = userAccountService.getUserInfoByPhone(system.getAppid(), phone);
         try {
            user = userAccountService.getUserInfoByPhone(system.getAppid(), phone);
         } catch (UserAccountException e) {
            try {
               LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
      }
      if (user == null) {
@@ -724,6 +748,97 @@
      }
   }
   @RequestMapping(value = "bindalipaywithverifynew")
   public void bindAlipayWithVerifyNew(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      if (uid == null || uid == 0) {
         out.print(JsonUtil.loadFalseResult(1, "请上传用户ID"));
         return;
      }
      if (StringUtil.isNullOrEmpty(name)) {
         out.print(JsonUtil.loadFalseResult(1, "请上传支付宝实名名称"));
         return;
      }
      if (StringUtil.isNullOrEmpty(account)) {
         out.print(JsonUtil.loadFalseResult(1, "请上传支付宝账号"));
         return;
      }
      UserInfo user = userInfoService.getUserById(uid);
      boolean bind = redisManager.isBindAlipayAccountSMSStateValid(user.getPhone());
      if (!bind) {
         out.print(JsonUtil.loadFalseResult(90002, "手机验证超时"));
         return;
      }
      String key = "bindalipay-" + uid;
      if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
         out.print(JsonUtil.loadFalseResult(1001, "服务器繁忙,请稍后重试"));
         return;
      }
      redisManager.cacheCommonString(key, "1", 120);
      // 可以展示给用户看的错误码
      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",
            "PERMIT_CHECK_PERM_IDENTITY_THEFT", "PERMIT_NON_BANK_LIMIT_PAYEE", "EXCEED_LIMIT_UNRN_DM_AMOUNT" };
      try {
         BindingAccount bindingAccount = bindingAccountService.changeAlipayBindingWithVerify(uid, name, account);
         out.print(JsonUtil.loadTrue(0, JsonUtil.getGson().toJson(bindingAccount),
               "系统已成功转账0.1元到提现账号中,提现账号验证通过,恭喜你!可以提现了。"));
      } catch (AlipayTransferException e1) {
         if (e1.getSubCode().equalsIgnoreCase("PAYEE_NOT_EXIST")) {
            String msg = "系统未能成功转账0.1元,提现账号信息有误,请核对后重新填写。";
            out.print(JsonUtil.loadFalseResult(1, msg));
         } else {
            for (String st : ALIPAY_CODES) {
               if (st.equalsIgnoreCase(e1.getSubCode())) {
                  out.print(JsonUtil.loadFalseResult(2, e1.getMsg()));
                  return;
               }
            }
            out.print(JsonUtil.loadFalseResult(3, "支付宝接口出错,验证失败,请联系客服。"));
            return;
         }
      } catch (AlipayApiException e2) {
         out.print(JsonUtil.loadFalseResult(4, e2.getErrMsg()));
         return;
      } catch (AlipayAccountException e3) {
         // 账户无余额
         if (e3.getCode() == AlipayAccountException.CODE_NO_MONEY) {
            out.print(JsonUtil.loadFalseResult(5, "你的账户目前没有余额,无需绑定提现账号。"));
            return;
            // 提现次数限制
         } else if (e3.getCode() == AlipayAccountException.CODE_TIMES_LIMIT) {
            out.print(JsonUtil.loadFalseResult(6, "每月仅可修改1次提现账号,请下月再试吧。"));
            return;
         } else {
            out.print(JsonUtil.loadFalseResult(7, e3.getMsg()));
            return;
         }
      } catch (Exception e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
         out.print(JsonUtil.loadFalseResult(8, "服务器内部错误,验证失败,请联系客服。"));
      } finally {
         redisManager.removeCommonString(key);
      }
   }
   /**
    * 获取用户资金详情
    * 
@@ -733,6 +848,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, "用户不存在"));
@@ -748,32 +864,42 @@
      }
      BigDecimal moneyLastMonth = inviteGetMoneyService.getMoneyLastMonth(uid + "");
      BigDecimal unOpenmoney = hongBaoService.getUnOpenHongBaoByUid(uid);
      BigDecimal totalFanMoney = hongBaoService.getMyTotalHongBaoByUid(user.getId());
      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", hongBaoService.getTotalTiChengMoney(uid).toString());// 累计提成
         data.put("totalUnGetTiChengMoney", hongBaoService.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", hongBaoService.getTotalTiChengMoney(uid));// 累计提成
         data.put("totalUnGetTiChengMoney", hongBaoService.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", hongBaoService.getTotalTiChengCount(uid) > 0);
         data.put("showTiCheng", spreadImgCount + shareCount > 0);
      }
      user.setNoOpenHongBao(unOpenmoney);