admin
2020-06-15 3e4ef41ffacd7f5fda2e81c3810cd11a6375b83c
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -53,7 +53,6 @@
import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.manger.order.TeamRewardManager;
import com.yeshi.fanli.service.manger.order.TeamSubsidyManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.cmq.HongBaoRecieveCMQManager;
@@ -108,9 +107,6 @@
   @Resource
   private TeamRewardManager teamRewardManager;
   @Resource
   private TeamSubsidyManager teamSubsidyManager;
   // 下级被封禁,红包失效
   private void invalidHongBaoForbidden(Long id) {
      HongBaoV2 updateHongBaoV2 = new HongBaoV2(id);
@@ -159,6 +155,9 @@
            }
         }
      }
      if(hongBaoList.size()==0)
         return;
      String taskKey = getTaskKey(uid);
@@ -228,6 +227,9 @@
            }
         }
      }
      if(hongBaoList.size()==0)
         return;
      // 邀请赚到账事务消息
@@ -294,6 +296,76 @@
            }
         }
      }
      if(hongBaoList.size()==0)
         return;
      // 邀请赚到账事务消息
      String taskKey = getTaskKey(uid);
      TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
            new Date());
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
      msg.setKey(taskKey);
      // 添加事务消息
      try {
         orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
            @Override
            public TransactionStatus execute(Message arg0, Object arg1) {
               try {
                  fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
               } catch (Exception e) {
                  return TransactionStatus.RollbackTransaction;
               }
               return TransactionStatus.CommitTransaction;
            }
         }, null);
      } catch (Exception e) {
         LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
      }
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void inviteSettleVipShop(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      // 查询UID的一二级邀请赚
      int sourceType = Constant.SOURCE_TYPE_VIP;
      List<Integer> types = new ArrayList<>();
      types.add(HongBaoV2.TYPE_YIJI);
      types.add(HongBaoV2.TYPE_ERJI);
      types.add(HongBaoV2.TYPE_SHARE_YIJI);
      types.add(HongBaoV2.TYPE_SHARE_ERJI);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
      for (int i = 0; i < hongBaoList.size(); i++) {
         HongBaoV2 item = hongBaoList.get(i);
         if (item != null && item.getParent() != null) {
            if (item != null) {
               HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(item.getParent().getId());
               if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {
                  CommonOrder co = hongBaoOrder.getCommonOrder();
                  // 上级用户不是正常用户,订单均不能到账
                  UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
                  if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
                     invalidHongBaoForbidden(item.getId());
                     hongBaoList.remove(i);
                     i--;
                  }
               }
            }
         }
      }
      if(hongBaoList.size()==0)
         return;
      // 邀请赚到账事务消息
      String taskKey = getTaskKey(uid);
@@ -409,10 +481,19 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void shareSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      shareSettleVipShop(Constant.SOURCE_TYPE_PDD, uid, maxPregetTime);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void shareSettleVipShop(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      shareSettleVipShop(Constant.SOURCE_TYPE_VIP, uid, maxPregetTime);
   }
   private void shareSettleVipShop(int sourceType, Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      /**
       * 处理分享赚
       */
      int sourceType = Constant.SOURCE_TYPE_PDD;
      List<Integer> types = new ArrayList<>();
      // 查询UID的分享赚订单
@@ -665,7 +746,6 @@
      List<Long> hbIdList = new ArrayList<>();
      Set<String> drawBackOrders = new HashSet<String>();
      List<Long> recieveHongBaoIds = new ArrayList<>();
      int shareGoodsCount = 0;
      Set<String> shareOrders = new HashSet<>();
      for (HongBaoV2 hongBao : hongBaoList) {
@@ -689,7 +769,6 @@
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
            if (hongBaoOrder != null) {
               balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
               shareGoodsCount += hongBaoOrder.getCommonOrder().getCount();
            }
            shareOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
            if (balanceTime != null
@@ -724,9 +803,8 @@
         }
         // 新版通知
         userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(),
               shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), null,
               null);
         userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, sharemoney,
               userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), new Date());
         for (String orderId : drawBackOrders)
            taoBaoWeiQuanDrawBackService.doWeiQuanShare(orderId);
@@ -757,7 +835,6 @@
      BigDecimal sharemoney = new BigDecimal(0);
      List<Long> hbIdList = new ArrayList<>();
      List<Long> recieveHongBaoIds = new ArrayList<>();
      int shareGoodsCount = 0;
      Set<String> shareOrders = new HashSet<>();
      for (HongBaoV2 hongBao : hongBaoList) {
@@ -778,9 +855,6 @@
            hbIdList.add(hongBao.getId());
            // 2018-08-05 过后的订单才处理维权
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
            if (hongBaoOrder != null) {
               shareGoodsCount += hongBaoOrder.getCommonOrder().getCount();
            }
            shareOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
         }
      }
@@ -809,10 +883,8 @@
            }
         }
         // 新版通知
         userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(),
               shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), null,
               null);
         userMoneyMsgNotificationService.shareOrderReceived(uid, sourceType, sharemoney,
               userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), new Date());
      }
      hongBaoV2SettleTempService.addTemp(recieveHongBaoIds, key);
@@ -820,27 +892,12 @@
      // 所有的返利到账红包ID
      for (Long hongBaoId : recieveHongBaoIds) {
         try {
            if(Constant.ENABLE_MQ)
            HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
            if (Constant.ENABLE_MQ)
               HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
         }
      }
   }
   /**
    * 邀请补贴结算
    *
    * @param orderId
    * @param sourceType
    * @throws ParamsException
    * @throws TeamEincomeRecordException
    */
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void inviteSubsidySettle(Long uid, String taskKey, Date maxPreGetTime)
         throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException {
      teamSubsidyManager.addToTeamEincome(uid, taskKey, maxPreGetTime);
   }
   private String getTaskKey(Long uid) {