From 784af16411d97c3e14f81dd4ebf1380c8b9effb0 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 31 七月 2019 10:33:18 +0800
Subject: [PATCH] 智能推荐修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java |   75 ++++++++++++++++++++-----------------
 1 files changed, 41 insertions(+), 34 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 6f59edf..ca70561 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
@@ -25,7 +25,6 @@
 import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
 import com.yeshi.fanli.dto.HongBao;
 import com.yeshi.fanli.dto.HongBaoDTO;
-import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail;
 import com.yeshi.fanli.entity.bus.user.HongBaoV2;
 import com.yeshi.fanli.entity.bus.user.ThreeSale;
 import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
@@ -48,7 +47,6 @@
 import com.yeshi.fanli.service.inter.order.ShareGoodsActivityOrderService;
 import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
 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.service.inter.user.UserSystemCouponRecordService;
 import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
@@ -95,9 +93,6 @@
 
 	@Resource
 	private ThreeSaleSerivce threeSaleSerivce;
-
-	@Resource
-	private UserNotificationService userNotificationService;
 
 	@Resource
 	private UserOrderMsgNotificationService userOrderMsgNotificationService;
@@ -152,6 +147,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;
@@ -183,30 +180,27 @@
 					BigDecimal money = notify.getMoney();
 					switch (t) {
 					case HongBaoV2.TYPE_ZIGOU:
-						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,
+						userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId,orderType,
 								commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu());
 						break;
 					}
@@ -226,23 +220,23 @@
 					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,
+						userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId,orderType,
 								commonOrder.getPayment(), money, state);
 					}
 				}
@@ -272,7 +266,7 @@
 		HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
 		if (oldHongBao == null)
 			throw new HongBaoException(10, "绾㈠寘瀵硅薄涓嶅瓨鍦�");
-		// 宸茬粡澶辨晥鎴栬�呭凡缁忛鍙栫殑绾㈠寘涓嶅仛澶勭悊
+		// 宸茬粡澶辨晥锛屽凡缁忛鍙栵紝鏂拌�佺姸鎬佷竴鑷寸殑绾㈠寘涓嶅仛澶勭悊
 		if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO || oldHongBao.getState() == HongBaoV2.STATE_YILINGQU)
 			return;
 
@@ -288,7 +282,8 @@
 					payMent = commonOrder.getSettlement();
 
 				if (payMent.compareTo(new BigDecimal(10)) < 0) {
-					mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo());
+					mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getSourceType(),
+							commonOrder.getOrderNo());
 				}
 			}
 
@@ -312,6 +307,14 @@
 			} else if (commonOrder.getState() == CommonOrder.STATE_SX) {
 				hongBao.setState(HongBaoV2.STATE_SHIXIAO);
 				hongBao.setMoney(new BigDecimal(0));
+
+			}
+
+			// 鏂拌�佺孩鍖呯姸鎬佷竴鑷翠笉澶勭悊
+			if (oldHongBao.getState().intValue() == hongBao.getState())
+				return;
+
+			if (hongBao.getState() == HongBaoV2.STATE_SHIXIAO) {
 				if (mianDan) {
 					try {
 						userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
@@ -321,6 +324,7 @@
 					}
 				}
 			}
+
 			hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
 
 			// 鍔犲叆閫氱煡
@@ -587,17 +591,20 @@
 					if (notificationMap.get(child.getType()) == null) {
 						HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
 						tempHongBao.setUserInfo(child.getUserInfo());
-						tempHongBao.setMoney(childUpdate.getMoney());
+						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());
-						tempHongBaoOrder.getCommonOrder().setPayment(
-								tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
-						tempHongBaoOrder.getHongBaoV2()
-								.setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(childUpdate.getMoney()));
+						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);
 					}
 
@@ -726,7 +733,7 @@
 					firstHongbao.setMoney(
 							MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
 				}
-				//杩斿埄涓�0鐨勪笉閫氱煡
+				// 杩斿埄涓�0鐨勪笉閫氱煡
 				if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
 					return;
 
@@ -777,8 +784,8 @@
 						secondHongbao.setMoney(
 								MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
 					}
-					
-					//杩斿埄涓�0鐨勪笉缁熻
+
+					// 杩斿埄涓�0鐨勪笉缁熻
 					if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
 						return;
 
@@ -949,7 +956,7 @@
 			hb.setMoney(hongBao.getMoney());
 
 			try {
-				userShareGoodsGroupService.updateOrderRecord(hb);
+				userShareGoodsGroupService.updateOrderRecord(hb,commonOrder.getSourceType());
 			} catch (UserShareGoodsRecordException e) {
 				try {
 					LogHelper.errorDetailInfo(e);
@@ -1034,9 +1041,9 @@
 	public List<HongBaoV2> listChildrenById(Long id) {
 		return hongBaoV2Mapper.listChildrenById(id);
 	}
-	
+
 	@Override
-	public List<Long> getUidByNear30DayShareSucceed(){
+	public List<Long> getUidByNear30DayShareSucceed() {
 		return hongBaoV2Mapper.getUidByNear30DayShareSucceed();
 	}
 }

--
Gitblit v1.8.0