| | |
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
|
| | | 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.service.inter.user.UserSystemCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
| | | import com.yeshi.fanli.service.manger.user.UserLevelManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | |
| | | @Resource
|
| | | private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
|
| | |
|
| | | @Resource
|
| | | private TeamUserLevelStatisticService teamUserLevelStatisticService;
|
| | |
|
| | | /**
|
| | | * 添加红包信息
|
| | | *
|
| | |
| | | throw new HongBaoException(1, "订单信息不完整");
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null) {
|
| | | miandan = saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate);
|
| | | hasAdd = true;
|
| | | HongBaoSaveResult result = saveHongBao(commonOrder, type, notificationMap, userLevel,
|
| | | placeOrderDate);
|
| | | miandan = result.isMiandan();
|
| | | hasAdd = result.isAdd();
|
| | | } else {
|
| | | boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap, placeOrderDate);
|
| | | if (update) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | int state = getOrderState(stateSet);
|
| | |
|
| | | /**
|
| | |
| | | case HongBaoV2.TYPE_ERJI:
|
| | |
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
|
| | | commonOrder.getThirdCreateTime());
|
| | |
|
| | | break;
|
| | |
|
| | | case HongBaoV2.TYPE_SHARE_YIJI:
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
|
| | | commonOrder.getThirdCreateTime());
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_ERJI:
|
| | |
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
|
| | | commonOrder.getThirdCreateTime());
|
| | |
|
| | | break;
|
| | |
| | | List<Long> uidList = new ArrayList<Long>();
|
| | | for (ThreeSale ts : threeSales)
|
| | | uidList.add(ts.getBoss().getId());
|
| | | List<TeamUserLevelStatistic> levelList = teamUserLevelStatisticService.listByUids(uidList);
|
| | | if (levelList != null)
|
| | | for (TeamUserLevelStatistic s : levelList) {
|
| | | resultList.add(new UserTeamLevel(s.getId(), s.getLevel()));
|
| | | }
|
| | |
|
| | | for (Long bossUid : uidList) {
|
| | | UserLevelEnum level = userLevelManager.getUserLevel(bossUid);
|
| | | resultList.add(new UserTeamLevel(bossUid, level));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | private List<UserTeamLevel> getBossList(List<HongBaoV2> children) {
|
| | | List<UserTeamLevel> resultList = new ArrayList<>();
|
| | | for (HongBaoV2 v2 : children) {
|
| | |
|
| | | UserLevelEnum level = UserLevelUtil.getByOrderRank(v2.getUrank());
|
| | | if (level == null)
|
| | | level = UserLevelEnum.daRen;
|
| | | UserTeamLevel teamLevel = new UserTeamLevel(v2.getUserInfo().getId(), level);
|
| | |
|
| | | if (v2.getType() == HongBaoV2.TYPE_YIJI || v2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
|
| | | resultList.add(0, teamLevel);
|
| | | } else {
|
| | | resultList.add(teamLevel);
|
| | | }
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | |
| | | // 获取子红包
|
| | | List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
|
| | | if (children != null && children.size() > 0) {
|
| | | List<UserTeamLevel> bossList = getBossList(oldHongBao.getUserInfo().getId(), 2);
|
| | | List<UserTeamLevel> bossList = getBossList(children);
|
| | |
|
| | | for (HongBaoV2 child : children) {
|
| | | if (child.getState() == HongBaoV2.STATE_YILINGQU)
|
| | |
| | | // 获取子红包
|
| | | List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
|
| | | if (children != null && children.size() > 0) {
|
| | | List<UserTeamLevel> bossList = getBossList(oldHongBao.getUserInfo().getId(), 2);
|
| | | List<UserTeamLevel> bossList = getBossList(children);
|
| | | for (HongBaoV2 child : children) {
|
| | | if (child.getState() == HongBaoV2.STATE_YILINGQU)
|
| | | continue;
|
| | |
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap,
|
| | | private HongBaoSaveResult saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap,
|
| | | UserLevelEnum buyerLevel, Date placeOrderDate) throws HongBaoException, UserAccountException {
|
| | |
|
| | | if (type == HongBaoV2.TYPE_ZIGOU) {
|
| | |
| | | orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel), mianDanMoney,
|
| | | buyerLevel);
|
| | | if (hongBao == null)
|
| | | return mianDanMoney != null;
|
| | | return new HongBaoSaveResult(false, mianDanMoney != null);
|
| | | addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
|
| | | UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
|
| | | if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1级BOSS存在且红包未失效,免单不支持多级分销
|
| | |
| | | BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel,
|
| | | bossList);
|
| | | if (money == null)// 返利资金为空不参与分成
|
| | | return mianDanMoney != null;
|
| | | return new HongBaoSaveResult(true, mianDanMoney != null);
|
| | |
|
| | | UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId());
|
| | |
|
| | |
| | | money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, bossList);
|
| | | bossLevel = userLevelManager.getUserLevel(boss.getId());
|
| | | if (money == null)
|
| | | return mianDanMoney != null;
|
| | | return new HongBaoSaveResult(true, mianDanMoney != null);
|
| | | HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
|
| | | HongBaoV2.TYPE_ERJI, money, bossLevel);
|
| | | addInviteHongBao(secondHongbao, null, notificationMap, commonOrder);
|
| | |
| | | } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
|
| | | // 分享赚不加入失效的订单
|
| | | if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
|
| | | return false;
|
| | | return new HongBaoSaveResult(false, false);
|
| | | // 分享赚
|
| | | BigDecimal money = null;
|
| | | if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO
|
| | |
| | | money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel);
|
| | |
|
| | | if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
|
| | | return false;
|
| | | return new HongBaoSaveResult(false, false);
|
| | | HongBaoV2 hongBao = createShareHongBao(commonOrder, money, buyerLevel);
|
| | | if (hongBao == null)
|
| | | return false;
|
| | | return new HongBaoSaveResult(false, false);
|
| | | addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
|
| | | // 4月17日后才有一级分享赚
|
| | | if (placeOrderDate.getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) {
|
| | |
| | |
|
| | | money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, bossList);
|
| | | if (money == null)
|
| | | return false;
|
| | | return new HongBaoSaveResult(true, false);
|
| | | UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId());
|
| | | HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
|
| | | HongBaoV2.TYPE_SHARE_YIJI, money, bossLevel);
|
| | |
| | | money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel,
|
| | | bossList);
|
| | | if (money == null)// 返利比例为0就不统计
|
| | | return false;
|
| | | return new HongBaoSaveResult(true, false);
|
| | | bossLevel = userLevelManager.getUserLevel(boss.getId());
|
| | | HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder,
|
| | | HongBaoV2.TYPE_SHARE_ERJI, money, bossLevel);
|
| | |
| | | } else
|
| | | throw new HongBaoException(2, "type错误");
|
| | |
|
| | | return false;
|
| | | return new HongBaoSaveResult(true, false);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | private void addInviteHongBao(HongBaoV2 child, String parentHongBaoUserName,
|
| | | Map<Integer, HongBaoOrder> notificationMap, CommonOrder commonOrder) {
|
| | | if (child != null) {
|
| | | // 老版本资金为0的红包不加入邀请订单
|
| | | if (child.getMoney() == null || (child.getMoney().compareTo(new BigDecimal(0)) == 0
|
| | | && commonOrder.getThirdCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME))
|
| | | return;
|
| | |
|
| | | hongBaoV2Mapper.insertSelective(child);
|
| | | // 用户通知
|
| | | if (notificationMap.get(child.getType()) == null) {
|
| | |
| | | return hongBao;
|
| | | }
|
| | |
|
| | | class HongBaoSaveResult {
|
| | | boolean add;
|
| | | boolean miandan;
|
| | |
|
| | | public void setMiandan(boolean miandan) {
|
| | | this.miandan = miandan;
|
| | | }
|
| | |
|
| | | public HongBaoSaveResult(boolean add, boolean miandan) {
|
| | | super();
|
| | | this.add = add;
|
| | | this.miandan = miandan;
|
| | | }
|
| | |
|
| | | public boolean isAdd() {
|
| | | return add;
|
| | | }
|
| | |
|
| | | public void setAdd(boolean add) {
|
| | | this.add = add;
|
| | | }
|
| | |
|
| | | public boolean isMiandan() {
|
| | | return miandan;
|
| | | }
|
| | | }
|
| | | }
|