From 0cc3b905e5945d1b4b02ee5f91a615bcfd8f08d6 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期四, 25 七月 2019 11:44:10 +0800
Subject: [PATCH] 京东兼容

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java |  148 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 125 insertions(+), 23 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
index c085968..c8d1580 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
@@ -152,6 +152,8 @@
 	public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException {
 		Set<Integer> stateSet = new HashSet<>();// 璁㈠崟鐘舵�丼et
 		if (commonOrderList != null && commonOrderList.size() > 0) {
+			int orderType = commonOrderList.get(0).getSourceType();
+
 			Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
 			int goodsCount = 0;
 			boolean hasAdd = false;
@@ -175,7 +177,6 @@
 			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();
@@ -184,28 +185,31 @@
 					BigDecimal money = notify.getMoney();
 					switch (t) {
 					case HongBaoV2.TYPE_ZIGOU:
-						userNotificationService.orderFanliStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK,
-								null, money);
-						userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType,commonOrder.getPayment(),
 								money, goodsCount, state);
 						break;
 					case HongBaoV2.TYPE_SHARE_GOODS:
 						userNotificationService.orderShareStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK,
 								null, money);
-						userOrderMsgNotificationService.orderShareStatistic(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderShareStatistic(uid, orderId,orderType, commonOrder.getPayment(),
 								money, goodsCount, state);
 						break;
 					case HongBaoV2.TYPE_YIJI:
 						userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount,
 								MsgOrderDetail.STATE_FK, null, money);
-						userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderInviteStatistic(uid, orderId,orderType, commonOrder.getPayment(),
 								money, goodsCount, state);
 						break;
 					case HongBaoV2.TYPE_ERJI:
 						userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount,
 								MsgOrderDetail.STATE_FK, null, money);
-						userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(),
+						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;
 					}
 				}
@@ -224,21 +228,24 @@
 					BigDecimal money = notify.getMoney();
 					switch (t) {
 					case HongBaoV2.TYPE_ZIGOU:
-						userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId,orderType, commonOrder.getPayment(),
 								money, state);
 						break;
 					case HongBaoV2.TYPE_SHARE_GOODS:
-						userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderShareStateChanged(uid, orderId,orderType, commonOrder.getPayment(),
 								money, state);
 						break;
 					case HongBaoV2.TYPE_YIJI:
-						userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId,orderType, commonOrder.getPayment(),
 								money, state);
 						break;
 					case HongBaoV2.TYPE_ERJI:
-						userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(),
+						userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId,orderType, commonOrder.getPayment(),
 								money, state);
 						break;
+					case HongBaoV2.TYPE_SHARE_YIJI:
+						userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId,orderType,
+								commonOrder.getPayment(), money, state);
 					}
 				}
 			}
@@ -283,7 +290,8 @@
 					payMent = commonOrder.getSettlement();
 
 				if (payMent.compareTo(new BigDecimal(10)) < 0) {
-					mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo());
+					mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getSourceType(),
+							commonOrder.getOrderNo());
 				}
 			}
 
@@ -548,17 +556,20 @@
 					childUpdate.setUpdateTime(new Date());
 					BigDecimal rate = null;
 					if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 涓�绾у垎浜禋
-						rate = hongBaoManageService.getFirstShareRate(child.getUrank(),
-								commonOrder.getCreateTime().getTime());
+						rate = hongBaoManageService.getFirstShareRate(1, commonOrder.getCreateTime().getTime());
 					} else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 浜岀骇鍒嗕韩璧�
-						rate = hongBaoManageService.getSecondShareRate(child.getUrank(),
-								commonOrder.getCreateTime().getTime());
+						rate = hongBaoManageService.getSecondShareRate(1, commonOrder.getCreateTime().getTime());
 					}
 
 					// 浠ュ疄闄呮敹鍏ヤ负鍑嗚绠楅浼版敹鐩�
 					if (CommonOrder.STATE_JS == commonOrder.getState()) {
 						childUpdate.setMoney(
 								MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
+						if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-16",
+								"yyyy-MM-dd"))
+							childUpdate.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
+									rate.divide(new BigDecimal(100))));
+
 						Calendar calendar = Calendar.getInstance();
 						calendar.setTime(commonOrder.getSettleTime());
 						calendar.add(Calendar.MONTH, 1);
@@ -566,13 +577,36 @@
 								calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
 								"yyyy-M-dd")));
 					} else if (CommonOrder.STATE_FK == commonOrder.getState()) {
-						if (commonOrder.getOrderNo().equalsIgnoreCase("314134177659155087"))
-							System.out.println("");
-
-						childUpdate.setMoney(
-								MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
+						if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-16",
+								"yyyy-MM-dd"))
+							childUpdate.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
+									rate.divide(new BigDecimal(100))));
+						else
+							childUpdate.setMoney(
+									MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
 					}
 					hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
+					// 娣诲姞閫氱煡
+					if (notificationMap.get(child.getType()) == null) {
+						HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
+						tempHongBao.setUserInfo(child.getUserInfo());
+						tempHongBao
+								.setMoney(childUpdate.getMoney() == null ? new BigDecimal(0) : childUpdate.getMoney());
+						CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
+						tempCommonOrder.setPayment(commonOrder.getPayment());
+						notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
+					} else {
+						// 澧炲姞浠樻閲戦涓庤祫閲�
+						HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType());
+						if (commonOrder.getPayment() != null)
+							tempHongBaoOrder.getCommonOrder().setPayment(
+									tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
+						if (childUpdate.getMoney() != null)
+							tempHongBaoOrder.getHongBaoV2()
+									.setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(childUpdate.getMoney()));
+						notificationMap.put(child.getType(), tempHongBaoOrder);
+					}
+
 				}
 		} else
 			throw new HongBaoException(2, "type閿欒");
@@ -698,6 +732,10 @@
 					firstHongbao.setMoney(
 							MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
 				}
+				// 杩斿埄涓�0鐨勪笉閫氱煡
+				if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
+					return;
+
 				hongBaoV2Mapper.insertSelective(firstHongbao);
 				// 鐢ㄦ埛閫氱煡
 				if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) {
@@ -745,6 +783,11 @@
 						secondHongbao.setMoney(
 								MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
 					}
+
+					// 杩斿埄涓�0鐨勪笉缁熻
+					if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
+						return;
+
 					hongBaoV2Mapper.insertSelective(secondHongbao);
 
 					// 鐢ㄦ埛閫氱煡
@@ -802,7 +845,6 @@
 						}
 					}
 				}
-
 			}
 
 			HongBaoV2 hongBao = new HongBaoV2();
@@ -851,6 +893,56 @@
 				notificationMap.put(type, tempHongBaoOrder);
 			}
 
+			// 4鏈�17鏃ュ悗鎵嶆湁涓�绾у垎浜禋
+			if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) {
+				UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
+				if (boss != null) {
+					BigDecimal firstLevelRate = hongBaoManageService.getFirstShareRate(1,
+							commonOrder.getThirdCreateTime().getTime());
+					HongBaoV2 child = new HongBaoV2();
+					child.setParent(hongBao);
+					child.setType(HongBaoV2.TYPE_SHARE_YIJI);
+					if (commonOrder.getState() == CommonOrder.STATE_FK) {
+						child.setState(HongBaoV2.STATE_BUKELINGQU);
+						child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
+								firstLevelRate.divide(new BigDecimal(100))));
+					} else if (commonOrder.getState() == CommonOrder.STATE_JS) {
+						child.setState(HongBaoV2.STATE_KELINGQU);
+						child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
+								firstLevelRate.divide(new BigDecimal(100))));
+						Calendar calendar = Calendar.getInstance();
+						calendar.setTime(commonOrder.getSettleTime());
+						calendar.add(Calendar.MONTH, 1);
+						child.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
+								calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
+								"yyyy-M-dd")));
+					}
+					child.setUserInfo(boss);
+					child.setUrank(boss.getRank());
+					child.setVersion(2);
+					child.setCreateTime(new Date());
+					hongBaoV2Mapper.insertSelective(child);
+					// 娣诲姞閫氱煡
+					if (notificationMap.get(HongBaoV2.TYPE_SHARE_YIJI) == null) {
+						HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
+						tempHongBao.setUserInfo(child.getUserInfo());
+						tempHongBao.setMoney(child.getMoney());
+						tempHongBao.setBeizhu(hongBao.getUserInfo().getNickName());
+						CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
+						tempCommonOrder.setPayment(commonOrder.getPayment());
+						notificationMap.put(HongBaoV2.TYPE_SHARE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
+					} else {
+						// 澧炲姞浠樻閲戦涓庤祫閲�
+						HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_SHARE_YIJI);
+						tempHongBaoOrder.getCommonOrder().setPayment(
+								tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
+						tempHongBaoOrder.getHongBaoV2()
+								.setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney()));
+						notificationMap.put(HongBaoV2.TYPE_SHARE_YIJI, tempHongBaoOrder);
+					}
+				}
+			}
+
 			// 淇敼缁熻鏁版嵁
 			Long goodsId = commonOrder.getCommonOrderGoods().getId();
 			// 鏌ヨ鍟嗗搧
@@ -863,7 +955,7 @@
 			hb.setMoney(hongBao.getMoney());
 
 			try {
-				userShareGoodsGroupService.updateOrderRecord(hb);
+				userShareGoodsGroupService.updateOrderRecord(hb,commonOrder.getSourceType());
 			} catch (UserShareGoodsRecordException e) {
 				try {
 					LogHelper.errorDetailInfo(e);
@@ -943,4 +1035,14 @@
 		else
 			return money;
 	}
+
+	@Override
+	public List<HongBaoV2> listChildrenById(Long id) {
+		return hongBaoV2Mapper.listChildrenById(id);
+	}
+
+	@Override
+	public List<Long> getUidByNear30DayShareSucceed() {
+		return hongBaoV2Mapper.getUidByNear30DayShareSucceed();
+	}
 }

--
Gitblit v1.8.0