package com.yeshi.fanli.controller.client; import java.io.IOException; import java.io.PrintWriter; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; 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.entity.accept.AcceptData; import com.yeshi.fanli.entity.admin.InviteGetMoney; import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture; import com.yeshi.fanli.entity.bus.user.ThreeSale; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.bus.user.UserInfoExtra; import com.yeshi.fanli.entity.system.System; import com.yeshi.fanli.entity.system.SystemClientParams; import com.yeshi.fanli.exception.NotExistObjectException; import com.yeshi.fanli.exception.banner.SwiperPictureException; import com.yeshi.fanli.exception.user.UserInfoExtraException; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.config.InviteGetMoneyService; import com.yeshi.fanli.service.inter.config.SystemClientParamsService; import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce; import com.yeshi.fanli.service.inter.user.SpreadUserImgService; import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.service.inter.user.UserRankingsService; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.account.UserUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** * * 类说明: 前端客户端所需接口 * * @author mawurui * @createTime 2018年4月2日 上午9:39:30 * @version /test/invite */ @Controller @RequestMapping("api/v1/invite") public class InviteGetMoneyController { @Resource private InviteGetMoneyService inviteGetMoneyService; @Resource private SystemClientParamsService systemClientParamsService; @Resource private SpreadUserImgService spreadUserImgService; @Resource private UserRankingsService userRankingsService; @Resource private ConfigService configService; @Resource private SwiperPictureService swiperPictureService; @Resource private UserInfoExtraService userInfoExtraService; @Resource private UserInfoService userInfoService; @Resource private ThreeSaleSerivce threeSaleSerivce; @RequestMapping(value = "/inviteGetMoney", method = RequestMethod.POST) public void everyDayTaskList(AcceptData acceptData, int pageIndex, PrintWriter out, String uid) throws NotExistObjectException { // 查询商品总数 Integer totalCount = 0; int totalPage = totalCount % Constant.PAGE_SIZE == 0 ? totalCount / Constant.PAGE_SIZE : totalCount / Constant.PAGE_SIZE + 1; PageEntity pageEntity = new PageEntity(pageIndex, Constant.PAGE_SIZE, totalCount, totalPage); /* * // 分页查询邀请提成榜 List inviteGetMoneyList = * inviteGetMoneyService.inviteGetMoneyList(pageIndex - 1, ""); * * // 名字*处理 for (InviteGetMoney inviteGetMoney : inviteGetMoneyList) { * * String name = inviteGetMoney.getName(); if (name != null) { if * (name.length() > 2) { name = Utils.getStarString(name, 1, * name.length() - 1); } else { name = name.substring(0, 1) + "**" + * name.substring(name.length() - 1); } } inviteGetMoney.setName(name); * inviteGetMoney.setRankIcon(UserUtil.getRankIcon(3)); } */ List inviteGetMoneyList = userRankingsService.getRank(0, 5); com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject(); data.put("pageEntity", JsonUtil.getSimpleGsonWithDate().toJson(pageEntity)); data.put("everyDayTaskList", new JSONArray()); data.put("inviteGetMoneyList", JSONArray.fromObject(JsonUtil.getSimpleGsonWithDate().toJson(inviteGetMoneyList))); if (uid.equals("0") || uid == null) { data.put("myTeam", "---"); data.put("moneyToday", "---"); data.put("moneyMonth", "---"); data.put("moneyLastMonth", "---"); } else { // 我的队员 int myFirstTeamCount = inviteGetMoneyService.myFirstTeamCount(uid); int mySecondTeamCount = inviteGetMoneyService.mySecondTeamCount(uid); int myTeamCount = myFirstTeamCount + mySecondTeamCount; data.put("myTeam", myTeamCount); // 今日 本月预估收益 BigDecimal moneyToday = inviteGetMoneyService.getMoneyToday(uid + ""); if (moneyToday == null) { moneyToday = new BigDecimal(0); } BigDecimal moneyMonth = inviteGetMoneyService.getMoneyMonth(uid + ""); if (moneyMonth == null) { moneyMonth = new BigDecimal(0); } BigDecimal moneyLastMonth = inviteGetMoneyService.getMoneyLastMonth(uid + ""); data.put("moneyToday", moneyToday.setScale(2, BigDecimal.ROUND_DOWN).toString()); data.put("moneyMonth", moneyMonth.setScale(2, BigDecimal.ROUND_DOWN).toString()); data.put("moneyLastMonth", moneyLastMonth.toString()); } // 活动规则 String key = "activityRules"; // key值 com.yeshi.fanli.entity.system.System system = new System(); system.setCreatetime(java.lang.System.currentTimeMillis()); system.setPlatform(1); system.setId(4L); SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, key); // 转换换行符 给前端 String valueN = values.getValue(); String valueBr = valueN.replace("\n", "

"); data.put("activityRules", valueBr); data.put("inviteList", String.format("http://%s/%s/client/share/friends_new.html", Constant.systemCommonConfig.getProjectHost(), Constant.systemCommonConfig.getProjectName())); try { List pictureList = swiperPictureService.getByBannerCard("invite_top_banner"); if (pictureList != null && pictureList.size() > 0) { SwiperPicture picture = pictureList.get(0); com.alibaba.fastjson.JSONObject pictureJson = new com.alibaba.fastjson.JSONObject(); pictureJson.put("src", picture.getSrc()); pictureJson.put("jumpDetail", picture.getJumpDetail()); pictureJson.put("params", picture.getParams()); data.put("topBanner", pictureJson); } } catch (SwiperPictureException e) { e.printStackTrace(); } data.put("desc", configService.get("invite_desc")); com.alibaba.fastjson.JSONObject root = new com.alibaba.fastjson.JSONObject(); root.put("code", 0); root.put("data", data); out.print(root.toString()); } /** * * 方法说明: 分享好友邀请图片 * * @author mawurui createTime 2018年4月3日 下午3:49:05 * @param pageIndex * @param out * @param uid * @throws NotExistObjectException * @throws IOException */ @RequestMapping(value = "/listInviteFriendImg", method = RequestMethod.POST) public void listInviteFriendImg(AcceptData acceptData, PrintWriter out, Long uid) throws NotExistObjectException, IOException { JSONObject data = new JSONObject(); if (uid != null && !uid.equals("0")) { List imgList = spreadUserImgService.getUserSpreadImg(uid); data.put("imgUrlList", JsonUtil.getSimpleGsonWithDate().toJson(imgList)); } // 邀请规则 String key = "inviteRules"; // key值 com.yeshi.fanli.entity.system.System system = new System(); system.setCreatetime(java.lang.System.currentTimeMillis()); system.setPlatform(1); system.setId(4L); SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, key); // 转换换行符 给前端 String valueN = values.getValue(); String valueBr = valueN.replace("\n", "

"); data.put("inviteRules", valueBr); out.print(JsonUtil.loadTrue(0, JsonUtil.getSimpleGson().toJson(data), "成功")); } /** * 邀请激活-特别提示语 * @param callback * @param out */ @RequestMapping(value = "getActivationTip") public void getActivationTip(AcceptData acceptData, String callback, PrintWriter out) { try { String tip = configService.get("invite_activation_tip"); if (tip == null || tip.trim().length() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无提醒")); return; } JSONObject data = new JSONObject(); data.put("tip", tip); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取失败")); e.printStackTrace(); } } /** * 激活邀请 * @param callback * @param uid 用户id * @param inviteCode 邀请嘛 * @param out */ @RequestMapping(value = "activationInvite") public void activationInvite(AcceptData acceptData, String callback, Long uid, String inviteCode, PrintWriter out) { try { if (uid == null || inviteCode == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); return; } String newCode = userInfoExtraService.activateInviteCode(uid, inviteCode); if (newCode == null || newCode.trim().length() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("激活失败")); return; } JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("激活成功")); } catch (UserInfoExtraException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("激活失败")); e.printStackTrace(); } } /** * 获取邀请码 * @param callback * @param uid 用户id * @param out */ @RequestMapping(value = "getInviteCode") public void getInviteCode(AcceptData acceptData, String callback, Long uid, PrintWriter out) { try { if (uid == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); return; } UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); if (userInfoExtra == null || userInfoExtra.getInviteCode() == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("邀请码不存在")); return; } String tip = configService.get("invite_activation_success_tip"); JSONObject data = new JSONObject(); data.put("inviteCode", userInfoExtra.getInviteCode()); data.put("tip", tip); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取数据失败")); e.printStackTrace(); } } /** * 获取邀请短连接 * @param callback * @param uid 用户id * @param out */ @RequestMapping(value = "getShortLink") public void getShortLink(AcceptData acceptData, String callback, Long uid, PrintWriter out) { try { if (uid == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); return; } String shortLink = UserUtil.getInviteShortLink(uid); JSONObject data = new JSONObject(); data.put("shortLink", shortLink); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("生成短连接失败")); e.printStackTrace(); } } /** * 获取邀请电话号码 * @param callback * @param uid 用户id * @param out */ @RequestMapping(value = "getUserPhone") public void getUserPhone(AcceptData acceptData, String callback, Long uid, PrintWriter out) { try { if (uid == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); return; } UserInfo userInfo = userInfoService.selectByPKey(uid); if (userInfo == null || userInfo.getPhone() == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂未绑定电话号码")); return; } JSONObject data = new JSONObject(); data.put("phone", userInfo.getPhone()); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取数据失败")); e.printStackTrace(); } } /** * 获取用户邀请上级 * @param callback * @param uid * @param out */ @RequestMapping(value = "getUserBoss") public void getUserBoss(AcceptData acceptData, String callback, Long uid, PrintWriter out) { if (uid == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不正确")); return; } try { ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid); if (threeSale == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "无上级邀请人")); return; } UserInfo boss = threeSale.getBoss(); if (boss == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("上级邀请人获取失败")); return; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); Long createTime = threeSale.getCreateTime(); Date inviteTime = new Date(createTime); JSONObject data = new JSONObject(); data.put("nickName", boss.getNickName()); data.put("portrait", boss.getPortrait()); data.put("inviteTime", sdf.format(inviteTime)); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取数据失败")); e.printStackTrace(); } } }