| | |
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.exception.order.HongBaoException;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoException;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService;
|
| | |
| | | @Resource
|
| | | private UserVIPInfoService userVIPInfoService;
|
| | |
|
| | | // 保存红包
|
| | | public void saveHongBao1(CommonOrder commonOrder, int commonOrderType) throws HongBaoException, UserInfoException {
|
| | | // 查询上2级的信息
|
| | | long uid = commonOrder.getUserInfo().getId();
|
| | | UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | |
|
| | | UserInfo lastUser = threeSaleSerivce.getBoss(uid);
|
| | | UserInfo superLastUser = null;
|
| | | if (lastUser != null) {
|
| | | lastUser = userInfoService.selectAvailableByPrimaryKey(lastUser.getId());
|
| | | if (lastUser != null)
|
| | | superLastUser = threeSaleSerivce.getBoss(lastUser.getId());
|
| | | if (superLastUser != null)
|
| | | superLastUser = userInfoService.selectAvailableByPrimaryKey(superLastUser.getId());
|
| | | }
|
| | |
|
| | | if (commonOrderType == CommonOrder.ORDER_TYPE_ZIGOU) {
|
| | | // 保存红包信息
|
| | |
|
| | | } else if (commonOrderType == CommonOrder.ORDER_TYPE_SHARE) {
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加红包信息
|
| | | *
|
| | |
| | | boolean hasAdd = false;
|
| | | boolean hasUpdate = false;
|
| | | Set<Integer> stateSet = new HashSet<>();// 订单状态Set
|
| | | boolean isVIP = userVIPInfoService.isVIP(commonOrderList.get(0).getUserInfo().getId());
|
| | | for (CommonOrder commonOrder : commonOrderList) {
|
| | | stateSet.add(commonOrder.getState());
|
| | | goodsCount += commonOrder.getCount();
|
| | |
| | | throw new HongBaoException(1, "订单信息不完整");
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null) {
|
| | | saveHongBao(commonOrder, type, isVIP, notificationMap);
|
| | | saveHongBao(commonOrder, type, notificationMap);
|
| | | hasAdd = true;
|
| | | } else {
|
| | | boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
|
| | |
| | | return CommonOrder.STATE_SX;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
|
| | | Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException, UserAccountException {
|
| | | System.out.println(commonOrder.getOrderNo());
|
| | |
| | | HongBaoV2.TYPE_YIJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
|
| | | firstRate.divide(new BigDecimal(100))));
|
| | | if (firstHongbao != null)
|
| | | addInviteHongBao(firstHongbao, notificationMap, commonOrder);
|
| | | addInviteHongBao(firstHongbao, null, notificationMap, commonOrder);
|
| | | }
|
| | | boss = threeSaleSerivce.getBoss(boss.getId());
|
| | | if (boss != null) {
|
| | |
| | | HongBaoV2.TYPE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
|
| | | secondRate.divide(new BigDecimal(100))));
|
| | | if (secondHongbao != null)
|
| | | addInviteHongBao(secondHongbao, notificationMap, commonOrder);
|
| | | addInviteHongBao(secondHongbao, null, notificationMap, commonOrder);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private void saveHongBao(CommonOrder commonOrder, int type, boolean vip, Map<Integer, HongBaoOrder> notificationMap)
|
| | | private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
|
| | | throws HongBaoException, UserAccountException {
|
| | |
|
| | | boolean vip = commonOrder.getUrank() != null && commonOrder.getUrank() == 100;
|
| | | if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
|
| | | BigDecimal fanliRate = hongBaoManageService
|
| | | .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime()));
|
| | |
| | | HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_YIJI,
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
|
| | |
|
| | | addInviteHongBao(firstHongbao, notificationMap, commonOrder);
|
| | | addInviteHongBao(firstHongbao, null, notificationMap, commonOrder);
|
| | |
|
| | | // 插入二级子红包
|
| | | boss = threeSaleSerivce.getBoss(boss.getId());
|
| | |
| | | HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
|
| | | HongBaoV2.TYPE_ERJI,
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
|
| | | addInviteHongBao(secondHongbao, notificationMap, commonOrder);
|
| | | addInviteHongBao(secondHongbao, null, notificationMap, commonOrder);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | HongBaoV2.TYPE_SHARE_YIJI,
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstLevelRate.divide(new BigDecimal(100))));
|
| | |
|
| | | addInviteHongBao(firstHongbao, notificationMap, commonOrder);
|
| | | addInviteHongBao(firstHongbao, hongBao.getUserInfo().getNickName(), notificationMap, commonOrder);
|
| | |
|
| | | // 二级分享赚
|
| | | boss = threeSaleSerivce.getBoss(boss.getId());
|
| | |
| | | HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder,
|
| | | HongBaoV2.TYPE_SHARE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
|
| | | secondLevelRate.divide(new BigDecimal(100))));
|
| | | addInviteHongBao(secondChild, notificationMap, commonOrder);
|
| | | addInviteHongBao(secondChild, null, notificationMap, commonOrder);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | * @param notificationMap
|
| | | * @param commonOrder
|
| | | */
|
| | | private void addInviteHongBao(HongBaoV2 child, Map<Integer, HongBaoOrder> notificationMap,
|
| | | CommonOrder commonOrder) {
|
| | | private void addInviteHongBao(HongBaoV2 child, String parentHongBaoUserName,
|
| | | Map<Integer, HongBaoOrder> notificationMap, CommonOrder commonOrder) {
|
| | | if (child != null) {
|
| | | hongBaoV2Mapper.insertSelective(child);
|
| | | // 用户通知
|
| | |
| | | HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
|
| | | tempHongBao.setUserInfo(child.getUserInfo());
|
| | | tempHongBao.setMoney(child.getMoney());
|
| | | if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI)
|
| | | tempHongBao.setBeizhu(parentHongBaoUserName);
|
| | |
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
|