yujian
2020-06-09 554de444b87aab5f93cb1593a8095612cf9479a7
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java
@@ -25,6 +25,7 @@
import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum;
import com.yeshi.fanli.entity.bus.user.TeamFansInfo;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.ThreeSaleDetail;
import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -55,6 +56,7 @@
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.invite.TeamDailyRecordService;
import com.yeshi.fanli.service.inter.user.invite.TeamFansInfoService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleDetailService;
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;
@@ -151,8 +153,9 @@
   @Resource
   private TeamDailyRecordService teamDailyRecordService;
   @Resource
   private ThreeSaleDetailService threeSaleDetailService;
   /**
    * 邀请码验证
@@ -868,7 +871,7 @@
               listId.add(focusInfo.getWorkerId());
            }
         }
         if (listId != null && listId.size() > 0) {
            if (type == 1) {
               listTeam = threeSaleSerivce.listFirstTeam(0, Constant.PAGE_SIZE, uid, listId);
@@ -880,36 +883,36 @@
         countSecond = teamFansInfoService.count(2, uid, focus);
      }
      JSONArray array = organizeTeamNew(acceptData, listTeam, uid, type, true);
      long count = (type == 1) ? firstTeam : countSecond;
      JSONObject result = new JSONObject();
      result.put("firstTeam", firstTeam);
      result.put("secondTeam", countSecond);
      result.put("count", count);
      result.put("list", array);
      // 统计H5链接
      if (page == 1) {
         result.put("link", configService.get(ConfigKeyEnum.teamStatisticsLink.getKey()));
      }
      out.print(JsonUtil.loadTrueResult(result));
   }
   /**
    * 验证是否存在筛选条件
    *
    * @param focus
    * @return
    */
   private boolean existScreen(ThreeSaleFocusDTO focus) {
      if (focus.getStateValid() != null || focus.getTaobaoBind() != null || focus.getWeixinBind() != null
            || focus.getMinFansNum() != null || focus.getMinFansNum() != null
            || focus.getMinActiveTime() != null || focus.getMaxActiveTime() != null
            || focus.getMinIncome() != null  || focus.getMaxIncome() != null
             || focus.getMinJoinTime() != null  || focus.getMaxJoinTime() != null
            || focus.getMinFansNum() != null || focus.getMinFansNum() != null || focus.getMinActiveTime() != null
            || focus.getMaxActiveTime() != null || focus.getMinIncome() != null || focus.getMaxIncome() != null
            || focus.getMinJoinTime() != null || focus.getMaxJoinTime() != null
            || !StringUtil.isNullOrEmpty(focus.getKey()) || !StringUtil.isNullOrEmpty(focus.getLevel()))
          return true;
         return true;
      return false;
   }
@@ -998,7 +1001,6 @@
            highVIP.put("total", statistic.getHighFirstCount() + statistic.getHighSecondCount());
            superVIP.put("total", statistic.getSuperFirstCount() + statistic.getSuperSecondCount());
         }
         int darenToday = 0;
         int highVIPToday = 0;
@@ -1006,10 +1008,10 @@
         String createId = teamDailyRecordService.createId(uid, new Date());
         TeamDailyRecord record = teamDailyRecordService.getById(createId);
         if (record != null) {
            if (record.getFirstDaRen() != null)
            if (record.getFirstDaRen() != null)
               darenToday += record.getFirstDaRen();
            if (record.getSecondDaRen() != null)
               darenToday += record.getSecondDaRen();
               darenToday += record.getSecondDaRen();
            if (record.getFirstHighVIP() != null)
               highVIPToday += record.getFirstHighVIP();
            if (record.getSecondHighVIP() != null)
@@ -1019,36 +1021,34 @@
            if (record.getSecondSuperVIP() != null)
               superVIPToday += record.getSecondSuperVIP();
         }
         // 获取当月第一天和最后一天
         // 获取当月第一天和最后一天
         Calendar cale = Calendar.getInstance();
           SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
           String firstday, lastday;
           // 获取前月的第一天
           cale = Calendar.getInstance();
           cale.add(Calendar.MONTH, 0);
           cale.set(Calendar.DAY_OF_MONTH, 1);
           firstday = format.format(cale.getTime());
           // 获取前月的最后一天
           cale = Calendar.getInstance();
           cale.add(Calendar.MONTH, 1);
           cale.set(Calendar.DAY_OF_MONTH, 0);
           lastday = format.format(cale.getTime());
           int darenMonth = 0;
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         String firstday, lastday;
         // 获取前月的第一天
         cale = Calendar.getInstance();
         cale.add(Calendar.MONTH, 0);
         cale.set(Calendar.DAY_OF_MONTH, 1);
         firstday = format.format(cale.getTime());
         // 获取前月的最后一天
         cale = Calendar.getInstance();
         cale.add(Calendar.MONTH, 1);
         cale.set(Calendar.DAY_OF_MONTH, 0);
         lastday = format.format(cale.getTime());
         int darenMonth = 0;
         int highVIPMonth = 0;
         int superVIPMonth = 0;
         Date date = new Date();
         Date minTime = TimeUtil.parseYYYYMMDD(firstday);
         Date maxTime = TimeUtil.parseYYYYMMDD_HHMMSS(lastday + " 23:59:59");
         List<TeamDailyRecord> listMonth = teamDailyRecordService.sumGroupByYearMonth(uid, minTime, maxTime);
         if (listMonth != null && listMonth.size() > 0) {
            TeamDailyRecord teamRecord = listMonth.get(0);
            if (teamRecord.getFirstDaRen() != null)
            if (teamRecord.getFirstDaRen() != null)
               darenMonth += teamRecord.getFirstDaRen();
            if (teamRecord.getSecondDaRen() != null)
               darenMonth += teamRecord.getSecondDaRen();
               darenMonth += teamRecord.getSecondDaRen();
            if (teamRecord.getFirstHighVIP() != null)
               highVIPMonth += teamRecord.getFirstHighVIP();
            if (teamRecord.getSecondHighVIP() != null)
@@ -1064,10 +1064,10 @@
         // 高级会会员
         highVIP.put("today", highVIPToday);
         highVIP.put("month", highVIPMonth);
          // 统计超级会员数量
         // 统计超级会员数量
         superVIP.put("today", superVIPToday);
         superVIP.put("month", superVIPMonth);
         json.put("daren", daren);
         json.put("highVIP", highVIP);
         json.put("superVIP", superVIP);
@@ -1114,9 +1114,7 @@
            bossNickName = boss.getNickName();
         }
      }
      JSONArray tagArray = new JSONArray();
      String memoName = user.getNickName();
      Long succeedTime = threeSale.getSucceedTime();
@@ -1159,11 +1157,11 @@
         weixin = userInfoExtra.getWeiXin();
         activeTime = userInfoExtra.getActiveTime();
      }
      if (activeTime == null) {
         activeTime = new Date(user.getCreatetime());
      }
      data.put("weixin", StringUtil.isNullOrEmpty(weixin) ? "" : weixin);
      data.put("loginTime", TimeUtil.formatDate(activeTime));
@@ -1203,19 +1201,213 @@
      if (directNum > 0) {
         indirectNum = threeSaleSerivce.countSecondTeam(workerId);
      }
      data.put("fansNum", "直接粉丝: " + directNum + "人\n" + "间接粉丝: " + indirectNum + "人");
      
      // 订单统计
      long countTB = commonOrderCountService.countOrderBySourceAndNearDay(workerId, Constant.SOURCE_TYPE_TAOBAO, 60);
      long countJD = commonOrderCountService.countOrderBySourceAndNearDay(workerId, Constant.SOURCE_TYPE_JD, 60);
      long countPDD = commonOrderCountService.countOrderBySourceAndNearDay(workerId, Constant.SOURCE_TYPE_PDD, 60);
      
      data.put("fansNum", "直接粉丝: "+directNum+"人\n" + "间接粉丝: "+indirectNum+"人");
      data.put("orderInfo", "淘宝 ("+countTB+"笔)\n" + "京东 ("+countJD+"笔)\n" + "拼多多 ("+countPDD+"笔)");
      StringBuilder builder = new StringBuilder();
      builder.append("淘宝 (" + countTB + "笔)");
      builder.append("\n京东 (" + countJD + "笔)");
      builder.append("\n拼多多 (" + countPDD + "笔)");
      if (VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion())) {
         long countVip = commonOrderCountService.countOrderBySourceAndNearDay(workerId, Constant.SOURCE_TYPE_VIP, 60);
         long countSL = commonOrderCountService.countOrderBySourceAndNearDay(workerId, Constant.SOURCE_TYPE_SUNING, 60);
         builder.append("\n唯品会 (" + countVip + "笔)");
         builder.append("\n苏宁 (" + countSL + "笔)");
      }
      data.put("orderInfo", builder.toString());
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 获取粉丝信息
    *
    * @param acceptData
    * @param uid
    * @param workerId
    * @param out
    */
   @RequestMapping(value = "fansSearch")
   public void fansSearch(String callback, AcceptData acceptData, Long uid, String key, PrintWriter out) {
      if (uid == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户未登录"));
         return;
      }
      if (StringUtil.isNullOrEmpty(key)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请输入筛选信息"));
         return;
      }
      List<TeamFansInfo> listfocus = teamFansInfoService.queryByUserInfo(key);
      if (listfocus == null || listfocus.size() == 0) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "暂无相关信息"));
         return;
      }
      Long fansId = null;
      for (TeamFansInfo teamFansInfo : listfocus) {
         Long workerId = teamFansInfo.getWorkerId();
         ThreeSaleDetail threeDetail = threeSaleDetailService.getByBossUidAndWorkerUid(uid, workerId);
         if (threeDetail != null) {
            fansId = workerId;
            break;
         }
      }
      if (fansId == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "暂无相关信息"));
         return;
      }
      ThreeSale threeSale = threeSaleSerivce.getByWorkerId(fansId);
      if (threeSale == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "暂无相关信息"));
         return;
      }
      UserInfo user = userInfoService.selectByPKey(fansId);
      if (user == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "暂无相关信息"));
         return;
      }
      JSONObject data = new JSONObject();
      JSONObject inviteBoss = getInviteBoss(threeSale.getBoss().getId());
      data.put("boss", inviteBoss);
      String phone = user.getPhone();
      boolean phoneCopy = true;
      if (StringUtil.isNullOrEmpty(phone)) {
         phone = "";
      } else {
         if (!userCustomSettingsService.validateDisplayPhoneByUid(fansId)) {
            phoneCopy = false;
            phone = phone.substring(0, 7) + "****";
         }
      }
      data.put("fansId", fansId);
      data.put("nickName", user.getNickName());
      data.put("portrait", user.getPortrait());
      data.put("phone", phone);
      data.put("phoneCopy", phoneCopy);
      data.put("joinTime", TimeUtil.formatDate(threeSale.getSucceedTime() == null ? threeSale.getCreateTime() : threeSale.getSucceedTime()));
      Date activeTime = null;
      String weixin = null;
      UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(fansId);
      if (userInfoExtra != null) {
         weixin = userInfoExtra.getWeiXin();
         activeTime = userInfoExtra.getActiveTime();
      }
      if (activeTime == null) {
         activeTime = new Date(user.getCreatetime());
      }
      String inviteCode = "";
      if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
         inviteCode = userInfoExtra.getInviteCode();
      if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip()))
         inviteCode = userInfoExtra.getInviteCodeVip();
      data.put("inviteCode", inviteCode);
      data.put("weixin", StringUtil.isNullOrEmpty(weixin) ? "" : weixin);
      data.put("loginTime", TimeUtil.formatDate(activeTime));
      UserExtraTaoBaoInfo userExtraTaoBaoInfo = userExtraTaoBaoInfoService.getByUid(fansId);
      if (userExtraTaoBaoInfo != null && !StringUtil.isNullOrEmpty(userExtraTaoBaoInfo.getRelationId())
            && !StringUtil.isNullOrEmpty(userExtraTaoBaoInfo.getSpecialId())) {
         data.put("taobao", true);
      } else {
         data.put("taobao", false);
      }
      // 当前等级
      UserLevelEnum level = null;
      UserVIPLevel vipLevel = userInviteService.getVIPLevelByUid(fansId);
      if (vipLevel != null && vipLevel.getLevel() != null) {
         level = UserLevelUtil.getByLevel(vipLevel.getLevel());
      }
      if (level == null) {
         level = UserLevelEnum.daRen;
      }
      data.put("level", UserLevelUtil.getShowLevel(level));
      // 粉丝统计
      long indirectNum = 0;
      long directNum = threeSaleSerivce.countFirstTeam(fansId);
      if (directNum > 0) {
         indirectNum = threeSaleSerivce.countSecondTeam(fansId);
      }
      data.put("fansNum", "直接粉丝: " + directNum + "人\n" + "间接粉丝: " + indirectNum + "人");
      // 订单统计
      long countTB = commonOrderCountService.countOrderBySourceAndNearDay(fansId, Constant.SOURCE_TYPE_TAOBAO, 60);
      long countJD = commonOrderCountService.countOrderBySourceAndNearDay(fansId, Constant.SOURCE_TYPE_JD, 60);
      long countPDD = commonOrderCountService.countOrderBySourceAndNearDay(fansId, Constant.SOURCE_TYPE_PDD, 60);
      StringBuilder builder = new StringBuilder();
      builder.append("淘宝 (" + countTB + "笔)");
      builder.append("\n京东 (" + countJD + "笔)");
      builder.append("\n拼多多 (" + countPDD + "笔)");
      if (VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion())) {
         long countVip = commonOrderCountService.countOrderBySourceAndNearDay(fansId, Constant.SOURCE_TYPE_VIP, 60);
         long countSL = commonOrderCountService.countOrderBySourceAndNearDay(fansId, Constant.SOURCE_TYPE_SUNING, 60);
         builder.append("\n唯品会 (" + countVip + "笔)");
         builder.append("\n苏宁 (" + countSL + "笔)");
      }
      data.put("orderInfo", builder.toString());
      JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
   }
   private JSONObject getInviteBoss(Long bossId) {
      UserInfo userInfo = userInfoService.selectByPKey(bossId);
      boolean phoneCopy = true;
      String phone = userInfo.getPhone();
      if (StringUtil.isNullOrEmpty(phone)) {
         phone = "";
      } else {
         if (!userCustomSettingsService.validateDisplayPhoneByUid(bossId)) {
            phoneCopy = false;
            phone = phone.substring(0, 7) + "****";
         }
      }
      // 微信号
      String weixin = "";
      UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(bossId);
      if (extra != null) {
         weixin = StringUtil.isNullOrEmpty(extra.getWeiXin()) ? "" : extra.getWeiXin();
      }
      // 当前等级
      UserLevelEnum level = null;
      UserVIPLevel vipLevel = userInviteService.getVIPLevelByUid(bossId);
      if (vipLevel != null && vipLevel.getLevel() != null) {
         level = UserLevelUtil.getByLevel(vipLevel.getLevel());
      }
      if (level == null) {
         level = UserLevelEnum.daRen;
      }
      level = UserLevelUtil.getShowLevel(level);
      JSONObject bossObject = new JSONObject();
      bossObject.put("nickName", userInfo.getNickName());
      bossObject.put("portrait", userInfo.getPortrait());
      bossObject.put("phone", phone);
      bossObject.put("phoneCopy", phoneCopy);
      bossObject.put("weixin", weixin);
      bossObject.put("level", level.name());
      return bossObject;
   }
   /**
    * 保存粉丝信息
    * 
    * @param acceptData
    * @param uid
@@ -1257,9 +1449,8 @@
      out.print(JsonUtil.loadTrueResult("保存成功"));
   }
   /**
    *  队员数量统计
    * 队员数量统计
    * 
    * @param acceptData
    * @param id
@@ -1271,53 +1462,55 @@
         Date minDate = null;
         Date maxDate = null;
         long timeStamp = System.currentTimeMillis();
         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis(timeStamp);
         // 今日预估
         calendar.add(Calendar.DAY_OF_YEAR, -1);
         minDate = new Date(TimeUtil.convertDateToTemp(TimeUtil.getGernalTime(timeStamp)));
         TeamDailyRecord todayRecord = createVO(teamDailyRecordService.sumTeamNumGroupByCountDay(uid, minDate, null));
         TeamDailyRecord todayRecord = createVO(
               teamDailyRecordService.sumTeamNumGroupByCountDay(uid, minDate, null));
         // 昨日预估
         calendar.add(Calendar.DAY_OF_YEAR, -1);
         maxDate = new Date(TimeUtil.convertDateToTemp(TimeUtil.getGernalTime(timeStamp)));
         minDate = DateUtil.reduceDay(1, maxDate);
         TeamDailyRecord yesterdayRecord = createVO(teamDailyRecordService.sumTeamNumGroupByCountDay(uid, minDate, maxDate));
         TeamDailyRecord yesterdayRecord = createVO(
               teamDailyRecordService.sumTeamNumGroupByCountDay(uid, minDate, maxDate));
         // 本月预估
         maxDate = new Date(timeStamp);
         calendar = Calendar.getInstance();
         minDate = new Date(TimeUtil
               .convertToTimeTemp(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1), "yyyy-M"));
         minDate = new Date(TimeUtil.convertToTimeTemp(
               calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1), "yyyy-M"));
         calendar.add(Calendar.MONTH, -1);
         TeamDailyRecord monthRecord = createVO(teamDailyRecordService.sumTeamNumGroupByYearMonth(uid, minDate, maxDate));
         TeamDailyRecord monthRecord = createVO(
               teamDailyRecordService.sumTeamNumGroupByYearMonth(uid, minDate, maxDate));
         // 累计
         TeamDailyRecord totalityRecord = createVO(teamDailyRecordService.sumTeamNumGroupByUid(uid, null, null));
         JSONObject today = new JSONObject();
         today.put("direct", todayRecord.getFirstNum());
         today.put("indirect", todayRecord.getSecondNum());
         today.put("beyond", todayRecord.getBeyondNum());
         JSONObject yesterday = new JSONObject();
         yesterday.put("direct", yesterdayRecord.getFirstNum());
         yesterday.put("indirect", yesterdayRecord.getSecondNum());
         yesterday.put("beyond", yesterdayRecord.getBeyondNum());
         JSONObject month = new JSONObject();
         month.put("direct", monthRecord.getFirstNum());
         month.put("indirect", monthRecord.getSecondNum());
         month.put("beyond", monthRecord.getBeyondNum());
         JSONObject totality = new JSONObject();
         totality.put("direct", totalityRecord.getFirstNum());
         totality.put("indirect", totalityRecord.getSecondNum());
         totality.put("beyond", totalityRecord.getBeyondNum());
         JSONObject json = new JSONObject();
         json.put("today", today);
         json.put("yesterday", yesterday);
@@ -1329,24 +1522,22 @@
         e.printStackTrace();
      }
   }
   private TeamDailyRecord createVO(List<TeamDailyRecord> list) {
      TeamDailyRecord totalityRecord = new TeamDailyRecord(0,0,0);
      TeamDailyRecord totalityRecord = new TeamDailyRecord(0, 0, 0);
      if (list != null && list.size() > 0) {
         for (TeamDailyRecord record: list) {
         for (TeamDailyRecord record : list) {
            totalityRecord.setFirstNum(totalityRecord.getFirstNum() + record.getFirstNum());
            totalityRecord.setSecondNum(totalityRecord.getSecondNum() + record.getSecondNum());
            totalityRecord.setBeyondNum(totalityRecord.getBeyondNum() + record.getBeyondNum());
         }
      }
      }
      return totalityRecord;
   }
   /**
    * 邀请排行榜
    *
    * @param callback
    * @param acceptData
    * @param uid
@@ -1359,14 +1550,14 @@
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("参数缺失"));
         return;
      }
      try {
         Date minDate = null;
         Date maxDate = null;
         long timeStamp = System.currentTimeMillis();
         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis(timeStamp);
         if (dateType == 1) {
            // 今日
            calendar.add(Calendar.DAY_OF_YEAR, -1);
@@ -1380,21 +1571,20 @@
            // 本月
            maxDate = new Date(timeStamp);
            calendar = Calendar.getInstance();
            minDate = new Date(TimeUtil
                  .convertToTimeTemp(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1), "yyyy-M"));
            minDate = new Date(TimeUtil.convertToTimeTemp(
                  calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1), "yyyy-M"));
            calendar.add(Calendar.MONTH, -1);
         }
         List<OrderRankingVO> list = teamDailyRecordService.getRankingByFirstNum(uid, minDate, maxDate);
         if (list.size() > 0) {
            for (OrderRankingVO vo: list) {
            for (OrderRankingVO vo : list) {
               UserInfo user = userInfoService.getUserByIdWithMybatis(vo.getUid());
               vo.setNickName(user.getNickName());
               vo.setPortrait(user.getPortrait());
            }
         }
         JSONObject json = new JSONObject();
         json.put("list", list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(json));
@@ -1403,5 +1593,5 @@
         e.printStackTrace();
      }
   }
}