From a6f34b99ee20e528b766c8ed5a61bd9c5aa0e7ae Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 16 十一月 2019 18:10:33 +0800
Subject: [PATCH] 淘宝相似商品推荐接口优化,根据商品ID搜索商品基本信息优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java |  100 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 67 insertions(+), 33 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 a3d4c19..2af35c3 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,8 @@
 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.ThreeSale;
+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 +26,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,8 +34,8 @@
 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;
 
@@ -66,6 +69,9 @@
 	@Resource	
 	private IntegralTaskRecordService integralTaskRecordService;
 	
+	@Resource
+	private UserActiveLogService userActiveLogService;
+	
 	
 	@Override
 	public List<RedPackWinInvite> getRewardList(int start, int count, Long uid) {
@@ -84,19 +90,29 @@
 	}
 	
 	
-	@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)
+		if (uid == null || source == null || StringUtil.isNullOrEmpty(orderNo))
 			return;
 		
-		// 涓婁竴绾х殑濂栧姳
-		UserInfo boss = threeSaleSerivce.getBoss(uid);
-		if(boss != null) {
-			bossReward(boss.getId(), uid, source, orderNo);
-		}
+		ThreeSale threeSale = threeSaleSerivce.getByWorkerIdAndTime(uid, Constant.RED_PACK_REWARD_TIME);
+		if(threeSale == null)
+			return;
+			
+		Long bossId = threeSale.getBoss().getId();
+		UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId);
+		if (activeLog == null) 
+			return;
+		
+		// 灏忎簬2.0.2鐗堟湰涓嶅鍔�
+		if (!VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android",
+				activeLog.getVersionCode()))
+			return;
+		
+		// 濂栧姳涓婄骇
+		bossReward(bossId, uid, source, orderNo);
 	}
 	
 	
@@ -108,7 +124,6 @@
 	 * @param orderNo
 	 * @throws Exception
 	 */
-	@RedPackGetVersionLimit(uid = "#uid")
 	@Transactional
 	private void  bossReward(Long uid, Long teamUid, Integer source, String orderNo)  throws Exception {
 		firstSharedOrderRewardToBoss(uid, teamUid, source, orderNo);
@@ -124,19 +139,23 @@
 	 */
 	@Transactional
 	private void firstSharedOrderRewardToBoss(Long uid, Long inviteeUid, Integer source, String orderNo) throws Exception{
-		// 鍚屼竴闃熷憳濂栧姳涓�娆�
+		// 1銆佸悓涓�闃熷憳濂栧姳涓�娆�
 		long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(uid, inviteeUid, RedPackWinInviteTypeEnum.firstSharedOrder.name());
 		if (totalReward > 0)
 			return;
 		
-		// 1銆佸垽鏂槸鍚︽槸鏀圭敤鎴烽涓垎浜鍗�
-		CommonOrderVO order = commonOrderService.firstValidOrderByUidAndType(inviteeUid, 2);
-		if (order == null || source != order.getSourceType() || !orderNo.equals(order.getOrderNo())) 
+		// 2銆佹槸鍚︿笅绾х殑棣栦釜鍒嗕韩璁㈠崟
+		CommonOrder commonOrder = commonOrderService.getFirstShareOrderByUid(inviteeUid);
+		if (commonOrder == null || !orderNo.equals(commonOrder.getOrderNo()) || source != commonOrder.getSourceType()) 
+			return ;
+		
+		// 3銆佸埌璐﹀鍔遍噾棰� 鏄惁澶т簬5
+		BigDecimal totalRewardMoney = commonOrderService.getTotalRewardMoneyByOrderNoAndSourceType(orderNo, source);
+		if (totalRewardMoney == null || totalRewardMoney.compareTo(Constant.RED_PACK_ORDER_REWARD_MIN) < 0)
 			return;
 		
 		// 2銆佸垽鏂槸绗嚑涓汉
 		long total = redPackWinInviteMapper.countByUidAndType(uid, RedPackWinInviteTypeEnum.firstSharedOrder.name());
-		
 		
 		// 璁$畻搴斿鍔犵孩鍖呴噾棰�
 		BigDecimal money = new BigDecimal(redPackConfigService.getValueByKey("first_shared_order"));
@@ -166,10 +185,11 @@
 		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), "璇峰埌鈥滄垜鐨�-绾㈠寘鈥濅腑鏌ョ湅");
 	}
 	
-	
+
 	/**
 	 * 涓婄骇濂栧姳锛氭鏈堝紑濮嬩骇鐢熸弧瓒虫潯浠剁殑鍒嗕韩璁㈠崟锛堝垎浜鍗曞疄浠樻鈮�10鍏冿級 杩炵画15涓湀 鑷劧鏈堣幏寰楋紙宸插埌璐︼級姣忔湀鏈�楂�2鍏�
 	 * @param uid
@@ -179,6 +199,7 @@
 	 */
 	@Transactional
 	private void firstSharedOrderRewardTheMonthToBoss(Long uid, Long inviteeUid, Integer source, String orderNo) throws Exception{
+		
 		// 1銆佸垽鏂槸鍚︽槸涓婁釜鏈堥鍗�
 		CommonOrderVO order = commonOrderService.firstValidOrderLastMonthByUidAndType(inviteeUid, 2);
 		if (order == null || source != order.getSourceType() || !orderNo.equals(order.getOrderNo()) ||
@@ -189,15 +210,15 @@
 		if (order.getPayment() == null || order.getPayment().compareTo(Constant.RED_PACK_PAY_MIN) < 0) 
 			return;
 		
-		// 鏌ヨ棣栧崟濂栧姳鏃堕棿
-		CommonOrderVO firstorder = commonOrderService.firstValidOrderByUidAndType(inviteeUid, 2);
-		if (firstorder == null || firstorder.getAccountTime() == null) 
-			return;
+		// 2銆佹槸鍚︿笅绾х殑棣栦釜鍒嗕韩璁㈠崟
+//		CommonOrder firstorder = commonOrderService.getFirstShareOrderByUid(inviteeUid);
+//		if (firstorder == null || (orderNo.equals(firstorder.getOrderNo()) && source == firstorder.getSourceType()));
+//			return;
 		
 		// 绗竴娆″埌璐︾殑娆℃湀寮�濮嬭繛缁�15涓湀 鑷劧鏈堣幏寰楋紙宸插埌璐︼級
-		int monthSpace = DateUtil.getMonthSpace( order.getAccountTime(), firstorder.getAccountTime());
-		if (monthSpace == 0 || monthSpace > Constant.RED_PACK_REWARd_MONTH) 
-			return;
+//		int monthSpace = DateUtil.getMonthSpace(order.getThirdCreateTime(), firstorder.getThirdCreateTime());
+//		if (monthSpace == 0 || monthSpace > Constant.RED_PACK_REWARD_MONTH) 
+//			return;
 		
 		
 		// 璁$畻闅忔満濂栧姳
@@ -225,21 +246,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), "璇峰埌鈥滄垜鐨�-绾㈠寘鈥濅腑鏌ョ湅");
 	}
 	
 	
-	@RequestSerializableByKeyService(key = "#uid")
 	@Override
-	@Transactional
+	@RequestSerializableByKeyService(key = "#uid")
+	@Transactional(rollbackFor = Exception.class)
 	public void inviteSucceedReward(Long uid) throws Exception{
 		// 楠岃瘉鏄惁瀛樺湪涓婄骇
-		UserInfo boss = threeSaleSerivce.getBoss(uid);
-		if(boss == null) 
+		ThreeSale threeSale = threeSaleSerivce.getByWorkerIdAndTime(uid, Constant.RED_PACK_REWARD_TIME);
+		if (threeSale == null)
+			return;
+		// 涓婄骇id
+		Long bossId = threeSale.getBoss().getId();
+			
+		UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId);
+		if (activeLog == null)
 			return;
 		
+		// 灏忎簬2.0.2鐗堟湰涓嶅鍔�
+		if (!VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android",
+				activeLog.getVersionCode()))
+			return;
+
 		// 鍚屼竴闃熷憳濂栧姳涓�娆�
-		long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(boss.getId(), uid, RedPackWinInviteTypeEnum.inviteSucceed.name());
+		long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(bossId, uid, RedPackWinInviteTypeEnum.inviteSucceed.name());
 		if (totalReward > 0)
 			return;
 		
@@ -283,20 +316,21 @@
 			winInvite.setCreateTime(new Date());
 			winInvite.setUpdateTime(new Date());
 			winInvite.setType(RedPackWinInviteTypeEnum.inviteSucceed);
-			winInvite.setUid(boss.getId());
+			winInvite.setUid(bossId);
 			winInvite.setTeamUid(uid);
 			winInvite.setMoney(money);
 			redPackWinInviteMapper.insertSelective(winInvite);
 			
 			// 澧炲姞绾㈠寘
-			redPackBalanceService.addRedPack(boss.getId(), money, RedPackDetailFactory.createInvite(winInvite));
+			redPackBalanceService.addRedPack(bossId, money, RedPackDetailFactory.createInvite(winInvite));
 			
 			// 娑堟伅
 			MsgRedPackAddContentDTO dto = new MsgRedPackAddContentDTO();
 			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), "绾㈠寘鍙敤浜庤喘涔颁細鍛�");
+			dto.setBalance("楼" + redPackBalanceService.getBalance(bossId).setScale(2));
+			userMoneyMsgNotificationService.redPackMsg(bossId, MsgTypeMoneyTypeEnum.redPackInviteSucceed,
+					new Gson().toJson(dto), "璇峰埌鈥滄垜鐨�-绾㈠寘鈥濅腑鏌ョ湅");
 		}
 	}
 	

--
Gitblit v1.8.0