package com.yeshi.fanli.controller.client; import java.io.IOException; import java.io.PrintWriter; import java.math.BigDecimal; 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.system.System; import com.yeshi.fanli.entity.system.SystemClientParams; import com.yeshi.fanli.exception.NotExistObjectException; import com.yeshi.fanli.service.inter.config.InviteGetMoneyService; import com.yeshi.fanli.service.inter.config.SystemClientParamsService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.user.QrCodeService; import com.yeshi.fanli.service.inter.user.SpreadUserImgService; import com.yeshi.fanli.service.inter.user.UserRankingsService; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.Constant; 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 QrCodeService qrCodeService; @Resource private SpreadUserImgService spreadUserImgService; @Resource private TaoBaoGoodsBriefService taoBaoGoodsBriefService; @Resource private UserRankingsService userRankingsService; @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); JSONObject data = new JSONObject(); data.put("pageEntity", JsonUtil.getSimpleGsonWithDate().toJson(pageEntity)); data.put("everyDayTaskList", new JSONArray()); data.put("inviteGetMoneyList", 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())); out.print(JsonUtil.loadTrue(0, JsonUtil.getSimpleGson().toJson(data), "成功")); } /** * * 方法说明: 分享好友邀请图片 * * @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), "成功")); } }