admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/InviteController.java
@@ -1,463 +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 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) + " 加入");
         // 添加是否为VIP
         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的微信,你可向TA学习如何通过板栗快省赚钱。");
         } 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) + "接受了TA的邀请");
      } else {
         bossData.put("hasBoss", false);
         bossData.put("helpLink", configService.getValue(ConfigKeyEnum.inviteCodeHlepLink.getKey(),system));
         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) + " 加入");
         // 添加是否为VIP
         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的微信,你可向TA学习如何通过板栗快省赚钱。");
         } 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) + "接受了TA的邀请");
      } else {
         bossData.put("hasBoss", false);
         bossData.put("helpLink", configService.getValue(ConfigKeyEnum.inviteCodeHlepLink.getKey(),system));
         bossData.put("weiXinTip", "恭喜你,我们的优质用户;\r\n你并没有邀请人,但你的邀请激活功能是被默认开启的;\r\n你拥有独特的无邀请人激活码。");
      }
      return bossData;
   }
}