From 52a5a39966f303be57876d817561597b8c0dc6c7 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 11 四月 2020 18:17:30 +0800
Subject: [PATCH] 团队收益相关规则修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java |   95 ++++++++++++++++-------------------------------
 1 files changed, 33 insertions(+), 62 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java
index 82ebf90..dcadc32 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java
@@ -26,7 +26,7 @@
 import com.yeshi.fanli.service.inter.order.CommonOrderService;
 import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
 import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
-import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyServiceV2;
+import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
 import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
 import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
 import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
@@ -37,7 +37,7 @@
 import com.yeshi.fanli.util.TimeUtil;
 
 @Service
-public class InviteOrderSubsidyServiceImplV2 implements InviteOrderSubsidyServiceV2 {
+public class InviteOrderSubsidyServiceImplV2 implements InviteOrderSubsidyService {
 
 	@Resource
 	private InviteOrderSubsidyMapper inviteOrderSubsidyMapper;
@@ -79,6 +79,11 @@
 		return inviteOrderSubsidyMapper.getByOrderNoAndTypeForUpdate(uid, orderNo, type);
 	}
 
+	@Override
+	public List<InviteOrderSubsidy> listByOrderNoAndType(String orderNo, Integer type) {
+		return inviteOrderSubsidyMapper.listByOrderNoAndType(orderNo, type);
+	}
+
 	@Transactional(rollbackFor = Exception.class)
 	private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy)
 			throws InviteOrderSubsidyException, OrderTeamRewardException, CommonOrderException {
@@ -101,12 +106,10 @@
 			update.setState(orderSubsidy.getState());
 			update.setUpdateTime(new Date());
 			inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
-			//TODO 鍒犻櫎娣诲姞濂栧姳
 		} else {// 娣诲姞
 			if (orderSubsidy.getCreateTime() == null)
 				orderSubsidy.setCreateTime(new Date());
 			inviteOrderSubsidyMapper.insertSelective(orderSubsidy);
-			//TODO 鍒犻櫎娣诲姞濂栧姳
 		}
 	}
 
@@ -117,9 +120,8 @@
 		if (list != null && list.size() > 0) {
 			// 蹇呴』鏄嚜璐鍗曟墠杩斿埄
 			HongBaoV2 parent = hongBaoV2Service.selectByPrimaryKey(list.get(0).getHongBaoV2().getId());
-			if (parent != null && parent.getUrank() != UserLevelEnum.superVIP.getOrderRank()
+			if (parent != null
 					&& (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS || parent.getType() == HongBaoV2.TYPE_ZIGOU)) {// 涓嶆槸瓒呯骇浼氬憳鐨勮嚜璐�/鍒嗕韩鎵嶈ˉ璐�
-				boolean isShare = (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS);
 
 				List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
 				if (orderList == null || orderList.size() == 0)
@@ -152,18 +154,7 @@
 					}
 
 					List<HongBaoV2> hbList = hongBaoV2Service.listByIds(idList);
-					int state = InviteOrderSubsidy.STATE_UNKNOWN;
-					// 纭畾鏄惁浣跨敤浜嗗鍔卞埜
-					if (orderHongBaoMapService.selectByOrderIdAndSourceType(orderId, sourceType) != null) {
-						state = InviteOrderSubsidy.STATE_INVALID;
-					} else {
-						// 纭畾鏄惁杩斿埄鍒拌处5澶╁悗
-						if (recieveMoneyMoreThan(hbList, 5)) {
-							state = InviteOrderSubsidy.STATE_VALID;
-						} else {
-							state = InviteOrderSubsidy.STATE_UNKNOWN;
-						}
-					}
+					Integer state = null;
 
 					// 浜х敓鏀硅鍗曠殑杩斿埄鎬婚噾棰�
 					BigDecimal totalBuyFanLiMoney = new BigDecimal(0);
@@ -172,22 +163,33 @@
 						if (v2.getState() == HongBaoV2.STATE_BUKELINGQU || v2.getState() == HongBaoV2.STATE_KELINGQU
 								|| v2.getState() == HongBaoV2.STATE_YILINGQU)
 							totalBuyFanLiMoney = totalBuyFanLiMoney.add(v2.getMoney());
+
+						if (state == null && (v2.getState() == HongBaoV2.STATE_KELINGQU
+								|| v2.getState() == HongBaoV2.STATE_YILINGQU)) {// 绾㈠寘鐘舵�佷负宸查鍙栨垨鑰呮槸寰呴鍙栵紝鍒欒缃负琛ヨ创鏈夋晥
+							state = InviteOrderSubsidy.STATE_VALID;
+						}
 					}
 
+					if (state == null)
+						state = InviteOrderSubsidy.STATE_UNKNOWN;
 					// 璁$畻濂栧姳閲�
 					for (Iterator<Long> its = uidHongBaoMap.keySet().iterator(); its.hasNext();) {
 						Long uid = its.next();
 						UserLevelEnum userLevel = userLevelManager.getUserLevel(uid, placeOrderTime);
 
 						int type = uidHongBaoMap.get(uid);
-						if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_ERJI) {
+						if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_ERJI
+								|| type == HongBaoV2.TYPE_SHARE_YIJI || type == HongBaoV2.TYPE_SHARE_ERJI) {
 							BigDecimal money = null;
-							if (type == HongBaoV2.TYPE_YIJI)
+							if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_SHARE_YIJI)
 								money = orderHongBaoMoneyComputeService.computeFirstTeamSubsidy(totalBuyFanLiMoney,
 										placeOrderTime, buyerUserLevel, userLevel);
 							else
 								money = orderHongBaoMoneyComputeService.computeSecondTeamSubsidy(totalBuyFanLiMoney,
 										placeOrderTime, buyerUserLevel, userLevel);
+
+							if (money == null)
+								continue;
 
 							InviteOrderSubsidy orderSubsidy = new InviteOrderSubsidy();
 							orderSubsidy.setMoney(money);
@@ -196,23 +198,17 @@
 							orderSubsidy.setOrderNo(orderId);
 							orderSubsidy.setSourceType(sourceType);
 							orderSubsidy.setState(state);
-							if (type == HongBaoV2.TYPE_YIJI)
+							if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_SHARE_YIJI)
 								orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_ONE);
 							else
 								orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_TWO);
-							// 浼氬憳鎵嶈兘琛ヨ创
-							if (userLevel != UserLevelEnum.daRen) {
-								try {
-									addOrderSubsidy(orderSubsidy);
-								} catch (OrderTeamRewardException e) {
-									throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
-								} catch (CommonOrderException e) {
-									throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
-								}
-								// 鍒嗕韩璧氫笉鑳戒娇鐢ㄨ繑鍒╁鍔卞埜锛屼笉鐢ㄧ瓑寰�5澶�
-								if (isShare) {
-									validByOrderIdAndSourceType(orderId, sourceType);
-								}
+
+							try {
+								addOrderSubsidy(orderSubsidy);
+							} catch (OrderTeamRewardException e) {
+								throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
+							} catch (CommonOrderException e) {
+								throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
 							}
 						}
 					}
@@ -220,29 +216,6 @@
 			}
 		}
 
-	}
-
-	private boolean recieveMoneyMoreThan(List<HongBaoV2> hbList, int day) {
-		// 鏄惁鍏ㄩ儴鏄埌璐︾姸鎬佹垨澶辨晥鐘舵��
-		int invalidCount = 0;// 澶辨晥涓暟
-		int recieveCount = 0;// 鍒拌处鐨勪釜鏁�
-		long maxGetTime = 0;
-		for (HongBaoV2 v2 : hbList) {
-			if (v2.getState() == HongBaoV2.STATE_SHIXIAO)
-				invalidCount++;
-			else if (v2.getState() == HongBaoV2.STATE_YILINGQU) {
-				recieveCount++;
-				if (v2.getGetTime() != null && v2.getGetTime().getTime() > maxGetTime)
-					maxGetTime = v2.getGetTime().getTime();
-
-			}
-		}
-		if (invalidCount + recieveCount == hbList.size() && recieveCount > 0 && maxGetTime > 0) {// 鍏ㄩ儴宸插埌璐�
-			// 鏌ヨ鍒拌处鏃堕棿璺濈褰撳墠鏃堕棿鏄惁瓒呰繃鎸囧畾澶�
-			if (System.currentTimeMillis() - maxGetTime > 1000 * 60 * 60 * 24L * day)
-				return true;
-		}
-		return false;
 	}
 
 	@Override
@@ -308,7 +281,6 @@
 		inviteOrderSubsidyMapper.updateByPrimaryKeySelective(orderSubsidy);
 	}
 
-	
 	@Override
 	public BigDecimal sumRecievedMoneyByUid(long uid, Integer level) {
 		BigDecimal money = inviteOrderSubsidyMapper.sumRecievedMoneyByUid(uid, level);
@@ -317,7 +289,7 @@
 		}
 		return money;
 	}
-	
+
 	@Override
 	public BigDecimal sumValidMoneyByUidAndDate(long uid, Integer day, Integer level) {
 		BigDecimal money = inviteOrderSubsidyMapper.sumValidMoneyByUidAndDate(uid, day, level);
@@ -326,7 +298,7 @@
 		}
 		return money;
 	}
-	
+
 	@Override
 	public BigDecimal sumMoneyByUidAndDateAndState(long uid, Integer day, Integer level, Integer state) {
 		BigDecimal money = inviteOrderSubsidyMapper.sumMoneyByUidAndDateAndState(uid, day, level, state);
@@ -335,6 +307,5 @@
 		}
 		return money;
 	}
-	
-	
+
 }

--
Gitblit v1.8.0