From 0d9ac58dc11f54351e5e18dba8e950717d78019f Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 09 九月 2019 14:55:24 +0800
Subject: [PATCH] 搜索发现

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java
index 38b279d..ed45539 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java
@@ -16,6 +16,7 @@
 import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
 import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
 import com.yeshi.fanli.entity.integral.CodePublishRecord;
+import com.yeshi.fanli.entity.integral.IntegralDetail;
 import com.yeshi.fanli.entity.integral.IntegralExchange;
 import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
 import com.yeshi.fanli.entity.money.UserMoneyDetail;
@@ -24,6 +25,7 @@
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
 import com.yeshi.fanli.service.inter.integral.CodePublishRecordService;
+import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
 import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
 import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
 import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService;
@@ -80,6 +82,8 @@
 	@Resource
 	private MsgInviteDetailService msgInviteDetailService;
 	
+	@Resource
+	private IntegralDetailService integralDetailService;
 	
 
 	@Override
@@ -108,6 +112,11 @@
 		IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
 		if (exchange == null)
 			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+		
+		Integer state = exchange.getState();
+		if (state == null || state != 1)
+			throw new IntegralExchangeException(1, "鍏戞崲娲诲姩鏈紑鍚�");
+		
 		
 		Integer goldCoin = exchange.getGoldCoin();
 		
@@ -186,9 +195,12 @@
 		if (exchange == null)
 			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
 
-		ExchangeTypeEnum type = exchange.getType();
+		Integer state = exchange.getState();
+		if (state == null || state != 1)
+			throw new IntegralExchangeException(1, "鍏戞崲娲诲姩鏈紑鍚�");
 		
 		long exchangeCount = 0;
+		ExchangeTypeEnum type = exchange.getType();
 		if (ExchangeTypeEnum.freeCouponBuy == type) {
 			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, null);
 			if (exchangeCount >= 1) {
@@ -212,33 +224,45 @@
 		}
 		
 		String thing = "";
+		String thingNum = "";
 		int couponNews = 0;
+		boolean once = false; // 鍏戞崲涓�娆℃槸鍚︽秷澶�
 		try {
 			if (ExchangeTypeEnum.freeCouponBuy == type) {
 				thing = "鑷喘鍏嶅崟鍒�";
+				thingNum = "1寮�";
 				userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
-				
+				once = true; 
 				couponNews = 1;
 			} else if (ExchangeTypeEnum.freeCouponGive == type) {
 				thing = "璧犻�佸厤鍗曞埜";
+				thingNum = "1寮�";
 				userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
 				couponNews = 1;
 			} else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
-				thing = "濂栧姳鍏嶅崟鍒�";
+				thing = "杩斿埄濂栧姳鍒�";
+				thingNum = "1寮�";
 				String percent = configService.get("exchange_rebate_percent");
 				userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, new BigDecimal(percent));
 				couponNews = 1;
 			} else if (ExchangeTypeEnum.inviteCodePublish == type) {
 				thing = "閭�璇风爜鍙戝竷鍗�";
+				thingNum = "3澶�";
 				if(codePublishRecordService.countValidRecord(uid) > 0)
 					throw new IntegralExchangeException(1, "涓夊ぉ涔嬪唴涓嶅彲閲嶅鍏戞崲");
 				codePublishRecordService.publishInviteCode(uid);
+				
+				exchange.setNeedJump(true);
+				exchange.setBtnName("鍘绘煡鐪�");
 			} else if (ExchangeTypeEnum.taoLiJin == type) {
 				thing = "鎺ㄥ箍绾㈠寘";
+				thingNum = exchange.getAmount() + "鍏�";
 				userTaoLiJinOriginService.exchangeMoney(uid, exchange.getAmount());
 			} else if (ExchangeTypeEnum.cash == type) {
 				thing = "鐜伴噾绾㈠寘";
 				BigDecimal money = exchange.getAmount();
+				thingNum = money + "鍏�";
+				
 				// 1銆佹彃鍏ョ孩鍖呮暟鎹�
 				HongBaoV2 hongBaoV2 = new HongBaoV2();
 				hongBaoV2.setMoney(money);
@@ -283,6 +307,14 @@
 			// 娣诲姞鍏戞崲璁板綍
 			integralExchangeRecordService.addExchangeRecord(id, uid);
 			
+			// 鍔犲叆鏄庣粏
+			IntegralDetail detail = new IntegralDetail();
+			detail.setUid(uid);
+			detail.setTitle("閲戝竵鍏戞崲-" + thing + "-" + thingNum);
+			detail.setMoney(-goldCoin);
+			detail.setCreateTime(new Date());
+			integralDetailService.insertSelective(detail);
+			
 			// 娑堟伅 
 			final String things = thing;
 			executor.execute(new Runnable() {
@@ -296,6 +328,9 @@
 					userOtherMsgNotificationService.exchangeMsg(uid, "", msgOther);
 				}
 			});
+			
+			if (once) // 鍏戞崲涔嬪悗娑堝け
+				exchange = null;
 			
 			return exchange;
 		} catch (Exception e) {
@@ -347,7 +382,7 @@
 	
 	
 	@Override
-	public void exchangeInviteCode(Long uid, Long id) throws IntegralExchangeException {
+	public String exchangeInviteCode(Long uid, Long id) throws IntegralExchangeException {
 		if (uid == null || uid <= 0)
 			throw new IntegralExchangeException(1, "鐢ㄦ埛鏈櫥褰�");
 
@@ -381,7 +416,6 @@
 				throw new IntegralExchangeException(1, "鍏戞崲澶辫触锛岃鐢ㄦ埛閭�璇风爜涓嶅瓨鍦�");
 			
 			String inviteCode = inviteExtra.getInviteCode();
-			userInfoExtraService.activateInviteCode(uid, inviteExtra.getInviteCode());
 			
 			// 鍓╀綑閲戝竵
 			int surplus = goldCoinHas.intValue() - goldCoin.intValue();
@@ -392,7 +426,14 @@
 			extraUpdate.setGoldCoin(surplus);
 			userInfoExtraService.saveUserInfoExtra(extraUpdate);
 			
-			
+			// 鍔犲叆鏄庣粏
+			IntegralDetail detail = new IntegralDetail();
+			detail.setUid(uid);
+			detail.setTitle("閲戝竵鍏戞崲-閭�璇风爜婵�娲诲崱-1缁�");
+			detail.setMoney(-goldCoin);
+			detail.setCreateTime(new Date());
+			integralDetailService.insertSelective(detail);
+						
 			// 娣诲姞鍏戞崲璁板綍
 			integralExchangeRecordService.addExchangeRecord(id, uid);
 			
@@ -415,11 +456,11 @@
 					userOtherMsgNotificationService.exchangeMsg(uid, beizu, msgOther);
 				}
 			});
+			
+			return inviteCode;
 		} catch (Exception e) {
 			LogHelper.errorDetailInfo(e);
 			throw new IntegralExchangeException(1, "鍏戞崲澶辫触");
 		}
-		
-		
 	}
 }

--
Gitblit v1.8.0