From 788deca1b4a24f8a24e49c24f7d89975a1d74bbe Mon Sep 17 00:00:00 2001
From: admin <2780501319@qq.com>
Date: 星期日, 03 十一月 2019 23:31:25 +0800
Subject: [PATCH] 商城订单退款处理

---
 fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java |  171 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 156 insertions(+), 15 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java b/fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
index dcbe47b..4c17f81 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -1,6 +1,7 @@
 package com.yeshi.fanli.util;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -172,9 +173,9 @@
 			doJDOrderJob();// 浜笢璁㈠崟澶勭悊
 			doPDDOrderJob();// 鎷煎澶氳鍗曞鐞�
 			doImportantTaoBaoGoodsUpdateJob();// 娣樺疂閲嶈鍟嗗搧鐨勪俊鎭洿鏂�
-			// doHongBaoRecieveIntegralGetJob();// 杩斿埄鍒拌处锛岄噾甯佸鍔�
+			doHongBaoRecieveIntegralGetJob();// 杩斿埄鍒拌处锛岄噾甯佸鍔�
 			// doPlaceOrderIntegralJob();// 涓嬪崟璧犻�侀噾甯佷换鍔�
-			doDouYinDeviceActiveJob();// 鎶栭煶璁惧婵�娲诲箍鍛婄洃娴�
+			// doDouYinDeviceActiveJob();// 鎶栭煶璁惧婵�娲诲箍鍛婄洃娴�
 		}
 	}
 
@@ -721,7 +722,6 @@
 					}
 				}
 			});
-
 	}
 
 	/**
@@ -743,20 +743,146 @@
 								HongBaoV2 hongBaoV2 = hongBaoV2Service.selectByPrimaryKey(hongBaoId);
 								if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU
 										&& hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) {
+									// 鍒拌处閫侀噾甯�
+									fanliGetIntegral(hongBaoV2);
+									HongBaoRecieveCMQManager.getInstance()
+											.deleteQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, key);
+									
+									//杩斿埄涓嶈冻0.01鍏冮�侀噾甯�
 									if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 鑷喘
-										integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId());
+										// 鍒ゆ柇鏄惁涓鸿鐢ㄦ埛鐨勯绗旂孩鍖�
+										List<Integer> typeList = new ArrayList<>();
+										typeList.add(HongBaoV2.TYPE_ZIGOU);
+										HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid(
+												typeList, hongBaoV2.getUserInfo().getId());
+										if (firstHongBao != null
+												&& firstHongBao.getId().longValue() == hongBaoV2.getId()) {// 鑷喘棣栧崟鍒拌处
+											// 鏌ヨ涓嬬骇绾㈠寘
+											BigDecimal firstLevelMoney = new BigDecimal(0);
+											BigDecimal secondLevelMoney = new BigDecimal(0);
+											// 鑾峰彇鏀瑰崟涓嬮潰鐨勭孩鍖�
+											List<HongBaoV2> hongBaoList = new ArrayList<>();
+											HongBaoOrder hongBaoOrder = hongBaoOrderService
+													.selectDetailByHongBaoId(hongBaoV2.getId());
+											if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 璁$畻鏀硅鍗曞彿涓嬮潰鐨勬墍鏈夎繑鍒╅噾棰�
+												CommonOrder commonOrder = hongBaoOrder.getCommonOrder();
+												List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId(
+														commonOrder.getSourceType(), commonOrder.getOrderNo());
+												for (CommonOrder co : list) {
+													HongBaoOrder hbo = hongBaoOrderService
+															.selectDetailByCommonOrderId(co.getId());
+													if (hbo != null && hbo.getHongBaoV2() != null)
+														hongBaoList.add(hbo.getHongBaoV2());
+												}
+											}
+
+											for (HongBaoV2 hb : hongBaoList) {
+												List<HongBaoV2> children = hongBaoV2Service
+														.listChildrenById(hb.getId());
+												if (children != null)
+													for (HongBaoV2 child : children)
+														if (child.getType() == HongBaoV2.TYPE_YIJI) {
+															firstLevelMoney = firstLevelMoney.add(child.getMoney());
+														} else if (child.getType() == HongBaoV2.TYPE_ERJI) {
+															secondLevelMoney = secondLevelMoney.add(child.getMoney());
+														}
+											}
+
+											// 鏌ヨ涓嬬骇鐨勭敓鏁堟椂闂�
+											ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState(
+													hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS);
+											if (threeSale != null && threeSale.getSucceedTime() != null && threeSale
+													.getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 閭�璇锋垚鍔熺殑鏃堕棿鏄惁鍦ㄤ笅鍗曠殑鏃堕棿涔嬪墠
+												// 鎴愬姛鏃堕棿瑕佸ぇ浜�20190910鏃ユ墠寮�濮嬮�侀噾甯�
+												if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901",
+														"yyyyMMdd")) {
+													if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 涓�绾ц繑鍒╁皬浜�0.01
+														integralTaskRecordService.firstRebateOrderRewardBoss(
+																threeSale.getBoss().getId(),
+																hongBaoV2.getUserInfo().getId(), null);
+														LogHelper.test("鑷喘-涓�绾х敤鎴�-" + threeSale.getBoss().getId()
+																+ "-hongBaoId:" + hongBaoV2.getId());
+													}
+												}
+											}
+											// 鏌ヨ涓嬩笅绾х敓鏁堟椂闂�
+											if (threeSale != null) {
+												threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState(
+														threeSale.getBoss().getId(), ThreeSale.STATE_SUCCESS);
+												if (threeSale != null && threeSale.getSucceedTime() != null && threeSale
+														.getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 閭�璇锋垚鍔熺殑鏃堕棿鏄惁鍦ㄤ笅鍗曠殑鏃堕棿涔嬪墠
+													// 鎴愬姛鏃堕棿瑕佸ぇ浜�20190910鏃ユ墠寮�濮嬮�侀噾甯�
+													if (threeSale.getSucceedTime() > TimeUtil
+															.convertToTimeTemp("20190901", "yyyyMMdd")) {
+														if (secondLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 浜岀骇杩斿埄灏忎簬0.01
+															integralTaskRecordService.firstRebateOrderRewardBossSuper(
+																	threeSale.getBoss().getId(),
+																	hongBaoV2.getUserInfo().getId(), null);
+															LogHelper.test("鑷喘-浜岀骇鐢ㄦ埛-" + threeSale.getBoss().getId()
+																	+ "-hongBaoId:" + hongBaoV2.getId());
+														}
+													}
+												}
+											}
+										}
 									} else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 鍒嗕韩璧�
-										integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId());
-									} else if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI
-											|| hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 涓�绾ч個璇疯禋
-										integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId());
-									} else if (hongBaoV2.getType() == HongBaoV2.TYPE_ERJI
-											|| hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 浜岀骇閭�璇疯禋
-										integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId());
+										// 鍒ゆ柇鏄惁涓鸿鐢ㄦ埛鐨勯绗旂孩鍖�
+										List<Integer> typeList = new ArrayList<>();
+										typeList.add(HongBaoV2.TYPE_SHARE_GOODS);
+										HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid(
+												typeList, hongBaoV2.getUserInfo().getId());
+										if (firstHongBao != null
+												&& firstHongBao.getId().longValue() == hongBaoV2.getId()) // 鍒嗕韩棣栫瑪鍒拌处
+										{
+
+											// 鏌ヨ涓嬬骇绾㈠寘
+											BigDecimal firstLevelMoney = new BigDecimal(0);
+											// 鑾峰彇鏀瑰崟涓嬮潰鐨勭孩鍖�
+											List<HongBaoV2> hongBaoList = new ArrayList<>();
+											HongBaoOrder hongBaoOrder = hongBaoOrderService
+													.selectDetailByHongBaoId(hongBaoV2.getId());
+											if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 璁$畻鏀硅鍗曞彿涓嬮潰鐨勬墍鏈夎繑鍒╅噾棰�
+												CommonOrder commonOrder = hongBaoOrder.getCommonOrder();
+												List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId(
+														commonOrder.getSourceType(), commonOrder.getOrderNo());
+												for (CommonOrder co : list) {
+													HongBaoOrder hbo = hongBaoOrderService
+															.selectDetailByCommonOrderId(co.getId());
+													if (hbo != null && hbo.getHongBaoV2() != null)
+														hongBaoList.add(hbo.getHongBaoV2());
+												}
+											}
+
+											for (HongBaoV2 hb : hongBaoList) {
+												List<HongBaoV2> children = hongBaoV2Service
+														.listChildrenById(hb.getId());
+												if (children != null)
+													for (HongBaoV2 child : children)
+														if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
+															firstLevelMoney = firstLevelMoney.add(child.getMoney());
+														}
+											}
+
+											ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState(
+													hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS);
+											if (threeSale != null && threeSale.getSucceedTime() != null && threeSale
+													.getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 閭�璇锋垚鍔熺殑鏃堕棿鏄惁鍦ㄤ笅鍗曠殑鏃堕棿涔嬪墠
+												// 鎴愬姛鏃堕棿瑕佸ぇ浜�20190910鏃ユ墠寮�濮嬮�侀噾甯�
+												if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901",
+														"yyyyMMdd")) {
+													if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 涓�绾ц繑鍒╁皬浜�0.01
+														integralTaskRecordService.firstSharerOrderRewardBoss(
+																threeSale.getBoss().getId(),
+																hongBaoV2.getUserInfo().getId(), null);
+														LogHelper.test("鍒嗕韩-涓�绾х敤鎴�-" + threeSale.getBoss().getId()
+																+ "-hongBaoId:" + hongBaoV2.getId());
+													}
+												}
+											}
+										}
 									}
 								}
-								HongBaoRecieveCMQManager.getInstance()
-										.deleteQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, key);
+
 							} catch (Exception e) {
 								try {
 									LogHelper.errorDetailInfo(e);
@@ -771,6 +897,21 @@
 				}
 			}
 		});
+	}
+
+	private void fanliGetIntegral(HongBaoV2 hongBaoV2) {
+		if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU
+				&& hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) {
+			if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 鑷喘璁㈠崟
+				integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId());
+			} else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 鍒嗕韩璁㈠崟
+				integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId());
+			} else if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 涓�绾ч個璇�
+				integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId());
+			} else if (hongBaoV2.getType() == HongBaoV2.TYPE_ERJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 浜岀骇閭�璇�
+				integralGetService.addInviteOrderLevelTwo(hongBaoV2.getUserInfo().getId());
+			}
+		}
 	}
 
 	private boolean isFirstValidOrder(String orderId, int sourceType, Long uid) {
@@ -928,7 +1069,7 @@
 							if (active.getType() == DouYinDeviceActiveQueueDTO.TYPE_AD) {// 鎶栭煶
 								DouYinClickEvent event = douYinClickEventService.selectByCallback(active.getCallback());
 								if (event != null) {
-									if (event.getOs() == 0) {
+									if (event.getOs() == 0 && !StringUtil.isNullOrEmpty(event.getUuid())) {
 										DeviceActive deviceActive = deviceActiveService
 												.getFirstActiveInfoByImei(event.getUuid());
 										if (deviceActive != null) {
@@ -951,7 +1092,7 @@
 								if (active.getPlatform() == 1) {
 									DeviceActive deviceActive = deviceActiveService
 											.getFirstActiveInfo(active.getDevice());
-									if (deviceActive != null && deviceActive.getImei() != null) {
+									if (deviceActive != null && !StringUtil.isNullOrEmpty(deviceActive.getImei())) {
 										DouYinClickEvent event = douYinClickEventService
 												.selectByUuid(deviceActive.getImei());
 										if (event != null) {// 鍥炶皟

--
Gitblit v1.8.0