package com.yeshi.fanli.controller.client.v1.h5;
|
|
import java.io.PrintWriter;
|
import java.lang.reflect.Type;
|
import java.math.BigDecimal;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import com.yeshi.fanli.util.SystemInfoUtil;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.yeshi.utils.DateUtil;
|
import org.yeshi.utils.JsonUtil;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.yeshi.fanli.dto.GoodsMoneyConfigParamsDTO;
|
import com.yeshi.fanli.entity.accept.AcceptData;
|
import com.yeshi.fanli.entity.bus.user.UserInfo;
|
import com.yeshi.fanli.entity.bus.user.UserRankings;
|
import com.yeshi.fanli.entity.goods.PullNewGoods;
|
import com.yeshi.fanli.service.inter.goods.PullNewGoodsService;
|
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
|
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
|
import com.yeshi.fanli.service.inter.user.QrCodeService;
|
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.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
|
import com.yeshi.fanli.util.factory.goods.TaoBaoGoodsFactory;
|
import com.yeshi.fanli.vo.user.PullNewRuleVO;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("api/apph5/v1/pullNew")
|
public class AppH5PullNewController {
|
|
@Resource
|
private PullNewGoodsService pullNewGoodsService;
|
|
@Resource
|
private RedPackConfigService redPackConfigService;
|
|
@Resource
|
private UserRankingsService userRankingsService;
|
|
@Resource
|
private HongBaoManageService hongBaoManageService;
|
|
@Resource
|
private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
|
|
@Resource
|
private QrCodeService qrCodeService;
|
|
@Resource
|
private UserInfoService userInfoService;
|
|
@Resource
|
private UserInfoExtraService userInfoExtraService;
|
|
|
|
/**
|
* 拉新商品
|
*
|
* @param acceptData
|
* @param callback
|
* @param uid
|
* @param page
|
* @param goodsType
|
* @param out
|
*/
|
@RequestMapping("getGoodsList")
|
public void getGoodsList(AcceptData acceptData, String callback, Long uid, Integer page, PrintWriter out) {
|
if (acceptData.getSystem() == null)
|
acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
|
JSONArray array = new JSONArray();
|
List<PullNewGoods> list = pullNewGoodsService.listQuery((page-1)*Constant.PAGE_SIZE, Constant.PAGE_SIZE);
|
if (list != null && list.size() > 0) {
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
|
GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
|
acceptData.getVersion(),acceptData.getSystem());
|
paramsDTO.setBaseFanliRate(hongBaoManageService.getBaseFanliRate(acceptData.getSystem()));
|
|
for (PullNewGoods goods : list) {
|
array.add(gson.toJson(GoodsDetailVOFactory.convertTaoBao(TaoBaoGoodsFactory.create(goods),paramsDTO)));
|
}
|
}
|
|
|
JSONObject data = new JSONObject();
|
if (page == 1) {
|
String ruleStr = redPackConfigService.getValueByKey("pullnew_activity_rule");
|
if (!StringUtil.isNullOrEmpty(ruleStr)) {
|
Type type = new TypeToken<PullNewRuleVO>() {
|
}.getType();
|
PullNewRuleVO rule = new Gson().fromJson(ruleStr, type);
|
rule.setRuleName(DateUtil.getCurrentMonthChinese() + "月活动规则");
|
data.put("rule", rule);
|
}
|
data.put("tip", redPackConfigService.getValueByKey("pullnew_page_tip"));
|
}
|
data.put("count", pullNewGoodsService.countQuery());
|
data.put("list", array);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
* 拉新排行榜
|
*
|
* @param acceptData
|
* @param callback
|
* @param uid
|
* @param page
|
* @param out
|
*/
|
@RequestMapping("getRankList")
|
public void getRankList(AcceptData acceptData, String callback, Long uid, PrintWriter out) {
|
if (acceptData.getSystem() == null)
|
acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
|
JSONArray array = new JSONArray();
|
List<UserRankings> list = userRankingsService.getRankList(0, 10);
|
if (list != null && list.size() > 0) {
|
for (UserRankings rank : list) {
|
JSONObject user = new JSONObject();
|
user.put("nickName", rank.getNickName());
|
user.put("portrait", rank.getPortrait());
|
user.put("money", "¥ " + rank.getShareReward().setScale(2, BigDecimal.ROUND_DOWN));
|
array.add(user);
|
}
|
}
|
JSONObject data = new JSONObject();
|
data.put("count", array.size());
|
data.put("list", array);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
* 创建分享图
|
*
|
* @param acceptData
|
* @param callback
|
* @param uid
|
* @param out
|
*/
|
@RequestMapping("getShareImg")
|
public void getShareImg(AcceptData acceptData, String callback, Long uid, PrintWriter out) {
|
if (acceptData.getSystem() == null)
|
acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
|
if (uid == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户未登录"));
|
return;
|
}
|
|
UserInfo userInfo = userInfoService.selectByPKey(uid);
|
if (userInfo == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该用户不存在"));
|
return;
|
}
|
|
String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
|
if (StringUtil.isNullOrEmpty(inviteCode)) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("邀请码未激活"));
|
return;
|
}
|
|
PullNewRuleVO rule = null;
|
String ruleStr = redPackConfigService.getValueByKey("pullnew_activity_rule");
|
if (!StringUtil.isNullOrEmpty(ruleStr)) {
|
Type type = new TypeToken<PullNewRuleVO>() {
|
}.getType();
|
rule = new Gson().fromJson(ruleStr, type);
|
rule.setRuleName(DateUtil.getCurrentMonthChinese() + "月活动规则");
|
}
|
|
String url = qrCodeService.drawPullNewPoster(uid, userInfo.getPortrait(), inviteCode, rule);
|
if (StringUtil.isNullOrEmpty(url)) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("生成分享图失败"));
|
return;
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("imgUrl",url);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
}
|