From 273e3ebef2a30c931590f51257403eda566fafcf Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 01 四月 2019 11:09:55 +0800
Subject: [PATCH] 订单统计BUG修复

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 105 insertions(+), 1 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 b7dfe1a..ca7ce6f 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
@@ -27,6 +27,7 @@
 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;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.order.CommonOrder;
@@ -337,7 +338,7 @@
 
 			// 鑾峰彇瀛愮孩鍖�
 			List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
-			if (children != null)
+			if (children != null&&children.size()>0)
 				for (HongBaoV2 child : children) {
 					HongBaoV2 childUpdate = new HongBaoV2(child.getId());
 					childUpdate.setState(hongBao.getState());
@@ -386,7 +387,110 @@
 					}
 
 				}
+			else {// 淇涔嬪墠浜岀骇,涓夌骇璁㈠崟鏈粺璁″埌鐨勬儏鍐�
+				if (!mianDan) {
+					ThreeSale threeSale = threeSaleSerivce.selectByWorkerId(commonOrder.getUserInfo().getId());
+					if (threeSale.getSucceedTime() != null
+							&& threeSale.getSucceedTime() <= commonOrder.getThirdCreateTime().getTime()) {
+						UserInfo boss = threeSaleSerivce.getBoss(commonOrder.getUserInfo().getId());
+						// 鎻掑叆涓�绾у瓙绾㈠寘
+						BigDecimal firstRate = hongBaoManageService
+								.getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
+						if (firstRate.compareTo(new BigDecimal(0)) <= 0)
+							return;
+						HongBaoV2 firstHongbao = new HongBaoV2();
+						firstHongbao.setUserInfo(boss);
+						firstHongbao.setUrank(boss.getRank());
+						firstHongbao.setParent(hongBao);
+						firstHongbao.setCreateTime(new Date());
+						firstHongbao.setType(HongBaoV2.TYPE_YIJI);
+						firstHongbao.setVersion(2);
+						firstHongbao.setState(hongBao.getState());
 
+						if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
+							firstHongbao.setMoney(
+									MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
+							Calendar calendar = Calendar.getInstance();
+							calendar.setTime(commonOrder.getSettleTime());
+							calendar.add(Calendar.MONTH, 1);
+							firstHongbao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
+									calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
+									"yyyy-M-dd")));
+						} else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
+							firstHongbao.setMoney(
+									MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
+						}
+						hongBaoV2Mapper.insertSelective(firstHongbao);
+						// 鐢ㄦ埛閫氱煡
+						if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) {
+							HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId());
+							tempHongBao.setUserInfo(firstHongbao.getUserInfo());
+							tempHongBao.setMoney(firstHongbao.getMoney());
+							CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
+							tempCommonOrder.setPayment(commonOrder.getPayment());
+							notificationMap.put(HongBaoV2.TYPE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
+						} else {
+							// 澧炲姞浠樻閲戦涓庤祫閲�
+							HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI);
+							tempHongBaoOrder.getCommonOrder().setPayment(
+									tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
+							tempHongBaoOrder.getHongBaoV2()
+									.setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney()));
+							notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder);
+						}
+
+						// 鎻掑叆浜岀骇瀛愮孩鍖�
+						boss = threeSaleSerivce.getBoss(boss.getId());
+						if (boss != null) {// 浜岀骇BOSS瀛樺湪
+							BigDecimal secondRate = hongBaoManageService
+									.getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
+							if (secondRate.compareTo(new BigDecimal(0)) <= 0)
+								return;
+							HongBaoV2 secondHongbao = new HongBaoV2();
+							secondHongbao.setUserInfo(boss);
+							secondHongbao.setUrank(boss.getRank());
+							secondHongbao.setParent(hongBao);
+							secondHongbao.setCreateTime(new Date());
+							secondHongbao.setType(HongBaoV2.TYPE_ERJI);
+							secondHongbao.setVersion(2);
+							secondHongbao.setState(hongBao.getState());
+							if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
+								secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(),
+										secondRate.divide(new BigDecimal(100))));
+								Calendar calendar = Calendar.getInstance();
+								calendar.setTime(commonOrder.getSettleTime());
+								calendar.add(Calendar.MONTH, 1);
+								secondHongbao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
+										calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
+										"yyyy-M-dd")));
+							} else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
+								secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(),
+										secondRate.divide(new BigDecimal(100))));
+							}
+							hongBaoV2Mapper.insertSelective(secondHongbao);
+
+							// 鐢ㄦ埛閫氱煡
+							if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) {
+								HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId());
+								tempHongBao.setUserInfo(secondHongbao.getUserInfo());
+								tempHongBao.setMoney(secondHongbao.getMoney());
+								CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
+								tempCommonOrder.setPayment(commonOrder.getPayment());
+								notificationMap.put(HongBaoV2.TYPE_ERJI,
+										new HongBaoOrder(tempCommonOrder, tempHongBao));
+							} else {
+								// 澧炲姞浠樻閲戦涓庤祫閲�
+								HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI);
+								tempHongBaoOrder.getCommonOrder().setPayment(
+										tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
+								tempHongBaoOrder.getHongBaoV2().setMoney(
+										tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney()));
+								notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder);
+							}
+						}
+					}
+				}
+			}
 		} else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
 			BigDecimal fanliRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
 			List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService

--
Gitblit v1.8.0