From 10d34d0d711ba1e4674160efc59e874c22939560 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期五, 06 九月 2019 16:13:14 +0800
Subject: [PATCH] 首单奖励

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java |   98 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 82 insertions(+), 16 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
index 540e7a3..95ebd4d 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
@@ -9,6 +9,8 @@
 
 import javax.annotation.Resource;
 
+import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.DateUtil;
@@ -50,6 +52,7 @@
 	@Resource
 	private IntegralTaskService integralTaskService;
 
+	@Lazy
 	@Resource
 	private IntegralTaskClassService integralTaskClassService;
 	
@@ -368,55 +371,118 @@
 		return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
 	}
 	
-	/**
-	 * 琚個璇蜂汉涓嬩簡棣栧崟锛堢涓�绗旇繑鍒╄鍗曪級 鐩存帴缁欓個璇蜂汉涓�绗旈噾甯�
-	 * @param uid
-	 */
+	
+	@Async()
 	@Override
-	public void firstOrderRewardInviter(Long uid, String beizu) {
-		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
-		if (userInfoExtra == null) 
+	public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) {
+		if (uid == null || originUid == null)
 			return;
 		
 		String reward = configService.get("first_order_reward_boss");
 		if (StringUtil.isNullOrEmpty(reward)) 
 			return;
+		firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
+	}
+	
+	@Async()
+	@Override
+	public void firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
+		if (uid == null || originUid == null)
+			return;
+		
+		String reward = configService.get("first_order_reward_boss_super");
+		if (StringUtil.isNullOrEmpty(reward)) 
+			return;
+		firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu);
+	}
+	
+	
+	@Async()
+	@Override
+	public void firstShareOrderReward(Long uid, String beizu) {
+		if(uid == null)
+			return;
+		
+		String reward = configService.get("first_share_order_reward");
+		if (StringUtil.isNullOrEmpty(reward)) 
+			return;
+		firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
+	}
+	
+	
+	@Async()
+	@Override
+	public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
+		if (uid == null || originUid == null)
+			return;
+		
+		String reward = configService.get("first_share_order_reward_boss");
+		if (StringUtil.isNullOrEmpty(reward)) 
+			return;
+		firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
+	}
+	
+	
+	/**
+	 * 闃熷憳棣栧崟濂栧姳閲戝竵
+	 * @param uid
+	 * @param addGoldCoin
+	 * @param level 鎵�灞炲摢绾ч槦鍛�
+	 * @param beizu
+	 */
+	private void firstOrderReward(Long uid, Long originUid, Integer addGoldCoin, String level, String beizu) {
+		if (uid == null)
+		     return;
+		String uniqueKey = uid.toString();
+		if (originUid != null) 
+			uniqueKey = uniqueKey + "-" + originUid;
+		
+		// 鍒ゆ柇鏄惁宸查鍙�
+		IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
+		if (detailRecord != null)
+			return;
+		
+		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+		if (userInfoExtra == null) 
+			return;
 		
 		Integer goldCoin = userInfoExtra.getGoldCoin();
 		if (goldCoin == null)
 			goldCoin = 0;
-		
-		int addGoldCoin = Integer.parseInt(reward);
 		goldCoin = goldCoin + addGoldCoin;
 		
 		try {
-			// 澧炲姞閲戝竵
 			UserInfoExtra extra = new UserInfoExtra();
 			extra.setId(userInfoExtra.getId());
 			extra.setGoldCoin(goldCoin);
 			userInfoExtraService.saveUserInfoExtra(extra);
 		} catch (UserInfoExtraException e) {
-			e.printStackTrace();
+			LogHelper.errorDetailInfo(e);
 			return;
 		}
 
 		// 閲戝竵璇︽儏
 		IntegralDetail detail = new IntegralDetail();
-		detail.setTitle("闃熷憳棣栫瑪濂栧姳");
+		detail.setTitle("閲戝竵濂栧姳");
 		detail.setUid(uid);
 		detail.setMoney(addGoldCoin);
 		detail.setRemark(beizu);
+		detail.setUniqueKey(uniqueKey);
 		detail.setCreateTime(new Date());
 		integralDetailService.insertSelective(detail);
 		
 		// 娑堟伅
 		MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
 		msgOther.setTitle("閲戝竵濂栧姳");
-		msgOther.setSource("涓�绾ч槦鍛橀绗斾笅鍗曪紝绯荤粺濂栧姳閭�璇蜂汉閲戝竵");
 		msgOther.setNum(addGoldCoin + "閲戝竵");
 		msgOther.setTotal(goldCoin + "閲戝竵");
-		msgOther.setExplain("浠呬竴绾ч槦鍛橀绗斾笅鍗曞鍔�");
-		userOtherMsgNotificationService.firstOrderRewardMsg(uid, "璁㈠崟宸插埌璐﹀悗绯荤粺浼氳嚜鍔ㄥ鍔�", msgOther);
+		if (StringUtil.isNullOrEmpty(level)) {
+			msgOther.setSource("棣栫瑪鍒嗕韩璁㈠崟锛岀郴缁熷鍔遍噾甯� ");
+			msgOther.setExplain("棣栫瑪鍒嗕韩璁㈠崟寰楀埌鐨勫閲戜笉瓒�0.01鍏冩椂濂栧姳 ");
+		} else {
+			msgOther.setSource(level + "绾ч槦鍛橀娆′笅鍗曪紝绯荤粺濂栧姳閲戝竵 ");
+			msgOther.setExplain("浠呮柊閭�璇烽槦鍛橀涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 ");
+		}
+		userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
 	}
-	
 }

--
Gitblit v1.8.0