From 684779576c02c13cb2a18a7d93e88da7e57fd4b8 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期二, 31 三月 2020 11:25:13 +0800
Subject: [PATCH] 2.1 需求

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java |  264 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 261 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java
index 063fd5e..a3ebca6 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java
@@ -16,6 +16,8 @@
 import org.yeshi.utils.DateUtil;
 import org.yeshi.utils.JsonUtil;
 
+import com.yeshi.fanli.dto.user.UserInviteLevelEnum;
+import com.yeshi.fanli.dto.vip.UserVIPLevel;
 import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
 import com.yeshi.fanli.entity.accept.AcceptData;
 import com.yeshi.fanli.entity.bus.msg.UserSystemMsg;
@@ -25,6 +27,7 @@
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
 import com.yeshi.fanli.entity.bus.user.UserInviteSeparate;
+import com.yeshi.fanli.entity.bus.user.UserInviteValidRecord;
 import com.yeshi.fanli.entity.bus.user.WeiXinUser;
 import com.yeshi.fanli.entity.system.BusinessSystem;
 import com.yeshi.fanli.entity.system.ConfigKeyEnum;
@@ -43,11 +46,14 @@
 import com.yeshi.fanli.service.inter.user.UserInviteSeparateService;
 import com.yeshi.fanli.service.inter.user.invite.ThreeSaleExtraInfoSerivce;
 import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
+import com.yeshi.fanli.service.inter.user.invite.UserInviteService;
+import com.yeshi.fanli.service.inter.user.invite.UserInviteValidRecordService;
 import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.RedisKeyEnum;
 import com.yeshi.fanli.util.RedisManager;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.VersionUtil;
 import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
 import com.yeshi.fanli.util.wx.WXLoginUtil;
@@ -97,6 +103,12 @@
 	
 	@Resource
 	private SystemClientParamsService systemClientParamsService;
+	
+	@Resource
+	private UserInviteService userInviteService;
+	
+	@Resource
+	private UserInviteValidRecordService userInviteValidRecordService;
 	
 	
 	
@@ -201,6 +213,11 @@
 			out.print(JsonUtil.loadFalseResult("绮変笣绫诲瀷涓嶆纭�"));
 			return;
 		}
+		
+		if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
+			getMyTeamNew(acceptData, page, uid, type, out);
+			return;
+		}
 
 		long count = 0;
 		List<ThreeSale> listTeam = null;
@@ -281,8 +298,6 @@
 					UserInviteSeparate separate = userInviteSeparateService.selectByWorkerIdAndBossId(worker.getId(), uid);
 					if (separate != null && separate.getEndTime() != null) {
 						try {
-							
-						
 							JSONObject contentJson1 = new JSONObject();
 							contentJson1.put("color", "#888888");
 							contentJson1.put("content", "灏嗕簬");
@@ -300,7 +315,6 @@
 							array.add(contentJson2);
 							array.add(contentJson3);
 							object.put("vipBreakTime",array);
-						
 						} catch (Exception e) {
 							e.printStackTrace();
 						}
@@ -363,6 +377,250 @@
 		return result;
 	}
 
+	
+	private void getMyTeamNew(AcceptData acceptData, long page, long uid, int type, PrintWriter out) {
+		if (type != 1 && type != 2) {
+			out.print(JsonUtil.loadFalseResult("绮変笣绫诲瀷涓嶆纭�"));
+			return;
+		}
+
+		long count = 0;
+		List<ThreeSale> listTeam = null;
+		if (type == 1) {
+			listTeam = threeSaleSerivce.listFirstTeamByUndeleted((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
+			count = threeSaleSerivce.countFirstTeamByUndeleted(uid);
+		} else if (type == 2) {
+			listTeam = threeSaleSerivce.listSecondTeamByUndeleted((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
+			count = threeSaleSerivce.countSecondTeamByUndeleted(uid);
+		}
+
+		JSONObject result = new JSONObject();
+		result.put("count", count);
+		result.put("list", organizeTeamNew(count, listTeam, uid, type, true));
+		
+		// 绗竴椤靛垽鏂槸鍚︽縺娲� 鏄惁鏈夐槦鍛�
+		if (type == 1 && page == 1) {
+			boolean hasCode = false;
+			UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+			if (userInfoExtra != null) {
+				if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
+					hasCode = true;
+			}
+			result.put("hasCode", hasCode);
+			result.put("hasTeam", count > 0 ? true : false);
+		}
+		out.print(JsonUtil.loadTrueResult(result));
+	}
+	
+	/**
+	 *  鍔犲伐鏁版嵁
+	 * @param count
+	 * @param list
+	 * @param uid
+	 * @param type 鏌ヨ绮変笣绫诲瀷 1鐩存帴 2闂存帴
+	 * @param wxtip 鏄渶瑕佸井淇℃彁绀�
+	 * @return
+	 */
+	private JSONArray organizeTeamNew(long count, List<ThreeSale> list, Long uid, int type, boolean wxtip) {
+		JSONArray resultArray = new JSONArray();
+		if (list == null || list.size() == 0) {
+			return resultArray;
+		}
+
+		Date todayTime = new Date();
+		SimpleDateFormat sdf = new SimpleDateFormat("MM.dd HH:mm");
+		SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
+		SimpleDateFormat formatYears = new SimpleDateFormat("yyyy");
+
+		List<Long> listWid = new ArrayList<>();
+		for (ThreeSale threeSale : list) {
+			listWid.add(threeSale.getWorker().getId());
+		}
+		
+		// 鏌ヨ鏈夋晥绮変笣id
+		int validType = UserInviteValidRecord.TYPE_TWO;
+		if (type == 1) {
+			validType = UserInviteValidRecord.TYPE_ONE;
+		}
+		List<Long> listVid = userInviteValidRecordService.getValidWorkerIdsByUid(uid, listWid, validType);
+	
+		for (ThreeSale threeSale : list) {
+			UserInfo worker = threeSale.getWorker();
+			Long workerId = worker.getId();
+
+			// 閭�璇风姸鎬�
+			Boolean state = threeSale.getState();
+			if (type == 2) {
+				if (state &&  threeSale.getStateSuper()) {
+					state = true;
+				} else {
+					state = false;
+				}
+			}
+			
+			
+			// 閭�璇锋垚鍔熸椂闂�
+			Long succeedTime = threeSale.getSucceedTime(); 
+			if (succeedTime == null) {
+				succeedTime = threeSale.getCreateTime();
+			}
+			
+			// 鏈夋晥绮変笣
+			boolean validFans = false; 
+			if (state && listVid != null && listVid.size() > 0 && listVid.contains(workerId)) {
+				validFans = true;
+			}
+			
+			// 鏈�杩戠櫥褰曟椂闂�
+			Date lastLoginTime = new Date(threeSale.getCreateTime());
+			UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(workerId);
+			if (userInfoExtra != null && userInfoExtra.getActiveTime() != null) {
+				lastLoginTime = userInfoExtra.getActiveTime();
+			} 
+			JSONObject loginJson = new JSONObject();
+			if (formatYears.format(todayTime).equals(formatYears.format(lastLoginTime))) {
+				loginJson.put("content", "鏈�杩戠櫥褰� " + sdf.format(lastLoginTime)); // 鏈勾
+			} else {
+				loginJson.put("content", "鏈�杩戠櫥褰� " + format.format(lastLoginTime)); // 寰�骞�
+			}
+			loginJson.put("color", "#888888");
+			
+			JSONArray array = new JSONArray();
+			array.add(loginJson);
+
+			// 绛夌骇
+			UserInviteLevelEnum level = null;
+			UserVIPLevel vipLevel = userInviteService.getVIPLevelByUid(uid);
+			if (vipLevel != null) {
+				if (vipLevel.getLevel() == UserVIPLevel.LEVEL_3) {
+					level = UserInviteLevelEnum.actived;
+				} else if (vipLevel.getLevel() == UserVIPLevel.LEVEL_7) {
+					level = UserInviteLevelEnum.actived;
+				} else if (vipLevel.getLevel() == UserVIPLevel.LEVEL_10) {
+					level = UserInviteLevelEnum.actived;
+				}
+			}
+			
+			if(level == null) {
+				if (userInfoExtra == null || StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
+					level = UserInviteLevelEnum.noActive;
+				} else {
+					level = UserInviteLevelEnum.actived;
+				}
+			}
+			
+			
+			JSONObject object = new JSONObject();
+			object.put("workerId", workerId);
+			object.put("nickName", worker.getNickName());
+			object.put("portrait", worker.getPortrait());
+			object.put("inviteId", threeSale.getId());
+			object.put("inviteTime", format.format(new Date(succeedTime)) + " 鍔犲叆");
+			object.put("state", state? 1 : 2);
+			object.put("recentMsg", array);
+			object.put("level", level.name());
+			object.put("validFans", validFans);
+			
+			
+			// 鍒ゆ柇鏄惁瀛樺湪鑴辩鍏崇郴闃熷憳
+			if (vipLevel != null) {
+				UserInviteSeparate separate = userInviteSeparateService.selectByWorkerIdAndBossId(workerId, uid);
+				if (separate != null && separate.getEndTime() != null) {
+					try {
+						JSONObject contentJson1 = new JSONObject();
+						contentJson1.put("color", "#888888");
+						contentJson1.put("content", "灏嗕簬");
+
+						String dateDiff = DateUtil.dateDiff4(new Date(), separate.getEndTime());
+						JSONObject contentJson2 = new JSONObject();
+						contentJson2.put("color", "#F14242");
+						contentJson2.put("content", dateDiff);
+
+						JSONObject contentJson3 = new JSONObject();
+						contentJson3.put("color", "#888888");
+						contentJson3.put("content", "鍚庤劚绂婚個璇峰叧绯�");
+						
+						JSONArray vipBreak = new JSONArray();
+						vipBreak.add(contentJson1);
+						vipBreak.add(contentJson2);
+						vipBreak.add(contentJson3);
+						object.put("vipBreakTime",vipBreak);
+						
+						List<String> tips = new ArrayList<String>();
+						tips.add("浜�"+ TimeUtil.formatDateDot(vipLevel.getSuccessTime()) + "鍗囩骇涓�" + level.getName());
+						if (type == 1) {
+							tips.add("浣犻渶瑕佸湪"+ dateDiff +"鍐呭崌绾т负浼氬憳锛屽惁鍒欐寜鐓ч個璇疯鍒橳A灏嗕笌浣犺劚绂婚個璇峰叧绯汇��");
+							tips.add("璧跺揩鍔犳补鍗囩骇涓轰細鍛樺惂锛�");
+						} else {
+							tips.add("浣犻渶瑕佽緟鍔㏕A鐨勯個璇蜂汉"+ threeSale.getBoss().getNickName()+ "鍦�"+dateDiff+"鍐呭崌绾т负浼氬憳锛屽惁鍒欒繖浣嶉棿鎺ョ矇涓�" +worker.getNickName()+"灏嗕笌浣犺劚绂婚個璇峰叧绯汇��");
+							tips.add("璧跺揩甯姪TA鍗囩骇涓轰細鍛樺惂锛�");
+						}
+						object.put("vipBreakTip",tips);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			}
+			
+						
+			if (wxtip && type == 1 && threeSale.getState() != null && threeSale.getState()) {
+				// 涓�绾ч槦鍛� 鏌ヨ鏄电О澶囨敞
+				String memoName = null;
+				ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo();
+				if (threeSaleExtraInfo != null) {
+					if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) {
+						memoName = threeSaleExtraInfo.getNickname();
+					}
+				}
+				object.put("memoName", memoName);
+				
+				// 娣诲姞寰俊淇℃伅
+				if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) {
+					object.put("weiXin", userInfoExtra.getWeiXin());
+					object.put("weiXinState", 3);
+					object.put("weiXinTip", "娣诲姞TA鐨勫井淇★紝浣犲彲鏁欐巿TA濡備綍閫氳繃鏉挎牀蹇渷璧氶挶鎶�宸с��");
+				} else {
+					if (!threeSaleExtraInfoSerivce.isRemindWorker(uid, workerId)) {
+						object.put("weiXinState", 1);
+						object.put("weiXinTip", "鐐瑰嚮鎻愰啋TA锛岀郴缁熶細鍙戦�佷竴灏佺珯鍐呬俊锛屾彁閱掑叾娣诲姞寰俊鍙枫��");
+					} else {
+						object.put("weiXinState", 2);
+						object.put("weiXinTip", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�");
+					}
+				}
+			}
+			
+			resultArray.add(object);
+		}
+		return resultArray;
+	}
+	
+	
+	/**
+	 * 鏌ョ湅涓嬬骇鐨勭洿鎺ョ矇涓�
+	 * @param acceptData
+	 * @param page
+	 * @param uid 褰撳墠UId
+	 * @param tid 涓嬬骇UId
+	 * @param out
+	 */
+	@RequestMapping(value = "getOthersTeam", method = RequestMethod.POST)
+	public void getOthersTeam(AcceptData acceptData, long page, Long uid, Long tid,  PrintWriter out) {
+		if (tid == null) {
+			out.print(JsonUtil.loadFalseResult("浼犻�掑弬鏁颁笉姝g‘"));
+			return;
+		}
+		
+		List<ThreeSale> listTeam = threeSaleSerivce.listFirstTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, tid, 1);
+		long count = threeSaleSerivce.countFirstTeam(tid, 1);
+
+		JSONObject result = new JSONObject();
+		result.put("count", count);
+		result.put("list", organizeTeamNew(count, listTeam, tid, 1, false));
+		out.print(JsonUtil.loadTrueResult(result));
+	}
+	
+	
 	/**
 	 * 鐢ㄦ埛闃熷憳缁熻- IOS
 	 * 

--
Gitblit v1.8.0