admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java
@@ -26,6 +26,7 @@
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.HongBaoDTO;
import com.yeshi.fanli.dto.order.HongBaoAddResult;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
@@ -150,11 +151,13 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException {
   public HongBaoAddResult addHongBao(List<CommonOrder> commonOrderList, int type)
         throws HongBaoException, UserAccountException {
      Set<Integer> stateSet = new HashSet<>();// 订单状态Set
      if (commonOrderList != null && commonOrderList.size() > 0) {
         int orderType = commonOrderList.get(0).getSourceType();
         boolean miandan = false;
         Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
         int goodsCount = 0;
         boolean hasAdd = false;
@@ -166,7 +169,7 @@
               throw new HongBaoException(1, "订单信息不完整");
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
            if (hongBaoOrder == null) {
               saveHongBao(commonOrder, type, notificationMap);
               miandan = saveHongBao(commonOrder, type, notificationMap);
               hasAdd = true;
            } else {
               boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
@@ -204,22 +207,24 @@
                  break;
               case HongBaoV2.TYPE_YIJI:
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               case HongBaoV2.TYPE_ERJI:
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,    commonOrder.getPayment(), money,
                        goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               case HongBaoV2.TYPE_SHARE_YIJI:
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
               case HongBaoV2.TYPE_SHARE_ERJI:
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,    commonOrder.getPayment(), money,
                        goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               }
            }
@@ -227,14 +232,14 @@
         int resultCode = 0;
         if (hasAdd && hasUpdate)
            return 12;
            return new HongBaoAddResult(HongBaoAddResult.CODE_ADD_AND_UPDATE, miandan);
         else if (hasAdd)
            return 1;
            return new HongBaoAddResult(HongBaoAddResult.CODE_ADD, miandan);
         else if (hasUpdate)
            return 2;
         return resultCode;
            return new HongBaoAddResult(HongBaoAddResult.CODE_UPDATE, miandan);
         return new HongBaoAddResult(resultCode, miandan);
      }
      return 0;
      return new HongBaoAddResult(0, false);
   }
   private int getOrderState(Set<Integer> states) {
@@ -264,7 +269,8 @@
         return false;
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime());
         // 免单处理
         boolean mianDan = false;
         List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
@@ -518,7 +524,8 @@
               && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))
            fanliRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
         else
            fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
            fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
                  commonOrder.getCreateTime().getTime());
         List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService
               .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo());
@@ -639,10 +646,11 @@
   }
   @Transactional(rollbackFor = Exception.class)
   private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
   private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
         throws HongBaoException, UserAccountException {
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime());
         // 查询是否有免单计划
         BigDecimal mianDanMoney = null;
         if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
@@ -743,7 +751,7 @@
            BigDecimal firstRate = hongBaoManageService
                  .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
            if (firstRate.compareTo(new BigDecimal(0)) <= 0)
               return;
               return mianDanMoney != null;
            HongBaoV2 firstHongbao = new HongBaoV2();
            firstHongbao.setUserInfo(boss);
            firstHongbao.setUrank(boss.getRank());
@@ -769,7 +777,7 @@
            }
            // 返利为0的不通知
            if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
               return;
               return mianDanMoney != null;
            hongBaoV2Mapper.insertSelective(firstHongbao);
            // 用户通知
@@ -796,7 +804,7 @@
               BigDecimal secondRate = hongBaoManageService
                     .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
               if (secondRate.compareTo(new BigDecimal(0)) <= 0)
                  return;
                  return mianDanMoney != null;
               HongBaoV2 secondHongbao = new HongBaoV2();
               secondHongbao.setUserInfo(boss);
               secondHongbao.setUrank(boss.getRank());
@@ -822,7 +830,7 @@
               // 返利为0的不统计
               if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
                  return;
                  return mianDanMoney != null;
               hongBaoV2Mapper.insertSelective(secondHongbao);
@@ -846,18 +854,19 @@
            }
         }
         return mianDanMoney != null;
      } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
         // 分享赚不加入失效的订单
         if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
            return;
            return false;
         // 分享赚
         BigDecimal shareRate = null;
         if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO
               && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))// 来自于淘礼金的分享
            shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
         else
            shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
            shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
                  commonOrder.getCreateTime().getTime());
         // 判断订单分享活动是否开启
         if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.shareGoodsActivityOpen.getKey()))) {
@@ -1015,6 +1024,8 @@
         }
      } else
         throw new HongBaoException(2, "type错误");
      return false;
   }
   @Override
@@ -1157,4 +1168,10 @@
      return hongBaoV2Mapper.listByOrderTradeId(tradeId);
   }
   @Override
   public Integer getDirectBossUrankByPid(Long pid) {
      return hongBaoV2Mapper.getDirectBossUrankByPid(pid);
   }
}