From 616608ec1005bff373bc380ecc3bf02a1063497c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 19 八月 2019 17:42:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 51 insertions(+), 8 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 70fc695..46b9769 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
@@ -198,8 +198,8 @@
 		}
 
 		SystemCoupon coupon = null;
-		if (couponType.equals(CouponTypeEnum.welfareFreeCoupon.name())) {
-			// 绂忓埄鍏嶅崟鍒�
+		if (couponType.equals(CouponTypeEnum.welfareFreeCoupon.name()) || couponType.equals(CouponTypeEnum.freeCoupon.name())) {
+			// 鍏嶅崟鍒�
 			coupon = systemCouponService.getCouponByType(couponType);
 		} else if (couponType.equals(CouponTypeEnum.rebatePercentCoupon.name())) {
 			// 闅忔満濂栧姳鍒�
@@ -219,6 +219,8 @@
 			if (countSuccess == 0) {
 				stateActivated = 0;
 			}
+		} else if (coupon.getType() == CouponTypeEnum.freeCoupon) {
+			stateActivated = 0;
 		}
 
 		// 缁撴潫鏃ユ湡
@@ -1892,12 +1894,16 @@
 					long num = 10000 + (long) (Math.random() * 10000);
 					token = UserUtil.getInviteCode(num);
 					
+					String endDay = DateUtil.plusDay(Constant.TOKEN_DAYS - 1,nowDate);
+					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+					Date endTime = format.parse(endDay);
+					
 					TokenRecord tokenRecord = new TokenRecord();
 					tokenRecord.setUid(uid);
 					tokenRecord.setIdentify(id+"");
 					tokenRecord.setType(tokenTypeEnum);
 					tokenRecord.setStartTime(nowDate);
-					tokenRecord.setEndTime(DateUtil.plusDayDate(3, nowDate));
+					tokenRecord.setEndTime(endTime);
 					tokenRecord.setToken(token);
 					tokenRecord.setState(0);
 					tokenRecordService.insertSelective(tokenRecord);
@@ -1915,16 +1921,30 @@
 				throw new UserSystemCouponException(1, "鍙d护鐢熸垚澶辫触");
 			
 			// 鎻掑叆璧犻�佽褰�
-			UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
-			giveRecord.setCouponId(id);
-			giveRecord.setGiveUid(uid);
-			giveRecord.setGiveTime(nowDate);
-			userSystemCouponGiveRecordService.insertSelective(giveRecord);
+			try {
+				String endDay = DateUtil.plusDay(Constant.GIVE_DAYS - 1, new Date());
+				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+				Date endTime = format.parse(endDay);
+				
+				UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
+				giveRecord.setCouponId(id);
+				giveRecord.setGiveUid(uid);
+				giveRecord.setGiveTime(nowDate);
+				giveRecord.setEndTime(endTime);
+				userSystemCouponGiveRecordService.insertSelective(giveRecord);
+			} catch (Exception e) {
+				LogHelper.errorDetailInfo(e);
+				throw new UserSystemCouponException(1, "璧犻�佽褰曞垱寤哄け璐�");
+			}
 		}
 		
 		if(StringUtil.isNullOrEmpty(token))
 			throw new UserSystemCouponException(1, "鍙d护鐢熸垚澶辫触");
 
+		userSystemCoupon.setState(UserSystemCoupon.STATE_IN_USE);
+		userSystemCoupon.setGive(true);
+		userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
+		
 		String tips = "閫佺粰浣犱竴寮犺繑鍒╁鍔卞埜蹇幓棰嗗彇鍚э紝澶嶅埗鏈潯娑堟伅[&%s&]锛屾墦寮�[杩斿埄鍒竇App棰嗗彇锛屼娇鐢ㄥ悗鍙杩斿埄鍔犲�嶃�俓r\n" 
 				+"----------------------------\r\n" 
 				+ "涓嬭浇[杩斿埄鍒竇App閾炬帴:%s\r\n"
@@ -1935,4 +1955,27 @@
 		return tips;
 	}
 
+	
+	@Override
+	public void updateGiveRecord(Long uid, Long id, String couponType) {
+		Date date = new Date();
+		// 鏇存柊鍒哥姸鎬侊細宸蹭娇鐢�
+		UserSystemCoupon userCoupon = new UserSystemCoupon();
+		userCoupon.setId(id);
+		userCoupon.setState(UserSystemCoupon.STATE_END_USE);
+		userCoupon.setUseTime(date);
+		userCoupon.setUpdateTime(date);
+		userSystemCouponMapper.updateByPrimaryKeySelective(userCoupon);
+
+		// 鎻掑叆浣跨敤鍒歌褰�
+		UserSystemCouponRecord couponRecord = new UserSystemCouponRecord();
+		couponRecord.setState(UserSystemCouponRecord.STATE_SUCCESS);
+		couponRecord.setUserSystemCoupon(userCoupon);
+		couponRecord.setCouponType(couponType);
+		couponRecord.setCreateTime(date);
+		couponRecord.setUpdateTime(date);
+		userSystemCouponRecordService.insertSelective(couponRecord);
+	}
+	
+	
 }

--
Gitblit v1.8.0