From 457265eb82265650cf6c87519803975f23bd2fd3 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 13 四月 2020 18:33:21 +0800 Subject: [PATCH] 订单统计与返利到账集成测试相关的bug修改 --- fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java | 265 ++++++++++++++++++++++++++++++---------------------- 1 files changed, 154 insertions(+), 111 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 02d8abe..2527f19 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 @@ -19,7 +19,6 @@ 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.OrderHongBaoRateParams; import com.yeshi.fanli.entity.bus.user.HongBaoV2; import com.yeshi.fanli.entity.bus.user.ThreeSale; import com.yeshi.fanli.entity.bus.user.UserInfo; @@ -27,9 +26,14 @@ 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.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; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService; import com.yeshi.fanli.service.inter.user.UserInfoService; @@ -42,6 +46,7 @@ import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.TaoBaoConstant; import com.yeshi.fanli.util.TimeUtil; +import com.yeshi.fanli.util.user.UserLevelUtil; @Component public class HongBaoV2AddManager { @@ -82,6 +87,12 @@ @Resource private UserLevelManager userLevelManager; + @Resource + private InviteOrderSubsidyService inviteOrderSubsidyService; + + @Resource + private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; + /** * 娣诲姞绾㈠寘淇℃伅 * @@ -90,17 +101,29 @@ * @return * @throws HongBaoException * @throws UserAccountException + * @throws CommonOrderException + * @throws OrderTeamRewardException + * @throws InviteOrderSubsidyException */ public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException { if (commonOrderList != null && commonOrderList.size() > 0) { int orderType = commonOrderList.get(0).getSourceType(); + String orderId = commonOrderList.get(0).getOrderNo(); Map<Integer, HongBaoOrder> notificationMap = new HashMap<>(); int goodsCount = 0; boolean hasAdd = false; boolean hasUpdate = false; Set<Integer> stateSet = new HashSet<>();// 璁㈠崟鐘舵�丼et + + UserLevelEnum userLevel = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank()); + + if (userLevel == null) + userLevel = UserLevelEnum.daRen; + + Date placeOrderDate = commonOrderList.get(0).getThirdCreateTime(); + for (CommonOrder commonOrder : commonOrderList) { stateSet.add(commonOrder.getState()); goodsCount += commonOrder.getCount(); @@ -108,19 +131,46 @@ throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�"); HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); if (hongBaoOrder == null) { - saveHongBao(commonOrder, type, notificationMap); + saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate); hasAdd = true; } else { - boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap); - if (update) + boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap, placeOrderDate); + if (update) { hasUpdate = true; + } } + } + + 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); + } } /** * 閫氱煡鐢ㄦ埛鐨勮繑鍒╂儏鍐� */ - int state = getOrderState(stateSet); + if (!Constant.IS_TEST) { if (hasAdd) { Iterator<Integer> its = notificationMap.keySet().iterator(); @@ -128,48 +178,49 @@ Integer t = its.next(); HongBaoV2 notify = notificationMap.get(t).getHongBaoV2(); CommonOrder commonOrder = notificationMap.get(t).getCommonOrder(); - String orderId = commonOrderList.get(0).getOrderNo(); Long uid = notify.getUserInfo().getId(); BigDecimal money = notify.getMoney(); switch (t) { case HongBaoV2.TYPE_ZIGOU: userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType, - commonOrder.getPayment(), money, goodsCount, commonOrder.getState(), + commonOrder.getPayment(), money, goodsCount, state, commonOrder.getThirdCreateTime()); break; case HongBaoV2.TYPE_SHARE_GOODS: userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType, - commonOrder.getPayment(), money, goodsCount, commonOrder.getState(), + commonOrder.getPayment(), money, goodsCount, state, commonOrder.getThirdCreateTime()); break; case HongBaoV2.TYPE_YIJI: userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, - commonOrder.getPayment(), money, goodsCount, commonOrder.getState(), + commonOrder.getPayment(), money, goodsCount, state, commonOrder.getThirdCreateTime()); break; case HongBaoV2.TYPE_ERJI: - - userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, commonOrder.getPayment(), money, - goodsCount, commonOrder.getState(), commonOrder.getThirdCreateTime()); + + userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state, + commonOrder.getThirdCreateTime()); break; case HongBaoV2.TYPE_SHARE_YIJI: userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, - commonOrder.getPayment(), money, goodsCount, commonOrder.getState(), + commonOrder.getPayment(), money, goodsCount, state, commonOrder.getThirdCreateTime()); break; case HongBaoV2.TYPE_SHARE_ERJI: - - userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, commonOrder.getPayment(), money, - goodsCount, commonOrder.getState(), commonOrder.getThirdCreateTime()); - break; - + userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state, + commonOrder.getThirdCreateTime()); + + break; + } } } @@ -203,19 +254,23 @@ @Transactional(rollbackFor = Exception.class) private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type, - Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException, UserAccountException { + Map<Integer, HongBaoOrder> notificationMap, Date placeOrderTime) + throws HongBaoException, UserAccountException { System.out.println(commonOrder.getOrderNo()); // 閿佽 HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBaoOrder.getHongBaoV2().getId()); if (oldHongBao == null) throw new HongBaoException(10, "绾㈠寘瀵硅薄涓嶅瓨鍦�"); + UserLevelEnum buyerLevel = UserLevelUtil.getByOrderRank(oldHongBao.getUrank()); + if (buyerLevel == null) + throw new HongBaoException(201, "鐢ㄦ埛绛夌骇涓虹┖"); + // 宸茬粡澶辨晥锛屽凡缁忛鍙栵紝鏂拌�佺姸鎬佷竴鑷寸殑绾㈠寘涓嶅仛澶勭悊 if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO || oldHongBao.getState() == HongBaoV2.STATE_YILINGQU) return false; if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚� - BigDecimal fanliRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(0, type, false, - oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); + BigDecimal money = orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel); // 鍏嶅崟澶勭悊 boolean mianDan = false; List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO, @@ -231,7 +286,7 @@ } } - HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, fanliRate, hongBaoOrder.getHongBaoV2().getId(), + HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, money, hongBaoOrder.getHongBaoV2().getId(), mianDan); // 鏂拌�佺孩鍖呯姸鎬佷竴鑷翠笉澶勭悊 @@ -258,12 +313,14 @@ tempHongBao.setMoney(hongBao.getMoney()); CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); tempCommonOrder.setPayment(commonOrder.getPayment()); + tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime()); notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); } else { // 澧炲姞浠樻閲戦涓庤祫閲� HongBaoOrder tempHongBaoOrder = notificationMap.get(type); tempHongBaoOrder.getCommonOrder() .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney())); notificationMap.put(type, tempHongBaoOrder); @@ -275,17 +332,14 @@ for (HongBaoV2 child : children) { if (child.getState() == HongBaoV2.STATE_YILINGQU) continue; - BigDecimal rate = null; + if (child.getType() == HongBaoV2.TYPE_YIJI) { - rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, oldHongBao.getType(), false, - oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); } else if (child.getType() == HongBaoV2.TYPE_ERJI) { - rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, oldHongBao.getType(), false, - oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); } - HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), - MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))), commonOrder); + HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder); hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); // 鍔犲叆閫氱煡 @@ -295,6 +349,7 @@ tempHongBao.setMoney(child.getMoney()); CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); tempCommonOrder.setPayment(commonOrder.getPayment()); + tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime()); notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao)); } else { // 澧炲姞浠樻閲戦涓庤祫閲� @@ -310,7 +365,7 @@ if (!mianDan) { ThreeSale threeSale = threeSaleSerivce.selectByWorkerId(commonOrder.getUserInfo().getId()); if (threeSale != null && threeSale.getSucceedTime() != null - && threeSale.getSucceedTime() <= commonOrder.getThirdCreateTime().getTime()) { + && threeSale.getSucceedTime() <= placeOrderTime.getTime()) { UserInfo boss = threeSaleSerivce.getBoss(commonOrder.getUserInfo().getId()); if (boss != null) { boss = userInfoService.selectAvailableByPrimaryKey(boss.getId()); @@ -318,12 +373,11 @@ if (boss != null) { // 鎻掑叆涓�绾у瓙绾㈠寘 - BigDecimal firstRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, type, - false, oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); - if (firstRate != null && firstRate.compareTo(new BigDecimal(0)) > 0) { + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + UserLevelEnum bossUserLevel = userLevelManager.getUserLevel(boss.getId()); + if (money != null) { HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder, - HongBaoV2.TYPE_YIJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(), - firstRate.divide(new BigDecimal(100)))); + HongBaoV2.TYPE_YIJI, money, bossUserLevel); if (firstHongbao != null) addInviteHongBao(firstHongbao, null, notificationMap, commonOrder); } @@ -332,13 +386,12 @@ boss = userInfoService.selectAvailableByPrimaryKey(boss.getId()); } if (boss != null) { - // 浜岀骇绾㈠寘 - BigDecimal secondRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, type, - false, oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); - if (secondRate != null && secondRate.compareTo(new BigDecimal(0)) > 0) { + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, + buyerLevel); + bossUserLevel = userLevelManager.getUserLevel(boss.getId()); + if (money != null) { HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder, - HongBaoV2.TYPE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(), - secondRate.divide(new BigDecimal(100)))); + HongBaoV2.TYPE_ERJI, money, bossUserLevel); if (secondHongbao != null) addInviteHongBao(secondHongbao, null, notificationMap, commonOrder); } @@ -348,10 +401,10 @@ } } } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { - BigDecimal fanliRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(0, type, false, - oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); - HongBaoV2 hongBao = createShareUpdateHongBao(commonOrder, fanliRate, oldHongBao.getId()); + BigDecimal money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel); + + HongBaoV2 hongBao = createShareUpdateHongBao(commonOrder, money, oldHongBao.getId()); hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); // 閫氱煡 if (notificationMap.get(type) == null) { @@ -360,6 +413,7 @@ tempHongBao.setMoney(hongBao.getMoney()); CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); tempCommonOrder.setPayment(commonOrder.getPayment()); + tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime()); notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); } else { // 澧炲姞浠樻閲戦涓庤祫閲� @@ -378,16 +432,12 @@ if (child.getState() == HongBaoV2.STATE_YILINGQU) continue; - BigDecimal rate = null; if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) { - rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, oldHongBao.getType(), false, - oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) { - rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, oldHongBao.getType(), false, - oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime())); + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); } - HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), - MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))), commonOrder); + HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder); hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); // 娣诲姞閫氱煡 if (notificationMap.get(child.getType()) == null) { @@ -397,6 +447,7 @@ .setMoney(childUpdate.getMoney() == null ? new BigDecimal(0) : childUpdate.getMoney()); CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); tempCommonOrder.setPayment(commonOrder.getPayment()); + tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime()); notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao)); } else { // 澧炲姞浠樻閲戦涓庤祫閲� @@ -418,13 +469,10 @@ } @Transactional(rollbackFor = Exception.class) - private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap) - throws HongBaoException, UserAccountException { + private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap, + UserLevelEnum buyerLevel, Date placeOrderDate) 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())); + if (type == HongBaoV2.TYPE_ZIGOU) { // 鏌ヨ鏄惁鏈夊厤鍗曡鍒� BigDecimal mianDanMoney = null; if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) { @@ -434,7 +482,6 @@ BigDecimal payMent = commonOrder.getPayment(); if (commonOrder.getState() == CommonOrder.STATE_JS) payMent = commonOrder.getSettlement(); - CommonOrderGoods goods = commonOrderGoodsMapper .selectByPrimaryKey(commonOrder.getCommonOrderGoods().getId()); if (goods != null) { @@ -459,33 +506,34 @@ } } - HongBaoV2 hongBao = createFanLiHongBao(commonOrder, fanliRate, mianDanMoney); + HongBaoV2 hongBao = createFanLiHongBao(commonOrder, + orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel), mianDanMoney, + buyerLevel); if (hongBao == null) return; addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap); UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId()); if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1绾OSS瀛樺湪涓旂孩鍖呮湭澶辨晥,鍏嶅崟涓嶆敮鎸佸绾у垎閿� - // 鎻掑叆涓�绾у瓙绾㈠寘 - BigDecimal firstRate = hongBaoManageService - .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime())); - if (firstRate.compareTo(new BigDecimal(0)) <= 0)// 杩斿埄姣斾緥涓�0鐨勪笉鍒嗘垚 + BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + if (money == null)// 杩斿埄璧勯噾涓虹┖涓嶅弬涓庡垎鎴� return; + UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId()); + HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_YIJI, - MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100)))); + money, bossLevel); addInviteHongBao(firstHongbao, null, notificationMap, commonOrder); // 鎻掑叆浜岀骇瀛愮孩鍖� boss = threeSaleSerivce.getBoss(boss.getId()); if (boss != null) {// 浜岀骇BOSS瀛樺湪涓旀槸闈炰細鍛樿鍗� - BigDecimal secondRate = hongBaoManageService - .getRate(new OrderHongBaoRateParams(2, type, false, vip, commonOrder.getThirdCreateTime())); - if (secondRate.compareTo(new BigDecimal(0)) <= 0) + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); + bossLevel = userLevelManager.getUserLevel(boss.getId()); + if (money == null) return; HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, - HongBaoV2.TYPE_ERJI, - MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100)))); + HongBaoV2.TYPE_ERJI, money, bossLevel); addInviteHongBao(secondHongbao, null, notificationMap, commonOrder); } } @@ -495,45 +543,48 @@ if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ) return; // 鍒嗕韩璧� - BigDecimal shareRate = null; + BigDecimal money = null; if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))// 鏉ヨ嚜浜庢窐绀奸噾鐨勫垎浜� - shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime()); - else - shareRate = hongBaoManageService - .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime())); + { + BigDecimal shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime()); + if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) + money = MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), + MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100))); + else + money = MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), + MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100))); + } else + money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel); - if (shareRate.compareTo(new BigDecimal(0)) <= 0) + if (money == null || money.compareTo(new BigDecimal(0)) <= 0) return; - HongBaoV2 hongBao = createShareHongBao(commonOrder, shareRate, vip); + HongBaoV2 hongBao = createShareHongBao(commonOrder, money, buyerLevel); if (hongBao == null) return; addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap); // 4鏈�17鏃ュ悗鎵嶆湁涓�绾у垎浜禋 - if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) { + if (placeOrderDate.getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) { UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId()); if (boss != null) { - BigDecimal firstLevelRate = hongBaoManageService - .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime())); - if (firstLevelRate == null || firstLevelRate.compareTo(new BigDecimal("0")) == 0) + money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel); + if (money == null) return; - + UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId()); HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, - HongBaoV2.TYPE_SHARE_YIJI, - MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstLevelRate.divide(new BigDecimal(100)))); + HongBaoV2.TYPE_SHARE_YIJI, money, bossLevel); addInviteHongBao(firstHongbao, hongBao.getUserInfo().getNickName(), notificationMap, commonOrder); // 浜岀骇鍒嗕韩璧� boss = threeSaleSerivce.getBoss(boss.getId()); if (boss != null) { - BigDecimal secondLevelRate = hongBaoManageService.getRate( - new OrderHongBaoRateParams(2, type, false, vip, commonOrder.getThirdCreateTime())); - if (secondLevelRate.compareTo(new BigDecimal(0)) <= 0)// 杩斿埄姣斾緥涓�0灏变笉缁熻 + money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel); + if (money == null)// 杩斿埄姣斾緥涓�0灏变笉缁熻 return; + bossLevel = userLevelManager.getUserLevel(boss.getId()); HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder, - HongBaoV2.TYPE_SHARE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(), - secondLevelRate.divide(new BigDecimal(100)))); + HongBaoV2.TYPE_SHARE_ERJI, money, bossLevel); addInviteHongBao(secondChild, null, notificationMap, commonOrder); } } @@ -586,6 +637,7 @@ CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); tempCommonOrder.setPayment(commonOrder.getPayment()); + tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime()); notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao)); } else { // 澧炲姞浠樻閲戦涓庤祫閲� @@ -610,7 +662,7 @@ * @return */ private HongBaoV2 createInviteHongBao(Long uid, HongBaoV2 parent, CommonOrder commonOrder, int hongBaoType, - BigDecimal money) { + BigDecimal money, UserLevelEnum userLevel) { if (parent == null) return null; if (parent.getState() == HongBaoV2.STATE_SHIXIAO) @@ -618,8 +670,6 @@ UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid); if (user == null) return null; - - UserLevelEnum level = userLevelManager.getUserLevel(uid); HongBaoV2 child = new HongBaoV2(); child.setParent(parent); @@ -638,11 +688,13 @@ } child.setUserInfo(user); - child.setUrank(level.getOrderRank()); + child.setUrank(user.getRank()); child.setVersion(2); child.setCreateTime(new Date()); child.setOrderType(commonOrder.getSourceType()); if (child.getMoney() == null) + return null; + if (child.getMoney().compareTo(new BigDecimal(0)) <= 0 && userLevel == UserLevelEnum.daRen) return null; return child; } @@ -655,22 +707,24 @@ * -杩斿埄姣斾緥 * @param mianDanMoney * 鍏嶅崟閲戦 + * @param isVIP-鏄惁涓篤IP璁㈠崟 * @return * @throws HongBaoException * @throws UserAccountException */ - private HongBaoV2 createFanLiHongBao(CommonOrder commonOrder, BigDecimal fanliRate, BigDecimal mianDanMoney) throws HongBaoException, UserAccountException { + private HongBaoV2 createFanLiHongBao(CommonOrder commonOrder, BigDecimal money, BigDecimal mianDanMoney, + UserLevelEnum userLevel) throws HongBaoException, UserAccountException { HongBaoV2 hongBao = new HongBaoV2(); hongBao.setUserInfo(commonOrder.getUserInfo()); hongBao.setCreateTime(new Date()); hongBao.setType(HongBaoV2.TYPE_ZIGOU); hongBao.setVersion(2); + hongBao.setMoney(money); if (commonOrder.getState() == CommonOrder.STATE_FK) { hongBao.setState(HongBaoV2.STATE_BUKELINGQU); - hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100)))); + } else if (commonOrder.getState() == CommonOrder.STATE_JS || CommonOrder.STATE_WQ == commonOrder.getState()) { hongBao.setState(HongBaoV2.STATE_KELINGQU); - hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100)))); if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 鎷煎澶�15澶╁崐鍒拌处 hongBao.setPreGetTime(new Date( commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 12L)); @@ -689,13 +743,7 @@ UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId()); if (user == null) throw new UserAccountException(1001, "鐢ㄦ埛涓嶅瓨鍦�/琚皝绂�"); - UserLevelEnum userLevel = userLevelManager.getUserLevel(commonOrder.getUserInfo().getId(), - commonOrder.getThirdCreateTime()); - if (userLevel != null) - hongBao.setUrank(userLevel.getOrderRank()); - else { - hongBao.setUrank(user.getRank()); - } + hongBao.setUrank(userLevel.getOrderRank()); hongBao.setOrderType(commonOrder.getSourceType()); return hongBao; } @@ -795,6 +843,7 @@ tempHongBao.setMoney(hongBao.getMoney()); CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); tempCommonOrder.setPayment(commonOrder.getPayment()); + tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime()); notificationMap.put(hongBao.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao)); } else { // 澧炲姞浠樻閲戦涓庤祫閲� @@ -816,18 +865,17 @@ * @throws HongBaoException * @throws UserAccountException */ - private HongBaoV2 createShareHongBao(CommonOrder commonOrder, BigDecimal shareRate, boolean isVip) + private HongBaoV2 createShareHongBao(CommonOrder commonOrder, BigDecimal money, UserLevelEnum userLevel) throws HongBaoException, UserAccountException { HongBaoV2 hongBao = new HongBaoV2(); hongBao.setCreateTime(new Date()); hongBao.setType(HongBaoV2.TYPE_SHARE_GOODS); hongBao.setVersion(2); + hongBao.setMoney(money); if (commonOrder.getState() == CommonOrder.STATE_FK) { hongBao.setState(HongBaoV2.STATE_BUKELINGQU); - hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), shareRate.divide(new BigDecimal(100)))); } else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) { hongBao.setState(HongBaoV2.STATE_KELINGQU); - hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), shareRate.divide(new BigDecimal(100)))); Calendar calendar = Calendar.getInstance(); calendar.setTime(commonOrder.getSettleTime()); calendar.add(Calendar.MONTH, 1); @@ -837,12 +885,7 @@ UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId()); if (user == null) throw new UserAccountException(1001, "鐢ㄦ埛涓嶅瓨鍦�/琚皝绂�"); - UserLevelEnum userLevel = userLevelManager.getUserLevel(commonOrder.getUserInfo().getId(), - commonOrder.getThirdCreateTime()); - if (userLevel != null) - hongBao.setUrank(userLevel.getOrderRank()); - else - hongBao.setUrank(user.getRank()); + hongBao.setUrank(userLevel.getOrderRank()); hongBao.setUserInfo(user); hongBao.setOrderType(commonOrder.getSourceType()); return hongBao; -- Gitblit v1.8.0