admin
2020-04-21 0b57cfd62e842b309d03467b96a331c673ecad7c
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java
@@ -59,7 +59,6 @@
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
import com.yeshi.fanli.vo.order.CommonOrderVO;
import com.yeshi.fanli.vo.order.CurrentBonusVO;
import com.yeshi.fanli.vo.order.GoodsRebateVO;
import com.yeshi.fanli.vo.order.HongBaoCountVO;
import com.yeshi.fanli.vo.order.OrderCountVO;
@@ -480,24 +479,6 @@
         dividend = new BigDecimal(0);
         // 总团队奖励
         teamMoney = bonus.add(subsidy).add(dividend);
         JSONObject paramsFanli = new JSONObject();
         paramsFanli.put("type", "1");
         data.put("paramsFanli", paramsFanli);
         data.put("jumpFanli", jumpDetailV2Service.getByTypeCache("fanli_share_statistics",
               Constant.getPlatformCode(acceptData.getPlatform()), Integer.parseInt(acceptData.getVersion())));
         JSONObject paramsShare = new JSONObject();
         paramsShare.put("type", "2");
         data.put("paramsShare", paramsShare);
         data.put("jumpShare", jumpDetailV2Service.getByTypeCache("fanli_share_statistics",
               Constant.getPlatformCode(acceptData.getPlatform()), Integer.parseInt(acceptData.getVersion())));
         JSONObject paramsTeam = new JSONObject();
         paramsTeam.put("type", "3");
         data.put("paramsTeam", paramsTeam);
         data.put("jumpTeam", jumpDetailV2Service.getByTypeCache("team_statistics",
               Constant.getPlatformCode(acceptData.getPlatform()), Integer.parseInt(acceptData.getVersion())));
      }
      data.put("inviteMoney", teamMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
      out.print(JsonUtil.loadTrueResult(data));
@@ -591,8 +572,7 @@
            hongBao = MoneyBigDecimalUtil.sub(hongBao, weiQuanMoney);
         }
      }
      orderRebateVO.setFanLiDesc(predictDesc + typeName);
      orderRebateVO.setFanLi("¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN));
      
      HongBaoV2 hongBaoV2 = hoList.get(0).getHongBaoV2();
      UserLevelEnum userLevel = UserLevelUtil.getByOrderRank(hongBaoV2.getUrank());
@@ -600,6 +580,15 @@
         userLevel = UserLevelEnum.daRen;
      UserLevelEnum upperLevel =  UserLevelEnum.superVIP;
         
      CommonOrder commonOrder1 = hoList.get(0).getCommonOrder();
      Date downTime = commonOrder1.getThirdCreateTime();
      Integer urank = commonOrder1.getUrank();
      UserLevelEnum buyerUserLevel = UserLevelUtil.getByOrderRank(urank);
      boolean direct = false;
      if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
         direct = true;
      }
      BigDecimal upperTotalMoney = new BigDecimal(0);
      List<GoodsRebateVO> voList = new ArrayList<>();
      for (HongBaoOrder hongBaoOrder : hoList) {
@@ -623,20 +612,20 @@
            payment = new BigDecimal(0);
         goodsVO.setActualPay("¥" + payment.setScale(2, BigDecimal.ROUND_DOWN));
         
         BigDecimal fanli = hongBaoOrder.getHongBaoV2().getMoney();
         // 基础佣金
         BigDecimal commission = orderHongBaoMoneyComputeService.computeBaseFanliMoney(commonOrder);
         if (type == 3) { // 奖金
            goodsVO.setBonus("¥" + hongBaoOrder.getHongBaoV2().getMoney() +"");
         } else { // 佣金
            goodsVO.setCommision("¥" +commission);
         }
         // 平台补贴
         BigDecimal vipFanli = hongBaoOrder.getHongBaoV2().getMoney();
         goodsVO.setSubsidy("¥" + vipFanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN));
         goodsVO.setCommision("¥" +commission.setScale(2, BigDecimal.ROUND_DOWN));
         // 平台补贴  = 返利 - 基础佣金
         goodsVO.setSubsidy("¥" + fanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN));
         //  达人补贴
         if (userLevel != UserLevelEnum.daRen) {
            BigDecimal darenFanli = orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, UserLevelEnum.daRen);
            goodsVO.setOriginSubsidy("¥" + darenFanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN) + "");
         }
         if (type == 3) { // 奖金
            goodsVO.setBonus("¥" + fanli.setScale(2, BigDecimal.ROUND_DOWN) +"");
         }
         
         voList.add(goodsVO);
@@ -645,9 +634,12 @@
            upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, upperLevel));
         } else if (type == 2) {
            upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, upperLevel));
         } else if (type == 3) {
            upperTotalMoney = upperTotalMoney.add(hongBao);
         }
      }
         
      // 团队补贴
      if (type == 3) {
         BigDecimal teamSubsidy = null;
@@ -655,17 +647,23 @@
         InviteOrderSubsidy inviteOrderSubsidy = inviteOrderSubsidyServiceV2.getByOrderNoAndType(uid, orderNo, sourceType);
         if (inviteOrderSubsidy != null) {
            teamSubsidy = inviteOrderSubsidy.getMoney();
            // 计算原比例
            BigDecimal originRate = orderHongBaoMoneyComputeService.getTeamSubsidyRate(downTime,buyerUserLevel, userLevel, direct);
            // 计算达人补贴
            if (userLevel != UserLevelEnum.daRen) {
               CommonOrder commonOrder = hoList.get(0).getCommonOrder();
               Integer urank = commonOrder.getUrank();
               UserLevelEnum buyerUserLevel = UserLevelUtil.getByOrderRank(urank);
               boolean direct = false;
               if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
                  direct = true;
               }
               // 计算上一级补贴
               lowerSubsidy = getLowerSubsidy(inviteOrderSubsidy.getMoney(), commonOrder.getThirdCreateTime(), buyerUserLevel, userLevel, direct);
               BigDecimal daRenRate = orderHongBaoMoneyComputeService.getTeamSubsidyRate(downTime,   buyerUserLevel,
                     UserLevelEnum.daRen, direct);
               lowerSubsidy = MoneyBigDecimalUtil.div(teamSubsidy.multiply(daRenRate), originRate);
            }
            // 计算超级会员补贴
            if (userLevel != UserLevelEnum.superVIP && userLevel != UserLevelEnum.tearcher) {
               BigDecimal vipRate = orderHongBaoMoneyComputeService.getTeamSubsidyRate(downTime,   buyerUserLevel,
                     UserLevelEnum.superVIP, direct);
               upperTotalMoney = upperTotalMoney.add(MoneyBigDecimalUtil.div(teamSubsidy.multiply(vipRate), originRate));
            }
         } else {
            teamSubsidy = BigDecimal.valueOf(0.00);
            lowerSubsidy =  BigDecimal.valueOf(0.00);
@@ -677,17 +675,23 @@
         orderRebateVO.setSubsidyDesc("团队补贴");
         orderRebateVO.setSubsidy("¥" + teamSubsidy.setScale(2, BigDecimal.ROUND_DOWN) +"");
         
         upperTotalMoney = upperTotalMoney.add(teamSubsidy);
         hongBao = hongBao.add(teamSubsidy);
      }
      orderRebateVO.setFanLiDesc(predictDesc + typeName);
      orderRebateVO.setFanLi("¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN));
      
      orderRebateVO.setType(type);
      orderRebateVO.setStateDesc(stateDesc);
      orderRebateVO.setListGoods(voList);
      orderRebateVO.setUserLevel(userLevel.name());
      if (downTime.getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME) {
         orderRebateVO.setUserLevel(UserLevelEnum.superVIP.name()); // 隐藏
      } else {
         orderRebateVO.setUserLevel(userLevel.name());
      }
      
      // 上级返利
      // 超级会员返利
      if (upperLevel != null) {
         upperTotalMoney = upperTotalMoney.add(hongBao);
         orderRebateVO.setUpperFanLi("¥" + upperTotalMoney);
         orderRebateVO.setJumpLink(upperLevel.getDetailLink());
      }
@@ -709,7 +713,6 @@
               freeState = state;
               break;
            }
         }
      }
      
@@ -745,14 +748,14 @@
         }
      } else {
         Date accountTime = hongBaoV2.getGetTime();
         if (accountTime != null) {
         // 到账时间 -红包金额限制
         if (accountTime != null && hongBao.compareTo(Constant.REWARD_COUPON_LIMIT_MONEY) <= 0) {
            boolean vip = userInviteService.verifyVIP(uid);
            Date endDay = DateUtil.plusDayDate(Constant.COUPON_REWARD_LIMIT_DAY, accountTime);
            long currentTime = java.lang.System.currentTimeMillis();
            if (endDay.getTime() > currentTime && !vip) {
               UserSystemCouponRecord couponRecord = userSystemCouponRecordService.getRecordByOrderNo(orderNo, null);
               if (couponRecord == null
                     || (couponRecord.getCouponType() == CouponTypeEnum.rebatePercentCoupon.name() && couponRecord.getState() != UserSystemCouponRecord.STATE_SUCCESS)) {
               if (couponRecord == null) {
                  orderRebateVO.setCoupon(true);
                  orderRebateVO.setCouponType(1);
                  orderRebateVO.setCouponText("立即使用");
@@ -767,99 +770,4 @@
      JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
   }
   
   private BigDecimal getLowerSubsidy(BigDecimal money, Date downTime,  UserLevelEnum buyerUserLevel, UserLevelEnum userLevel, boolean direct) {
      // 原始比例
      BigDecimal originRate = orderHongBaoMoneyComputeService.getTeamSubsidyRate(downTime,
            buyerUserLevel, userLevel, direct);
      // 小一级比例
      BigDecimal darenRate = orderHongBaoMoneyComputeService.getTeamSubsidyRate(downTime,   buyerUserLevel, UserLevelEnum.daRen, direct);
      return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.div(money,originRate), darenRate);
   }
   /**
    * 数据统计
    * @param acceptData
    * @param uid
    * @param type 1自购 2分享 3团队
    * @param out
    */
   @RequestMapping(value = "getCurrentBonus", method = RequestMethod.POST)
   public void getCurrentBonus(AcceptData acceptData, Long uid, Integer type, PrintWriter out) {
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
         return;
      }
      JSONObject data = new JSONObject();
      if (type == 1 || type == 2) {
         CurrentBonusVO bonus = new CurrentBonusVO();
         bonus.setToday(hongBaoV2CountService.geBonusByuid(uid, 1, type, 2).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonus.setYesterday(hongBaoV2CountService.geBonusByuid(uid, 2, type, 2).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonus.setThisMonth(hongBaoV2CountService.geBonusByuid(uid, 3, type, 2).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonus.setLastMonth(hongBaoV2CountService.geBonusByuid(uid, 4, type, 2).setScale(2, BigDecimal.ROUND_DOWN).toString());
         CurrentBonusVO bonusNot = new CurrentBonusVO();
         bonusNot.setToday(hongBaoV2CountService.geBonusByuid(uid, 1, type, 1).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonusNot.setYesterday(hongBaoV2CountService.geBonusByuid(uid, 2, type, 1).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonusNot.setThisMonth(hongBaoV2CountService.geBonusByuid(uid, 3, type, 1).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonusNot.setLastMonth(hongBaoV2CountService.geBonusByuid(uid, 4, type, 1).setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("bonus",bonus);
         data.put("bonusNot",bonusNot);
         data.put("total", hongBaoV2CountService.geBonusByuid(uid, null, type, 2).setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("totalNot", hongBaoV2CountService.geBonusByuid(uid, null, type, 1).setScale(2, BigDecimal.ROUND_DOWN).toString());
      } else {
         CurrentBonusVO bonus = new CurrentBonusVO();
         bonus.setToday(hongBaoV2CountService.geBonusByuid(uid, 1, type, 4).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonus.setYesterday(hongBaoV2CountService.geBonusByuid(uid, 2, type, 4).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonus.setThisMonth(hongBaoV2CountService.geBonusByuid(uid, 3, type, 4).setScale(2, BigDecimal.ROUND_DOWN).toString());
         bonus.setLastMonth(hongBaoV2CountService.geBonusByuid(uid, 4, type, 2).setScale(2, BigDecimal.ROUND_DOWN).toString());
         CurrentBonusVO subsidy = new CurrentBonusVO();
         subsidy.setToday(inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid,1,null).setScale(2, BigDecimal.ROUND_DOWN).toString());
         subsidy.setYesterday(inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid,2,null).setScale(2, BigDecimal.ROUND_DOWN).toString());
         subsidy.setThisMonth(inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid,3,null).setScale(2, BigDecimal.ROUND_DOWN).toString());
         subsidy.setLastMonth(inviteOrderSubsidyServiceV2.sumMoneyByUidAndDateAndState(uid,4,null,3).setScale(2, BigDecimal.ROUND_DOWN).toString());
         // TODO 分红统计
         CurrentBonusVO dividend = new CurrentBonusVO();
         dividend.setThisMonth("0.00");
         dividend.setLastMonth("0.00");
         BigDecimal totalBonus = hongBaoV2CountService.geBonusByuid(uid, null, type, 2);
         BigDecimal totalubsidy = inviteOrderSubsidyServiceV2.sumRecievedMoneyByUid(uid,null);
         BigDecimal totalDividend = new BigDecimal(0);
         BigDecimal total = totalDividend.add(totalBonus).add(totalubsidy);
         data.put("bonus",bonus);
         data.put("subsidy",subsidy);
         data.put("dividend",dividend);
         data.put("subsidy",subsidy);
         data.put("total", total.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("totalBonus", totalBonus.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("totalubsidy", totalubsidy.setScale(2, BigDecimal.ROUND_DOWN).toString());
         data.put("totalDividend", totalDividend.setScale(2, BigDecimal.ROUND_DOWN).toString());
      }
      String key = null;
      if (type == 1) {
         key = ConfigKeyEnum.bonusCountLinkFanli.getKey();
      } else if (type == 2) {
         key = ConfigKeyEnum.bonusCountLinkShare.getKey();
      } else {
         key = ConfigKeyEnum.bonusCountLinkTeam.getKey();
      }
      data.put("link",configService.get(key));
      out.print(JsonUtil.loadTrueResult(data));
   }
}