From cd637932a970e7935b17d41568fe89c92775bccc Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 06 十二月 2019 17:18:27 +0800
Subject: [PATCH] 双12活动添加,邀请码发布修改,爬单新规则添加

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
index d27acd5..2b816ec 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
@@ -18,7 +18,6 @@
 import com.yeshi.fanli.entity.common.AdminUser;
 import com.yeshi.fanli.entity.money.UserMoneyDetail;
 import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum;
-import com.yeshi.fanli.entity.redpack.RedPackBalance;
 import com.yeshi.fanli.entity.redpack.RedPackDetail;
 import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum;
 import com.yeshi.fanli.entity.redpack.RedPackExchange;
@@ -30,6 +29,7 @@
 import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
 import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
 import com.yeshi.fanli.service.inter.redpack.RedPackExchangeService;
+import com.yeshi.fanli.service.inter.redpack.RedPackForbidService;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
@@ -54,6 +54,9 @@
 	
 	@Resource
 	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
+	
+	@Resource
+	private RedPackForbidService redPackForbidService;
 	
 	
 	@Override
@@ -87,31 +90,32 @@
 	public void exchangeCash(Long uid, BigDecimal amount) throws RedPackExchangeException {
 		if (uid == null || amount == null)
 			throw new RedPackExchangeException(1, "鍙傛暟涓嶆纭�");
-
+		
+		if(redPackForbidService.verifyForbid(uid))
+			throw new RedPackExchangeException(1, "绾㈠寘鍔熻兘宸茶灏佺");
+		
 		String extractBanlenMin = redPackConfigService.getValueByKey("extract_banlen_min");
 	
-		RedPackBalance balance = redPackBalanceService.selectByPrimaryKey(uid);
-		if (balance == null)
+		BigDecimal balance =  redPackBalanceService.getBalance(uid);
+		if (balance == null || balance.compareTo(new BigDecimal(extractBanlenMin)) < 0)
 			throw new RedPackExchangeException(1, "浣欓涓嶈冻" + extractBanlenMin + "鍏�");
 		
-		if (balance.getState() != null && balance.getState() == RedPackBalance.STATE_LOCKED) 
-			throw new RedPackExchangeException(1, "绾㈠寘宸插皝绂侊紝鎰熻阿浣跨敤");
-		
-		BigDecimal balanceMoney = balance.getMoney();
-		if (balanceMoney == null || balanceMoney.compareTo(new BigDecimal(extractBanlenMin)) < 0)
-			throw new RedPackExchangeException(1, "浣欓涓嶈冻" + extractBanlenMin + "鍏�");
-		
-		if (balanceMoney.compareTo(amount) < 0)
+		if (balance.compareTo(amount) < 0)
 			throw new RedPackExchangeException(1, "鎻愮幇浣欓涓嶈冻");
-		
 		
 		String moneyMin = redPackConfigService.getValueByKey("extract_money_min");
 		String moneyMax = redPackConfigService.getValueByKey("extract_money_max");
 		if (amount.compareTo(new BigDecimal(moneyMin)) < 0 || amount.compareTo(new BigDecimal(moneyMax)) > 0)
 			throw new RedPackExchangeException(1, "鎻愮幇閲戦鑷冲皯" + moneyMin + "鍏冭嚦澶�" + moneyMax + "鍏�");
 		
-		Date nowDate = new Date();
 		
+		long countToday = redPackExchangeMapper.countTodayByUid(uid);
+		String extractDayMax = redPackConfigService.getValueByKey("extract_day_max");
+		if (!StringUtil.isNullOrEmpty(extractDayMax) && countToday >= Long.parseLong(extractDayMax)) 
+			throw new RedPackExchangeException(1, "浠婃棩绾㈠寘鎻愮幇娆℃暟瓒呴檺");
+		
+		
+		Date nowDate = new Date();
 		// 鎻愮幇鐢宠
 		RedPackExchange exchange = new RedPackExchange();
 		exchange.setUid(uid);
@@ -139,6 +143,9 @@
 		if (RedPackExchange.STATE_INIT != record.getState())
 			throw new RedPackExchangeException(1,"璇ョ敵璇峰凡琚鐞嗭紝璇峰埛鏂�");
 
+		if(redPackForbidService.verifyForbid(record.getUid()))
+			throw new RedPackExchangeException(1, "绾㈠寘鍔熻兘宸茶灏佺");
+		
 		Date nowDate = new Date();
 		record.setAuditId(admin.getId());
 		record.setAuditTime(nowDate);
@@ -171,6 +178,7 @@
 			throw new RedPackExchangeException(1,"鏇存柊鎻愮幇鏄庣粏鍑洪敊");
 		}
 		
+	
 		//娑堟伅
 		SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
 		String beizu = "绾㈠寘鎻愮幇鎴愬姛鍚庤鍒扳�滄垜鐨�-璐︽埛浣欓鈥濅腑鏌ョ湅";
@@ -181,6 +189,7 @@
 		dto.setMoney("楼" + record.getMoney().setScale(2));		
 		dto.setBalance("楼" + redPackBalanceService.getBalance(record.getUid()));
 		userMoneyMsgNotificationService.redPackMsg(record.getUid(), MsgTypeMoneyTypeEnum.redPackExchangePass, new Gson().toJson(dto), beizu);
+		
 	}
 	
 

--
Gitblit v1.8.0