From ec60e757d358636dcac1589c44a66f3e276fe58c Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期一, 29 六月 2020 14:41:42 +0800
Subject: [PATCH] 拉新
---
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java | 471 +++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 286 insertions(+), 185 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 cc875e0..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
@@ -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,16 +20,22 @@
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.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.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.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.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;
@@ -36,10 +43,12 @@
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.UserVIPInfoService;
+import com.yeshi.fanli.service.manger.user.UserLevelManager;
import com.yeshi.fanli.util.Constant;
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 {
@@ -77,6 +86,15 @@
@Resource
private UserVIPInfoService userVIPInfoService;
+ @Resource
+ private UserLevelManager userLevelManager;
+
+ @Resource
+ private InviteOrderSubsidyService inviteOrderSubsidyService;
+
+ @Resource
+ private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
+
/**
* 娣诲姞绾㈠寘淇℃伅
*
@@ -85,17 +103,32 @@
* @return
* @throws HongBaoException
* @throws UserAccountException
+ * @throws CommonOrderException
+ * @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();
+ 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();
+
+ boolean miandan = false;
+
for (CommonOrder commonOrder : commonOrderList) {
stateSet.add(commonOrder.getState());
goodsCount += commonOrder.getCount();
@@ -103,100 +136,90 @@
throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�");
HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
if (hongBaoOrder == null) {
- saveHongBao(commonOrder, type, notificationMap);
- hasAdd = true;
+ HongBaoSaveResult result = saveHongBao(commonOrder, type, notificationMap, userLevel,
+ placeOrderDate);
+ miandan = result.isMiandan();
+ hasAdd = result.isAdd();
} else {
- boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
- if (update)
+ boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap, placeOrderDate);
+ if (update) {
hasUpdate = true;
+ }
}
}
+
+ int state = getOrderState(stateSet);
/**
* 閫氱煡鐢ㄦ埛鐨勮繑鍒╂儏鍐�
*/
- int state = getOrderState(stateSet);
- if (!Constant.IS_TEST) {
- if (hasAdd) {
- Iterator<Integer> its = notificationMap.keySet().iterator();
- while (its.hasNext()) {
- 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, state);
- break;
- case HongBaoV2.TYPE_SHARE_GOODS:
- userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType,
- commonOrder.getPayment(), money, goodsCount, state);
- break;
- case HongBaoV2.TYPE_YIJI:
- userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
- commonOrder.getPayment(), money, goodsCount, state);
- break;
- case HongBaoV2.TYPE_ERJI:
- userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
- commonOrder.getPayment(), money, goodsCount, state);
- break;
- case HongBaoV2.TYPE_SHARE_YIJI:
- userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId, orderType,
- commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu());
- break;
- }
+
+ // if (!Constant.IS_TEST) {
+ if (hasAdd) {
+ // 鑾峰彇璁㈠崟琛ヨ创
+
+ Iterator<Integer> its = notificationMap.keySet().iterator();
+ while (its.hasNext()) {
+ Integer t = its.next();
+ HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
+ CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
+ Long uid = notify.getUserInfo().getId();
+
+ BigDecimal money = notify.getMoney();
+ switch (t) {
+ case HongBaoV2.TYPE_ZIGOU:
+ userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType,
+ commonOrder.getPayment(), money, goodsCount, state, commonOrder.getThirdCreateTime());
+
+ break;
+ case HongBaoV2.TYPE_SHARE_GOODS:
+
+ userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType,
+ commonOrder.getPayment(), money, goodsCount, state, commonOrder.getThirdCreateTime());
+
+ break;
+ case HongBaoV2.TYPE_YIJI:
+ userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
+ commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
+ commonOrder.getThirdCreateTime());
+
+ break;
+ case HongBaoV2.TYPE_ERJI:
+
+ userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
+ 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.getThirdCreateTime());
+ break;
+ case HongBaoV2.TYPE_SHARE_ERJI:
+
+ userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
+ commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
+ commonOrder.getThirdCreateTime());
+
+ break;
+
}
}
-
- // 娣诲姞鏂扮増鏈�氱煡
-
- if (!hasAdd) {
- Iterator<Integer> its = notificationMap.keySet().iterator();
- while (its.hasNext()) {
- 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.orderFanLiStateChanged(uid, orderId, orderType,
- commonOrder.getPayment(), money, state);
- break;
- case HongBaoV2.TYPE_SHARE_GOODS:
- userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, orderType,
- commonOrder.getPayment(), money, state);
- break;
- case HongBaoV2.TYPE_YIJI:
- userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
- commonOrder.getPayment(), money, state);
- break;
- case HongBaoV2.TYPE_ERJI:
- userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
- commonOrder.getPayment(), money, state);
- break;
- case HongBaoV2.TYPE_SHARE_YIJI:
- userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId, orderType,
- commonOrder.getPayment(), money, state);
- }
- }
- }
+ // }
}
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) {
@@ -213,21 +236,61 @@
return CommonOrder.STATE_SX;
}
- @Transactional(rollbackFor = Exception.class)
+ 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());
+
+ 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;
+ }
+
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,
@@ -243,7 +306,7 @@
}
}
- HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, fanliRate, hongBaoOrder.getHongBaoV2().getId(),
+ HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, money, hongBaoOrder.getHongBaoV2().getId(),
mianDan);
// 鏂拌�佺孩鍖呯姸鎬佷竴鑷翠笉澶勭悊
@@ -270,12 +333,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);
@@ -284,20 +349,21 @@
// 鑾峰彇瀛愮孩鍖�
List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
if (children != null && children.size() > 0) {
+ List<UserTeamLevel> bossList = getBossList(children);
+
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,
+ bossList);
} 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,
+ bossList);
}
- 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);
// 鍔犲叆閫氱煡
@@ -307,6 +373,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 {
// 澧炲姞浠樻閲戦涓庤祫閲�
@@ -322,20 +389,22 @@
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());
}
if (boss != null) {
+ List<UserTeamLevel> bossList = getBossList(oldHongBao.getUserInfo().getId(), 2);
+
// 鎻掑叆涓�绾у瓙绾㈠寘
- 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,
+ bossList);
+ 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);
}
@@ -344,13 +413,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, bossList);
+ 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);
}
@@ -360,10 +428,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) {
@@ -372,6 +440,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 {
// 澧炲姞浠樻閲戦涓庤祫閲�
@@ -385,21 +454,20 @@
// 鑾峰彇瀛愮孩鍖�
List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
- if (children != null)
+ if (children != null && children.size() > 0) {
+ List<UserTeamLevel> bossList = getBossList(children);
for (HongBaoV2 child : children) {
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,
+ bossList);
} 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,
+ bossList);
}
- 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) {
@@ -409,6 +477,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 {
// 澧炲姞浠樻閲戦涓庤祫閲�
@@ -423,6 +492,7 @@
}
}
+ }
} else
throw new HongBaoException(2, "type閿欒");
@@ -430,13 +500,10 @@
}
@Transactional(rollbackFor = Exception.class)
- private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
- throws HongBaoException, UserAccountException {
+ private HongBaoSaveResult 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) {
@@ -446,7 +513,6 @@
BigDecimal payMent = commonOrder.getPayment();
if (commonOrder.getState() == CommonOrder.STATE_JS)
payMent = commonOrder.getSettlement();
-
CommonOrderGoods goods = commonOrderGoodsMapper
.selectByPrimaryKey(commonOrder.getCommonOrderGoods().getId());
if (goods != null) {
@@ -471,33 +537,38 @@
}
}
- HongBaoV2 hongBao = createFanLiHongBao(commonOrder, fanliRate, mianDanMoney, vip);
+ HongBaoV2 hongBao = createFanLiHongBao(commonOrder,
+ orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel), mianDanMoney,
+ buyerLevel);
if (hongBao == null)
- return;
+ 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瀛樺湪涓旂孩鍖呮湭澶辨晥,鍏嶅崟涓嶆敮鎸佸绾у垎閿�
- // 鎻掑叆涓�绾у瓙绾㈠寘
- BigDecimal firstRate = hongBaoManageService
- .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime()));
- if (firstRate.compareTo(new BigDecimal(0)) <= 0)// 杩斿埄姣斾緥涓�0鐨勪笉鍒嗘垚
- return;
+
+ List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
+
+ BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel,
+ bossList);
+ if (money == null)// 杩斿埄璧勯噾涓虹┖涓嶅弬涓庡垎鎴�
+ return new HongBaoSaveResult(true, mianDanMoney != null);
+
+ 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)
- return;
+ money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, bossList);
+ bossLevel = userLevelManager.getUserLevel(boss.getId());
+ if (money == null)
+ return new HongBaoSaveResult(true, mianDanMoney != null);
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);
}
}
@@ -505,47 +576,54 @@
} else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
// 鍒嗕韩璧氫笉鍔犲叆澶辨晥鐨勮鍗�
if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
- return;
+ return new HongBaoSaveResult(false, false);
// 鍒嗕韩璧�
- 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)
- return;
- HongBaoV2 hongBao = createShareHongBao(commonOrder, shareRate, vip);
+ if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
+ return new HongBaoSaveResult(false, false);
+ HongBaoV2 hongBao = createShareHongBao(commonOrder, money, buyerLevel);
if (hongBao == null)
- return;
+ return new HongBaoSaveResult(false, false);
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)
- return;
+ List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
+
+ money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, bossList);
+ if (money == null)
+ return new HongBaoSaveResult(true, false);
+ 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灏变笉缁熻
- return;
+ money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel,
+ bossList);
+ if (money == null)// 杩斿埄姣斾緥涓�0灏变笉缁熻
+ return new HongBaoSaveResult(true, false);
+ 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);
}
}
@@ -575,6 +653,8 @@
// }
} else
throw new HongBaoException(2, "type閿欒");
+
+ return new HongBaoSaveResult(true, false);
}
/**
@@ -587,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) {
@@ -598,6 +683,7 @@
CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
tempCommonOrder.setPayment(commonOrder.getPayment());
+ tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
} else {
// 澧炲姞浠樻閲戦涓庤祫閲�
@@ -622,7 +708,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)
@@ -630,7 +716,6 @@
UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
if (user == null)
return null;
- boolean isVIP = userVIPInfoService.isVIP(uid);
HongBaoV2 child = new HongBaoV2();
child.setParent(parent);
@@ -649,13 +734,11 @@
}
child.setUserInfo(user);
- child.setUrank(user.getRank());
+ child.setUrank(userLevel.getOrderRank());
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 && !isVIP)
return null;
return child;
}
@@ -673,19 +756,19 @@
* @throws HongBaoException
* @throws UserAccountException
*/
- private HongBaoV2 createFanLiHongBao(CommonOrder commonOrder, BigDecimal fanliRate, BigDecimal mianDanMoney,
- boolean isVIP) 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));
@@ -704,28 +787,24 @@
UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
if (user == null)
throw new UserAccountException(1001, "鐢ㄦ埛涓嶅瓨鍦�/琚皝绂�");
- if (isVIP) {
- hongBao.setUrank(100);// VIP鐨勭瓑绾ц缃负100
- } else {
- hongBao.setUrank(user.getRank());
- }
+ hongBao.setUrank(userLevel.getOrderRank());
hongBao.setOrderType(commonOrder.getSourceType());
return hongBao;
}
- private HongBaoV2 createFanLiUpdateHongBao(CommonOrder commonOrder, BigDecimal fanliRate, Long hongBaoId,
+ private HongBaoV2 createFanLiUpdateHongBao(CommonOrder commonOrder, BigDecimal money, Long hongBaoId,
boolean mianDan) throws HongBaoException, UserAccountException {
HongBaoV2 hongBao = new HongBaoV2(hongBaoId);
hongBao.setUpdateTime(new Date());
+ 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))));
+
if (mianDan)
hongBao.setMoney(commonOrder.getPayment());
} else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) {
hongBao.setState(HongBaoV2.STATE_KELINGQU);
- hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 鎷煎澶�15澶╄繃1涓皬鏃跺埌璐�
hongBao.setPreGetTime(new Date(
commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 1L));
@@ -752,17 +831,16 @@
* @throws HongBaoException
* @throws UserAccountException
*/
- private HongBaoV2 createShareUpdateHongBao(CommonOrder commonOrder, BigDecimal fanliRate, Long hongBaoId)
+ private HongBaoV2 createShareUpdateHongBao(CommonOrder commonOrder, BigDecimal money, Long hongBaoId)
throws HongBaoException, UserAccountException {
HongBaoV2 hongBao = new HongBaoV2(hongBaoId);
hongBao.setUpdateTime(new Date());
+ 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.getState() == CommonOrder.STATE_WQ) {
hongBao.setState(HongBaoV2.STATE_KELINGQU);
- hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
Calendar calendar = Calendar.getInstance();
calendar.setTime(commonOrder.getSettleTime());
calendar.add(Calendar.MONTH, 1);
@@ -808,6 +886,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 {
// 澧炲姞浠樻閲戦涓庤祫閲�
@@ -829,18 +908,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);
@@ -850,13 +928,36 @@
UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
if (user == null)
throw new UserAccountException(1001, "鐢ㄦ埛涓嶅瓨鍦�/琚皝绂�");
- if (isVip)
- hongBao.setUrank(100);
- else
- hongBao.setUrank(user.getRank());
+ hongBao.setUrank(userLevel.getOrderRank());
hongBao.setUserInfo(user);
hongBao.setOrderType(commonOrder.getSourceType());
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