From 71298bf0680d1204d403a9f9bd11e985088c8495 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 08 一月 2019 16:35:54 +0800
Subject: [PATCH] 新版订单与返利的修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java |   87 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 76 insertions(+), 11 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 19ed847..c268891 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
@@ -5,7 +5,10 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import javax.annotation.Resource;
 
@@ -40,6 +43,7 @@
 import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.order.CommonOrderService;
 import com.yeshi.fanli.service.inter.user.UserInfoService;
+import com.yeshi.fanli.service.inter.user.UserNotificationService;
 import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.MoneyBigDecimalUtil;
@@ -348,18 +352,51 @@
 	@Resource
 	private ThreeSaleSerivce threeSaleSerivce;
 
+	@Resource
+	private UserNotificationService userNotificationService;
+
 	@Transactional
 	@Override
-	public void addHongBao(CommonOrder commonOrder, int type) throws HongBaoException {
-		if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null)
-			throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�");
-		HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
-		if (hongBaoOrder == null) {
-			saveHongBao(commonOrder, type);
-		} else {
-			updateHongBao(hongBaoOrder, commonOrder, type);
-		}
+	public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException {
 
+		if (commonOrderList != null && commonOrderList.size() > 0) {
+			Map<Integer, HongBaoV2> notificationMap = new HashMap<>();
+			for (CommonOrder commonOrder : commonOrderList) {
+				if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null)
+					throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�");
+				HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
+				if (hongBaoOrder == null) {
+					saveHongBao(commonOrder, type, notificationMap);
+				} else {
+					updateHongBao(hongBaoOrder, commonOrder, type);
+				}
+			}
+			/**
+			 * 閫氱煡鐢ㄦ埛鐨勮繑鍒╂儏鍐�
+			 */
+			Iterator<Integer> its = notificationMap.keySet().iterator();
+			while (its.hasNext()) {
+				Integer t = its.next();
+				HongBaoV2 notify = notificationMap.get(t);
+				String orderId = commonOrderList.get(0).getOrderNo();
+				Long uid = notify.getUserInfo().getId();
+				BigDecimal money = notify.getMoney();
+				switch (t) {
+				case HongBaoV2.TYPE_ZIGOU:
+					userNotificationService.orderFanliStatisticed(uid, orderId);
+					break;
+				case HongBaoV2.TYPE_SHARE_GOODS:
+					userNotificationService.orderShareStatisticed(uid, orderId, money);
+					break;
+				case HongBaoV2.TYPE_YIJI:
+					userNotificationService.orderInviteStatisticed(uid, orderId, money);
+					break;
+				case HongBaoV2.TYPE_ERJI:
+					userNotificationService.orderInviteStatisticed(uid, orderId, money);
+					break;
+				}
+			}
+		}
 	}
 
 	@Transactional
@@ -490,7 +527,8 @@
 	}
 
 	@Transactional
-	private void saveHongBao(CommonOrder commonOrder, int type) throws HongBaoException {
+	private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoV2> notificationMap)
+			throws HongBaoException {
 		if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚�
 			BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
 			HongBaoV2 hongBao = new HongBaoV2();
@@ -522,6 +560,12 @@
 			hongBaoOrder.setCreateTime(new Date());
 			hongBaoOrder.setHongBaoV2(hongBao);
 			hongBaoOrderMapper.insertSelective(hongBaoOrder);
+			// 鍔犲叆閫氱煡
+			if (notificationMap.get(type) == null)
+				notificationMap.put(type, hongBao);
+			else {
+				notificationMap.get(type).setMoney(notificationMap.get(type).getMoney().add(hongBao.getMoney()));
+			}
 
 			UserInfo boss = threeSaleSerivce.getBoss(user.getId());
 			if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1绾OSS瀛樺湪涓旂孩鍖呮湭澶辨晥
@@ -554,6 +598,13 @@
 							MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
 				}
 				hongBaoV2Mapper.insertSelective(firstHongbao);
+				// 鐢ㄦ埛閫氱煡
+				if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null)
+					notificationMap.put(HongBaoV2.TYPE_YIJI, firstHongbao);
+				else {
+					notificationMap.get(HongBaoV2.TYPE_YIJI)
+							.setMoney(notificationMap.get(HongBaoV2.TYPE_YIJI).getMoney().add(firstHongbao.getMoney()));
+				}
 
 				// 鎻掑叆浜岀骇瀛愮孩鍖�
 				boss = threeSaleSerivce.getBoss(boss.getId());
@@ -571,7 +622,7 @@
 					secondHongbao.setVersion(2);
 					secondHongbao.setState(hongBao.getState());
 					if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
-						firstHongbao.setMoney(
+						secondHongbao.setMoney(
 								MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
 						Calendar calendar = Calendar.getInstance();
 						calendar.setTime(commonOrder.getSettleTime());
@@ -584,6 +635,14 @@
 								MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
 					}
 					hongBaoV2Mapper.insertSelective(secondHongbao);
+
+					// 鐢ㄦ埛閫氱煡
+					if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null)
+						notificationMap.put(HongBaoV2.TYPE_ERJI, secondHongbao);
+					else {
+						notificationMap.get(HongBaoV2.TYPE_ERJI).setMoney(
+								notificationMap.get(HongBaoV2.TYPE_ERJI).getMoney().add(secondHongbao.getMoney()));
+					}
 				}
 
 			}
@@ -623,6 +682,12 @@
 			hongBaoOrder.setHongBaoV2(hongBao);
 			hongBaoOrderMapper.insertSelective(hongBaoOrder);
 
+			if (notificationMap.get(type) == null)
+				notificationMap.put(type, hongBao);
+			else {
+				notificationMap.get(type).setMoney(notificationMap.get(type).getMoney().add(hongBao.getMoney()));
+			}
+
 			// 淇敼缁熻鏁版嵁
 			Long goodsId = commonOrder.getCommonOrderGoods().getId();
 			// 鏌ヨ鍟嗗搧

--
Gitblit v1.8.0