From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 30 七月 2019 09:07:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java |  186 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 167 insertions(+), 19 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java
index a289caa..692f57f 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java
@@ -8,6 +8,7 @@
 
 import javax.annotation.Resource;
 
+import org.springframework.core.task.TaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -15,16 +16,21 @@
 import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
 import com.yeshi.fanli.entity.bus.user.ThreeSale;
 import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
+import com.yeshi.fanli.entity.bus.user.UserActiveLog;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.exception.ThreeSaleException;
+import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
 import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService;
 import com.yeshi.fanli.service.inter.msg.UserInviteMsgNotificationService;
+import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
+import com.yeshi.fanli.service.inter.user.UserActiveLogService;
 import com.yeshi.fanli.service.inter.user.UserInfoService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.ThreeSaleCMQManager;
+import com.yeshi.fanli.util.VersionUtil;
+import com.yeshi.fanli.util.cmq.ThreeSaleCMQManager;
 
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
@@ -49,6 +55,17 @@
 
 	@Resource
 	private MsgInviteDetailService msgInviteDetailService;
+	
+	@Resource
+	private UserTaoLiJinOriginService userTaoLiJinOriginService;
+	
+	@Resource
+	private UserActiveLogService userActiveLogService;
+	
+	@Resource(name = "taskExecutor")
+	private TaskExecutor executor;
+	
+	
 
 	public UserInfo getBoss(final long uid) {
 		return threeSaleMapper.selectBoss(uid);
@@ -297,20 +314,12 @@
 		return threeSaleMapper.countSuperiorQuery(state, uid);
 	}
 
-	@Override
-	public List<ThreeSale> listFirstTeam(long start, int count, Long uid) {
-		return threeSaleMapper.listFirstTeam(start, count, uid);
-	}
 
 	@Override
 	public long countFirstTeam(Long uid, Integer state) {
 		return threeSaleMapper.countFirstTeam(uid, state);
 	}
 
-	@Override
-	public List<ThreeSale> listSecondTeam(long start, int count, Long uid) {
-		return threeSaleMapper.listSecondTeam(start, count, uid);
-	}
 
 	@Override
 	public long countSecondTeam(Long uid, Integer state) {
@@ -333,26 +342,26 @@
 	}
 
 	@Override
-	public JSONObject getMyFirstTeam(long start, int count, Long uid) {
+	public JSONObject getMyFirstTeam(long start, int count, Long uid, Integer state) {
 
-		List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid);
+		List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid, state);
 		if (list == null) {
 			list = new ArrayList<ThreeSale>();
 		}
 
-		long countTotal = threeSaleMapper.countFirstTeam(uid, null);
+		long countTotal = threeSaleMapper.countFirstTeam(uid, state);
 
 		return organizeTeam(countTotal, list);
 	}
 
 	@Override
-	public JSONObject getMySecondTeam(long start, int count, Long uid) {
-		List<ThreeSale> list = threeSaleMapper.listSecondTeam(start, count, uid);
+	public JSONObject getMySecondTeam(long start, int count, Long uid, Integer state) {
+		List<ThreeSale> list = threeSaleMapper.listSecondTeam(start, count, uid, state);
 		if (list == null) {
 			list = new ArrayList<ThreeSale>();
 		}
 
-		long countTotal = threeSaleMapper.countSecondTeam(uid, null);
+		long countTotal = threeSaleMapper.countSecondTeam(uid, state);
 
 		return organizeTeam(countTotal, list);
 	}
@@ -484,11 +493,11 @@
 
 	@Override
 	@Transactional
-	public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
+	public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter, String platform, String version) throws ThreeSaleException {
 
-		if (invitee == null || inviter == null)
+		if (invitee == null || inviter == null) 
 			throw new ThreeSaleException(1, "鐢ㄦ埛淇℃伅涓虹┖");
-
+		
 		// 鑾峰彇鏈夋晥鐨勯個璇峰叧绯�
 		ThreeSale threeSale = threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId());
 
@@ -510,7 +519,6 @@
 			threeSale.setCreateTime(java.lang.System.currentTimeMillis());
 			threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
 			threeSaleMapper.insertSelective(threeSale);
-
 		}
 
 		List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), invitee.getId());
@@ -528,9 +536,149 @@
 
 		// 閭�璇锋秷鎭�
 		userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale);
+		
+		executor.execute(new Runnable() {
+			@Override
+			public void run() {
+				try {
+					UserActiveLog activeLog  = userActiveLogService.getUserLatestActiveInfo(inviter.getId());
+					if (activeLog != null  && !StringUtil.isNullOrEmpty(activeLog.getVersionCode()) ) {
+						String versionCode = activeLog.getVersionCode();
+						String channel = activeLog.getChannel();
+						
+						boolean result = false;
+						// 娓犻亾鏄痑ppstore 鍒ゆ柇涓篒OS
+						if (!StringUtil.isNullOrEmpty(channel) && "appstore".equalsIgnoreCase(channel)) {
+							result = VersionUtil.greaterThan_1_5_60("ios", versionCode);
+						} else {
+							result = VersionUtil.greaterThan_1_5_60("android", versionCode);
+						}
+						
+						if (result) {
+							// 琚個璇峰悕绉�
+							String inviteName= invitee.getNickName();
+							if (StringUtil.isNullOrEmpty(inviteName)) {
+								UserInfo userInfo = userInfoService.selectByPKey(invitee.getId());
+								if (userInfo != null) {
+									inviteName= userInfo.getNickName();
+								}
+							}
+							// 濂栧姳閭�璇风孩鍖咃紙娣樼ぜ閲戯級
+							userTaoLiJinOriginService.addInviteWinMoney(inviter.getId(), inviteName);
+						}
+					}
+				} catch (Exception e) {
+					LogHelper.errorDetailInfo(e);
+				}
+			}
+		});
+		
+		
 	}
 
 	@Override
+	@Transactional
+	public void bindRelationshipByWX(UserInfo invitee, Long inviterId, ThreeSale threeSaleOld, String platform, String version) throws ThreeSaleException {
+
+		if (invitee == null || (inviterId == null && threeSaleOld == null))
+			throw new ThreeSaleException(1, "鐢ㄦ埛淇℃伅涓虹┖");
+		
+		ThreeSale threeSale = null;
+		if (inviterId != null ) {
+			// 鏂板缓绔嬬‘瀹氬叧绯�
+			threeSale  = new ThreeSale();
+			threeSale.setBoss(new UserInfo(inviterId));
+			threeSale.setWorker(invitee);
+			threeSale.setState(true);
+			threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
+			threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
+			threeSale.setCreateTime(java.lang.System.currentTimeMillis());
+			threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
+			threeSaleMapper.insertSelective(threeSale);
+			
+			// 閭�璇峰叧绯诲け鏁�  1.5.3 涔嬪墠澶辨晥
+			if (threeSaleOld != null) {
+				ThreeSale three  = new ThreeSale();
+				three.setId(threeSaleOld.getId());
+				three.setExpire(ThreeSale.EXPIRE_OUTOFDATE);
+				three.setUpdateTime(java.lang.System.currentTimeMillis());
+				threeSaleMapper.updateByPrimaryKeySelective(three);
+			}
+		} else if (threeSaleOld != null && inviterId == null) {
+			// 1.5.3 涔嬪墠鐢熸晥
+			threeSaleOld.setState(true);
+			threeSaleOld.setExpire(ThreeSale.EXPIRE_NORMAL);
+			threeSaleOld.setSucceedTime(java.lang.System.currentTimeMillis());
+			threeSaleOld.setUpdateTime(java.lang.System.currentTimeMillis());
+			threeSaleMapper.updateByPrimaryKeySelective(threeSaleOld);
+			
+			threeSale = threeSaleOld;
+		}
+
+		if (threeSale == null) {
+			throw new ThreeSaleException(1, "鍏崇郴缁戝畾澶辫触");
+		}
+		
+		UserInfo boss = userInfoService.selectByPKey(threeSale.getBoss().getId());
+		threeSale.setBoss(boss);
+		
+		// 娣诲姞鍒伴槦鍒�
+		ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale);
+	
+		// 閭�璇锋秷鎭�
+		userInviteMsgNotificationService.inviteSuccess(threeSale.getBoss().getId(), threeSale);
+		
+		
+		executor.execute(new Runnable() {
+			@Override
+			public void run() {
+				try {
+					UserActiveLog activeLog  = userActiveLogService.getUserLatestActiveInfo(inviterId);
+					if (activeLog != null  && !StringUtil.isNullOrEmpty(activeLog.getVersionCode()) ) {
+						boolean result = false;
+						String versionCode = activeLog.getVersionCode();
+						String channel = activeLog.getChannel();
+						
+						// 娓犻亾鏄痑ppstore 鍒ゆ柇涓篒OS
+						if (!StringUtil.isNullOrEmpty(channel) && "appstore".equalsIgnoreCase(channel)) {
+							result = VersionUtil.greaterThan_1_5_60("ios", versionCode);
+						} else {
+							result = VersionUtil.greaterThan_1_5_60("android", versionCode);
+						}
+						
+						if (result) {
+							// 琚個璇峰悕绉�
+							String inviteName= invitee.getNickName();
+							if (StringUtil.isNullOrEmpty(inviteName)) {
+								UserInfo userInfo = userInfoService.selectByPKey(invitee.getId());
+								if (userInfo != null) {
+									inviteName= userInfo.getNickName();
+								}
+							}
+							// 濂栧姳閭�璇风孩鍖咃紙娣樼ぜ閲戯級
+							userTaoLiJinOriginService.addInviteWinMoney(inviterId, inviteName);
+						}
+					}
+				} catch (Exception e) {
+					LogHelper.errorDetailInfo(e);
+				}
+			}
+		});
+	}
+	
+	/**
+	 * 鏍规嵁閭�璇疯�呮煡璇㈠叧绯�
+	 * 
+	 * @param workerId
+	 * @return
+	 */
+	@Override
+	public ThreeSale getByWorkerId(Long workerId) {
+		return threeSaleMapper.getByWorkerId(workerId);
+	}
+	
+	
+	@Override
 	public long countSuccessFirstTeam(Long uid) {
 		return threeSaleMapper.countFirstTeam(uid, 1);
 	}

--
Gitblit v1.8.0