From ee5c8055b1c0dd7c67a9025a76b10bd287c93d9a Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 15 四月 2020 09:52:27 +0800
Subject: [PATCH] 资金明细增加团队分红

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java |  261 +++++++++++++++++----------------------------------
 1 files changed, 88 insertions(+), 173 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java
index 03cbab1..442cbfb 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java
@@ -20,7 +20,6 @@
 
 import com.yeshi.fanli.entity.accept.AcceptData;
 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.UserSystemCouponRecord;
 import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
@@ -42,6 +41,7 @@
 import com.yeshi.fanli.service.inter.order.ESOrderService;
 import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
 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.tb.TaoBaoWeiQuanOrderService;
 import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
@@ -64,7 +64,6 @@
 import com.yeshi.fanli.vo.order.HongBaoCountVO;
 import com.yeshi.fanli.vo.order.OrderCountVO;
 import com.yeshi.fanli.vo.order.OrderRebateVO;
-import com.yeshi.fanli.vo.order.TeamBonusVO;
 import com.yeshi.fanli.vo.user.UserInfoExtraVO;
 import com.yeshi.fanli.vo.user.UserSettingsVO;
 
@@ -127,6 +126,9 @@
 	
 	@Resource
 	private ThreeSaleSerivce threeSaleSerivce;
+	
+	@Resource
+	private OrderHongBaoMapService orderHongBaoMapService;
 
 	/**
 	 * 璁㈠崟鍒楄〃
@@ -295,7 +297,6 @@
 			data.put("count", count);
 			data.put("result_list", JsonUtil.getApiCommonGson().toJson(list));
 			data.put("helpUrl", configService.get(ConfigKeyEnum.orderListHelp.getKey()));
-			data.put("bonusLink", configService.get(ConfigKeyEnum.orderBonusLink.getKey()));
 			data.put("validMoney", "楼 " + validMoney);
 			data.put("invalidMoney", "楼 " + invalidMoney);
 			data.put("findOrderHelpUrl", orderFindUrl);
@@ -502,153 +503,6 @@
 		out.print(JsonUtil.loadTrueResult(data));
 	}
 
-	/**
-	 * 鍥㈤槦鏀剁泭缁熻  缁熻宸插埌璐︽湭鍒拌处 锛� 绱鍙粺璁″凡鍒拌处
-	 * @param acceptData
-	 * @param uid
-	 * @param type 1-鍥㈤槦琛ヨ创   2-鍥㈤槦濂栧姳 3-瀵煎笀娲ヨ创
-	 */
-	@RequestMapping(value = "getTeamBonus", method = RequestMethod.POST)
-	public void getTeamBonus(AcceptData acceptData, Long uid, Integer type, PrintWriter out) {
-		if (uid == null) {
-			out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
-			return;
-		}
-
-		UserInfo user = userInfoService.selectByPKey(uid);
-		if (user == null) {
-			out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛涓嶅瓨鍦�"));
-			return;
-		}
-
-		if (type == null || type < 1 || type > 3) {
-			type = 1;
-		}
-
-		if (type == 1) {
-			// 琛ヨ创
-			sumTeamSubsidy(out, user);
-		} else if (type == 2) {
-			// 濂栧姳
-			//TODO 鍥㈤槦濂栧姳宸茬粡鍒犻櫎
-		} else {
-			// 瀵煎笀娲ヨ创
-			JSONObject data = new JSONObject();
-			data.put("exist", false);
-			data.put("link", configService.get(ConfigKeyEnum.tutorSubsidyLink.getKey()));
-			out.print(JsonUtil.loadTrueResult(data));
-		}
-	}
-
-	/**
-	 * 缁熻琛ヨ创
-	 * @param out
-	 * @param user
-	 */
-	private void sumTeamSubsidy(PrintWriter out, UserInfo user) {
-		Long uid = user.getId();
-		// 鏄惁VIP
-		boolean vip = userVIPInfoService.isVIP(uid);
-
-		JSONObject data = new JSONObject();
-		data.put("link", configService.get(ConfigKeyEnum.orderTeamSubsidyLink.getKey()));
-		if (!vip) {
-			data.put("exist", false);
-			out.print(JsonUtil.loadTrueResult(data));
-			return;
-		}
-
-		data.put("exist", true);
-		data.put("portrait", user.getPortrait());
-
-		// 浠婃棩缁熻
-		BigDecimal todayDirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 1,
-				InviteOrderSubsidy.LEVEL_ONE);
-		if (todayDirect == null) {
-			todayDirect = new BigDecimal(0);
-		}
-		BigDecimal todayIndirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 1,
-				InviteOrderSubsidy.LEVEL_TWO);
-		if (todayIndirect == null) {
-			todayIndirect = new BigDecimal(0);
-		}
-		TeamBonusVO today = new TeamBonusVO();
-		today.setDirect(todayDirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		today.setIndirect(todayIndirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		today.setTotal(
-				MoneyBigDecimalUtil.add(todayDirect, todayIndirect).setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-		// 鏄ㄦ棩缁熻
-		BigDecimal yesterdayDirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 2,
-				InviteOrderSubsidy.LEVEL_ONE);
-		if (yesterdayDirect == null) {
-			yesterdayDirect = new BigDecimal(0);
-		}
-		BigDecimal yesterdayIndirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 2,
-				InviteOrderSubsidy.LEVEL_TWO);
-		if (yesterdayIndirect == null) {
-			yesterdayIndirect = new BigDecimal(0);
-		}
-		TeamBonusVO yesterday = new TeamBonusVO();
-		yesterday.setDirect(yesterdayDirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		yesterday.setIndirect(yesterdayIndirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		yesterday.setTotal(MoneyBigDecimalUtil.add(yesterdayDirect, yesterdayIndirect)
-				.setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-		// 鏈湀缁熻
-		BigDecimal thisMonthDirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 3,
-				InviteOrderSubsidy.LEVEL_ONE);
-		if (thisMonthDirect == null) {
-			thisMonthDirect = new BigDecimal(0);
-		}
-		BigDecimal thisMonthIndirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 3,
-				InviteOrderSubsidy.LEVEL_TWO);
-		if (thisMonthIndirect == null) {
-			thisMonthIndirect = new BigDecimal(0);
-		}
-		TeamBonusVO thisMonth = new TeamBonusVO();
-		thisMonth.setDirect(thisMonthDirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		thisMonth.setIndirect(thisMonthIndirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		thisMonth.setTotal(MoneyBigDecimalUtil.add(thisMonthDirect, thisMonthIndirect)
-				.setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-		// 鏈湀缁熻
-		BigDecimal lastMonthDirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 4,
-				InviteOrderSubsidy.LEVEL_ONE);
-		if (lastMonthDirect == null) {
-			lastMonthDirect = new BigDecimal(0);
-		}
-		BigDecimal lastMonthIndirect = inviteOrderSubsidyServiceV2.sumValidMoneyByUidAndDate(uid, 4,
-				InviteOrderSubsidy.LEVEL_TWO);
-		if (lastMonthIndirect == null) {
-			lastMonthIndirect = new BigDecimal(0);
-		}
-		TeamBonusVO lastMonth = new TeamBonusVO();
-		lastMonth.setDirect(lastMonthDirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		lastMonth.setIndirect(lastMonthIndirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		lastMonth.setTotal(MoneyBigDecimalUtil.add(lastMonthDirect, lastMonthIndirect)
-				.setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-		BigDecimal direct = inviteOrderSubsidyServiceV2.sumRecievedMoneyByUid(uid, InviteOrderSubsidy.LEVEL_ONE);
-		if (direct == null) {
-			direct = new BigDecimal(0);
-		}
-		BigDecimal indirect = inviteOrderSubsidyServiceV2.sumRecievedMoneyByUid(uid, InviteOrderSubsidy.LEVEL_TWO);
-		if (indirect == null) {
-			indirect = new BigDecimal(0);
-		}
-		BigDecimal total = MoneyBigDecimalUtil.add(direct, indirect);
-
-		data.put("today", today);
-		data.put("yesterday", yesterday);
-		data.put("thisMonth", thisMonth);
-		data.put("lastMonth", lastMonth);
-		data.put("total", total.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		data.put("direct", direct.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		data.put("indirect", indirect.setScale(2, BigDecimal.ROUND_DOWN).toString());
-		out.print(JsonUtil.loadTrueResult(data));
-	}
-
 	
 	/**
 	 * 杩斿埄璇存槑
@@ -727,7 +581,7 @@
 				BigDecimal weiQuanMoney = commonOrderService.getWeiQuanMoney(listWQ, sourceType, uid);
 				
 				orderRebateVO.setWq(true);
-				orderRebateVO.setWqMoney("-楼"+ weiQuanMoney.setScale(2, BigDecimal.ROUND_DOWN));
+				orderRebateVO.setWqMoney("楼"+ weiQuanMoney.setScale(2, BigDecimal.ROUND_DOWN));
 				if (hongBao.compareTo(weiQuanMoney) > 0) {
 					orderRebateVO.setWqDesc("閮ㄥ垎鍞悗閫�鍥�");
 				} else {
@@ -738,14 +592,14 @@
 			}
 		}
 		orderRebateVO.setFanLiDesc(predictDesc + typeName);
-		orderRebateVO.setFanLi("楼" + hongBao.setScale(2));
+		orderRebateVO.setFanLi("楼" + hongBao.setScale(2, BigDecimal.ROUND_DOWN));
 		
 		HongBaoV2 hongBaoV2 = hoList.get(0).getHongBaoV2();
 		UserLevelEnum userLevel = UserLevelUtil.getByOrderRank(hongBaoV2.getUrank());
 		if (userLevel == null)
 			userLevel = UserLevelEnum.daRen;
 		UserLevelEnum upperLevel =  UserLevelEnum.superVIP;
-				
+			
 		BigDecimal upperTotalMoney = new BigDecimal(0);
 		List<GoodsRebateVO> voList = new ArrayList<>();
 		for (HongBaoOrder hongBaoOrder : hoList) {
@@ -767,8 +621,7 @@
 				payment = hongBaoOrder.getCommonOrder().getSettlement();
 			if (payment == null)
 				payment = new BigDecimal(0);
-			goodsVO.setActualPay("楼" + payment.setScale(2));
-
+			goodsVO.setActualPay("楼" + payment.setScale(2, BigDecimal.ROUND_DOWN));
 			
 			BigDecimal commission = orderHongBaoMoneyComputeService.computeBaseFanliMoney(commonOrder);
 			if (type == 3) { // 濂栭噾
@@ -779,16 +632,20 @@
 			
 			// 骞冲彴琛ヨ创
 			BigDecimal vipFanli = hongBaoOrder.getHongBaoV2().getMoney();
-			goodsVO.setSubsidy(vipFanli.subtract(commission).setScale(2) + "");
+			goodsVO.setSubsidy("楼" + vipFanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN));
 			//  杈句汉琛ヨ创
 			if (userLevel != UserLevelEnum.daRen) {
 				BigDecimal darenFanli = orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, UserLevelEnum.daRen);
-				goodsVO.setOriginSubsidy("楼" + darenFanli.subtract(commission).setScale(2) + "");
+				goodsVO.setOriginSubsidy("楼" + darenFanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN) + "");
 			}
 			
 			voList.add(goodsVO);
-		
-			upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, upperLevel));
+			
+			if (type == 1 ) {
+				upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, upperLevel));
+			} else if (type == 2) {
+				upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, upperLevel));
+			}
 		}
 			
 		// 鍥㈤槦琛ヨ创
@@ -815,34 +672,92 @@
 			}
 			
 			if (userLevel != UserLevelEnum.daRen) {
-				orderRebateVO.setOriginSubsidy("楼" + lowerSubsidy.setScale(2));
+				orderRebateVO.setOriginSubsidy("楼" + lowerSubsidy.setScale(2, BigDecimal.ROUND_DOWN));
 			}
 			orderRebateVO.setSubsidyDesc("鍥㈤槦琛ヨ创");
-			orderRebateVO.setSubsidy("楼" + teamSubsidy.setScale(2) +"");
+			orderRebateVO.setSubsidy("楼" + teamSubsidy.setScale(2, BigDecimal.ROUND_DOWN) +"");
+			
+			upperTotalMoney = upperTotalMoney.add(teamSubsidy);
 		}
 		
 		orderRebateVO.setType(type);
 		orderRebateVO.setStateDesc(stateDesc);
 		orderRebateVO.setListGoods(voList);
+		orderRebateVO.setUserLevel(userLevel.name());
 		
 		// 涓婄骇杩斿埄
 		if (upperLevel != null) {
+			upperTotalMoney = upperTotalMoney.add(hongBao);
 			orderRebateVO.setUpperFanLi("楼" + upperTotalMoney);
-			orderRebateVO.setUserLevel(upperLevel.name());
 			orderRebateVO.setJumpLink(upperLevel.getDetailLink());
 		}
 
-		// 濂栧姳鍒镐娇鐢�
-		Date accountTime = hongBaoCountVO.getAccountTime();
-		if (accountTime != null) {
-			boolean vip = userInviteService.verifyVIP(uid);
-			Date endDay = DateUtil.plusDayDate(Constant.COUPON_REWARD_LIMIT_DAY, accountTime);
-			long currentTime = java.lang.System.currentTimeMillis();
-			if (endDay.getTime() > currentTime && !vip) {
-				UserSystemCouponRecord couponRecord = userSystemCouponRecordService.getRecordByOrderNo(orderNo, null);
-				if (couponRecord == null 
-						|| (couponRecord.getCouponType() == CouponTypeEnum.rebatePercentCoupon.name() && couponRecord.getState() != UserSystemCouponRecord.STATE_SUCCESS)) {
-					orderRebateVO.setCoupon(true);
+		int freeState = 0;
+		boolean rewardSuccess = false;
+		List<String> listNo = new ArrayList<String>();
+		listNo.add(orderNo);
+		List<UserSystemCouponRecord> useRecord = userSystemCouponRecordService.getRecordByOrderNoList(sourceType, listNo);
+		if (useRecord != null && useRecord.size() > 0) {
+			for (UserSystemCouponRecord couponRecord : useRecord) {
+				Integer state = couponRecord.getState();
+				String cType = couponRecord.getCouponType();
+				if (CouponTypeEnum.rebatePercentCoupon.name().equals(cType) && UserSystemCouponRecord.STATE_SUCCESS == state) {
+					rewardSuccess = true;
+					break;
+				} else if (CouponTypeEnum.freeCoupon.name().equals(cType) || CouponTypeEnum.welfareFreeCoupon.name().equals(cType)
+						|| CouponTypeEnum.freeCouponBuy.name().equals(cType)) {
+					freeState = state;
+					break;
+				}
+			
+			}
+		}
+		
+		if (rewardSuccess) {  // 宸蹭娇鐢ㄥ鍔卞埜
+			JSONObject params = new JSONObject();
+			params.put("orderNo", orderNo);
+			params.put("goodsType", sourceType + "");
+			BigDecimal couponMoney = orderHongBaoMapService.getCouponHongbaoByOrderNo(orderNo, uid);
+			if (couponMoney == null) {
+				couponMoney = new BigDecimal(0);
+			}
+			orderRebateVO.setCouponType(1);
+			orderRebateVO.setCouponUse(true);
+			orderRebateVO.setCouponText("濂栧姳鎴愬姛");
+			orderRebateVO.setCouponDesc("宸插啀杩斅�" +couponMoney.setScale(2, BigDecimal.ROUND_DOWN));
+			orderRebateVO.setCouponParams(params.toString());
+			orderRebateVO.setCouponJumpDetail(jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
+		} else if (freeState > 0) { // 宸蹭娇鐢ㄥ厤鍗曞埜
+			JSONObject params = new JSONObject();
+			params.put("orderNo", orderNo);
+			params.put("goodsType", sourceType + "");
+			orderRebateVO.setCouponType(2);
+			orderRebateVO.setCouponUse(true);
+			orderRebateVO.setCouponParams(params.toString());
+			orderRebateVO.setCouponJumpDetail(jumpDetailV2Service.getByTypeCache("freeCouponDetail"));
+			if (UserSystemCouponRecord.STATE_FREE_ON == freeState) {
+				orderRebateVO.setCouponText("鍏嶅崟涓�");
+			} else if (UserSystemCouponRecord.STATE_SUCCESS == freeState) {
+				orderRebateVO.setCouponText("鍏嶅崟鎴愬姛");
+			} else if (UserSystemCouponRecord.STATE_FAIL_RULE == freeState
+					|| UserSystemCouponRecord.STATE_FAIL_DRAWBACK == freeState) {
+				orderRebateVO.setCouponText("鍏嶅崟澶辫触");
+			}
+		} else {
+			Date accountTime = hongBaoV2.getGetTime();
+			if (accountTime != null) { 
+				boolean vip = userInviteService.verifyVIP(uid);
+				Date endDay = DateUtil.plusDayDate(Constant.COUPON_REWARD_LIMIT_DAY, accountTime);
+				long currentTime = java.lang.System.currentTimeMillis();
+				if (endDay.getTime() > currentTime && !vip) {
+					UserSystemCouponRecord couponRecord = userSystemCouponRecordService.getRecordByOrderNo(orderNo, null);
+					if (couponRecord == null 
+							|| (couponRecord.getCouponType() == CouponTypeEnum.rebatePercentCoupon.name() && couponRecord.getState() != UserSystemCouponRecord.STATE_SUCCESS)) {
+						orderRebateVO.setCoupon(true);
+						orderRebateVO.setCouponType(1);
+						orderRebateVO.setCouponText("绔嬪嵆浣跨敤");
+						orderRebateVO.setCouponDesc("杩斿埄鍐嶈繑");
+					}
 				}
 			}
 		}

--
Gitblit v1.8.0