admin
2020-05-21 49ed4f4521ce433a14810a0119bf3f2f7f6e606a
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;
@@ -152,7 +154,8 @@
   @Resource
   private TeamDailyRecordService teamDailyRecordService;
   
   @Resource
   private ThreeSaleDetailService threeSaleDetailService;
   /**
    * 邀请码验证
@@ -898,14 +901,14 @@
   
   /**
    * 验证是否存在筛选条件
    *
    * @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.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;
@@ -999,7 +1002,6 @@
            superVIP.put("total", statistic.getSuperFirstCount() + statistic.getSuperSecondCount());
         }
         
         int darenToday = 0;
         int highVIPToday = 0;
         int superVIPToday = 0;
@@ -1019,7 +1021,6 @@
            if (record.getSecondSuperVIP() != null)
               superVIPToday += record.getSecondSuperVIP();
         }
         
         // 获取当月第一天和最后一天 
         Calendar cale = Calendar.getInstance();
@@ -1114,8 +1115,6 @@
            bossNickName = boss.getNickName();
         }
      }
      
      JSONArray tagArray = new JSONArray();
      String memoName = user.getNickName();
@@ -1222,6 +1221,180 @@
    * @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);
      }
      // 订单统计
      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);
      data.put("fansNum", "直接粉丝: " + directNum + "人\n" + "间接粉丝: " + indirectNum + "人");
      data.put("orderInfo", "淘宝 (" + countTB + "笔)\n" + "京东 (" + countJD + "笔)\n" + "拼多多 (" + countPDD + "笔)");
      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
    * @param workerId
    * @param out
    */
   @RequestMapping(value = "saveTags")
   public void saveTags(AcceptData acceptData, Long uid, Long workerId, String tags, PrintWriter out) {
      if (uid == null || workerId == null) {
@@ -1257,7 +1430,6 @@
      out.print(JsonUtil.loadTrueResult("保存成功"));
   }
   /**
    *  队员数量统计
    * 
@@ -1278,21 +1450,24 @@
         // 今日预估
         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));
@@ -1317,7 +1492,6 @@
         totality.put("indirect", totalityRecord.getSecondNum());
         totality.put("beyond", totalityRecord.getBeyondNum());
         
         JSONObject json = new JSONObject();
         json.put("today", today);
         json.put("yesterday", yesterday);
@@ -1329,7 +1503,6 @@
         e.printStackTrace();
      }
   }
   
   private TeamDailyRecord createVO(List<TeamDailyRecord> list) {
      TeamDailyRecord totalityRecord = new TeamDailyRecord(0,0,0);
@@ -1343,10 +1516,9 @@
      return totalityRecord;
   }
   
   /**
    * 邀请排行榜
    *
    * @param callback
    * @param acceptData
    * @param uid
@@ -1380,11 +1552,10 @@
            // 本月
            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) {