admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java
@@ -13,6 +13,7 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -25,18 +26,22 @@
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;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.entity.order.ShareGoodsActivityOrder;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.order.ShareGoodsActivityOrderException;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.exception.user.UserAccountException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
@@ -107,6 +112,7 @@
   @Resource
   private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
   @Lazy
   @Resource
   private UserSystemCouponService userSystemCouponService;
@@ -143,13 +149,15 @@
      return hongBaoV2Mapper.selectByPrimaryKey(id);
   }
   @Transactional
   @Transactional(rollbackFor = Exception.class)
   @Override
   public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException {
   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;
@@ -161,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);
@@ -169,6 +177,7 @@
                  hasUpdate = true;
            }
         }
         /**
          * 通知用户的返利情况
          */
@@ -185,77 +194,52 @@
               switch (t) {
               case HongBaoV2.TYPE_ZIGOU:
                  userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, goodsCount, state);
                        commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               case HongBaoV2.TYPE_SHARE_GOODS:
                  userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, goodsCount, state);
                        commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               case HongBaoV2.TYPE_YIJI:
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, goodsCount, state);
                        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, state);
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               case HongBaoV2.TYPE_SHARE_YIJI:
                  userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu());
                  break;
               }
            }
         }
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
         // 添加新版本通知
         if (!hasAdd) {
            Iterator<Integer> its = notificationMap.keySet().iterator();
            while (its.hasNext()) {
               Integer t = its.next();
               HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
               CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
               String orderId = commonOrderList.get(0).getOrderNo();
               Long uid = notify.getUserInfo().getId();
               BigDecimal money = notify.getMoney();
               switch (t) {
               case HongBaoV2.TYPE_ZIGOU:
                  userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, orderType,
                        commonOrder.getPayment(), money, state);
               case HongBaoV2.TYPE_SHARE_ERJI:
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                        commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                        commonOrder.getThirdCreateTime());
                  break;
               case HongBaoV2.TYPE_SHARE_GOODS:
                  userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, orderType,
                        commonOrder.getPayment(), money, state);
                  break;
               case HongBaoV2.TYPE_YIJI:
                  userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
                        commonOrder.getPayment(), money, state);
                  break;
               case HongBaoV2.TYPE_ERJI:
                  userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
                        commonOrder.getPayment(), money, state);
                  break;
               case HongBaoV2.TYPE_SHARE_YIJI:
                  userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId, orderType,
                        commonOrder.getPayment(), money, state);
               }
            }
         }
         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) {
@@ -272,9 +256,9 @@
      return CommonOrder.STATE_SX;
   }
   @Transactional
   @Transactional(rollbackFor = Exception.class)
   private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
         Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException {
         Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException, UserAccountException {
      System.out.println(commonOrder.getOrderNo());
      // 锁行
      HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBaoOrder.getHongBaoV2().getId());
@@ -285,7 +269,8 @@
         return false;
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
               commonOrder.getCreateTime().getTime());
         // 免单处理
         boolean mianDan = false;
         List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
@@ -310,7 +295,8 @@
                  MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
            if (mianDan)
               hongBao.setMoney(commonOrder.getPayment());
         } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
         } else if (commonOrder.getState() == CommonOrder.STATE_JS
               || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
@@ -366,6 +352,9 @@
         List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
         if (children != null && children.size() > 0)
            for (HongBaoV2 child : children) {
               if (child.getState() == HongBaoV2.STATE_YILINGQU)
                  continue;
               HongBaoV2 childUpdate = new HongBaoV2(child.getId());
               childUpdate.setState(hongBao.getState());
               childUpdate.setUpdateTime(new Date());
@@ -432,6 +421,7 @@
                  firstHongbao.setType(HongBaoV2.TYPE_YIJI);
                  firstHongbao.setVersion(2);
                  firstHongbao.setState(hongBao.getState());
                  firstHongbao.setOrderType(commonOrder.getSourceType());
                  if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
                     firstHongbao.setMoney(
@@ -445,24 +435,31 @@
                  } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
                     firstHongbao.setMoney(
                           MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
                  } else if (hongBao.getState() == HongBaoV2.STATE_SHIXIAO) {
                     firstHongbao.setMoney(new BigDecimal(0));
                  }
                  hongBaoV2Mapper.insertSelective(firstHongbao);
                  // 用户通知
                  if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) {
                     HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId());
                     tempHongBao.setUserInfo(firstHongbao.getUserInfo());
                     tempHongBao.setMoney(firstHongbao.getMoney());
                     CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                     tempCommonOrder.setPayment(commonOrder.getPayment());
                     notificationMap.put(HongBaoV2.TYPE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
                  } else {
                     // 增加付款金额与资金
                     HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI);
                     tempHongBaoOrder.getCommonOrder().setPayment(
                           tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                     tempHongBaoOrder.getHongBaoV2()
                           .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney()));
                     notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder);
                  if (firstHongbao.getMoney() != null
                        && firstHongbao.getMoney().compareTo(new BigDecimal(0)) > 0) {
                     hongBaoV2Mapper.insertSelective(firstHongbao);
                     // 用户通知
                     if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) {
                        HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId());
                        tempHongBao.setUserInfo(firstHongbao.getUserInfo());
                        tempHongBao.setMoney(firstHongbao.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        notificationMap.put(HongBaoV2.TYPE_YIJI,
                              new HongBaoOrder(tempCommonOrder, tempHongBao));
                     } else {
                        // 增加付款金额与资金
                        HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI);
                        tempHongBaoOrder.getCommonOrder().setPayment(
                              tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                        tempHongBaoOrder.getHongBaoV2().setMoney(
                              tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney()));
                        notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder);
                     }
                  }
                  // 插入二级子红包
@@ -480,6 +477,7 @@
                     secondHongbao.setType(HongBaoV2.TYPE_ERJI);
                     secondHongbao.setVersion(2);
                     secondHongbao.setState(hongBao.getState());
                     secondHongbao.setOrderType(commonOrder.getSourceType());
                     if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
                        secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                              secondRate.divide(new BigDecimal(100))));
@@ -492,26 +490,29 @@
                     } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
                        secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                              secondRate.divide(new BigDecimal(100))));
                     }
                     hongBaoV2Mapper.insertSelective(secondHongbao);
                     // 用户通知
                     if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) {
                        HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId());
                        tempHongBao.setUserInfo(secondHongbao.getUserInfo());
                        tempHongBao.setMoney(secondHongbao.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        notificationMap.put(HongBaoV2.TYPE_ERJI,
                              new HongBaoOrder(tempCommonOrder, tempHongBao));
                     } else {
                        // 增加付款金额与资金
                        HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI);
                        tempHongBaoOrder.getCommonOrder().setPayment(
                              tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                        tempHongBaoOrder.getHongBaoV2().setMoney(
                              tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney()));
                        notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder);
                     } else if (hongBao.getState() == HongBaoV2.STATE_SHIXIAO)
                        secondHongbao.setMoney(new BigDecimal(0));
                     if (secondHongbao.getMoney() != null
                           && secondHongbao.getMoney().compareTo(new BigDecimal(0)) > 0) {
                        hongBaoV2Mapper.insertSelective(secondHongbao);
                        // 用户通知
                        if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) {
                           HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId());
                           tempHongBao.setUserInfo(secondHongbao.getUserInfo());
                           tempHongBao.setMoney(secondHongbao.getMoney());
                           CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                           tempCommonOrder.setPayment(commonOrder.getPayment());
                           notificationMap.put(HongBaoV2.TYPE_ERJI,
                                 new HongBaoOrder(tempCommonOrder, tempHongBao));
                        } else {
                           // 增加付款金额与资金
                           HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI);
                           tempHongBaoOrder.getCommonOrder().setPayment(tempHongBaoOrder.getCommonOrder()
                                 .getPayment().add(commonOrder.getPayment()));
                           tempHongBaoOrder.getHongBaoV2().setMoney(
                                 tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney()));
                           notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder);
                        }
                     }
                  }
               }
@@ -523,7 +524,8 @@
               && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))
            fanliRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
         else
            fanliRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
            fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
                  commonOrder.getCreateTime().getTime());
         List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService
               .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo());
@@ -538,7 +540,8 @@
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
         } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
         } else if (commonOrder.getState() == CommonOrder.STATE_JS
               || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
@@ -574,6 +577,9 @@
         List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
         if (children != null)
            for (HongBaoV2 child : children) {
               if (child.getState() == HongBaoV2.STATE_YILINGQU)
                  continue;
               HongBaoV2 childUpdate = new HongBaoV2(child.getId());
               // 统一设置状态
               childUpdate.setState(hongBao.getState());
@@ -586,7 +592,8 @@
               }
               // 以实际收入为准计算预估收益
               if (CommonOrder.STATE_JS == commonOrder.getState()) {
               if (CommonOrder.STATE_JS == commonOrder.getState()
                     || CommonOrder.STATE_WQ == commonOrder.getState()) {
                  childUpdate.setMoney(
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
                  if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-16",
@@ -638,11 +645,12 @@
      return true;
   }
   @Transactional
   private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
         throws HongBaoException {
   @Transactional(rollbackFor = Exception.class)
   private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
         throws HongBaoException, UserAccountException {
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(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) {
@@ -686,7 +694,8 @@
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
         } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
         } else if (commonOrder.getState() == CommonOrder.STATE_JS
               || CommonOrder.STATE_WQ == commonOrder.getState()) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
@@ -706,7 +715,10 @@
            hongBao.setMoney(mianDanMoney);
         UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
         if (user == null)
            throw new UserAccountException(1001, "用户不存在/被封禁");
         hongBao.setUrank(user.getRank());
         hongBao.setOrderType(commonOrder.getSourceType());
         hongBaoV2Mapper.insertSelective(hongBao);
         // 添加红包与订单的映射
         HongBaoOrder hongBaoOrder = new HongBaoOrder();
@@ -739,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());
@@ -748,6 +760,7 @@
            firstHongbao.setType(HongBaoV2.TYPE_YIJI);
            firstHongbao.setVersion(2);
            firstHongbao.setState(hongBao.getState());
            firstHongbao.setOrderType(commonOrder.getSourceType());
            if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
               firstHongbao.setMoney(
@@ -764,7 +777,7 @@
            }
            // 返利为0的不通知
            if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
               return;
               return mianDanMoney != null;
            hongBaoV2Mapper.insertSelective(firstHongbao);
            // 用户通知
@@ -791,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());
@@ -800,6 +813,7 @@
               secondHongbao.setType(HongBaoV2.TYPE_ERJI);
               secondHongbao.setVersion(2);
               secondHongbao.setState(hongBao.getState());
               secondHongbao.setOrderType(commonOrder.getSourceType());
               if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
                  secondHongbao.setMoney(
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
@@ -816,7 +830,7 @@
               // 返利为0的不统计
               if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
                  return;
                  return mianDanMoney != null;
               hongBaoV2Mapper.insertSelective(secondHongbao);
@@ -840,21 +854,22 @@
            }
         }
         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(commonOrder.getCreateTime().getTime());
            shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
                  commonOrder.getCreateTime().getTime());
         // 判断订单分享活动是否开启
         if ("1".equalsIgnoreCase(configService.get("share_goods_activity_open"))) {
         if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.shareGoodsActivityOpen.getKey()))) {
            // 没有订单,并且是渠道ID来的,并且
            UserExtraTaoBaoInfo taoBaoExtraInfo = userExtraTaoBaoInfoService
                  .getByUid(commonOrder.getUserInfo().getId());
@@ -890,7 +905,8 @@
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), shareRate.divide(new BigDecimal(100))));
         } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
         } else if (commonOrder.getState() == CommonOrder.STATE_JS
               || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(
                  MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), shareRate.divide(new BigDecimal(100))));
@@ -901,8 +917,11 @@
                  calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd")));
         }
         UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
         if (user == null)
            throw new UserAccountException(1001, "用户不存在/被封禁");
         hongBao.setUrank(user.getRank());
         hongBao.setUserInfo(user);
         hongBao.setOrderType(commonOrder.getSourceType());
         hongBaoV2Mapper.insertSelective(hongBao);
         // 插入红包与订单映射
         HongBaoOrder hongBaoOrder = new HongBaoOrder();
@@ -941,7 +960,8 @@
                  child.setState(HongBaoV2.STATE_BUKELINGQU);
                  child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
                        firstLevelRate.divide(new BigDecimal(100))));
               } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
               } else if (commonOrder.getState() == CommonOrder.STATE_JS
                     || commonOrder.getState() == CommonOrder.STATE_WQ) {
                  child.setState(HongBaoV2.STATE_KELINGQU);
                  child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
                        firstLevelRate.divide(new BigDecimal(100))));
@@ -956,7 +976,8 @@
               child.setUrank(boss.getRank());
               child.setVersion(2);
               child.setCreateTime(new Date());
               if (child.getMoney().compareTo(new BigDecimal(0)) > 0) {
               child.setOrderType(commonOrder.getSourceType());
               if (child.getMoney() != null && child.getMoney().compareTo(new BigDecimal(0)) > 0) {
                  hongBaoV2Mapper.insertSelective(child);
                  // 添加通知
                  if (notificationMap.get(HongBaoV2.TYPE_SHARE_YIJI) == null) {
@@ -1001,9 +1022,10 @@
               e1.printStackTrace();
            }
         }
      } else
         throw new HongBaoException(2, "type错误");
      return false;
   }
   @Override
@@ -1080,6 +1102,13 @@
   }
   @Override
   public List<HongBaoV2> listChildrenByIds(List<Long> idList) {
      if (idList == null || idList.size() == 0)
         return null;
      return hongBaoV2Mapper.listChildrenByIds(idList);
   }
   @Override
   public List<Long> getUidByNear30DayShareSucceed() {
      return hongBaoV2Mapper.getUidByNear30DayShareSucceed();
   }
@@ -1128,4 +1157,21 @@
         return hongBaoV2List.get(0);
      return null;
   }
   @Override
   public List<HongBaoV2> listByIds(List<Long> idList) {
      return hongBaoV2Mapper.listByIds(idList);
   }
   @Override
   public List<HongBaoDTO> listByOrderTradeId(String tradeId) {
      return hongBaoV2Mapper.listByOrderTradeId(tradeId);
   }
   @Override
   public Integer getDirectBossUrankByPid(Long pid) {
      return hongBaoV2Mapper.getDirectBossUrankByPid(pid);
   }
}