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的分享赚订单
@@ -817,21 +898,6 @@
            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) {