admin
2019-09-22 b9f8ef2c4737b6e6be4b12fc8f7bafb033bfcfe5
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java
@@ -22,17 +22,17 @@
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleExtraInfoSerivce;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
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.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v2/invite")
@@ -40,27 +40,28 @@
   @Resource
   private ConfigService configService;
   @Resource
   private PushService pushService;
   @Resource
   private UserSystemMsgService userSystemMsgService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserInfoService userInfoService;
   @Resource
   private UserInfoExtraService userInfoExtraService;
   @Resource
   private ThreeSaleExtraInfoSerivce threeSaleExtraInfoSerivce;
   /**
    * 邀请码验证
    *
    * @param out
    */
   @RequestMapping(value = "verifyCode")
@@ -76,16 +77,17 @@
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
      }
   }
   /**
    * 邀请码微信
    *
    * @param out
    */
   @RequestMapping(value = "verifyWX")
   public void verifyWX(AcceptData acceptData, Long uid, String code, PrintWriter out) {
      try {
         UserInfo userInfo = userInfoExtraService.getInviterInfo(uid, code);
         UserInfo userInfo = userInfoExtraService.getInviterInfo(
               Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()), uid, code);
         JSONObject data = new JSONObject();
         data.put("nickName", userInfo.getNickName());
         data.put("portrait", userInfo.getPortrait());
@@ -95,7 +97,7 @@
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
      }
   }
   /**
    * 用户队员列表查询 1.5.3查询有效队员
    * 
@@ -119,10 +121,10 @@
         listTeam = threeSaleSerivce.listSecondTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid, 1);
         count = threeSaleSerivce.countSecondTeam(uid, 1);
      }
      // 组织数据
      JSONObject resultData = organizeTeam(count, listTeam, uid, type);
      // 第一页判断是否激活 是否有队员
      if (type == 1 && page == 1) {
         boolean hasCode = false;
@@ -132,15 +134,14 @@
               hasCode = true;
         }
         resultData.put("hasCode", hasCode);
         resultData.put("hasTeam", count > 0? true:false);
         resultData.put("hasTeam", count > 0 ? true : false);
      }
      out.print(JsonUtil.loadTrueResult(resultData));
   }
   /**
    * 组织数据
    *
    * @param count
    * @param list
    * @param uid
@@ -150,28 +151,28 @@
   private JSONObject organizeTeam(long count, List<ThreeSale> list, Long uid, int type) {
      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");
      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) + " 加入");
         String fontColor1 = "#888888";
         JSONArray array = new JSONArray();
         if (threeSale.getState()) {
@@ -190,9 +191,9 @@
               contentJson.put("content", "最近登录 " + format.format(lastLoginTime));
            }
            array.add(contentJson);
            // 一级队员 查询
            if(type == 1) {
            if (type == 1) {
               String memoName = null;
               ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo();
               if (threeSaleExtraInfo != null) {
@@ -201,7 +202,7 @@
                  }
               }
               object.put("memoName", memoName);
               UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(workerId);
               if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) {
                  object.put("weiXin", userInfoExtra.getWeiXin());
@@ -217,7 +218,7 @@
                  }
               }
            }
         }
         }
         object.put("state", 1);
         object.put("recentMsg", array);
         resultArray.add(object);
@@ -228,7 +229,6 @@
      return result;
   }
   /**
    * 用户队员统计- IOS
    * 
@@ -240,7 +240,7 @@
   public void countMyTeam(AcceptData acceptData, long uid, PrintWriter out) {
      JSONObject bossData = getBossInfo(acceptData, uid, threeSaleSerivce.getMyBoss(uid));
      JSONObject resultData = new JSONObject();
      long firstTeam = threeSaleSerivce.countFirstTeam(uid, 1);
      resultData.put("boss", bossData);
      resultData.put("helpLink", configService.get("team_help_url"));
@@ -248,25 +248,25 @@
      resultData.put("firstTeamTotal", threeSaleSerivce.countFirstTeam(uid, null));
      resultData.put("secondTeam", threeSaleSerivce.countSecondTeam(uid, 1));
      resultData.put("secondTeamTotal", threeSaleSerivce.countSecondTeam(uid, null));
      boolean hasTeam = true;
      if (firstTeam <= 0) {
         hasTeam = false;
         resultData.put("invitelink", configService.get("invite_activation_url"));
      }
      resultData.put("hasTeam", hasTeam);
      boolean hasCode = false;
      boolean bdWeiXin = false;
      UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
      if (userInfoExtra != null) {
         if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
            hasCode = true;
         if (!StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin()))
            bdWeiXin = true;
      }
      // 未激活邀请码
      resultData.put("hasCode", hasCode);
      if (!hasCode) {
@@ -276,7 +276,7 @@
         tipCode.add("邀请激活功能,必须要有邀请码,邀请码可以通过金币兑换,也可以全网搜索。");
         resultData.put("tipCode", tipCode);
      }
      // 未添加微信号
      List<String> tipWeiXin = new ArrayList<String>();
      if (!bdWeiXin) {
@@ -286,12 +286,13 @@
      resultData.put("tipWeiXin", tipWeiXin);
      resultData.put("tipWeiXinAdd", "添加微信号后,你的邀请人和一级队员可以通过微信与你建立联系。");
      resultData.put("bdWeiXin", bdWeiXin);
      out.print(JsonUtil.loadTrueResult(resultData));
   }
   /**
    * 上级信息组织
    *
    * @param acceptData
    * @param uid
    * @param threeSale
@@ -308,7 +309,7 @@
         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());
@@ -327,15 +328,14 @@
      } else {
         bossData.put("hasBoss", false);
         bossData.put("helpLink", configService.get("invite_code_hlep_link"));
         bossData.put("weiXinTip", "恭喜你,我们的优质用户;\r\n你并没有邀请人,但你的邀请激活功能是被默认开启的;\r\n你拥有独特的无邀请人激活码。");
         bossData.put("weiXinTip", "恭喜你,我们的优质用户;\r\n你并没有邀请人,但你的邀请激活功能是被默认开启的;\r\n你拥有独特的无邀请人激活码。");
      }
      return bossData;
   }
   }
   /**
    * 站内信提醒队员添加微信号
    *
    * @param acceptData
    * @param uid
    * @param inviteId
@@ -347,41 +347,86 @@
         out.print(JsonUtil.loadFalseResult("传递参数缺失"));
         return;
      }
      UserInfo userInfo = userInfoService.selectByPKey(uid);
      if (userInfo == null) {
         out.print(JsonUtil.loadFalseResult("用户信息不存在"));
         return;
      }
      ThreeSale threeSale = threeSaleSerivce.selectByPrimaryKey(inviteId);
      if (threeSale == null) {
         out.print(JsonUtil.loadFalseResult("关系id不存在"));
         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 {
         // TODO版本区分
//         List<String> listIOS = new ArrayList<String>();
//         List<String> listAndroid = new ArrayList<String>();
//         pushService.pushZNX(remindId, "", "", listIOS, listAndroid);
//         userSystemMsgService.addUserSystemMsg(remindId, UserSystemMsgTypeEnum.question,
//               "", "", UserSystemMsg.TIME_TAG_EMERGENT, null);
         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("提醒失败"));
         return;
      }
   }
}