From 0b57cfd62e842b309d03467b96a331c673ecad7c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 21 四月 2020 14:08:18 +0800
Subject: [PATCH] 删除普通会员等级

---
 fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java |  110 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 74 insertions(+), 36 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java b/fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java
index 6a14fc8..dde11fd 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java
@@ -16,15 +16,17 @@
 import com.yeshi.fanli.entity.bus.user.ThreeSale;
 import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
 import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
-import com.yeshi.fanli.entity.money.UserMoneyDetail;
+import com.yeshi.fanli.entity.order.CommonOrder;
 import com.yeshi.fanli.entity.order.dividents.TeamDividentsDebt;
 import com.yeshi.fanli.entity.order.dividents.TeamDividentsRecord;
 import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
 import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceUser;
 import com.yeshi.fanli.exception.ParamsException;
 import com.yeshi.fanli.exception.money.TeamDividentsDebtException;
+import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
 import com.yeshi.fanli.exception.money.UserMoneyDetailException;
 import com.yeshi.fanli.exception.order.dividents.TeamDividentsRecordException;
+import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException;
 import com.yeshi.fanli.service.inter.money.TeamDividentsDebtService;
 import com.yeshi.fanli.service.inter.money.UserMoneyService;
 import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
@@ -33,10 +35,12 @@
 import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
 import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
+import com.yeshi.fanli.service.manger.money.TeamEincomeManager;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.TimeUtil;
-import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
+import com.yeshi.fanli.util.factory.order.dividents.TeamDividentsSourceOrderFactory;
+import com.yeshi.fanli.util.user.UserLevelUtil;
 
 /**
  * 鍥㈤槦鍒嗙孩绠$悊
@@ -70,6 +74,28 @@
 	@Resource
 	private HongBaoManageService hongBaoManageService;
 
+	@Resource
+	private TeamEincomeManager teamEincomeManager;
+
+	@Transactional(rollbackFor = Exception.class)
+	public void addDividentsSourceOrder(List<CommonOrder> commonOrderList) throws TeamDividentsSourceOrderException {
+		if (commonOrderList.get(0).getThirdCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
+			return;
+
+		UserLevelEnum level = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank());
+		if (level == null)
+			level = UserLevelEnum.daRen;
+		BigDecimal rate = getSourceOrderDividentsRate(level);
+		TeamDividentsSourceOrder order = TeamDividentsSourceOrderFactory.create(commonOrderList, rate);
+		if (order == null)
+			return;
+		try {
+			teamDividentsSourceOrderService.addTeamDividentsSourceOrder(order);
+		} catch (ParamsException e) {
+			throw new TeamDividentsSourceOrderException(101, "鍙傛暟涓嶅畬鏁�");
+		}
+	}
+
 	/**
 	 *  寮�濮嬪垎绾�
 	 * @Title: startDividents
@@ -87,31 +113,42 @@
 
 	// 鏄惁鍙互鍒嗙孩
 	private boolean isCanDividents(TeamUserLevelStatistic tus) {
-		if (Constant.IS_TEST)
-			return true;
+//		if (Constant.IS_TEST && tus.getLevel() != UserLevelEnum.daRen && tus.getLevel() != UserLevelEnum.normalVIP)
+//			return true;
 
 		if (tus != null && (tus.getLevel() == UserLevelEnum.highVIP || tus.getLevel() == UserLevelEnum.superVIP
 				|| tus.getLevel() == UserLevelEnum.tearcher)) {
-			if (tus.getLevel() == UserLevelEnum.highVIP) {
-				int vipFirstCount = tus.getNormalFirstCount() + tus.getHighFirstCount() + tus.getSuperFirstCount()
-						+ tus.getTearcherFirstCount();
-				if (vipFirstCount >= 3)// 鐩存帴绮変笣鏅�氫細鍛樼瓑绾т互涓婄殑鐢ㄦ埛>=3
+
+			if (tus.getLevel() == UserLevelEnum.tearcher) {
+				int firstCount = tus.getSuperFirstCount() + tus.getTearcherFirstCount();
+				int secondCount = tus.getHighSecondCount() + tus.getSuperSecondCount() + tus.getTearcherSecondCount();
+				if (firstCount >= 3 && secondCount >= 3) {// 鐩存帴绮変笣瓒呯骇浼氬憳绛夌骇浠ヤ笂鐨勭敤鎴�>=3
+					// 闂存帴绮変笣鏅�氫細鍛樹互涓婄瓑绾�>=3
 					return true;
-			} else if (tus.getLevel() == UserLevelEnum.superVIP) {
+				} else {
+					// 濡傛灉瀵煎笀涓嶆弧瓒虫潯浠跺氨闇�瑕侀檷绾т负瓒呯骇浼氬憳
+					tus.setLevel(UserLevelEnum.superVIP);
+				}
+			}
+
+			if (tus.getLevel() == UserLevelEnum.superVIP) {
 				int firstCount = tus.getSuperFirstCount() + tus.getTearcherFirstCount();
 				int secondCount = tus.getNormalSecondCount() + tus.getHighSecondCount() + tus.getSuperSecondCount()
 						+ tus.getTearcherSecondCount();
 				if (firstCount >= 3 && secondCount >= 3) {// 鐩存帴绮変笣瓒呯骇浼氬憳绛夌骇浠ヤ笂鐨勭敤鎴�>=3
 															// 闂存帴绮変笣鏅�氫細鍛樹互涓婄瓑绾�>=3
 					return true;
+				} else {
+					// 濡傛灉瓒呯骇浼氬憳涓嶆弧瓒虫潯浠跺氨闇�瑕侀檷绾т负楂樼骇浼氬憳
+					tus.setLevel(UserLevelEnum.highVIP);
 				}
-			} else {
-				int firstCount = tus.getSuperFirstCount() + tus.getTearcherFirstCount();
-				int secondCount = tus.getHighSecondCount() + tus.getSuperSecondCount() + tus.getTearcherSecondCount();
-				if (firstCount >= 3 && secondCount >= 3) {// 鐩存帴绮変笣瓒呯骇浼氬憳绛夌骇浠ヤ笂鐨勭敤鎴�>=3
-															// 闂存帴绮変笣楂樼骇浼氬憳浠ヤ笂绛夌骇>=3
+			}
+
+			if (tus.getLevel() == UserLevelEnum.highVIP) {
+				int vipFirstCount = tus.getNormalFirstCount() + tus.getHighFirstCount() + tus.getSuperFirstCount()
+						+ tus.getTearcherFirstCount();
+				if (vipFirstCount >= 3)// 鐩存帴绮変笣鏅�氫細鍛樼瓑绾т互涓婄殑鐢ㄦ埛>=3
 					return true;
-				}
 			}
 		}
 		return false;
@@ -152,7 +189,7 @@
 		if (threeSalesList == null)
 			return;
 
-		Map<Long, UserLevelEnum> uidLevel = new HashMap<Long, UserLevelEnum>();
+		Map<Long, UserLevelEnum> uidLevelMap = new HashMap<Long, UserLevelEnum>();
 		for (ThreeSale ts : threeSalesList) {
 			if (ts.getBoss() != null) {
 				TeamUserLevelStatistic tus = teamUserLevelStatisticService.selectByUid(ts.getBoss().getId());
@@ -161,15 +198,20 @@
 				tus = teamUserLevelStatisticService.selectByUid(ts.getBoss().getId());
 
 				if (isCanDividents(tus)) {
-					uidLevel.put(tus.getId(), tus.getLevel());
+					uidLevelMap.put(tus.getId(), tus.getLevel());
 				}
 			}
 		}
 
-		BigDecimal perDivident = computePerDivident(uidLevel, totalMoney);
-		for (Iterator<Long> its = uidLevel.keySet().iterator(); its.hasNext();) {
+		// 娌℃湁鍙備笌鍒嗙孩鐨勭敤鎴�
+		if (uidLevelMap == null || uidLevelMap.size() == 0) {
+			return;
+		}
+
+		BigDecimal perDivident = computePerDivident(uidLevelMap, totalMoney);
+		for (Iterator<Long> its = uidLevelMap.keySet().iterator(); its.hasNext();) {
 			Long uid = its.next();
-			BigDecimal dividents = computeUserDivident(perDivident, uidLevel.get(uid));
+			BigDecimal dividents = computeUserDivident(perDivident, uidLevelMap.get(uid));
 			// 灏嗚祫閲戝垎閰嶅埌鍙備笌鍒嗙孩鐨勭敤鎴�
 			TeamDividentsSourceUser teamDividentsSourceUser = new TeamDividentsSourceUser();
 			teamDividentsSourceUser.setDay(day);
@@ -178,22 +220,22 @@
 			teamDividentsSourceUser.setTargetUid(uid);
 			teamDividentsSourceUserService.addTeamDividentsSourceUser(teamDividentsSourceUser);
 		}
-		// if (1 / 0 > 0)
-		// return;
 	}
 
 	// 璁$畻骞冲潎鍒嗙孩
 	private BigDecimal computePerDivident(Map<Long, UserLevelEnum> uidLevels, BigDecimal totalMoney) {
-		int count = 0;
+		BigDecimal count = new BigDecimal(0);
 		for (Iterator<Long> its = uidLevels.keySet().iterator(); its.hasNext();) {
 			Long uid = its.next();
 			if (uidLevels.get(uid) == UserLevelEnum.highVIP) {
-				count += 1;
+				count = count.add(new BigDecimal(1));
 			} else if (uidLevels.get(uid) == UserLevelEnum.superVIP) {
-				count += 2;
+				count = count.add(new BigDecimal(2));
+			} else if (uidLevels.get(uid) == UserLevelEnum.tearcher) {
+				count = count.add(new BigDecimal(2.5));
 			}
 		}
-		return MoneyBigDecimalUtil.div(totalMoney, new BigDecimal(count));
+		return MoneyBigDecimalUtil.div(totalMoney, count);
 	}
 
 	private BigDecimal computeUserDivident(BigDecimal perDivident, UserLevelEnum userLevel) {
@@ -202,7 +244,7 @@
 		} else if (userLevel == UserLevelEnum.superVIP) {
 			return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2));
 		} else if (userLevel == UserLevelEnum.tearcher) {
-			return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2));
+			return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2.5));
 		}
 		return null;
 	}
@@ -233,11 +275,12 @@
 	 * @throws
 	 */
 	@Transactional(rollbackFor = Exception.class)
-	public void addDividents(Long uid, String day)
-			throws TeamDividentsRecordException, TeamDividentsDebtException, UserMoneyDetailException, ParamsException {
+	public void addToTeamEincome(Long uid, Date preSendTime) throws TeamDividentsRecordException,
+			TeamDividentsDebtException, UserMoneyDetailException, ParamsException, TeamEincomeRecordException {
+		String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
 		BigDecimal money = teamDividentsSourceUserService.sumMoneyByUidAndDay(uid, day);
 		// 鏌ヨ闇�瑕佹墸闄ょ殑璧勯噾
-		List<TeamDividentsDebt> list = teamDividentsDebtService.listNeedRepayDebt(uid, 1, 1000);
+		List<TeamDividentsDebt> list = teamDividentsDebtService.listNeedRepayDebt(uid, preSendTime, 1, 1000);
 		for (TeamDividentsDebt debt : list) {
 			if (money.subtract(debt.getLeftMoney()).compareTo(new BigDecimal(0)) >= 0) {// 杩樻湁閽辫繕
 				money = money.subtract(debt.getLeftMoney());
@@ -259,12 +302,8 @@
 
 		// 鏈夊垎绾㈡墠鏄剧ず璧勯噾鏄庣粏
 		if (money.compareTo(new BigDecimal(0)) > 0) {
-			UserMoneyDetail detail = UserMoneyDetailFactory.createOrderTeamDividents(uid, money, new Date());
-			// 澧炲姞璧勯噾
-			userMoneyService.addUserMoney(uid, money, detail);
-			// TODO 鍔犲叆閫氱煡
+			teamEincomeManager.addTeamDividents(uid, preSendTime, money);
 		}
-
 	}
 
 	/**
@@ -318,7 +357,6 @@
 		} else if (sourceOrder.getState() == TeamDividentsSourceOrder.STATE_CAN_SEND) {
 			teamDividentsSourceOrderService.invalidOrder(orderNo, sourceType, "璁㈠崟缁存潈");
 		}
-
 	}
 
 	/**

--
Gitblit v1.8.0