From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/InviteController.java | 930 ++++++++++++++++++++++++++++----------------------------- 1 files changed, 463 insertions(+), 467 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/InviteController.java b/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/InviteController.java index 1ff6e9f..ad9598f 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/InviteController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/InviteController.java @@ -1,467 +1,463 @@ -package com.yeshi.fanli.controller.wxmp.v1; - -import java.io.PrintWriter; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.yeshi.utils.JsonUtil; - -import com.yeshi.fanli.dto.WXMPAcceptData; -import com.yeshi.fanli.entity.bus.msg.UserSystemMsg; -import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum; -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.entity.bus.user.UserInfoExtra; -import com.yeshi.fanli.entity.system.ConfigKeyEnum; -import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.msg.UserSystemMsgService; -import com.yeshi.fanli.service.inter.push.PushService; -import com.yeshi.fanli.service.inter.user.UserInfoExtraService; -import com.yeshi.fanli.service.inter.user.UserInfoService; -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.vip.UserVIPInfoService; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.StringUtil; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -@Controller("WXMPInviteController") -@RequestMapping("/wxmp/api/v1/invite") -public class InviteController { - - @Resource - private ThreeSaleSerivce threeSaleSerivce; - - @Resource - private ConfigService configService; - - @Resource - private UserInfoExtraService userInfoExtraService; - - @Resource - private UserVIPInfoService userVIPInfoService; - - @Resource - private ThreeSaleExtraInfoSerivce threeSaleExtraInfoSerivce; - - @Resource - private UserInfoService userInfoService; - - @Resource - private PushService pushService; - - @Resource - private UserSystemMsgService userSystemMsgService; - - /** - * 涓撳睘閭�璇风爜鏉′欢 - * - * @param acceptData - * @param uid - * @param inviteId - * @param out - */ - @RequestMapping(value = "tailorCode") - public void tailorCode(WXMPAcceptData acceptData, String callback, Long uid, PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult("鐢ㄦ埛id缂哄け")); - return; - } - - JSONArray array1 = new JSONArray(); - array1.add("1.閭�璇风爜鍙府鍔╁ソ鍙嬫縺娲婚個璇峰姛鑳斤紱"); - array1.add("2.濂藉弸閫氳繃浣犵殑閭�璇风爜婵�娲婚個璇峰姛鑳藉悗锛屽皢鎴愪负浣犵殑鐩存帴绮変笣锛屾湭鏉ヤ骇鐢熺殑璁㈠崟浣犻兘鏈夊閲戯紱"); - array1.add("3.閭�璇风爜鍏锋湁鍞竴鎬с��"); - - JSONObject desc1 = new JSONObject(); - desc1.put("title", "閭�璇风爜鐨勪綔鐢�"); - desc1.put("content",array1); - - JSONArray array2 = new JSONArray(); - array2.add("1.浣犲彲浠ヨ嚜鐢辫缃�4~12浣嶇畝鍗曟槗璁扮殑閭�璇风爜锛�"); - array2.add("2.涓撳睘閭�璇风爜鏄浣犲拰浣犵殑鍥㈤槦灏婅吹韬唤鐨勫桨鏄俱��"); - - JSONObject desc2 = new JSONObject(); - desc2.put("title", "涓撳睘閭�璇风爜浼樺娍"); - desc2.put("content",array2); - - JSONArray array = new JSONArray(); - array.add(desc1); - array.add(desc2); - - JSONObject data = new JSONObject(); - data.put("desc", array); - data.put("num", threeSaleSerivce.countFirstTeam(uid)); - data.put("limit", Constant.INVITE_CODRE_TAILOR_LIMIT); - - out.print(JsonUtil.loadTrueResult(data)); - } - - /** - * 鐢ㄦ埛闃熷憳缁熻 1.4.1 - * - * @param acceptData - * @param id - * @param out - */ - @RequestMapping(value = "countMyTeam", method = RequestMethod.POST) - public void countMyTeam(WXMPAcceptData acceptData, long uid, PrintWriter out) { - try { - long firstTeam = threeSaleSerivce.countFirstTeam(uid); - long secondTeam = threeSaleSerivce.countSecondTeam(uid); - JSONObject bossData = new JSONObject(); - ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid); - if (threeSale != null) { - UserInfo boss = threeSale.getBoss(); - if (boss != null) { - bossData.put("nickName", boss.getNickName()); - bossData.put("portrait", boss.getPortrait()); - } - - SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); - Long createTime = threeSale.getCreateTime(); - Date inviteTime = new Date(createTime); - bossData.put("inviteTime", "閭�璇锋椂闂�: " + sdf.format(inviteTime)); - } - - JSONObject resultData = new JSONObject(); - - String helpLink = configService.get(ConfigKeyEnum.teamHelpUrl.getKey()); - if (helpLink == null) { - helpLink = ""; - } - resultData.put("helpLink", helpLink); - resultData.put("firstTeam", firstTeam); - resultData.put("firstTeamTotal", firstTeam); - resultData.put("secondTeam", secondTeam); - resultData.put("secondTeamTotal", secondTeam); - resultData.put("boss", bossData); - - boolean hasCode = false; - String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); - if (inviteCode != null && inviteCode.trim().length() > 0) { - hasCode = true; // 宸叉湁閭�璇风爜 - } else { - // 閭�璇锋縺娲婚摼鎺� - resultData.put("activationlink", configService.get(ConfigKeyEnum.inviteActivationUrl.getKey())); - } - resultData.put("hasCode", hasCode); - - out.print(JsonUtil.loadTrueResult(resultData)); - - } catch (Exception e) { - out.print(JsonUtil.loadFalseResult("缁熻澶辫触")); - e.printStackTrace(); - } - } - - /** - * - * @param acceptData - * @param id - * @param out - */ - @RequestMapping(value = "listMyTeam") - public void listMyTeam(WXMPAcceptData acceptData, int 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.listFirstTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid); - count = threeSaleSerivce.countFirstTeam(uid); - } else if (type == 2) { - listTeam = threeSaleSerivce.listSecondTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid); - count = threeSaleSerivce.countSecondTeam(uid); - } - - boolean needVIPInfo = true; - - // 缁勭粐鏁版嵁 - JSONObject resultData = organizeTeam(count, listTeam, uid, type, needVIPInfo); - - // 绗竴椤靛垽鏂槸鍚︽縺娲� 鏄惁鏈夐槦鍛� - if (type == 1 && page == 1) { - boolean hasCode = false; - UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); - if (userInfoExtra != null) { - if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) - hasCode = true; - } - resultData.put("hasCode", hasCode); - resultData.put("hasTeam", count > 0 ? true : false); - } - out.print(JsonUtil.loadTrueResult(resultData)); - } - - /** - * 缁勭粐鏁版嵁 - * - * @param count - * @param list - * @param uid - * @param type - * @return - */ - private JSONObject organizeTeam(long count, List<ThreeSale> list, Long uid, int type, boolean needVipInfo) { - JSONObject result = new JSONObject(); - JSONArray resultArray = new JSONArray(); - - 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> workerIdList = new ArrayList<>(); - Map<Long, Boolean> vipMap = null; - if (needVipInfo) { - for (ThreeSale threeSale : list) - workerIdList.add(threeSale.getWorker().getId()); - if (workerIdList.size() > 0) - vipMap = userVIPInfoService.listByUids(workerIdList); - } - for (ThreeSale threeSale : list) { - UserInfo worker = threeSale.getWorker(); - if (worker == null) { - continue; - } - Long workerId = worker.getId(); - - JSONObject object = new JSONObject(); - object.put("workerId", worker.getId()); - object.put("nickName", worker.getNickName()); - object.put("portrait", worker.getPortrait()); - object.put("inviteId", threeSale.getId()); - - Date inviteTime = new Date(threeSale.getCreateTime()); - object.put("inviteTime", format.format(inviteTime) + " 鍔犲叆"); - // 娣诲姞鏄惁涓篤IP - if (vipMap != null && vipMap.get(worker.getId()) != null) { - object.put("vip", vipMap.get(worker.getId())); - } - String fontColor1 = "#888888"; - JSONArray array = new JSONArray(); - if (threeSale.getState()) { - Long lastLoginTime = worker.getLastLoginTime(); - if (lastLoginTime == null) { - lastLoginTime = threeSale.getCreateTime(); - } - - 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); - - // 涓�绾ч槦鍛� 鏌ヨ - if (type == 1) { - String memoName = null; - ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo(); - if (threeSaleExtraInfo != null) { - if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) { - memoName = threeSaleExtraInfo.getNickname(); - } - } - object.put("memoName", memoName); - - UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(workerId); - 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", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�"); - } - } - } - } - object.put("state", 1); - object.put("recentMsg", array); - resultArray.add(object); - } - - result.put("count", count); - result.put("list", resultArray); - return result; - } - - /** - * 鑾峰彇鐢ㄦ埛淇℃伅 - * @param acceptData - * @param uid - * @param out - */ - @RequestMapping(value = "getBossInfo", method = RequestMethod.POST) - public void getBossInfo(WXMPAcceptData acceptData, Long uid, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); - return; - } - JSONObject bossData = getBossInfo(uid, threeSaleSerivce.getMyBoss(uid)); - out.print(JsonUtil.loadTrueResult(bossData)); - } - - /** - * 绔欏唴淇℃彁閱掗槦鍛樻坊鍔犲井淇″彿 - * - * @param acceptData - * @param uid - * @param inviteId - * @param out - */ - @RequestMapping(value = "remindBossAddWX") - public void remindTeam(WXMPAcceptData acceptData, Long uid, PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult("浼犻�掑弬鏁扮己澶�")); - return; - } - - UserInfo userInfo = userInfoService.selectByPKey(uid); - if (userInfo == null) { - out.print(JsonUtil.loadFalseResult("鐢ㄦ埛淇℃伅涓嶅瓨鍦�")); - return; - } - - ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid); - if (threeSale == null) { - out.print(JsonUtil.loadFalseResult("娌℃湁閭�璇蜂汉")); - return; - } - - Long remindId = null; - boolean remindBoss = true; - if (uid.longValue() == threeSale.getWorker().getId().longValue()) { - remindId = threeSale.getBoss().getId(); // 鎻愰啋涓婄骇 - } else if (uid.longValue() == threeSale.getBoss().getId().longValue()) { - remindBoss = false; - remindId = threeSale.getWorker().getId(); // 鎻愰啋涓嬬骇 - } - - if (remindId == null) { - out.print(JsonUtil.loadFalseResult("淇℃伅楠岃瘉鏈�氳繃")); - return; - } - - Long bossId = null; - Long workerId = null; - String title = "绮変笣鎻愰啋娑堟伅"; - String content = ""; - if (remindBoss) { - // 鎻愮ず闃熼暱 - bossId = remindId; - workerId = uid; - content = "浣犵殑鐩存帴绮変笣" + userInfo.getNickName() - + "锛屾彁閱掍綘娣诲姞寰俊鍙凤紝浠ヤ究浜庡拰浣犲彇寰楄仈绯诲拰瀛︿範鐪侀挶鎶�宸э紝璧跺揩鍘绘坊鍔犲惂锛涙敞锛氳鍗囩骇鍒版湰杞欢鏈�鏂扮増鏈湪鈥滄垜鐨�-鎴戠殑淇℃伅鈥濅腑娣诲姞銆�"; - } else { - // 鎻愮ず闃熷憳 - bossId = uid; - workerId = remindId; - content = "浣犵殑閭�璇蜂汉" + userInfo.getNickName() - + "锛屾彁閱掍綘娣诲姞寰俊鍙凤紝浠ヤ究浜庡拰浣犲彇寰楄仈绯诲府鍔╀綘鏇村ソ鐨勭渷閽憋紝璧跺揩鍘绘坊鍔犲惂锛涙敞锛氳鍗囩骇鍒版湰杞欢鏈�鏂扮増鏈湪鈥滄垜鐨�-鎴戠殑淇℃伅鈥濅腑娣诲姞銆�"; - } - - try { - List<String> listIOS = new ArrayList<String>(); - List<String> listAndroid = new ArrayList<String>(); - pushService.pushZNX(remindId, title, content, listIOS, listAndroid); - - userSystemMsgService.addUserSystemMsg(remindId, UserSystemMsgTypeEnum.common, title, content, - UserSystemMsg.TIME_TAG_COMMON, null); - - ThreeSaleExtraInfo newInfo = new ThreeSaleExtraInfo(); - if (remindBoss) { - newInfo.setRemindBoss(1); - } else { - newInfo.setRemindWorker(1); - } - - ThreeSaleExtraInfo threeExtra = threeSaleExtraInfoSerivce.getbyBossIdAndWorkerId(bossId, workerId); - if (threeExtra != null) { - newInfo.setId(threeExtra.getId()); - newInfo.setUpdateTime(new Date()); - threeSaleExtraInfoSerivce.updateByPrimaryKeySelective(newInfo); - } else { - newInfo.setBoss(new UserInfo(bossId)); - newInfo.setWorker(new UserInfo(workerId)); - newInfo.setCreateTime(new Date()); - newInfo.setUpdateTime(new Date()); - threeSaleExtraInfoSerivce.insertSelective(newInfo); - } - - JSONObject data = new JSONObject(); - data.put("weiXinState", 2); - data.put("weiXinTip", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�"); - out.print(JsonUtil.loadTrueResult(data)); - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadFalseResult("鎻愰啋澶辫触")); - } - } - - /** - * 涓婄骇淇℃伅缁勭粐 - * - * @param acceptData - * @param uid - * @param threeSale - * @return - */ - private JSONObject getBossInfo(long uid, ThreeSale threeSale) { - JSONObject bossData = new JSONObject(); - if (threeSale != null && threeSale.getBoss() != null) { - UserInfo boss = threeSale.getBoss(); - bossData.put("hasBoss", true); - bossData.put("inviteId", threeSale.getId()); - bossData.put("nickName", boss.getNickName()); - bossData.put("portrait", boss.getPortrait()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); - Long createTime = threeSale.getCreateTime(); - Date inviteTime = new Date(createTime); - - UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(boss.getId()); - if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) { - bossData.put("weiXin", userInfoExtra.getWeiXin()); - bossData.put("weiXinState", 3); - bossData.put("weiXinTip", "娣诲姞TA鐨勫井淇★紝浣犲彲鍚慣A瀛︿範濡備綍閫氳繃鏉挎牀蹇渷璧氶挶銆�"); - } else { - if (!threeSaleExtraInfoSerivce.isRemindBoss(boss.getId(), uid)) { - bossData.put("weiXinState", 1); - bossData.put("weiXinTip", "鐐瑰嚮鎻愰啋TA锛岀郴缁熶細鍙戦�佷竴灏佺珯鍐呬俊锛屾彁閱掑叾娣诲姞寰俊鍙枫��"); - } else { - bossData.put("weiXinState", 2); - bossData.put("weiXinTip", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�"); - } - } - bossData.put("inviteTime", "浣犱簬 " + sdf.format(inviteTime) + "鎺ュ彈浜員A鐨勯個璇�"); - } else { - bossData.put("hasBoss", false); - bossData.put("helpLink", configService.get(ConfigKeyEnum.inviteCodeHlepLink.getKey())); - bossData.put("weiXinTip", "鎭枩浣狅紝鎴戜滑鐨勪紭璐ㄧ敤鎴凤紱\r\n浣犲苟娌℃湁閭�璇蜂汉锛屼絾浣犵殑閭�璇锋縺娲诲姛鑳芥槸琚粯璁ゅ紑鍚殑锛沑r\n浣犳嫢鏈夌嫭鐗圭殑鏃犻個璇蜂汉婵�娲荤爜銆�"); - } - return bossData; - } -} +package com.yeshi.fanli.controller.wxmp.v1; + +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.SystemEnum; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.yeshi.utils.JsonUtil; + +import com.yeshi.fanli.dto.WXMPAcceptData; +import com.yeshi.fanli.entity.bus.msg.UserSystemMsg; +import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum; +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.entity.bus.user.UserInfoExtra; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; +import com.yeshi.fanli.service.inter.config.ConfigService; +import com.yeshi.fanli.service.inter.msg.UserSystemMsgService; +import com.yeshi.fanli.service.inter.push.PushService; +import com.yeshi.fanli.service.inter.user.UserInfoExtraService; +import com.yeshi.fanli.service.inter.user.UserInfoService; +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.vip.UserVIPInfoService; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +@Controller("WXMPInviteController") +@RequestMapping("/wxmp/api/v1/invite") +public class InviteController { + + @Resource + private ThreeSaleSerivce threeSaleSerivce; + + @Resource + private ConfigService configService; + + @Resource + private UserInfoExtraService userInfoExtraService; + + @Resource + private UserVIPInfoService userVIPInfoService; + + @Resource + private ThreeSaleExtraInfoSerivce threeSaleExtraInfoSerivce; + + @Resource + private UserInfoService userInfoService; + + @Resource + private PushService pushService; + + @Resource + private UserSystemMsgService userSystemMsgService; + + /** + * 涓撳睘閭�璇风爜鏉′欢 + * + * @param acceptData + * @param uid + * @param out + */ + @RequestMapping(value = "tailorCode") + public void tailorCode(WXMPAcceptData acceptData, String callback, Long uid, PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult("鐢ㄦ埛id缂哄け")); + return; + } + + JSONArray array1 = new JSONArray(); + array1.add("1.閭�璇风爜鍙府鍔╁ソ鍙嬫縺娲婚個璇峰姛鑳斤紱"); + array1.add("2.濂藉弸閫氳繃浣犵殑閭�璇风爜婵�娲婚個璇峰姛鑳藉悗锛屽皢鎴愪负浣犵殑鐩存帴绮変笣锛屾湭鏉ヤ骇鐢熺殑璁㈠崟浣犻兘鏈夊閲戯紱"); + array1.add("3.閭�璇风爜鍏锋湁鍞竴鎬с��"); + + JSONObject desc1 = new JSONObject(); + desc1.put("title", "閭�璇风爜鐨勪綔鐢�"); + desc1.put("content",array1); + + JSONArray array2 = new JSONArray(); + array2.add("1.浣犲彲浠ヨ嚜鐢辫缃�4~12浣嶇畝鍗曟槗璁扮殑閭�璇风爜锛�"); + array2.add("2.涓撳睘閭�璇风爜鏄浣犲拰浣犵殑鍥㈤槦灏婅吹韬唤鐨勫桨鏄俱��"); + + JSONObject desc2 = new JSONObject(); + desc2.put("title", "涓撳睘閭�璇风爜浼樺娍"); + desc2.put("content",array2); + + JSONArray array = new JSONArray(); + array.add(desc1); + array.add(desc2); + + JSONObject data = new JSONObject(); + data.put("desc", array); + data.put("num", threeSaleSerivce.countFirstTeam(uid)); + data.put("limit", Constant.INVITE_CODRE_TAILOR_LIMIT); + + out.print(JsonUtil.loadTrueResult(data)); + } + + /** + * 鐢ㄦ埛闃熷憳缁熻 1.4.1 + * + * @param acceptData + * @param out + */ + @RequestMapping(value = "countMyTeam", method = RequestMethod.POST) + public void countMyTeam(WXMPAcceptData acceptData, long uid, PrintWriter out) { + try { + long firstTeam = threeSaleSerivce.countFirstTeam(uid); + long secondTeam = threeSaleSerivce.countSecondTeam(uid); + JSONObject bossData = new JSONObject(); + ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid); + if (threeSale != null) { + UserInfo boss = threeSale.getBoss(); + if (boss != null) { + bossData.put("nickName", boss.getNickName()); + bossData.put("portrait", boss.getPortrait()); + } + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); + Long createTime = threeSale.getCreateTime(); + Date inviteTime = new Date(createTime); + bossData.put("inviteTime", "閭�璇锋椂闂�: " + sdf.format(inviteTime)); + } + + JSONObject resultData = new JSONObject(); + + String helpLink = configService.getValue(ConfigKeyEnum.teamHelpUrl.getKey(),acceptData.getSystem()); + if (helpLink == null) { + helpLink = ""; + } + resultData.put("helpLink", helpLink); + resultData.put("firstTeam", firstTeam); + resultData.put("firstTeamTotal", firstTeam); + resultData.put("secondTeam", secondTeam); + resultData.put("secondTeamTotal", secondTeam); + resultData.put("boss", bossData); + + boolean hasCode = false; + String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); + if (inviteCode != null && inviteCode.trim().length() > 0) { + hasCode = true; // 宸叉湁閭�璇风爜 + } else { + // 閭�璇锋縺娲婚摼鎺� + resultData.put("activationlink", configService.getValue(ConfigKeyEnum.inviteActivationUrl.getKey(),acceptData.getSystem())); + } + resultData.put("hasCode", hasCode); + + out.print(JsonUtil.loadTrueResult(resultData)); + + } catch (Exception e) { + out.print(JsonUtil.loadFalseResult("缁熻澶辫触")); + e.printStackTrace(); + } + } + + /** + * + * @param acceptData + * @param out + */ + @RequestMapping(value = "listMyTeam") + public void listMyTeam(WXMPAcceptData acceptData, int 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.listFirstTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid); + count = threeSaleSerivce.countFirstTeam(uid); + } else if (type == 2) { + listTeam = threeSaleSerivce.listSecondTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid); + count = threeSaleSerivce.countSecondTeam(uid); + } + + boolean needVIPInfo = true; + + // 缁勭粐鏁版嵁 + JSONObject resultData = organizeTeam(count, listTeam, uid, type, needVIPInfo); + + // 绗竴椤靛垽鏂槸鍚︽縺娲� 鏄惁鏈夐槦鍛� + if (type == 1 && page == 1) { + boolean hasCode = false; + UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); + if (userInfoExtra != null) { + if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) + hasCode = true; + } + resultData.put("hasCode", hasCode); + resultData.put("hasTeam", count > 0 ? true : false); + } + out.print(JsonUtil.loadTrueResult(resultData)); + } + + /** + * 缁勭粐鏁版嵁 + * + * @param count + * @param list + * @param uid + * @param type + * @return + */ + private JSONObject organizeTeam(long count, List<ThreeSale> list, Long uid, int type, boolean needVipInfo) { + JSONObject result = new JSONObject(); + JSONArray resultArray = new JSONArray(); + + 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> workerIdList = new ArrayList<>(); + Map<Long, Boolean> vipMap = null; + if (needVipInfo) { + for (ThreeSale threeSale : list) + workerIdList.add(threeSale.getWorker().getId()); + if (workerIdList.size() > 0) + vipMap = userVIPInfoService.listByUids(workerIdList); + } + for (ThreeSale threeSale : list) { + UserInfo worker = threeSale.getWorker(); + if (worker == null) { + continue; + } + Long workerId = worker.getId(); + + JSONObject object = new JSONObject(); + object.put("workerId", worker.getId()); + object.put("nickName", worker.getNickName()); + object.put("portrait", worker.getPortrait()); + object.put("inviteId", threeSale.getId()); + + Date inviteTime = new Date(threeSale.getCreateTime()); + object.put("inviteTime", format.format(inviteTime) + " 鍔犲叆"); + // 娣诲姞鏄惁涓篤IP + if (vipMap != null && vipMap.get(worker.getId()) != null) { + object.put("vip", vipMap.get(worker.getId())); + } + String fontColor1 = "#888888"; + JSONArray array = new JSONArray(); + if (threeSale.getState()) { + Long lastLoginTime = worker.getLastLoginTime(); + if (lastLoginTime == null) { + lastLoginTime = threeSale.getCreateTime(); + } + + 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); + + // 涓�绾ч槦鍛� 鏌ヨ + if (type == 1) { + String memoName = null; + ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo(); + if (threeSaleExtraInfo != null) { + if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) { + memoName = threeSaleExtraInfo.getNickname(); + } + } + object.put("memoName", memoName); + + UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(workerId); + 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", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�"); + } + } + } + } + object.put("state", 1); + object.put("recentMsg", array); + resultArray.add(object); + } + + result.put("count", count); + result.put("list", resultArray); + return result; + } + + /** + * 鑾峰彇鐢ㄦ埛淇℃伅 + * @param acceptData + * @param uid + * @param out + */ + @RequestMapping(value = "getBossInfo", method = RequestMethod.POST) + public void getBossInfo(WXMPAcceptData acceptData, Long uid, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); + return; + } + JSONObject bossData = getBossInfo(uid, threeSaleSerivce.getMyBoss(uid),acceptData.getSystem()); + out.print(JsonUtil.loadTrueResult(bossData)); + } + + /** + * 绔欏唴淇℃彁閱掗槦鍛樻坊鍔犲井淇″彿 + * + * @param acceptData + * @param uid + * @param out + */ + @RequestMapping(value = "remindBossAddWX") + public void remindTeam(WXMPAcceptData acceptData, Long uid, PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult("浼犻�掑弬鏁扮己澶�")); + return; + } + + UserInfo userInfo = userInfoService.selectByPKey(uid); + if (userInfo == null) { + out.print(JsonUtil.loadFalseResult("鐢ㄦ埛淇℃伅涓嶅瓨鍦�")); + return; + } + + ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid); + if (threeSale == null) { + out.print(JsonUtil.loadFalseResult("娌℃湁閭�璇蜂汉")); + return; + } + + Long remindId = null; + boolean remindBoss = true; + if (uid.longValue() == threeSale.getWorker().getId().longValue()) { + remindId = threeSale.getBoss().getId(); // 鎻愰啋涓婄骇 + } else if (uid.longValue() == threeSale.getBoss().getId().longValue()) { + remindBoss = false; + remindId = threeSale.getWorker().getId(); // 鎻愰啋涓嬬骇 + } + + if (remindId == null) { + out.print(JsonUtil.loadFalseResult("淇℃伅楠岃瘉鏈�氳繃")); + return; + } + + Long bossId = null; + Long workerId = null; + String title = "绮変笣鎻愰啋娑堟伅"; + String content = ""; + if (remindBoss) { + // 鎻愮ず闃熼暱 + bossId = remindId; + workerId = uid; + content = "浣犵殑鐩存帴绮変笣" + userInfo.getNickName() + + "锛屾彁閱掍綘娣诲姞寰俊鍙凤紝浠ヤ究浜庡拰浣犲彇寰楄仈绯诲拰瀛︿範鐪侀挶鎶�宸э紝璧跺揩鍘绘坊鍔犲惂锛涙敞锛氳鍗囩骇鍒版湰杞欢鏈�鏂扮増鏈湪鈥滄垜鐨�-鎴戠殑淇℃伅鈥濅腑娣诲姞銆�"; + } else { + // 鎻愮ず闃熷憳 + bossId = uid; + workerId = remindId; + content = "浣犵殑閭�璇蜂汉" + userInfo.getNickName() + + "锛屾彁閱掍綘娣诲姞寰俊鍙凤紝浠ヤ究浜庡拰浣犲彇寰楄仈绯诲府鍔╀綘鏇村ソ鐨勭渷閽憋紝璧跺揩鍘绘坊鍔犲惂锛涙敞锛氳鍗囩骇鍒版湰杞欢鏈�鏂扮増鏈湪鈥滄垜鐨�-鎴戠殑淇℃伅鈥濅腑娣诲姞銆�"; + } + + try { + List<String> listIOS = new ArrayList<String>(); + List<String> listAndroid = new ArrayList<String>(); + pushService.pushZNX(remindId, title, content, listIOS, listAndroid,acceptData.getSystem()); + + userSystemMsgService.addUserSystemMsg(remindId, UserSystemMsgTypeEnum.common, title, content, + UserSystemMsg.TIME_TAG_COMMON, null); + + ThreeSaleExtraInfo newInfo = new ThreeSaleExtraInfo(); + if (remindBoss) { + newInfo.setRemindBoss(1); + } else { + newInfo.setRemindWorker(1); + } + + ThreeSaleExtraInfo threeExtra = threeSaleExtraInfoSerivce.getbyBossIdAndWorkerId(bossId, workerId); + if (threeExtra != null) { + newInfo.setId(threeExtra.getId()); + newInfo.setUpdateTime(new Date()); + threeSaleExtraInfoSerivce.updateByPrimaryKeySelective(newInfo); + } else { + newInfo.setBoss(new UserInfo(bossId)); + newInfo.setWorker(new UserInfo(workerId)); + newInfo.setCreateTime(new Date()); + newInfo.setUpdateTime(new Date()); + threeSaleExtraInfoSerivce.insertSelective(newInfo); + } + + JSONObject data = new JSONObject(); + data.put("weiXinState", 2); + data.put("weiXinTip", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�"); + out.print(JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadFalseResult("鎻愰啋澶辫触")); + } + } + + /** + * 涓婄骇淇℃伅缁勭粐 + * + * @param uid + * @param threeSale + * @return + */ + private JSONObject getBossInfo(long uid, ThreeSale threeSale, SystemEnum system) { + JSONObject bossData = new JSONObject(); + if (threeSale != null && threeSale.getBoss() != null) { + UserInfo boss = threeSale.getBoss(); + bossData.put("hasBoss", true); + bossData.put("inviteId", threeSale.getId()); + bossData.put("nickName", boss.getNickName()); + bossData.put("portrait", boss.getPortrait()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); + Long createTime = threeSale.getCreateTime(); + Date inviteTime = new Date(createTime); + + UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(boss.getId()); + if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) { + bossData.put("weiXin", userInfoExtra.getWeiXin()); + bossData.put("weiXinState", 3); + bossData.put("weiXinTip", "娣诲姞TA鐨勫井淇★紝浣犲彲鍚慣A瀛︿範濡備綍閫氳繃鏉挎牀蹇渷璧氶挶銆�"); + } else { + if (!threeSaleExtraInfoSerivce.isRemindBoss(boss.getId(), uid)) { + bossData.put("weiXinState", 1); + bossData.put("weiXinTip", "鐐瑰嚮鎻愰啋TA锛岀郴缁熶細鍙戦�佷竴灏佺珯鍐呬俊锛屾彁閱掑叾娣诲姞寰俊鍙枫��"); + } else { + bossData.put("weiXinState", 2); + bossData.put("weiXinTip", "绯荤粺宸插彂閫佹彁閱掞紝閭�璇蜂汉娣诲姞寰俊鍚庝綘鍙鍒讹紝濡傚鏂硅繜杩熶笉娣诲姞锛屼綘鍙仈绯讳汉宸ュ鏈嶅姹傚府鍔�"); + } + } + bossData.put("inviteTime", "浣犱簬 " + sdf.format(inviteTime) + "鎺ュ彈浜員A鐨勯個璇�"); + } else { + bossData.put("hasBoss", false); + bossData.put("helpLink", configService.getValue(ConfigKeyEnum.inviteCodeHlepLink.getKey(),system)); + bossData.put("weiXinTip", "鎭枩浣狅紝鎴戜滑鐨勪紭璐ㄧ敤鎴凤紱\r\n浣犲苟娌℃湁閭�璇蜂汉锛屼絾浣犵殑閭�璇锋縺娲诲姛鑳芥槸琚粯璁ゅ紑鍚殑锛沑r\n浣犳嫢鏈夌嫭鐗圭殑鏃犻個璇蜂汉婵�娲荤爜銆�"); + } + return bossData; + } +} -- Gitblit v1.8.0