From d085ca89e39b4cda025a9a53d3797fbe8b242ae7 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 21 十月 2019 17:11:30 +0800
Subject: [PATCH] 订单补偿 +  奖励券使用倒计时

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java |   68 +++++++++++++++++++++++----------
 1 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
index ab7f52a..eec79be 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -16,11 +16,12 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.DateUtil;
+import org.yeshi.utils.entity.DateInfo;
 
 import com.yeshi.fanli.dao.mybatis.user.UserSystemCouponMapper;
 import com.yeshi.fanli.dto.msg.MsgOtherCouponActivateDTO;
 import com.yeshi.fanli.dto.msg.MsgOtherGiveContentDTO;
-import com.yeshi.fanli.dto.msg.MsgOtherSystemGiveDTO;
+import com.yeshi.fanli.entity.accept.AcceptData;
 import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
 import com.yeshi.fanli.entity.bus.user.HongBaoV2;
 import com.yeshi.fanli.entity.bus.user.Order;
@@ -66,6 +67,7 @@
 import com.yeshi.fanli.util.RedisManager;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TokenUtil;
+import com.yeshi.fanli.util.VersionUtil;
 import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
 import com.yeshi.fanli.util.factory.msg.MsgOtherSystemGiveDTOFactory;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
@@ -764,55 +766,79 @@
 
 	@Transactional
 	@Override
-	public void useOrderCoupon(Long uid, Long id, String orderNo, Integer sourceType)
+	public void useOrderCoupon(Long uid, Long id, String orderNo, Integer sourceType, AcceptData acceptData)
 			throws UserSystemCouponException, Exception {
-
-		if (id == null) {
+		if (id == null)
 			throw new UserSystemCouponException(1, "鍒竔d涓嶅瓨鍦�");
-		}
 
-		if (sourceType == null) {
+		if (sourceType == null)
 			sourceType = Constant.SOURCE_TYPE_TAOBAO;
-		}
 
 		// 鐢ㄦ埛鍒�
 		UserSystemCoupon userSystemCoupon = selectByPrimaryKey(id);
-		if (userSystemCoupon == null) {
+		if (userSystemCoupon == null)
 			throw new UserSystemCouponException(1, "鍒镐俊鎭笉瀛樺湪");
-		}
 
-		if (userSystemCoupon.getUid().longValue() != uid) {
+		if (userSystemCoupon.getUid().longValue() != uid)
 			throw new UserSystemCouponException(1, "涓嶅睘浜庤鐢ㄦ埛鐨勫埜");
-		}
 
 		Integer state = userSystemCoupon.getState();
 		Integer stateActivated = userSystemCoupon.getStateActivated();
-		if (UserSystemCoupon.STATE_CAN_USE != state || 1 != stateActivated) {
+		if (UserSystemCoupon.STATE_CAN_USE != state || 1 != stateActivated)
 			throw new UserSystemCouponException(1, "璇ュ埜涓嶈兘琚娇鐢�");
-		}
 
 		// 绯荤粺鍒镐俊鎭�
 		SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
 		if (systemCoupon != null && systemCoupon.getId() != null) {
 			systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
-			if (systemCoupon == null) {
+			if (systemCoupon == null)
 				throw new UserSystemCouponException(1, "鍒稿凡涓嶅瓨鍦�");
-			}
 		}
-
-		if (systemCoupon.getType() != CouponTypeEnum.rebatePercentCoupon) {
+		
+		if (systemCoupon.getType() != CouponTypeEnum.rebatePercentCoupon)
 			throw new UserSystemCouponException(1, "鍒哥被鍨嬩笉鍖归厤");
-		}
 
-		if (orderNo == null || orderNo.trim().length() == 0) {
+		if (orderNo == null || orderNo.trim().length() == 0)
 			throw new UserSystemCouponException(1, "璁㈠崟鍙蜂笉瀛樺湪");
-		}
 
 		// 璁㈠崟
 		CommonOrderVO orderVO = commonOrderService.getCommonOrderByOrderNo(uid, orderNo, CommonOrder.STATE_JS,
 				sourceType);
-		if (orderVO == null) {
+		if (orderVO == null)
 			throw new UserSystemCouponException(1, "璁㈠崟淇℃伅鑾峰彇澶辫触");
+		
+		// 鐗堟湰鍖哄垎锛�2.0.2
+		if (VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(), acceptData.getVersion())) {
+			Date thirdCreateTime = orderVO.getThirdCreateTime();
+			if (thirdCreateTime != null) {
+				long downOrderTime = thirdCreateTime.getTime();
+				long limitDate = Long.parseLong("1573315200000"); // TODO 鏃ユ湡寰呯‘瀹�2019-11-10
+				if (downOrderTime > limitDate) {
+					Date endDay = DateUtil.plusDayDate(4, thirdCreateTime);
+					long currentTime = java.lang.System.currentTimeMillis();
+					if (endDay.getTime() > currentTime) {
+						boolean valid = false;
+						DateInfo dateInfo = DateUtil.dateDiff3(currentTime, endDay.getTime());
+						if (dateInfo != null) {
+							if (dateInfo.getDay() > 0) 
+								valid = true;
+
+							if (!valid && dateInfo.getHour() > 0)
+								valid = true;
+							
+
+							if (!valid && dateInfo.getMinute() > 0) 
+								valid = true;
+							
+							if (!valid && dateInfo.getSecond() >= 0)
+								valid = true;
+						}
+						
+						if (!valid) 
+							throw new UserSystemCouponException(1, "璇ヨ鍗曞凡涓嶈兘浣跨敤浣跨敤濂栧姳鍒革紝璇︽儏璇峰挩璇㈠鏈�");
+					}
+				}
+			}
 		}
 
 		BigDecimal hongBao = orderVO.getHongBao();

--
Gitblit v1.8.0