From 5396bf8f7e14a559f825e275579e0091a9d29e73 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 12 十一月 2019 16:01:43 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 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 3019d5f..9b91ba3 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
@@ -2256,9 +2256,103 @@
 		sendBackGiveCoupon(list);
 	}
 
+	
+	@Override
+	@RequestSerializableByKeyService(key = "#giveid")
+	@Transactional(rollbackFor = Exception.class)
+	public void sendBackByGiveId(Long giveid) {
+		if (giveid == null)
+			return;
+		
+		UserSystemCouponGiveRecord giveRecord = userSystemCouponGiveRecordService.selectByPrimaryKey(giveid);
+		if (giveRecord == null)
+			return;
+		
+		if (giveRecord.getState() != null && giveRecord.getState() != UserSystemCouponGiveRecord.STATE_INIT) 
+			return;
+		
+		// 鏇存柊璧犻�佽褰�
+		UserSystemCouponGiveRecord updateRecord = new UserSystemCouponGiveRecord();
+		updateRecord.setId(giveid);
+		updateRecord.setState(UserSystemCouponGiveRecord.STATE_OVERDUE);
+		userSystemCouponGiveRecordService.updateByPrimaryKeySelective(updateRecord);
+		
+		// 鍙d护澶辨晥
+		tokenRecordService.invalidByCoupon(giveid);
+
+		Long couponId = giveRecord.getCouponId();
+		if (couponId == null) 
+			return;
+		
+		UserSystemCoupon userCoupon = userSystemCouponMapper.selectByPrimaryKey(couponId);
+		if (userCoupon == null)
+			return;
+		
+		Integer state = userCoupon.getState();
+		if (state != UserSystemCoupon.STATE_IN_USE)
+			return;
+
+		Date now = new Date();
+		Date endTime = userCoupon.getEndTime();
+		if (endTime != null && endTime.getTime() < now.getTime()) {
+			List<UserSystemCoupon> list = new ArrayList<UserSystemCoupon>();
+			list.add(userCoupon);
+			updateCounponInvalid(list);
+			return;
+		}
+
+		// 閫�鍥炲埜
+		UserSystemCoupon userSystemCoupon = new UserSystemCoupon();
+		userSystemCoupon.setId(userCoupon.getId());
+		userSystemCoupon.setGive(false);
+		userSystemCoupon.setUseTime(null);
+		userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
+		userSystemCoupon.setUpdateTime(new Date());
+		userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
+
+		// 浣跨敤璁板綍
+		UserSystemCouponRecord useRecord = userSystemCouponRecordService.getNearByUserCouponId(couponId);
+		if (useRecord != null) {
+			UserSystemCouponRecord useRecordUpdate = new UserSystemCouponRecord();
+			useRecordUpdate.setId(useRecord.getId());
+			useRecordUpdate.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
+			useRecordUpdate.setUpdateTime(new Date());
+			userSystemCouponRecordService.updateByPrimaryKeySelective(useRecordUpdate);
+		}
+
+		SystemCoupon systemCoupon = userCoupon.getSystemCoupon();
+		if (systemCoupon != null)
+			systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
+
+		if (systemCoupon == null)
+			return;
+
+		// 閫�鍥炴秷鎭�
+		String couponName = systemCoupon.getName();
+		if (CouponTypeEnum.freeCouponGive == systemCoupon.getType()) {
+			couponName = "鍏嶅崟鍒�";
+		} else if (CouponTypeEnum.rebatePercentCoupon == systemCoupon.getType()) {
+			couponName = "濂栧姳鍒�";
+		}
+
+		String beiZhu = "璇峰埌鎴戠殑-绂忓埄涓績鏌ョ湅";
+		SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
+		MsgOtherGiveContentDTO msgOther = new MsgOtherGiveContentDTO();
+		msgOther.setType(MsgOtherGiveContentDTO.TYEP_COUPON);
+		msgOther.setTitle(couponName + "閫�鍥�");
+		msgOther.setGiveType("浣犺禒閫佺殑" + couponName + "鏈鎴愬姛棰嗗彇");
+		msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
+		msgOther.setReturnTime(sd.format(new Date()));
+		userOtherMsgNotificationService.tokenGiveMsg(giveRecord.getGiveUid(), beiZhu, msgOther);
+	}
+	
+	
 	@Override
 	public void sendBackGiveCoupon(List<UserSystemCouponGiveRecord> overdueList) {
 		for (UserSystemCouponGiveRecord record : overdueList) {
+			if (record.getState() != null && record.getState() != UserSystemCouponGiveRecord.STATE_INIT) 
+				continue;
+			
 			// 鏇存柊璧犻�佽褰�
 			UserSystemCouponGiveRecord updateRecord = new UserSystemCouponGiveRecord();
 			updateRecord.setId(record.getId());

--
Gitblit v1.8.0