| | |
| | | package com.yeshi.fanli.controller;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
| | | import javax.servlet.http.HttpSession;
|
| | |
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.ui.Model;
|
| | | import org.springframework.web.bind.annotation.PathVariable;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.wx.WXUtil;
|
| | |
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
|
| | | import com.yeshi.fanli.entity.bus.user.InviteUser;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.system.BusinessSystem;
|
| | | import com.yeshi.fanli.entity.system.CustomerContent;
|
| | | import com.yeshi.fanli.entity.system.CustomerName;
|
| | | import com.yeshi.fanli.entity.system.SystemClientParams;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.exception.share.ShareGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.BusinessSystemService;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.util.AESUtil;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.GsonUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import com.yeshi.fanli.util.wx.WXLoginUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | |
| | |
|
| | | private static final String DOWNURL2 = "http://121.42.200.138/apk/fanliquan20180124.apk";
|
| | |
|
| | | @RequestMapping("coupon")
|
| | | public String conpon(Model model) {
|
| | | List<TaoBaoCoupon> couponList = taoBaoCouponService.getTaoBaoCouponList("", 1);
|
| | | BigDecimal proportion = hongBaoManageService.getFanLiRate();
|
| | | String jsonArr = Utils.imgListSize(JsonUtil.getApiCommonGson().toJson(couponList));
|
| | | JSONArray jsonArray = JSONArray.fromObject(jsonArr);
|
| | | List<TaoBaoCoupon> collection = (List<TaoBaoCoupon>) JSONArray.toCollection(jsonArray, TaoBaoCoupon.class);
|
| | | model.addAttribute("couponList", collection);
|
| | | model.addAttribute("proportion", proportion);
|
| | | return "coupon";
|
| | | }
|
| | |
|
| | | //该方法以及废弃
|
| | | @Deprecated
|
| | | @RequestMapping("findThreeFriendsCount")
|
| | | public void findThreeFriendsCount(long id, String callback, PrintWriter out) {
|
| | | |
| | | }
|
| | |
|
| | | //该方法以及废弃
|
| | | @Deprecated
|
| | | @RequestMapping("findThreeFriends")
|
| | | public void findThreeFriends(long id, int type, int page, String callback, PrintWriter out) {
|
| | | |
| | | }
|
| | |
|
| | | @RequestMapping(value = "getConpon", method = RequestMethod.POST)
|
| | | public void getConpon(int page, PrintWriter out) {
|
| | | List<TaoBaoCoupon> taoBaoCouponList = taoBaoCouponService.getTaoBaoCouponList("", page);
|
| | | BigDecimal proportion = hongBaoManageService.getFanLiRate();
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("taoBaoCouponList", Utils.imgListSize(JsonUtil.getApiCommonGson().toJson(taoBaoCouponList)));
|
| | | data.put("proportion", proportion);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | @RequestMapping("share")
|
| | | public String getShare(Model model, String uid) {
|
| | | String value = configService.get("share_message");
|
| | | try {
|
| | | if (uid == null) {
|
| | | uid = "0";
|
| | | }
|
| | | String base64String = StringUtil.getBase64String(uid + "");
|
| | | String format = MessageFormat.format(value, base64String);
|
| | | model.addAttribute("share", format);
|
| | | model.addAttribute("down",
|
| | | "http://file.sovideo.cn/buxinjie/weixinfriendinvite/index.html?yqm=" + base64String);
|
| | | model.addAttribute("shareCode", "邀请码:" + base64String);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "getcash";
|
| | | }
|
| | |
|
| | | @RequestMapping("shares")
|
| | | public String getShares(Model model, String uid) {
|
| | | String value = configService.get("share_message");
|
| | | try {
|
| | | if (uid == null) {
|
| | | uid = "0";
|
| | | }
|
| | | String base64String = StringUtil.getBase64String(uid + "");
|
| | | String format = MessageFormat.format(value, base64String);
|
| | | model.addAttribute("share", format);
|
| | | model.addAttribute("uid", uid);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "invite";
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "/{uid}")
|
| | | public String threeShareRep(@PathVariable String uid, String code, String state, String packages, String platform,
|
| | | String ios, HttpSession httpSession, HttpServletRequest request) {
|
| | |
|
| | | BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages);
|
| | | String wxState = (String) httpSession.getAttribute("wxState");
|
| | | // 通过配置参数获取
|
| | | String down = DOWNURL2;
|
| | |
|
| | | SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
|
| | | "fenxiao_download_apk_url");
|
| | | if (params != null)
|
| | | down = params.getValue();
|
| | | if ("2".equalsIgnoreCase(ios)) {
|
| | | down = DOWNURL;
|
| | | }
|
| | | if (state == null || !state.equals(wxState)) {// 不是微信返回的!
|
| | | // request.setAttribute("error", "1");
|
| | | return "redirect:" + down;
|
| | | }
|
| | |
|
| | | if (code == null) {// 用户取消了登陆!
|
| | | return "redirect:" + down;
|
| | | }
|
| | |
|
| | | UserInfo inviter = userInfoService.getUserById(Long.parseLong(uid));
|
| | | if (inviter == null) {// 没得这个人
|
| | | return "redirect:" + down;
|
| | | }
|
| | | boolean b = userInfoService.inviteWXUserInfo(code, inviter);
|
| | | if (!b) { // 绑定失败
|
| | | // request.setAttribute("msg", "非常遗憾,你已领取过红包,请勿再次领取。");
|
| | | return "redirect:" + down;
|
| | | }
|
| | |
|
| | | return "redirect:" + down;
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "/new/{uid}")
|
| | | public String threeShareRepNew(@PathVariable String uid, String code, String state, String packages,
|
| | | String platform, String ios, HttpSession httpSession, HttpServletRequest request) {
|
| | |
| | | if (params != null)
|
| | | down = params.getValue();
|
| | |
|
| | | if (!state.equals(wxState)) {// 不是微信返回的!
|
| | | if (state!=null&&!state.equals(wxState)) {// 不是微信返回的!
|
| | | // request.setAttribute("error", "1");
|
| | | return "redirect:" + down;
|
| | | }
|
| | |
| | | userInviteRecordService.saveInviteRecord(code, uid);
|
| | |
|
| | | return "redirect:" + down;
|
| | | }
|
| | |
|
| | | @RequestMapping("threeShare")
|
| | | public String threeShare(HttpServletRequest request, HttpSession session, long uid) {
|
| | | String serverName = request.getServerName();
|
| | | String contextPath = request.getContextPath();
|
| | | UserInfo userInfo = userInfoService.getUserById(uid);
|
| | | if (userInfo == null) {
|
| | | return "share/error";
|
| | | }
|
| | |
|
| | | try {
|
| | | String header = request.getHeader("User-Agent");// MicroMessenger:微信浏览器
|
| | | String ios = "ios=1";
|
| | | if (header.contains("iPhone")) {
|
| | | ios = "ios=2";
|
| | | }
|
| | | String redirect_uri = "http://" + serverName + contextPath + "/client/" + uid + "?packages="
|
| | | + Constant.systemCommonConfig.getAndroidPackageName() + "&platform=ANDROID&" + ios;
|
| | | redirect_uri = URLEncoder.encode(redirect_uri, "utf-8");
|
| | | long currentTimeMillis = java.lang.System.currentTimeMillis();
|
| | | String md5 = StringUtil.Md5(currentTimeMillis + "");
|
| | | session.setAttribute("wxState", md5);
|
| | | String baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WXLoginUtil.WEXIN_APPID
|
| | | + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=" + md5
|
| | | + "#wechat_redirect";
|
| | | // List<HongBaoMessage> list =
|
| | | // shamUserService.findShamThreeSaleInfo();
|
| | | request.setAttribute("jumpUrl", baseUrl);
|
| | | request.setAttribute("name", userInfo.getNickName());
|
| | | request.setAttribute("picture", userInfo.getPortrait());
|
| | | // request.setAttribute("list", list);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | return "share2/yaoqing";
|
| | | }
|
| | |
|
| | | // 新版分享
|
| | |
| | | }
|
| | |
|
| | | return "share2/yaoqing";
|
| | | }
|
| | |
|
| | | @RequestMapping("callBack")
|
| | | public void callBack(HttpServletRequest request, PrintWriter out) {
|
| | | if (!StringUtil.isNullOrEmpty(request.getParameter("echostr"))) {
|
| | | out.print(request.getParameter("echostr"));
|
| | | return;
|
| | | }
|
| | |
|
| | | Map<String, String> map = WXUtil.parseXML(request);
|
| | | String ghId = map.get("ToUserName");
|
| | | if (ghId == null) {
|
| | | out.print("");
|
| | | return;
|
| | | }
|
| | | String type = map.get("MsgType");
|
| | | if ("event".equalsIgnoreCase(type)) {
|
| | | String event = map.get("Event");
|
| | | if (event.equalsIgnoreCase("subscribe")) {// 关注
|
| | | Map<String, String> parmas = new HashMap<>();
|
| | | parmas.put("ToUserName", map.get("FromUserName"));
|
| | | parmas.put("FromUserName", ghId);
|
| | | parmas.put("CreateTime", java.lang.System.currentTimeMillis() / 1000 + "");
|
| | | parmas.put("MsgType", "text");
|
| | | parmas.put("Content", Constant.wxGZConfig.getWelcomeMsg());
|
| | | out.print(WXUtil.loadWXMessage(parmas));
|
| | | }
|
| | | } else if ("text".equalsIgnoreCase(type)) {
|
| | | String content = map.get("Content");
|
| | | if (!StringUtil.isNullOrEmpty(content)) {
|
| | | try {
|
| | | if (request.getSession().getAttribute("search-quan-" + map.get("FromUserName")) == null) {
|
| | | request.getSession().setAttribute("search-quan-" + map.get("FromUserName"), "1");
|
| | | SearchFilter sf = new SearchFilter();
|
| | | sf.setPage(1);
|
| | | sf.setPageSize(5);
|
| | | sf.setKey(content);
|
| | | sf.setQuan(1);
|
| | | TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiao(sf);
|
| | | if (result == null || result.getTaoBaoGoodsBriefs() == null
|
| | | || result.getTaoBaoGoodsBriefs().size() <= 0) {
|
| | | Map<String, String> parmas = new HashMap<>();
|
| | | parmas.put("ToUserName", map.get("FromUserName"));
|
| | | parmas.put("FromUserName", ghId);
|
| | | parmas.put("CreateTime", java.lang.System.currentTimeMillis() / 1000 + "");
|
| | | parmas.put("MsgType", "text");
|
| | | parmas.put("Content", String.format("[微笑]抱歉,没有能为你找到关于【%s】的优惠券,[机智]你可以试试其他关键词", content));
|
| | | out.print(WXUtil.loadWXMessage(parmas));
|
| | | } else {
|
| | | String host = HttpUtil.getHost(Constant.wxGZConfig.getH5Url());
|
| | | String url = HttpUtil.getShortLink("http://" + host + "/search.html?key=" + content);
|
| | | String text = String.format("[得意]已经为你找到了关于【%s】的优惠券 \n 👉 %s", content, url);
|
| | | Map<String, String> parmas = new HashMap<>();
|
| | | parmas.put("ToUserName", map.get("FromUserName"));
|
| | | parmas.put("FromUserName", ghId);
|
| | | parmas.put("CreateTime", java.lang.System.currentTimeMillis() / 1000 + "");
|
| | | parmas.put("MsgType", "text");
|
| | | parmas.put("Content", text);
|
| | | out.print(WXUtil.loadWXMessage(parmas));
|
| | | }
|
| | | }
|
| | |
|
| | | } finally {
|
| | | request.getSession().removeAttribute("search-quan-" + map.get("FromUserName"));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @RequestMapping("shareGoods")
|
| | | public void shareGoods(String auctionId, PrintWriter out) {
|
| | | TaoBaoGoodsBrief alimama = null;
|
| | | try {
|
| | | alimama = redisManager.getTaoBaoGoodsBrief(Long.parseLong(auctionId));
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (alimama != null) {
|
| | | List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | | TaoBaoGoodsBrief tb = null;
|
| | | try {
|
| | | tb = redisManager.getTaoBaoGoodsBrief(Long.parseLong(auctionId));
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(tb, config.get(0));
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("tb", GsonUtil.toJsonExpose(taoBaoGoodsBriefExtra));
|
| | | if ("1".equalsIgnoreCase(tb.getTkMktStatus())) {// 营销计划
|
| | | data.put("yxjh", 1);
|
| | | } else
|
| | | data.put("yxjh", 0);
|
| | |
|
| | | out.println(JsonUtil.loadTrueResult(data));
|
| | | return;
|
| | | }
|
| | | JsonUtil.loadFalseResult("商品已下架!");
|
| | | }
|
| | |
|
| | | @RequestMapping("getShareGoodsInfo")
|
| | |
| | | out.print(JsonUtil.loadFalseResult(e1.getCode(), e1.getMsg()));
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @RequestMapping("getShareGoodsDetail")
|
| | | public void getShareGoodsDetail(String uid, long id, String sign, PrintWriter out) {
|
| | | // 添加分享
|
| | | uid = AESUtil.decrypt(uid);
|
| | | if (StringUtil.isNullOrEmpty(uid)) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户ID不存在"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | UserShareGoodsHistory userShareGoodsHistory = shareGoodsService
|
| | | .getShareGoodsHistoryDetail(Long.parseLong(uid), id);
|
| | | if (userShareGoodsHistory == null) {
|
| | | out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
|
| | | return;
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = redisManager.getTaoBaoGoodsBrief(userShareGoodsHistory.getGoodsId());
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | JSONObject data = JSONObject.fromObject(JsonUtil.getSimpleGson().toJson(userShareGoodsHistory));
|
| | | JSONObject goodsJSON = new JSONObject();
|
| | | goodsJSON.put("title", goods.getTitle());
|
| | | goodsJSON.put("zkPrice", goods.getZkPrice());
|
| | | // 有券
|
| | | if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
|
| | | BigDecimal finalPrice = goods.getZkPrice();
|
| | | if (goods.getCouponStartFee().compareTo(goods.getZkPrice()) <= 0
|
| | | && goods.getZkPrice().compareTo(goods.getCouponAmount()) >= 0) {
|
| | | finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount());
|
| | | }
|
| | | goodsJSON.put("finalPrice", finalPrice);
|
| | | }
|
| | | data.put("goods", goodsJSON);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (ShareGoodsException e1) {
|
| | | out.print(JsonUtil.loadFalseResult(e1.getCode(), e1.getMsg()));
|
| | |
|
| | | e1.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|