From 851e43f3d0a79154cb4dc3a55738a83a97797c2d Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 13 十一月 2019 10:04:34 +0800
Subject: [PATCH] 红包提现次数限制

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java |  115 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 61 insertions(+), 54 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java
index c17cb30..d16ce64 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java
@@ -14,6 +14,7 @@
 import com.yeshi.fanli.dao.mybatis.redpack.RedPackWinInviteMapper;
 import com.yeshi.fanli.dto.msg.MsgRedPackAddContentDTO;
 import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
+import com.yeshi.fanli.entity.bus.user.UserActiveLog;
 import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.order.CommonOrder;
@@ -24,6 +25,7 @@
 import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
 import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
 import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService;
+import com.yeshi.fanli.service.inter.user.UserActiveLogService;
 import com.yeshi.fanli.service.inter.user.UserInfoService;
 import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
 import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
@@ -31,6 +33,9 @@
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.VersionUtil;
+import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
+import com.yeshi.fanli.util.annotation.redpack.RedPackGetVersionLimit;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
 import com.yeshi.fanli.vo.order.CommonOrderVO;
 
@@ -64,6 +69,9 @@
 	@Resource	
 	private IntegralTaskRecordService integralTaskRecordService;
 	
+	@Resource
+	private UserActiveLogService userActiveLogService;
+	
 	
 	@Override
 	public List<RedPackWinInvite> getRewardList(int start, int count, Long uid) {
@@ -77,7 +85,15 @@
 	}
 	
 	@Override
+	public BigDecimal getRewardMoney(Long uid) {
+		return redPackWinInviteMapper.getRewardMoney(uid);
+	}
+	
+	
+	@RedPackGetVersionLimit(uid = "#uid")
+	@RequestSerializableByKeyService(key = "#uid")
 	@Transactional(rollbackFor = Exception.class)
+	@Override
 	public void orderArriveReward(Long uid, Integer source, String orderNo) throws Exception {
 		if (uid == null || source == null || orderNo == null)
 			return;
@@ -85,58 +101,34 @@
 		// 涓婁竴绾х殑濂栧姳
 		UserInfo boss = threeSaleSerivce.getBoss(uid);
 		if(boss != null) {
-			firstReward(uid, source, orderNo);
-			firstSharedOrderRewardToBoss(boss.getId(), uid, source, orderNo);
-			firstSharedOrderRewardTheMonthToBoss(boss.getId(), uid, source, orderNo);
+			UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(boss.getId());
+			if (activeLog == null) 
+				return;
+			
+			// 灏忎簬2.0.2鐗堟湰涓嶅鍔�
+			if (!VersionUtil.greaterThan_2_0_2("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android",
+					activeLog.getVersionCode()))
+				return;
+			
+			bossReward(boss.getId(), uid, source, orderNo);
 		}
 	}
 	
+	
 	/**
-	 * 琚個璇蜂汉涓嬮鍗曡繑鍒╋紙涓嬪崟灏辩粰锛夛細
-	 * 瀹屾垚棣栫瑪璁㈠崟 锛堝凡鍒拌处锛� 棣栧崟=涓嶉檺鍒堕噾棰濄�佷笉闄愬埗鍟嗗搧銆佷笉闄愬埗鏁伴噺銆佷笉闄愬埗璁㈠崟绫诲瀷锛�
+	 * 涓婄骇濂栧姳
 	 * @param uid
+	 * @param teamUid
 	 * @param source
 	 * @param orderNo
-	 * @param bossId
+	 * @throws Exception
 	 */
+	@RedPackGetVersionLimit(uid = "#uid")
 	@Transactional
-	private void firstReward(Long uid, Integer source, String orderNo) throws Exception{
-		// 濂栧姳涓�娆�
-		long total = redPackWinInviteMapper.countByUidAndType(uid, RedPackWinInviteTypeEnum.newUserReward.name());
-		if (total > 1)
-			return;
-		
-		// 1銆佸垽鏂槸鍚︾敤鎴烽涓鍗�
-		CommonOrderVO order = commonOrderService.firstValidOrderByUid(uid);
-		if (order == null || source == order.getSourceType() || orderNo.equals(order.getOrderNo())) 
-			return;
-		
-		// 閲戦
-		BigDecimal money = new BigDecimal(redPackConfigService.getValueByKey("new_user_first_order"));
-		
-		// 3銆佽幏寰楃孩鍖呰褰�
-		RedPackWinInvite winInvite = new RedPackWinInvite();
-		winInvite.setCreateTime(new Date());
-		winInvite.setUpdateTime(new Date());
-		winInvite.setType(RedPackWinInviteTypeEnum.newUserReward);
-		winInvite.setUid(uid);
-		winInvite.setTeamUid(null);
-		winInvite.setMoney(money);
-		winInvite.setSource(source);
-		winInvite.setOrderNo(orderNo);
-		redPackWinInviteMapper.insertSelective(winInvite);
-		
-		// 4銆佸鍔犵孩鍖�
-		redPackBalanceService.addRedPack(uid, money, RedPackDetailFactory.createNewUserReward(winInvite));
-		
-		//娑堟伅
-		MsgRedPackAddContentDTO dto = new MsgRedPackAddContentDTO();
-		dto.setTitle("绾㈠寘澧炲姞");
-		dto.setMoney("楼" + money.setScale(2));
-		dto.setBalance("楼" + redPackBalanceService.getBalance(uid).setScale(2));
-		userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackNewUserReward, new Gson().toJson(dto), "绾㈠寘鍙敤浜庤喘涔颁細鍛�");
+	private void  bossReward(Long uid, Long teamUid, Integer source, String orderNo)  throws Exception {
+		firstSharedOrderRewardToBoss(uid, teamUid, source, orderNo);
+		firstSharedOrderRewardTheMonthToBoss(uid, teamUid, source, orderNo);
 	}
-	
 	
 	/**
 	 * 涓婄骇濂栧姳锛氳閭�璇蜂汉瀹屾垚棣栫瑪鍒嗕韩璁㈠崟 锛堝凡鍒拌处锛� 
@@ -149,16 +141,17 @@
 	private void firstSharedOrderRewardToBoss(Long uid, Long inviteeUid, Integer source, String orderNo) throws Exception{
 		// 鍚屼竴闃熷憳濂栧姳涓�娆�
 		long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(uid, inviteeUid, RedPackWinInviteTypeEnum.firstSharedOrder.name());
-		if (totalReward > 1)
+		if (totalReward > 0)
 			return;
 		
 		// 1銆佸垽鏂槸鍚︽槸鏀圭敤鎴烽涓垎浜鍗�
 		CommonOrderVO order = commonOrderService.firstValidOrderByUidAndType(inviteeUid, 2);
-		if (order == null || source == order.getSourceType() || orderNo.equals(order.getOrderNo())) 
+		if (order == null || source != order.getSourceType() || !orderNo.equals(order.getOrderNo())) 
 			return;
 		
 		// 2銆佸垽鏂槸绗嚑涓汉
 		long total = redPackWinInviteMapper.countByUidAndType(uid, RedPackWinInviteTypeEnum.firstSharedOrder.name());
+		
 		
 		// 璁$畻搴斿鍔犵孩鍖呴噾棰�
 		BigDecimal money = new BigDecimal(redPackConfigService.getValueByKey("first_shared_order"));
@@ -188,7 +181,8 @@
 		dto.setTitle("绾㈠寘澧炲姞");
 		dto.setMoney("楼" + money.setScale(2));
 		dto.setBalance("楼" + redPackBalanceService.getBalance(uid).setScale(2));
-		userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackFirstSharedOrder, new Gson().toJson(dto), "绾㈠寘鍙敤浜庤喘涔颁細鍛�");
+		userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackFirstSharedOrder, 
+				new Gson().toJson(dto), "璇峰埌鈥滄垜鐨�-绾㈠寘鈥濅腑鏌ョ湅");
 	}
 	
 	
@@ -201,9 +195,9 @@
 	 */
 	@Transactional
 	private void firstSharedOrderRewardTheMonthToBoss(Long uid, Long inviteeUid, Integer source, String orderNo) throws Exception{
-		// 1銆佸垽鏂槸鍚︽槸鏈湀棣栧崟
-		CommonOrderVO order = commonOrderService.firstValidOrderTheMonthByUidAndType(inviteeUid, 2);
-		if (order == null || source == order.getSourceType() || orderNo.equals(order.getOrderNo()) ||
+		// 1銆佸垽鏂槸鍚︽槸涓婁釜鏈堥鍗�
+		CommonOrderVO order = commonOrderService.firstValidOrderLastMonthByUidAndType(inviteeUid, 2);
+		if (order == null || source != order.getSourceType() || !orderNo.equals(order.getOrderNo()) ||
 				order.getAccountTime() == null) 
 			return;
 		
@@ -247,21 +241,33 @@
 		dto.setTitle("绾㈠寘澧炲姞");
 		dto.setMoney("楼" + money.setScale(2));
 		dto.setBalance("楼" + redPackBalanceService.getBalance(uid).setScale(2));
-		userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackMonthSharedOrder, new Gson().toJson(dto), "绾㈠寘鍙敤浜庤喘涔颁細鍛�");
+		userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackMonthSharedOrder,
+				new Gson().toJson(dto), "璇峰埌鈥滄垜鐨�-绾㈠寘鈥濅腑鏌ョ湅");
 	}
 	
 	
-
-	@Transactional
-	private void inviteSucceedReward(Long uid) throws Exception{
+	@Override
+	@RedPackGetVersionLimit(uid = "#uid")
+	@RequestSerializableByKeyService(key = "#uid")
+	@Transactional(rollbackFor = Exception.class)
+	public void inviteSucceedReward(Long uid) throws Exception{
 		// 楠岃瘉鏄惁瀛樺湪涓婄骇
 		UserInfo boss = threeSaleSerivce.getBoss(uid);
 		if(boss == null) 
 			return;
 		
+		UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(boss.getId());
+		if (activeLog == null)
+			return;
+		
+		// 灏忎簬2.0.2鐗堟湰涓嶅鍔�
+		if (!VersionUtil.greaterThan_2_0_2("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android",
+				activeLog.getVersionCode()))
+			return;
+
 		// 鍚屼竴闃熷憳濂栧姳涓�娆�
 		long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(boss.getId(), uid, RedPackWinInviteTypeEnum.inviteSucceed.name());
-		if (totalReward > 1)
+		if (totalReward > 0)
 			return;
 		
 		// 1銆佺粦瀹氱數璇濆彿鐮�
@@ -317,7 +323,8 @@
 			dto.setTitle("绾㈠寘澧炲姞");
 			dto.setMoney("楼" + money.setScale(2));
 			dto.setBalance("楼" + redPackBalanceService.getBalance(boss.getId()).setScale(2));
-			userMoneyMsgNotificationService.redPackMsg(boss.getId(), MsgTypeMoneyTypeEnum.redPackInviteSucceed, new Gson().toJson(dto), "绾㈠寘鍙敤浜庤喘涔颁細鍛�");
+			userMoneyMsgNotificationService.redPackMsg(boss.getId(), MsgTypeMoneyTypeEnum.redPackInviteSucceed,
+					new Gson().toJson(dto), "璇峰埌鈥滄垜鐨�-绾㈠寘鈥濅腑鏌ョ湅");
 		}
 	}
 	

--
Gitblit v1.8.0