yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoServiceImpl.java
@@ -996,131 +996,6 @@
         System.out.println("订单:" + order);
   }
   @Transactional
   @Override
   public void addHongBao(Order order, TaoBaoOrder taoBaoOrder, Long orderItemId) {
      OrderItem orderItem = orderItemMapper.selectByPrimaryKey(orderItemId);
      // 订单返利比例
      BigDecimal proportion = hongBaoManageService.getFanLiRate();
      BigDecimal baseRate = proportion.divide(new BigDecimal(100));
      // 创建红包
      JSONObject data = new JSONObject();
      HongBao hongBao = null;
      if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算"))
         // 订单结算应该取结算金额与预估收入
         hongBao = HongBaoFactory.createHongBao(MoneyBigDecimalUtil.mul(baseRate, taoBaoOrder.geteIncome()),
               data.toString(), order.getId(), null, order.getUserInfo(), 1, taoBaoOrder.getSettlement(),
               taoBaoOrder.getAuctionId());
      else
         hongBao = HongBaoFactory.createHongBao(MoneyBigDecimalUtil.mul(baseRate, taoBaoOrder.getEstimate()),
               data.toString(), order.getId(), null, order.getUserInfo(), 1, taoBaoOrder.getPayment(),
               taoBaoOrder.getAuctionId());
      hongBao.setOrderId(taoBaoOrder.getOrderId());
      hongBao.setOrderItemId(orderItem.getId());
      hongBao.setPreGettime(0L);
      if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算")
            && !StringUtil.isNullOrEmpty(taoBaoOrder.getSettlementTime()))
         hongBao.setBalanceTime(
               new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getSettlementTime(), "yyyy-MM-dd HH:mm:ss")));
      UserInfo boss = threeSaleMapper.selectBoss(order.getUserInfo().getId());
      if (boss != null) {
         hongBao.setHasChild(true);
      }
      // 如果失效就判定已经失效
      if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效"))
         hongBao.setState(HongBao.STATE_SHIXIAO);
      hongBaoMapper.insertSelective(hongBao);
      // 通知用户订单被统计
      if (!taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效")) {
         try {
            userNotificationService.orderFanliStatisticed(hongBao.getUserInfo().getId(), order.getOrderId());
         } catch (Exception e) {
         }
      }
      // 提成订单不处理失效订单
      if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效"))
         return;
      if (boss != null) {
         // 计算上级返利金额
         HongBaoManage hbm = hongBaoManageMapper
               .selectByKey("sale_6_" + (boss.getRank() == null ? 0 : boss.getRank()));
         BigDecimal rate = null;
         if (hbm == null)
            rate = new BigDecimal(0);
         else
            rate = new BigDecimal(hbm.getValue()).divide(new BigDecimal(100));
         if (rate.compareTo(new BigDecimal(0)) > 0) {
            HongBao hongBao2 = null;
            if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算")) {
               // 订单结算应该取结算金额与预估收入
               hongBao2 = HongBaoFactory.createHongBao(
                     MoneyBigDecimalUtil.mul(rate, MoneyBigDecimalUtil.mul(taoBaoOrder.geteIncome(), baseRate)),
                     null, hongBao, boss, Constant.ONESALE);
            } else {
               hongBao2 = HongBaoFactory.createHongBao(
                     MoneyBigDecimalUtil.mul(rate, MoneyBigDecimalUtil.mul(taoBaoOrder.getEstimate(), baseRate)),
                     null, hongBao, boss, Constant.ONESALE);
            }
            HongBaoFactory.createHongBao(
                  MoneyBigDecimalUtil.mul(rate, MoneyBigDecimalUtil.mul(taoBaoOrder.getEstimate(), baseRate)),
                  null, hongBao, boss, Constant.ONESALE);
            // 设置订单号
            hongBao2.setOrderId(taoBaoOrder.getOrderId());
            hongBaoMapper.insertSelective(hongBao2);
            try {
               // 通知提成订单被统计
               userNotificationService.tiChengStatisticed(hongBao2.getUserInfo().getId(), hongBao2.getOrderId(),
                     hongBao2.getMoney());
            } catch (Exception e) {
            }
         }
         UserInfo boss2 = threeSaleMapper.selectBoss(boss.getId());
         // 计算上上级返利
         if (boss2 != null) {
            hbm = hongBaoManageMapper.selectByKey("sale_7_" + (boss.getRank() == null ? 0 : boss.getRank()));
            if (hbm == null)
               rate = new BigDecimal(0);
            else
               rate = new BigDecimal(hbm.getValue()).divide(new BigDecimal(100));
            if (rate.compareTo(new BigDecimal(0)) > 0) {
               // 订单结算应该取结算金额与预估收入
               HongBao hongBao3 = null;
               if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算"))
                  hongBao3 = HongBaoFactory.createHongBao(
                        MoneyBigDecimalUtil.mul(rate,
                              MoneyBigDecimalUtil.mul(taoBaoOrder.geteIncome(), baseRate)),
                        null, hongBao, boss2, Constant.TWOSALE);
               else
                  hongBao3 = HongBaoFactory.createHongBao(
                        MoneyBigDecimalUtil.mul(rate,
                              MoneyBigDecimalUtil.mul(taoBaoOrder.getEstimate(), baseRate)),
                        null, hongBao, boss2, Constant.TWOSALE);
               // 设置返利订单号
               hongBao3.setOrderId(taoBaoOrder.getOrderId());
               hongBaoMapper.insertSelective(hongBao3);
               try {
                  // 通知提成订单被统计
                  userNotificationService.tiChengStatisticed(hongBao3.getUserInfo().getId(),
                        hongBao3.getOrderId(), hongBao3.getMoney());
               } catch (Exception e) {
               }
            }
         }
      }
   }
   @Override
   public BigDecimal getTotalTiChengMoney(Long uid) {
@@ -1234,50 +1109,17 @@
   
   @Override
   public List<Object> count24HOderByChannel(String channel, Integer type, String years,
   public List<Map<String, Object>> count24HOderByChannel(String channel, Integer type, String years,
         String startTime, String endTime) throws Exception{
      List<Map<String, Object>> list = hongBaoMapper.count24HOderByChannel(channel, type, years,
            startTime, endTime);
      if (list == null || list.size() == 0) {
         return null;
      }
      switch (type){
         case 1: // 按天处理
            return dayFactory(startTime, endTime, list);
         case 2: // 按月处理
            return monthFactory(list);
         case 3:
            return yearFactory(list);
         default:
            return null;
      }
      return hongBaoMapper.count24HOderByChannel(channel, type, years, startTime, endTime);
   }
   
   @Override
   public List<Object> countHistoryOderByChannel(String channel, Integer type, String years,
   public List<Map<String, Object>> countHistoryOderByChannel(String channel, Integer type, String years,
         String startTime, String endTime) throws Exception{
      
      List<Map<String, Object>> list = hongBaoMapper.countHistoryOderByChannel(channel, type, years,
      return hongBaoMapper.countHistoryOderByChannel(channel, type, years,
            startTime, endTime);
      if (list == null || list.size() == 0) {
         return null;
      }
      switch (type){
         case 1: // 按天处理
            return dayFactory(startTime, endTime, list);
         case 2: // 按月处理
            return monthFactory(list);
         case 3:
            return yearFactory(list);
         default:
            return null;
      }
   }
   
   
@@ -1321,7 +1163,7 @@
         
         for (int j = 0; j < list.size(); j++) {
            Map<String, Object> map = list.get(j);
            Object createDate = map.get("createDate");
            Object createDate = map.get("showDate");
            String month = createDate.toString();
            if (plusDay.equalsIgnoreCase(month)) {
               payMoney = map.get("payMoney");
@@ -1350,7 +1192,7 @@
           SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
         Date parseDate = sdf.parse(plusDay.toString());
         
         mapObject.put("createDate", sdf2.format(parseDate));
         mapObject.put("showDate", sdf2.format(parseDate));
         
         listObject.add(mapObject);
         
@@ -1375,7 +1217,7 @@
         
         for (int j = 0; j < list.size(); j++) {
            Map<String, Object> map = list.get(j);
            Object createDate = map.get("createDate");
            Object createDate = map.get("showDate");
            String month = createDate.toString();
            if ((i+"").equalsIgnoreCase(month) || i == Integer.parseInt(month)) {
               payMoney = map.get("payMoney");
@@ -1400,7 +1242,7 @@
         }
         mapObject.put("commision", commision);
         
         mapObject.put("createDate", i + "月");
         mapObject.put("showDate", i + "月");
         
         listObject.add(mapObject);
      }
@@ -1430,8 +1272,7 @@
         if (commision == null) {
             commision = 0;
         }
         map.put("commision", commision + "年");
         map.put("commision", commision);
         
         listObject.add(map);
      }