From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 23 五月 2020 09:54:38 +0800 Subject: [PATCH] 足迹、收藏订单兼容新需求 --- fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java | 140 +++++++++++++++++++++++++--------------------- 1 files changed, 76 insertions(+), 64 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java b/fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java index 3ad78c1..10ff0a0 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java @@ -25,17 +25,14 @@ 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.entity.order.HongBaoOrder; -import com.yeshi.fanli.entity.order.InviteOrderSubsidy; import com.yeshi.fanli.exception.order.CommonOrderException; import com.yeshi.fanli.exception.order.HongBaoException; import com.yeshi.fanli.exception.order.InviteOrderSubsidyException; import com.yeshi.fanli.exception.user.UserAccountException; -import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService; import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService; @@ -45,7 +42,6 @@ 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; @@ -99,9 +95,6 @@ @Resource private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; - @Resource - private TeamUserLevelStatisticService teamUserLevelStatisticService; - /** * 娣诲姞绾㈠寘淇℃伅 * @@ -143,8 +136,10 @@ 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) { @@ -153,31 +148,7 @@ } } - if (hasAdd) { - try { - inviteOrderSubsidyService.addOrUpdateByOrder(orderId, orderType); - } catch (InviteOrderSubsidyException e) { - throw new HongBaoException(201, "娣诲姞琛ヨ创鍑洪敊"); - } catch (CommonOrderException e) { - throw new HongBaoException(202, "娣诲姞琛ヨ创鍑洪敊"); - } - } - int state = getOrderState(stateSet); - - if (hasAdd || hasUpdate) { - // 琛ヨ创澶辨晥 - if (state == CommonOrder.STATE_SX) - inviteOrderSubsidyService.invalidByOrderIdAndSourceType(orderId, orderType); - else - try { - inviteOrderSubsidyService.addOrUpdateByOrder(orderId, orderType); - } catch (InviteOrderSubsidyException e) { - LogHelper.errorDetailInfo(e, "娣樺疂璁㈠崟琛ヨ创鏇存柊澶辫触", orderId); - } catch (CommonOrderException e) { - LogHelper.errorDetailInfo(e, "娣樺疂璁㈠崟琛ヨ创鏇存柊澶辫触", orderId); - } - } /** * 閫氱煡鐢ㄦ埛鐨勮繑鍒╂儏鍐� @@ -194,15 +165,6 @@ CommonOrder commonOrder = notificationMap.get(t).getCommonOrder(); Long uid = notify.getUserInfo().getId(); - List<InviteOrderSubsidy> subsidyList = inviteOrderSubsidyService.listByOrderNoAndTypeAndUid(orderId, - orderType, uid); - BigDecimal subsidy = new BigDecimal(0); - if (subsidyList != null) - for (InviteOrderSubsidy s : subsidyList) { - if (s.getState() != InviteOrderSubsidy.STATE_INVALID) - subsidy = subsidy.add(s.getOriginalMoney()); - } - BigDecimal money = notify.getMoney(); switch (t) { case HongBaoV2.TYPE_ZIGOU: @@ -218,27 +180,27 @@ break; case HongBaoV2.TYPE_YIJI: userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, - commonOrder.getPayment(), money, subsidy, goodsCount, state, + commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state, commonOrder.getThirdCreateTime()); break; case HongBaoV2.TYPE_ERJI: userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, - commonOrder.getPayment(), money, subsidy, 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, subsidy, 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, subsidy, goodsCount, state, + commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state, commonOrder.getThirdCreateTime()); break; @@ -282,13 +244,32 @@ 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; } @@ -368,7 +349,7 @@ // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); if (children != null && children.size() > 0) { - List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + List<UserTeamLevel> bossList = getBossList(children); for (HongBaoV2 child : children) { if (child.getState() == HongBaoV2.STATE_YILINGQU) @@ -415,7 +396,7 @@ } if (boss != null) { - List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + List<UserTeamLevel> bossList = getBossList(oldHongBao.getUserInfo().getId(), 2); // 鎻掑叆涓�绾у瓙绾㈠寘 money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, @@ -474,7 +455,7 @@ // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); if (children != null && children.size() > 0) { - List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + List<UserTeamLevel> bossList = getBossList(children); for (HongBaoV2 child : children) { if (child.getState() == HongBaoV2.STATE_YILINGQU) continue; @@ -519,7 +500,7 @@ } @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) { @@ -560,7 +541,7 @@ 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绾OSS瀛樺湪涓旂孩鍖呮湭澶辨晥,鍏嶅崟涓嶆敮鎸佸绾у垎閿� @@ -570,7 +551,7 @@ 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()); @@ -585,7 +566,7 @@ 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); @@ -595,7 +576,7 @@ } 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 @@ -612,10 +593,10 @@ 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")) { @@ -626,7 +607,7 @@ 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); @@ -639,7 +620,7 @@ 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); @@ -673,7 +654,7 @@ } else throw new HongBaoException(2, "type閿欒"); - return false; + return new HongBaoSaveResult(true, false); } /** @@ -686,6 +667,11 @@ 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) { @@ -948,4 +934,30 @@ 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; + } + } } -- Gitblit v1.8.0