From b59fef5c00b15fdfdfa9d4be26e5bf6b41c75458 Mon Sep 17 00:00:00 2001
From: admin <2780501319@qq.com>
Date: 星期日, 23 二月 2020 00:16:52 +0800
Subject: [PATCH] 2.0.7相关服务端功能添加

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java
index 5e942ae..3f56d12 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java
@@ -14,16 +14,19 @@
 import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
 import com.yeshi.fanli.entity.bus.user.UserLotteryRecord;
 import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
 import com.yeshi.fanli.entity.system.SystemCoupon;
 import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
 import com.yeshi.fanli.exception.user.UserInfoExtraException;
 import com.yeshi.fanli.exception.user.UserLotteryRecordException;
 import com.yeshi.fanli.exception.user.UserSystemCouponException;
+import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.config.SystemCouponService;
 import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
 import com.yeshi.fanli.service.inter.user.UserLotteryRecordService;
 import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
+import com.yeshi.fanli.util.StringUtil;
 
 import net.sf.json.JSONObject;
 
@@ -92,6 +95,8 @@
 			record.setUid(uid);
 			record.setType(type);
 			record.setCount(num);
+		} else {
+			record.setCount(num);
 		}
 		return record;
 	}
@@ -124,7 +129,7 @@
 		}
 		
 		// 鎶藉瑙勫垯
-		String lotteryRule = configService.get("lottery_rule_newbies");
+		String lotteryRule = configService.get(ConfigKeyEnum.lotteryRuleNewbies.getKey());
 					
 		JSONObject data = new JSONObject();
 		data.put("count", count);
@@ -164,14 +169,15 @@
 			throw new UserLotteryRecordException(2, "鎶藉娆℃暟涓嶈冻");
 		} 
 		
+		String prize = null;
+		String couponType = null;
 		// 鏂颁汉鎶藉 -宸叉娊涓鍝�
 		List<UserSystemCoupon> list = userSystemCouponService.getUserCouponBySource(uid, UserSystemCoupon.SOURCE_NEWBIES);
-	
-		String prize = null;
+		
 		if (list == null || list.size() == 0) {
 			prize = getLotteryPrizeNewbies(count, 0, null);
 		} else if (list.size() == 1) {
-			String couponType = null;
+			
 			UserSystemCoupon userSystemCoupon = list.get(0);
 			SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
 			if (systemCoupon != null) {
@@ -186,9 +192,12 @@
 		
 		if (prize == null || prize.trim().length() == 0) {
 			prize = "NoPrize";
+		} else if (prize.equals(couponType)) {
+			// 宸插瓨鍦ㄦ鍒�
+			prize = "NoPrize";
 		} else {
 			try {
-				userSystemCouponService.insertUserCoupon(uid, prize, UserSystemCoupon.SOURCE_NEWBIES);
+				userSystemCouponService.insertUserCoupon(uid, prize, UserSystemCoupon.SOURCE_NEWBIES, null,true);
 			} catch (UserSystemCouponException e) {
 				e.printStackTrace();
 			} catch (Exception e) {
@@ -281,7 +290,7 @@
 		}
 		
 		// 鎶藉瑙勫垯
-		String lotteryRule = configService.get("lottery_rule_daily_rebate");
+		String lotteryRule = configService.get(ConfigKeyEnum.lotteryRuleDailyRebate.getKey());
 					
 		JSONObject data = new JSONObject();
 		data.put("count", count);
@@ -307,13 +316,14 @@
 			throw new UserLotteryRecordException(2,  "鎶藉娆℃暟涓嶈冻");
 		} 
 		
-		String prize = "";
+		String prize = null;
 		// 浠婃棩澶╁ぉ鎶藉-宸叉娊涓嫢鏈夊埜鏁伴噺
 		int todayHas = userSystemCouponService.countTodatyUserCouponBySource(uid, UserSystemCoupon.SOURCE_DAILY_REBATE);
 		
 		if (todayHas == 0) {
 			// 鎶藉
 			prize = getLotteryPrizeDaily(count);
+			LogHelper.test(uid + "涓缁撴灉锛�" + prize);
 			try {
 				int num = 0;
 				if ("rebateCoupon".equals(prize)) {
@@ -321,8 +331,11 @@
 				} else if ("doubleCoupon".equals(prize)) {
 					num = 2;
 				} 
+				
 				// 鎻掑叆濂栧姳鍒�
-				userSystemCouponService.randomRewardCoupon(num, uid, UserSystemCoupon.SOURCE_DAILY_REBATE);
+				if (num > 0) {
+					userSystemCouponService.randomRewardCoupon(num, uid, UserSystemCoupon.SOURCE_DAILY_REBATE);
+				}
 				
 			} catch (UserSystemCouponException e) {
 				throw new UserLotteryRecordException(1, "鎶藉澶辫触");
@@ -339,9 +352,11 @@
 		updateRecord.setUpdateTime(new Date());
 		userLotteryRecordMapper.updateByPrimaryKeySelective(updateRecord);
 		
-		if (prize == null || prize.trim().length() == 0) {
+		LogHelper.test(uid + "杩斿洖H5涓缁撴灉锛�" + prize);
+		if (StringUtil.isNullOrEmpty(prize)) {
 			prize = "NoPrize";
 		}
+		LogHelper.test(uid + "杩斿洖H5涓缁撴灉澶勭悊绌哄�硷細" + prize);
 		
 		Map<String,Object> map = new HashMap<String, Object>();
 		map.put("count", count);
@@ -363,7 +378,7 @@
 		String rebateCoupon = "rebateCoupon"; // 涓�寮犲鍔卞埜
 		String doubleCoupon = "doubleCoupon"; // 涓ゅ紶濂栧姳鍒�
 		
-		if (count== 1) {
+		if (count == 1) {
 			// 鍓╀綑鏈�鍚庝竴娆″繀涓�
 			long result = (1 + Math.round(Math.random() * (9)));
 			if (result <= 7) {
@@ -373,7 +388,7 @@
 			}
 		} else {
 			long result = (1 + Math.round(Math.random() * (9)));
-			if (result <= 2) {
+			if (result <= 3) {
 				prize = rebateCoupon;
 			} else if (result <= 5) {
 				prize = doubleCoupon; 

--
Gitblit v1.8.0