From 374fa38b5e4c17c079e027e9987e966f30a5cd36 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 05 一月 2019 12:13:46 +0800
Subject: [PATCH] 新版订单统计,返利,到账修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java |  211 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 151 insertions(+), 60 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
index f4dce2c..e9c79ea 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -19,12 +19,14 @@
 import com.yeshi.fanli.dao.mybatis.AccountDetailsMapper;
 import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
 import com.yeshi.fanli.dao.mybatis.HongBaoManageMapper;
+import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
 import com.yeshi.fanli.dao.mybatis.MoneyRecordMapper;
 import com.yeshi.fanli.dao.mybatis.PidOrderMapper;
 import com.yeshi.fanli.dao.mybatis.ThreeSaleGiftMapper;
 import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
 import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
 import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
+import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
 import com.yeshi.fanli.dao.mybatis.order.OrderItemMapper;
 import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
 import com.yeshi.fanli.dao.mybatis.share.PidUserMapper;
@@ -39,6 +41,7 @@
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.money.UserMoneyDetail;
 import com.yeshi.fanli.entity.order.CommonOrder;
+import com.yeshi.fanli.entity.order.HongBaoOrder;
 import com.yeshi.fanli.entity.taobao.PidOrder;
 import com.yeshi.fanli.entity.taobao.PidUser;
 import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
@@ -74,7 +77,6 @@
 import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.factory.AccountDetailsFactory;
 import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
-import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
 
 @Service
 public class OrderProcessServiceImpl implements OrderProcessService {
@@ -156,6 +158,9 @@
 
 	@Resource
 	private UserMoneyDetailMapper userMoneyDetailMapper;
+
+	@Resource
+	private HongBaoV2Mapper hongBaoV2Mapper;
 
 	@Override
 	public void processOrder(Map<String, List<TaoBaoOrder>> orders) {
@@ -302,7 +307,7 @@
 	@Override
 	public void fanli() {
 		// 鑾峰彇涓荤孩鍖�
-		List<HongBao> hongBaoList = hongBaoMapper.selectCanBalanceHongBaoByType(HongBao.TYPE_TAOBAO, 100);
+		List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBao.TYPE_TAOBAO, 100);
 		//
 		// /**
 		// * 闇�瑕佸疄鏃舵洿鏂板緟杩斿埄鐨勮鍗�
@@ -338,16 +343,16 @@
 		/**
 		 * 寮�濮嬭繑鍒�
 		 */
-		for (HongBao hb : hongBaoList) {
+		for (HongBaoV2 hb : hongBaoList) {
 			//
-			if (hb.getState() == HongBao.STATE_SHIXIAO || hb.getState() == HongBao.STATE_YILINGQU)
+			if (hb.getState() == HongBaoV2.STATE_SHIXIAO || hb.getState() == HongBaoV2.STATE_YILINGQU)
 				continue;
 
-			if (hb.getPreGettime() == null || hb.getPreGettime() == 0
-					|| hb.getPreGettime() > System.currentTimeMillis())
+			if (hb.getPreGetTime() == null || hb.getPreGetTime().getTime() == 0
+					|| hb.getPreGetTime().getTime() > System.currentTimeMillis())
 				continue;
 			try {
-				CMQManager.getInstance().addFanLiMsg(hb);
+				CMQManager.getInstance().addFanLiMsgNew(hb);
 			} catch (Exception e) {
 				try {
 					LogHelper.errorDetailInfo(e);
@@ -571,6 +576,84 @@
 		}
 	}
 
+	@Resource
+	private HongBaoOrderMapper hongBaoOrderMapper;
+
+	@Override
+	@Transactional
+	public void fanli(HongBaoV2 hb) throws TaoBaoWeiQuanException {
+		// 鏌ヨ鏈�鏂扮殑绾㈠寘鏁版嵁
+		hb = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hb.getId());
+		// 鏌ヨ绾㈠寘鐩稿叧鑱旂殑璁㈠崟
+		HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb.getId());
+		if (hongBaoOrder == null) {
+			LogHelper.error("杩斿埄澶辫触:" + hb.getId());
+			return;
+		}
+		// 缁存潈涓殑涓嶈繑鍒�
+		List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
+				.selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "缁存潈鍒涘缓");
+		if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
+			return;
+
+		taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
+				.selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "绛夊緟澶勭悊");
+		if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
+			return;
+
+		long currentTimeMillis = System.currentTimeMillis();
+		if (hb.getState() != HongBao.STATE_SHIXIAO) {
+			// 璁剧疆涓哄凡杩斿埄
+			// 澶勭悊涓荤孩鍖�
+			if (hb.getState() != HongBaoV2.STATE_SHIXIAO && hb.getState() != HongBaoV2.STATE_YILINGQU
+					&& hb.getType() == HongBaoV2.TYPE_ZIGOU) {
+				// 濡傛灉绾㈠寘娌¤棰嗗彇
+				HongBaoV2 updateHongBao = new HongBaoV2();
+				updateHongBao.setId(hb.getId());
+				updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
+				updateHongBao.setGetTime(new Date(currentTimeMillis));
+				hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
+				userInfoMapper.addHongBaoByUid(hb.getUserInfo().getId(), hb.getMoney());
+
+				AccountDetails accountDetails = AccountDetailsFactory.create("+" + hb.getMoney(),
+						AccountDetailsFactory.FANLI, null, null, hb.getUserInfo());
+				accountDetailsMapper.insertSelective(accountDetails);
+
+				// 鎻掑叆鏂扮増璧勯噾鏄庣粏
+				try {
+					UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createFanLi(hb.getUserInfo().getId(),
+							hongBaoOrder.getCommonOrder().getOrderNo(), hongBaoOrder.getCommonOrder().getSourceType(),
+							hb.getId(), hb.getMoney());
+					userMoneyDetail.setId(accountDetails.getId());
+					userMoneyDetailMapper.insert(userMoneyDetail);
+				} catch (UserMoneyDetailException e1) {
+					try {
+						LogHelper.errorDetailInfo(e1);
+					} catch (Exception e2) {
+						e2.printStackTrace();
+					}
+				}
+
+				// 娣诲姞璧勯噾鏄庣粏涓庣孩鍖呯殑鏄犲皠鍏崇郴
+				accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hb.getId(), accountDetails.getId());
+
+				// 缁存潈鎵f锛�2018-08-05鍚庡紑濮嬪疄琛岋級
+				if (hongBaoOrder.getCommonOrder().getSettleTime() != null && hongBaoOrder.getCommonOrder()
+						.getSettleTime().getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
+					taoBaoWeiQuanDrawBackService.doWeiQuanFanli(hongBaoOrder.getCommonOrder().getOrderNo());
+				}
+
+				// 绔欏唴淇�+鎺ㄩ��
+				try {
+					userNotificationService.orderFanliRecieved(hb.getUserInfo().getId(),
+							hongBaoOrder.getCommonOrder().getOrderNo(), hb.getMoney());
+				} catch (Exception e) {
+				}
+
+			}
+		}
+	}
+
 	@Override
 	public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) {
 		if (orderList != null)
@@ -604,14 +687,10 @@
 	@Override
 	public void fanliInvaiteAndShare() {
 		// 鏌ュ嚭閭�璇疯禋涓庡垎浜禋璇ヨ繑鍒╃殑鐢ㄦ埛ID
-		List<Long> shareUids = pidOrderMapper.getUidCanBalanceList();
-		List<Long> inviteUids = hongBaoMapper.selectUidCanBalanceHongBaoByChildHongBao();
+		List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceShareAndInvite(1000);
 		Set<Long> uidSets = new HashSet<>();
-		if (shareUids != null)
-			for (Long uid : shareUids)
-				uidSets.add(uid);
-		if (inviteUids != null)
-			for (Long uid : inviteUids)
+		if (inviteAndShareUids != null)
+			for (Long uid : inviteAndShareUids)
 				uidSets.add(uid);
 		// 鏍规嵁鐢ㄦ埛ID
 		Iterator<Long> its = uidSets.iterator();
@@ -626,13 +705,23 @@
 		}
 	}
 
-	private HongBao filterWeiQuanINGHongBao(HongBao hongBao) {
+	private HongBaoV2 filterWeiQuanINGHongBao(HongBaoV2 hongBao) {
+
+		long hbId = hongBao.getId();
+		if (hongBao.getParent() != null) {
+			hbId = hongBao.getParent().getId();
+		}
+
+		HongBaoOrder hongbaoOrder = hongBaoOrderMapper.selectByHongBaoId(hbId);
+
+		if (hongbaoOrder == null)
+			return null;
 
 		List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
-				.selectListByOrderIdAndState(hongBao.getOrderId(), "缁存潈鍒涘缓");
+				.selectListByOrderIdAndState(hongbaoOrder.getCommonOrder().getOrderNo(), "缁存潈鍒涘缓");
 
 		List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList1 = taoBaoWeiQuanOrderMapper
-				.selectListByOrderIdAndState(hongBao.getOrderId(), "绛夊緟澶勭悊");
+				.selectListByOrderIdAndState(hongbaoOrder.getCommonOrder().getOrderNo(), "绛夊緟澶勭悊");
 		if ((taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
 				|| (taoBaoWeiQuanList1 != null && taoBaoWeiQuanList1.size() > 0)) {
 			return null;
@@ -647,40 +736,40 @@
 		 * 澶勭悊閭�璇疯禋璁㈠崟
 		 */
 		// 鏌ヨUID鐨勯個璇疯禋璁㈠崟
-		List<HongBao> hongBaoList = hongBaoMapper.selectCanBalanceHongBaoByChildHongBaoAndUid(uid);
+		List<Integer> types = new ArrayList<>();
+		types.add(HongBaoV2.TYPE_YIJI);
+		types.add(HongBaoV2.TYPE_ERJI);
+		List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 1000);
 
 		List<Long> hbIdList = new ArrayList<>();
 
 		BigDecimal invitemoney = new BigDecimal(0);
 		// 闇�瑕佸垽鏂��娆剧殑璁㈠崟鍙�
 		Set<String> drawBackOrders = new HashSet<String>();
-		for (HongBao hongBao : hongBaoList) {
+		for (HongBaoV2 hongBao : hongBaoList) {
 			hongBao = filterWeiQuanINGHongBao(hongBao);
 			if (hongBao == null)
 				continue;
 
-			hongBao = hongBaoMapper.selectByPrimaryKeyForUpdate(hongBao.getId());
-			if (hongBao.getState() == HongBao.STATE_BUKELINGQU || hongBao.getState() == HongBao.STATE_KELINGQU) {
+			hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
+			if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
 				invitemoney = invitemoney.add(hongBao.getMoney());
-				HongBao updateHongBao = new HongBao();
+				HongBaoV2 updateHongBao = new HongBaoV2();
 				updateHongBao.setId(hongBao.getId());
-				updateHongBao.setGetTime(System.currentTimeMillis());
-				updateHongBao.setState(HongBao.STATE_YILINGQU);
-				hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
+				updateHongBao.setGetTime(new Date());
+				updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
+				hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
 				// 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
 				hbIdList.add(hongBao.getId());
 				// 2018-08-05 杩囧悗鐨勮鍗曟墠澶勭悊缁存潈
-				Date balanceTime = null;
-				if (hongBao.getParent() != null)
-					balanceTime = hongBao.getParent().getBalanceTime();
-				else
-					balanceTime = hongBao.getBalanceTime();
+
+				HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId());
+
+				Date balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
 				if (balanceTime != null
 						&& balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
-					if (!StringUtil.isNullOrEmpty(hongBao.getOrderId()))
-						drawBackOrders.add(hongBao.getOrderId());
-					else if (hongBao.getParent() != null && !StringUtil.isNullOrEmpty(hongBao.getParent().getOrderId()))
-						drawBackOrders.add(hongBao.getParent().getOrderId());
+					if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
+						drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
 				}
 			}
 		}
@@ -689,33 +778,34 @@
 		 * 澶勭悊涓�绾т簩绾у垎浜禋(灞炰簬閭�璇疯禋绫诲瀷)
 		 */
 
-		List<HongBao> totalHongBaoList = new ArrayList<>();
+		List<HongBaoV2> totalHongBaoList = new ArrayList<>();
 		// 鏌ヨUID鐨勪簩绾ф垨鑰呬笁绾у垎浜禋璁㈠崟
 		// TODO 鏆傛椂鏌ヨ10000鏉℃暟鎹紝鍚庨潰鍐嶅仛鍒嗛〉
-		List<HongBao> hbList = hongBaoMapper.selectCanBalanceHongBaoByTypeAndUid(HongBao.TYPE_SHARE_YIJI, uid, 10000);
+		types.clear();
+		types.add(HongBaoV2.TYPE_SHARE_YIJI);
+		types.add(HongBaoV2.TYPE_SHARE_ERJI);
+		List<HongBaoV2> hbList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 10000);
 
 		if (hbList != null && hbList.size() > 0)
 			totalHongBaoList.addAll(hbList);
 
-		hbList = hongBaoMapper.selectCanBalanceHongBaoByTypeAndUid(HongBao.TYPE_SHARE_ERJI, uid, 10000);
-		if (hbList != null && hbList.size() > 0)
-			totalHongBaoList.addAll(hbList);
-
-		for (HongBao hb : totalHongBaoList) {
-			if (hb.getState() == HongBao.STATE_BUKELINGQU || hb.getState() == HongBao.STATE_KELINGQU) {
+		for (HongBaoV2 hb : totalHongBaoList) {
+			if (hb.getState() == HongBaoV2.STATE_BUKELINGQU || hb.getState() == HongBaoV2.STATE_KELINGQU) {
 				hb = filterWeiQuanINGHongBao(hb);
 				if (hb == null)
 					continue;
 				invitemoney = invitemoney.add(hb.getMoney());
-				HongBao updateHongBao = new HongBao();
+				HongBaoV2 updateHongBao = new HongBaoV2();
 				updateHongBao.setId(hb.getId());
-				updateHongBao.setGetTime(System.currentTimeMillis());
-				updateHongBao.setState(HongBao.STATE_YILINGQU);
-				hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
+				updateHongBao.setGetTime(new Date());
+				updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
+				hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
 				// 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
 				hbIdList.add(hb.getId());
-				if (!StringUtil.isNullOrEmpty(hb.getOrderId()))
-					drawBackOrders.add(hb.getOrderId());
+
+				HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb.getParent().getId());
+				if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
+					drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
 			}
 		}
 
@@ -765,30 +855,31 @@
 		 */
 		BigDecimal sharemoney = new BigDecimal(0);
 		// 鏌ヨUID鐨勫垎浜禋璁㈠崟
-		List<PidOrder> pidOrderList = pidOrderMapper.getCanBalanceListByUid(uid);
-		for (PidOrder pidOrder : pidOrderList) {
-			HongBao hongBao = hongBaoMapper.selectByPrimaryKeyForUpdate(pidOrder.getHongBao().getId());
+		types.clear();
+		types.add(HongBaoV2.TYPE_SHARE_GOODS);
+		List<HongBaoV2> hongBaoShareList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 10000);
+		for (HongBaoV2 hongBao : hongBaoShareList) {
+			hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
 			hongBao = filterWeiQuanINGHongBao(hongBao);
 			if (hongBao == null)
 				continue;
-			if (hongBao.getState() == HongBao.STATE_BUKELINGQU || hongBao.getState() == HongBao.STATE_KELINGQU) {
+			if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
 				sharemoney = sharemoney.add(hongBao.getMoney());
-				HongBao updateHongBao = new HongBao();
+				HongBaoV2 updateHongBao = new HongBaoV2();
 				updateHongBao.setId(hongBao.getId());
-				updateHongBao.setGetTime(System.currentTimeMillis());
+				updateHongBao.setGetTime(new Date());
 				updateHongBao.setState(HongBao.STATE_YILINGQU);
-				hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
+				hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
 				// 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
 				hbIdList.add(hongBao.getId());
 				// 2018-08-05 杩囧悗鐨勮鍗曟墠澶勭悊缁存潈
 				Date balanceTime = null;
-				if (hongBao.getParent() != null)
-					balanceTime = hongBao.getParent().getBalanceTime();
-				else
-					balanceTime = hongBao.getBalanceTime();
+				HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
+				if (hongBaoOrder != null)
+					balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
 				if (balanceTime != null
 						&& balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
-					drawBackOrders.add(pidOrder.getOrderId());
+					drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
 				}
 			}
 		}

--
Gitblit v1.8.0