yujian
2020-06-08 b3da9f82b7740d39742fef1a81a56c22fe1c8b9c
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -107,7 +107,6 @@
   @Resource
   private TeamRewardManager teamRewardManager;
   // 下级被封禁,红包失效
   private void invalidHongBaoForbidden(Long id) {
      HongBaoV2 updateHongBaoV2 = new HongBaoV2(id);
@@ -156,6 +155,9 @@
            }
         }
      }
      if(hongBaoList.size()==0)
         return;
      String taskKey = getTaskKey(uid);
@@ -225,6 +227,9 @@
            }
         }
      }
      if(hongBaoList.size()==0)
         return;
      // 邀请赚到账事务消息
@@ -291,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);
@@ -406,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的分享赚订单
@@ -815,7 +899,6 @@
         }
      }
   }
   private String getTaskKey(Long uid) {
      return uid + "-" + UUID.randomUUID().toString();