From 83bb6e0580b646c5d89da1cdb4085787c8136822 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期四, 23 四月 2020 14:29:48 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div --- fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java | 148 +++++++++++++++++++++++++++---------------------- 1 files changed, 82 insertions(+), 66 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 d1528e1..bb92104 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 @@ -1,6 +1,7 @@ package com.yeshi.fanli.service.manger.order; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -19,19 +20,20 @@ import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper; import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper; import com.yeshi.fanli.dto.HongBao; +import com.yeshi.fanli.dto.order.HongBaoAddResult; +import com.yeshi.fanli.dto.order.UserTeamLevel; 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; @@ -41,6 +43,7 @@ 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; @@ -94,6 +97,9 @@ @Resource private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; + @Resource + private TeamUserLevelStatisticService teamUserLevelStatisticService; + /** * 娣诲姞绾㈠寘淇℃伅 * @@ -106,7 +112,8 @@ * @throws OrderTeamRewardException * @throws InviteOrderSubsidyException */ - public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException { + public HongBaoAddResult addHongBao(List<CommonOrder> commonOrderList, int type) + throws HongBaoException, UserAccountException { if (commonOrderList != null && commonOrderList.size() > 0) { int orderType = commonOrderList.get(0).getSourceType(); @@ -125,6 +132,8 @@ Date placeOrderDate = commonOrderList.get(0).getThirdCreateTime(); + boolean miandan = false; + for (CommonOrder commonOrder : commonOrderList) { stateSet.add(commonOrder.getState()); goodsCount += commonOrder.getCount(); @@ -132,7 +141,7 @@ throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�"); HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); if (hongBaoOrder == null) { - saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate); + miandan = saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate); hasAdd = true; } else { boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap, placeOrderDate); @@ -142,31 +151,8 @@ } } - 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); - } - } /** * 閫氱煡鐢ㄦ埛鐨勮繑鍒╂儏鍐� @@ -183,15 +169,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: @@ -207,27 +184,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; @@ -239,14 +216,14 @@ int resultCode = 0; if (hasAdd && hasUpdate) - return 12; + return new HongBaoAddResult(HongBaoAddResult.CODE_ADD_AND_UPDATE, miandan); else if (hasAdd) - return 1; + return new HongBaoAddResult(HongBaoAddResult.CODE_ADD, miandan); else if (hasUpdate) - return 2; - return resultCode; + return new HongBaoAddResult(HongBaoAddResult.CODE_UPDATE, miandan); + return new HongBaoAddResult(resultCode, miandan); } - return 0; + return new HongBaoAddResult(0, false); } private int getOrderState(Set<Integer> states) { @@ -261,6 +238,24 @@ return CommonOrder.STATE_JS; } return CommonOrder.STATE_SX; + } + + private List<UserTeamLevel> getBossList(Long uid, int deep) { + List<UserTeamLevel> resultList = new ArrayList<>(); + List<ThreeSale> threeSales = threeSaleSerivce.getMyBossDeepList(uid, deep); + + if (threeSales != null) { + 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())); + } + } + + return resultList; } private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type, @@ -339,14 +334,18 @@ // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); if (children != null && children.size() > 0) { + List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + for (HongBaoV2 child : children) { if (child.getState() == HongBaoV2.STATE_YILINGQU) continue; if (child.getType() == HongBaoV2.TYPE_YIJI) { - money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, + bossList); } else if (child.getType() == HongBaoV2.TYPE_ERJI) { - money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, + bossList); } HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder); @@ -382,8 +381,11 @@ } if (boss != null) { + List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + // 鎻掑叆涓�绾у瓙绾㈠寘 - money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, + bossList); UserLevelEnum bossUserLevel = userLevelManager.getUserLevel(boss.getId()); if (money != null) { HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder, @@ -397,7 +399,7 @@ } if (boss != null) { money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, - buyerLevel); + buyerLevel, bossList); bossUserLevel = userLevelManager.getUserLevel(boss.getId()); if (money != null) { HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder, @@ -437,15 +439,18 @@ // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); - if (children != null) + if (children != null && children.size() > 0) { + List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); for (HongBaoV2 child : children) { if (child.getState() == HongBaoV2.STATE_YILINGQU) continue; if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) { - money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, + bossList); } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) { - money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, + bossList); } HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder); hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); @@ -472,6 +477,7 @@ } } + } } else throw new HongBaoException(2, "type閿欒"); @@ -479,7 +485,7 @@ } @Transactional(rollbackFor = Exception.class) - private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap, + private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap, UserLevelEnum buyerLevel, Date placeOrderDate) throws HongBaoException, UserAccountException { if (type == HongBaoV2.TYPE_ZIGOU) { @@ -520,13 +526,17 @@ orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel), mianDanMoney, buyerLevel); if (hongBao == null) - return; + return 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瀛樺湪涓旂孩鍖呮湭澶辨晥,鍏嶅崟涓嶆敮鎸佸绾у垎閿� - BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + + List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + + BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, + bossList); if (money == null)// 杩斿埄璧勯噾涓虹┖涓嶅弬涓庡垎鎴� - return; + return mianDanMoney != null; UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId()); @@ -538,10 +548,10 @@ // 鎻掑叆浜岀骇瀛愮孩鍖� boss = threeSaleSerivce.getBoss(boss.getId()); if (boss != null) {// 浜岀骇BOSS瀛樺湪涓旀槸闈炰細鍛樿鍗� - money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, bossList); bossLevel = userLevelManager.getUserLevel(boss.getId()); if (money == null) - return; + return mianDanMoney != null; HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_ERJI, money, bossLevel); addInviteHongBao(secondHongbao, null, notificationMap, commonOrder); @@ -551,7 +561,7 @@ } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { // 鍒嗕韩璧氫笉鍔犲叆澶辨晥鐨勮鍗� if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ) - return; + return false; // 鍒嗕韩璧� BigDecimal money = null; if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO @@ -568,18 +578,21 @@ money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel); if (money == null || money.compareTo(new BigDecimal(0)) <= 0) - return; + return false; HongBaoV2 hongBao = createShareHongBao(commonOrder, money, buyerLevel); if (hongBao == null) - return; + return false; addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap); // 4鏈�17鏃ュ悗鎵嶆湁涓�绾у垎浜禋 if (placeOrderDate.getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) { UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId()); if (boss != null) { - money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + + List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2); + + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, bossList); if (money == null) - return; + return false; UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId()); HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_SHARE_YIJI, money, bossLevel); @@ -589,9 +602,10 @@ // 浜岀骇鍒嗕韩璧� boss = threeSaleSerivce.getBoss(boss.getId()); if (boss != null) { - money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, + bossList); if (money == null)// 杩斿埄姣斾緥涓�0灏变笉缁熻 - return; + return false; bossLevel = userLevelManager.getUserLevel(boss.getId()); HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_SHARE_ERJI, money, bossLevel); @@ -624,6 +638,8 @@ // } } else throw new HongBaoException(2, "type閿欒"); + + return false; } /** -- Gitblit v1.8.0