From 88b54772dbcf5ecab1e2316e4e4626ac901b8908 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期二, 22 一月 2019 15:58:24 +0800 Subject: [PATCH] 邀请码添加返回状态 --- fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java | 327 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 209 insertions(+), 118 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 46610e3..bd3ac09 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 @@ -28,9 +28,11 @@ import com.yeshi.fanli.entity.bus.user.ThreeSale; import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; +import com.yeshi.fanli.exception.ThreeSaleException; import com.yeshi.fanli.service.inter.config.InviteGetMoneyService; import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce; +import com.yeshi.fanli.service.inter.msg.UserInviteMsgNotificationService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; @@ -52,12 +54,12 @@ @Resource private UserInfoMapper userInfoMapper; - + @Resource private ThreeSaleMapper threeSaleMapper; - - + @Resource + private UserInviteMsgNotificationService userInviteMsgNotificationService; public UserInfo getBoss(final long uid) { return (UserInfo) dao.excute(new HibernateCallback<UserInfo>() { @@ -92,26 +94,83 @@ } @Transactional - public void bind(UserInfo invitee, UserInfo inviter) { - ThreeSale threeSale = new ThreeSale(); - threeSale.setBoss(inviter); - threeSale.setWorker(invitee); - threeSale.setState(false); - threeSale.setCreateTime(System.currentTimeMillis()); - dao.save(threeSale); + public void bind(UserInfo invitee, UserInfo inviter) throws ThreeSaleException { + if (invitee == null || inviter == null) + throw new ThreeSaleException(1, "鐢ㄦ埛淇℃伅涓虹┖"); + if (invitee.getId() == null)// 璇ョ敤鎴疯繕涓嶅瓨鍦� + { + // 淇濆瓨鐢ㄦ埛 + UserInfo inviteeUser = userInfoService.addUser(invitee, Constant.APPID); + if (inviteeUser == null) + throw new ThreeSaleException(2, "鍒涘缓鐢ㄦ埛澶辫触"); + // 淇濆瓨鍏崇郴 + ThreeSale threeSale = new ThreeSale(); + threeSale.setBoss(inviter); + threeSale.setCreateTime(java.lang.System.currentTimeMillis()); + threeSale.setExpire(ThreeSale.EXPIRE_NORMAL); + threeSale.setState(false); + threeSale.setUpdateTime(java.lang.System.currentTimeMillis()); + threeSale.setWorker(inviteeUser); + threeSaleMapper.insertSelective(threeSale); + + //鍒涘缓閫氱煡 + userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale); + + + } else {// 鏄凡缁忓瓨鍦ㄧ殑鐢ㄦ埛 + + // 鐢ㄦ埛宸茬粡瀛樺湪鎴戜滑鐨勭敤鎴峰簱涓� + if (invitee.getLastLoginTime() == null || invitee.getLastLoginTime() == 0L) { + // 鐢ㄦ埛鏈櫥褰� + int outOfDateCount = 0;// 杩囨湡鏁伴噺 + // 鏌ヨ閭�璇峰叧绯� + List<ThreeSale> list = listByWorkerId(invitee.getId()); + if (list != null && list.size() > 0) { + for (ThreeSale ts : list) { + if (!ts.getState() && ts.getExpire() == ThreeSale.EXPIRE_OUTOFDATE) { + outOfDateCount++; + } + } + // 鍏ㄩ儴鏄け鏁堢姸鎬� + if (outOfDateCount == list.size()) { + // 鍙互纭畾鍏崇郴 + ThreeSale threeSale = new ThreeSale(); + threeSale.setBoss(inviter); + threeSale.setCreateTime(java.lang.System.currentTimeMillis()); + threeSale.setExpire(ThreeSale.EXPIRE_NORMAL); + threeSale.setState(false); + threeSale.setUpdateTime(java.lang.System.currentTimeMillis()); + threeSale.setWorker(invitee); + threeSaleMapper.insertSelective(threeSale); + userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale); + // threeSaleSerivce.bind(invitee, inviter); + + } else { + // 杩樺瓨鍦ㄦ湁鏁堢殑閭�璇凤紝鍒欎笉鍋氬鐞� + } + } else { + // 鐢ㄦ埛鏈櫥褰�,鍙堜笉瀛樺湪閭�璇峰叧绯�,涓嶅仛澶勭悊 + } + } else { + // 宸茬粡鐧诲綍锛屼笉鍋氬鐞� + } + } } @Transactional public void effective(UserInfo invitee) { - List<ThreeSale> list = dao.list("from ThreeSale ts where ts.worker.id = ? ", + List<ThreeSale> list = dao.list("from ThreeSale ts where ts.worker.id = ? and ts.state=0 and ts.expire=0", new Serializable[] { invitee.getId() }); if (list.size() > 0) { ThreeSale threeSale = list.get(0); UserInfo inviter = threeSale.getBoss(); threeSale.setState(true); + threeSale.setSucceedTime(System.currentTimeMillis()); dao.update(threeSale); if (inviter != null) reComputeUserRank(inviter.getId()); + //閫氱煡 + userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale); // } // }); } @@ -279,44 +338,42 @@ } @Override - public List<ThreeSale> queryMyFirstTeamList(int start, int count, String key, Long bossId){ + public List<ThreeSale> queryMyFirstTeamList(int start, int count, String key, Long bossId) { return threeSaleMapper.queryMyFirstTeamList(start, count, key, bossId); } - + @Override - public long queryCountMyFirstTeamList(String key, Long bossId){ + public long queryCountMyFirstTeamList(String key, Long bossId) { return threeSaleMapper.queryCountMyFirstTeamList(key, bossId); } - + @Override - public List<ThreeSale> queryMySecondTeamList(int start, int count, String key, Long bossId){ + public List<ThreeSale> queryMySecondTeamList(int start, int count, String key, Long bossId) { return threeSaleMapper.queryMySecondTeamList(start, count, key, bossId); } - + @Override - public long queryCountMySecondTeamList(String key, Long bossId){ + public long queryCountMySecondTeamList(String key, Long bossId) { return threeSaleMapper.queryCountMySecondTeamList(key, bossId); } - - + @Override - public int deleteByPrimaryKey(Long id){ + public int deleteByPrimaryKey(Long id) { return threeSaleMapper.deleteByPrimaryKey(id); } - + @Override - public List<Long> queryLongTimeFailed(int daysNum){ + public List<Long> queryLongTimeFailed(int daysNum) { return threeSaleMapper.queryLongTimeFailed(daysNum); } - - + @Override - public List<ThreeSale> queryLongTimeSuccess(int daysNum){ + public List<ThreeSale> queryLongTimeSuccess(int daysNum) { return threeSaleMapper.queryLongTimeSuccess(daysNum); } - + @Override - public int updateExpire(List<Long> list){ + public int updateExpire(List<Long> list) { return threeSaleMapper.updateExpire(list); } @@ -371,19 +428,17 @@ public long countSecondTeam(Long uid, Integer state) { return threeSaleMapper.countSecondTeam(uid, state); } - + @Override public ThreeSale getMyBoss(Long uid) { return threeSaleMapper.getMyBoss(uid); } - - + @Override public ThreeSale selectByPrimaryKey(Long id) { return threeSaleMapper.selectByPrimaryKey(id); } - - + @Override public List<ThreeSale> listbyIdAndBossId(Long id, Long uid, Integer expire) { return threeSaleMapper.listbyIdAndBossId(id, uid, expire); @@ -391,14 +446,14 @@ @Override public JSONObject getMyFirstTeam(long start, int count, Long uid) { - + List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid); if (list == null) { list = new ArrayList<ThreeSale>(); } - + long countTotal = threeSaleMapper.countFirstTeam(uid, null); - + return organizeTeam(countTotal, list); } @@ -408,133 +463,169 @@ if (list == null) { list = new ArrayList<ThreeSale>(); } - + long countTotal = threeSaleMapper.countSecondTeam(uid, null); - + return organizeTeam(countTotal, list); } - - public JSONObject organizeTeam(long count, List<ThreeSale> list) { - + JSONObject result = new JSONObject(); - - JSONArray resultArray = new JSONArray(); - - for (ThreeSale threeSale: list) { + + JSONArray resultArray = new JSONArray(); + + for (ThreeSale threeSale : list) { JSONObject object = new JSONObject(); SimpleDateFormat sdf = new SimpleDateFormat("MM.dd HH:mm"); SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm"); SimpleDateFormat formatYears = new SimpleDateFormat("yyyy"); - + Date todayTime = new Date(); // 閭�璇穒d object.put("inviteId", threeSale.getId()); - + + // 鍔犲叆闃熷垪鏃堕棿 Long createTime = threeSale.getCreateTime(); Date inviteTime = new Date(createTime); - - if (formatYears.format(todayTime).equals(formatYears.format(inviteTime))) { - // 鏈勾 - object.put("inviteTime", sdf.format(inviteTime) + " 鍔犲叆"); - } else { - // 寰�骞� - object.put("inviteTime", format.format(inviteTime) + " 鍔犲叆"); + object.put("inviteTime", format.format(inviteTime) + " 鍔犲叆"); + + String memoName = ""; + ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo(); + if (threeSaleExtraInfo != null) { + if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) { + memoName = threeSaleExtraInfo.getNickname(); + } } - - - String nickName = null; + object.put("memoName", memoName); + + String nickName = ""; + String portrait = ""; Long lastLoginTime = null; - String portrait = null; - Long workerId = null; - + UserInfo worker = threeSale.getWorker(); if (worker != null) { - workerId = worker.getId(); portrait = worker.getPortrait(); lastLoginTime = worker.getLastLoginTime(); nickName = worker.getNickName(); } - - object.put("workerId", workerId); + object.put("nickName", nickName); object.put("portrait", portrait); - - int type = 0; + + int state = 0; String fontColor1 = "#888888"; String fontColor2 = "#F14242"; - - JSONArray array = new JSONArray(); + + JSONArray array = new JSONArray(); if (threeSale.getState()) { - type = 1; + state = 1; if (lastLoginTime == null) { lastLoginTime = threeSale.getCreateTime(); } - - JSONArray array1 = new JSONArray(); - array1.add(fontColor1); - array1.add("鏈�杩戠櫥闄� " + sdf.format(lastLoginTime)); - - array.add(array1); - - } else if ( threeSale.getExpire()!= null && (threeSale.getExpire() == 1 || threeSale.getExpire().equals(1))) { - type = 2; - JSONArray array1 = new JSONArray(); - array1.add(fontColor1); - array1.add("宸茬粡鑴辩閭�璇峰叧绯�"); - - array.add(array1); + + JSONObject contentJson = new JSONObject(); + contentJson.put("color", fontColor1); + + if (formatYears.format(todayTime).equals(formatYears.format(lastLoginTime))) { + // 鏈勾 + contentJson.put("content", "鏈�杩戠櫥褰� " + sdf.format(lastLoginTime)); + } else { + // 寰�骞� + contentJson.put("content", "鏈�杩戠櫥褰� " + format.format(lastLoginTime)); + } + + array.add(contentJson); + + } else if (threeSale.getExpire() != null + && (threeSale.getExpire() == 1 || threeSale.getExpire().equals(1))) { + state = 2; + JSONObject contentJson = new JSONObject(); + contentJson.put("color", fontColor1); + contentJson.put("content", "宸茬粡鑴辩閭�璇峰叧绯�"); + array.add(contentJson); } else { - type = 0; - + state = 0; + Calendar c = Calendar.getInstance(); c.setTime(inviteTime); c.add(Calendar.DAY_OF_MONTH, 60);// 閭�璇蜂笉瓒呰繃60澶� - - - long days = (c.getTimeInMillis() -todayTime.getTime()) / (1000*3600*24); + + long days = (c.getTimeInMillis() - todayTime.getTime()) / (1000 * 3600 * 24); if (days < 0) { days = 0; } - - JSONArray array1 = new JSONArray(); - array1.add(fontColor1); - array1.add("灏嗕簬"); - - JSONArray array2 = new JSONArray(); - array2.add(fontColor2); - array2.add(days+"澶�"); - - JSONArray array3 = new JSONArray(); - array3.add(fontColor1); - array3.add("鍚庤劚绂婚個璇峰叧绯�"); - - array.add(array1); - array.add(array2); - array.add(array3); + + JSONObject contentJson1 = new JSONObject(); + contentJson1.put("color", fontColor1); + contentJson1.put("content", "灏嗕簬"); + + JSONObject contentJson2 = new JSONObject(); + contentJson2.put("color", fontColor2); + contentJson2.put("content", days + "澶�"); + + JSONObject contentJson3 = new JSONObject(); + contentJson3.put("color", fontColor1); + contentJson3.put("content", "鍚庤劚绂婚個璇峰叧绯�"); + + array.add(contentJson1); + array.add(contentJson2); + array.add(contentJson3); } - - object.put("type", type); + + object.put("state", state); object.put("recentMsg", array); - - ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo(); - if (threeSaleExtraInfo != null) { - if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) { - nickName = threeSaleExtraInfo.getNickname(); - } - } - - object.put("nickName", nickName); - + resultArray.add(object); } - + result.put("count", count); result.put("result_list", resultArray); - + return result; - + } + + @Override + public List<ThreeSale> listByWorkerId(Long workerId) { + return threeSaleMapper.listByWorkerId(workerId); } + @Override + public int getSuccessRelationshipNum(Long uid) { + return threeSaleMapper.getSuccessRelationshipNum(uid); + } + + @Override + @Transactional + public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException { + + if (invitee == null || inviter == null) + throw new ThreeSaleException(1, "鐢ㄦ埛淇℃伅涓虹┖"); + + // 鑾峰彇鏈夋晥鐨勯個璇峰叧绯� + ThreeSale threeSale = + threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId()); + + if (threeSale != null) { + // 鏈夋晥鍏崇郴--鐢熸晥 + threeSale.setState(true); + threeSale.setExpire(ThreeSale.EXPIRE_NORMAL); + threeSale.setSucceedTime(java.lang.System.currentTimeMillis()); + threeSale.setUpdateTime(java.lang.System.currentTimeMillis()); + threeSaleMapper.updateByPrimaryKeySelective(threeSale); + } else { + // 鏂板缓绔嬬‘瀹氬叧绯� + threeSale = new ThreeSale(); + threeSale.setBoss(inviter); + 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); + } + + } + } -- Gitblit v1.8.0