From 01e773cf27e572b8fb83538d85f31130930d93d1 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期四, 15 八月 2019 15:57:23 +0800 Subject: [PATCH] 券赠送 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java | 305 +++++++++++++++++++++++++++----------------------- 1 files changed, 162 insertions(+), 143 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java index 0bb666b..b48198e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java @@ -7,6 +7,7 @@ import javax.annotation.Resource; +import org.json.simple.JSONArray; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -17,6 +18,7 @@ import com.yeshi.fanli.dto.jd.JDCouponInfo; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.dto.pdd.PDDGoodsResult; +import com.yeshi.fanli.dto.pdd.PDDPromotionUrl; import com.yeshi.fanli.dto.pdd.PDDSearchFilter; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.user.ShamUser; @@ -583,8 +585,7 @@ if (couponInfo != null) { // 鍒搁摼鎺ュ鐞� String materialId = "https://item.jd.com/" + id + ".html"; - String url = JDApiUtil.convertLink(materialId, couponInfo.getLink(), JDApiUtil.POSITION_COUPON + "", - null); + String url = JDApiUtil.convertLink(materialId, couponInfo.getLink(), JDApiUtil.POSITION_COUPON + "", null); couponInfo.setLink(url); } @@ -715,9 +716,11 @@ BigDecimal shareRate = hongBaoManageService.getShareRate(); GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, fanLiRate, shareRate); CouponInfoVO couponInfo = goodsDetail.getCouponInfo(); + PDDPromotionUrl convertUrl = null; if (couponInfo != null) { - String url = PinDuoDuoApiUtil.getPromotionUrl(id, PinDuoDuoApiUtil.PID_COUPON + "", null); - couponInfo.setLink(url); + convertUrl = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_COUPON + "", null); + if (convertUrl != null) + couponInfo.setLink(convertUrl.getUrl()); } ShopInfoVO shopInfo = goodsDetail.getShopInfo(); @@ -741,6 +744,11 @@ String salesTip = pddGoods.getSalesTip(); if (!StringUtil.isNullOrEmpty(salesTip)) { + int indexOf = salesTip.indexOf("+"); + if (indexOf > 0) { + salesTip = salesTip.substring(0, indexOf); + } + int totalSales = 0; if (salesTip.contains("涓�")) { salesTip = salesTip.substring(0, salesTip.indexOf("涓�")); @@ -776,12 +784,7 @@ extraVO.setStorage(userGoodsStorageService.isExistStorage(uid, id, Constant.SOURCE_TYPE_PDD)); } - // 娴嬭瘯 - SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, - "goods_detail_jump_taobao"); - if ("1".equalsIgnoreCase((params.getValue() + "").trim())) { - extraVO.setIsNative(true); - } + extraVO.setIsNative(true); // 鍒嗕韩璺緞 String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(), @@ -803,6 +806,11 @@ ShareVO shareInfoVO = new ShareVO(); shareInfoVO.setHelpLink(helpLink); extraVO.setShare(shareInfoVO); + + if (convertUrl != null) { + extraVO.setCouponJumpLink(convertUrl.getUrl()); + extraVO.setNativeCouponJumpLink(PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl())); + } JSONObject object = new JSONObject(); object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO)); @@ -834,148 +842,158 @@ goodsType = Constant.SOURCE_TYPE_TAOBAO; } - // 浜笢 - if (goodsType == Constant.SOURCE_TYPE_JD) { - JSONObject data = new JSONObject(); - data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>())); - - List<JDGoods> list = JDUtil.getRecommendGoodsById(id); - if (list == null) { - list = new ArrayList<JDGoods>(); - } else if (list.size() > 10) { - list = list.subList(0, 10); - } - - BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); - BigDecimal shareRate = hongBaoManageService.getShareRate(); - List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>(); - - for (JDGoods goods : list) { - listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, fanLiRate, shareRate)); - } - - // 鍙栧伓鏁颁釜鏁版嵁 - if (listDetailVO.size() % 2 != 0) { - listDetailVO.remove(listDetailVO.size() - 1); - } - - data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO)); - out.print(JsonUtil.loadTrueResult(data)); - return; - } - - // 鎷煎澶� - if (goodsType == Constant.SOURCE_TYPE_PDD) { - JSONObject data = new JSONObject(); - data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>())); - - List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>(); - - List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id); - if (goodsIdList != null && goodsIdList.size() > 0) { - PDDSearchFilter pddfilter = new PDDSearchFilter(); - pddfilter.setPage(1); - pddfilter.setPageSize(Constant.PAGE_SIZE); - Long[] strings = new Long[goodsIdList.size()]; - pddfilter.setGoodsIdList(goodsIdList.toArray(strings)); - - PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter); - if (result != null) { - List<PDDGoodsDetail> goodsList = result.getGoodsList(); - if (goodsList != null && goodsList.size() > 0) { - - if (goodsList.size() > 10) { - goodsList = goodsList.subList(0, 10); - } - - BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); - BigDecimal shareRate = hongBaoManageService.getShareRate(); - for (PDDGoodsDetail goods : goodsList) { - listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, fanLiRate, shareRate)); - } - } - } - } - - // 鍙栧伓鏁颁釜鏁版嵁 - if (listDetailVO.size() % 2 != 0) { - listDetailVO.remove(listDetailVO.size() - 1); - } - - data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO)); - out.print(JsonUtil.loadTrueResult(data)); - return; - } - - List<TaoBaoGoodsBrief> goodsList = TaoKeApiUtil.getRelationGoodsRecommend(id, 10); - // 鍒濆鍖� - if (goodsList == null) { - goodsList = new ArrayList<TaoBaoGoodsBrief>(); - } - - List<GoodsDetailVO> listExtra = new ArrayList<GoodsDetailVO>(); - TaoKeAppInfo app = new TaoKeAppInfo(); - app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); - app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); - app.setAdzoneId(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]); - app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT); - - List<Long> ids = new ArrayList<>(); - for (TaoBaoGoodsBrief goods : goodsList) - ids.add(goods.getAuctionId()); - try { - goodsList = TaoKeApiUtil.getBatchGoodsInfo(ids); - } catch (TaoKeApiException e1) { - e1.printStackTrace(); - } catch (TaobaoGoodsDownException e1) { - e1.printStackTrace(); - } - if (goodsList != null && goodsList.size() > 0) { + // 浜笢 + if (goodsType == Constant.SOURCE_TYPE_JD) { + JSONObject data = new JSONObject(); + data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>())); - BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); - BigDecimal shareRate = hongBaoManageService.getShareRate(); + List<JDGoods> list = JDUtil.getRecommendGoodsById(id); + if (list == null) { + list = new ArrayList<JDGoods>(); + } else if (list.size() > 10) { + list = list.subList(0, 10); + } - goodsList.parallelStream().forEach(goods -> { - if (goods != null) { - // 鑾峰彇璇︽儏 - TaoBaoGoodsBrief taoBaoGoodsBrief = null; - try { - taoBaoGoodsBrief = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goods.getAuctionId()); - } catch (Exception e) { - e.printStackTrace(); - } + BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); + BigDecimal shareRate = hongBaoManageService.getShareRate(); + List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>(); - if (taoBaoGoodsBrief == null) { - TaoBaoGoodsBrief newGoods = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app); - goods.setCouponInfo(newGoods.getCouponInfo()); - goods.setCouponLink(newGoods.getCouponLink()); - goods.setTkRate(newGoods.getTkRate()); - taoBaoGoodsBrief = goods; - } + for (JDGoods goods : list) { + listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, fanLiRate, shareRate)); + } - if (taoBaoGoodsBrief != null) { - listExtra.add(GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate)); + // 鍙栧伓鏁颁釜鏁版嵁 + if (listDetailVO.size() % 2 != 0) { + listDetailVO.remove(listDetailVO.size() - 1); + } + + data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO)); + out.print(JsonUtil.loadTrueResult(data)); + return; + } + + // 鎷煎澶� + if (goodsType == Constant.SOURCE_TYPE_PDD) { + JSONObject data = new JSONObject(); + data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>())); + + List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>(); + + List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id); + if (goodsIdList != null && goodsIdList.size() > 0) { + PDDSearchFilter pddfilter = new PDDSearchFilter(); + pddfilter.setPage(1); + pddfilter.setPageSize(Constant.PAGE_SIZE); + Long[] strings = new Long[goodsIdList.size()]; + pddfilter.setGoodsIdList(goodsIdList.toArray(strings)); + + PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter); + if (result != null) { + List<PDDGoodsDetail> goodsList = result.getGoodsList(); + if (goodsList != null && goodsList.size() > 0) { + + if (goodsList.size() > 10) { + goodsList = goodsList.subList(0, 10); + } + + BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); + BigDecimal shareRate = hongBaoManageService.getShareRate(); + for (PDDGoodsDetail goods : goodsList) { + listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, fanLiRate, shareRate)); + } + } } } - }); - } - List<GoodsDetailVO> listQuality = new ArrayList<GoodsDetailVO>(); - // 鍙栧伓鏁颁釜鏁版嵁 - if (listExtra.size() % 2 != 0) { - listExtra.remove(listExtra.size() - 1); - } + // 鍙栧伓鏁颁釜鏁版嵁 + if (listDetailVO.size() % 2 != 0) { + listDetailVO.remove(listDetailVO.size() - 1); + } - if (listQuality.size() % 2 != 0) { - listQuality.remove(listQuality.size() - 1); - } + data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO)); + out.print(JsonUtil.loadTrueResult(data)); + return; + } - JSONObject data = new JSONObject(); - data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listExtra)); - data.put("listGuess", JsonUtil.getApiCommonGson().toJson(listQuality)); - out.print(JsonUtil.loadTrueResult(data)); + List<TaoBaoGoodsBrief> goodsList = TaoKeApiUtil.getRelationGoodsRecommend(id, 10); + // 鍒濆鍖� + if (goodsList == null) { + goodsList = new ArrayList<TaoBaoGoodsBrief>(); + } + + List<GoodsDetailVO> listExtra = new ArrayList<GoodsDetailVO>(); + TaoKeAppInfo app = new TaoKeAppInfo(); + app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); + app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); + app.setAdzoneId(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]); + app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT); + + List<Long> ids = new ArrayList<>(); + for (TaoBaoGoodsBrief goods : goodsList) + ids.add(goods.getAuctionId()); + + try { + goodsList = TaoKeApiUtil.getBatchGoodsInfo(ids); + } catch (TaoKeApiException e1) { + e1.printStackTrace(); + } catch (TaobaoGoodsDownException e1) { + e1.printStackTrace(); + } + + if (goodsList != null && goodsList.size() > 0) { + + BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); + BigDecimal shareRate = hongBaoManageService.getShareRate(); + + goodsList.parallelStream().forEach(goods -> { + if (goods != null) { + // 鑾峰彇璇︽儏 + TaoBaoGoodsBrief taoBaoGoodsBrief = null; + try { + taoBaoGoodsBrief = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goods.getAuctionId()); + } catch (Exception e) { + e.printStackTrace(); + } + + if (taoBaoGoodsBrief == null) { + TaoBaoGoodsBrief newGoods = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app); + goods.setCouponInfo(newGoods.getCouponInfo()); + goods.setCouponLink(newGoods.getCouponLink()); + goods.setTkRate(newGoods.getTkRate()); + taoBaoGoodsBrief = goods; + } + + if (taoBaoGoodsBrief != null) { + listExtra.add( + GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate)); + } + } + }); + } + + List<GoodsDetailVO> listQuality = new ArrayList<GoodsDetailVO>(); + // 鍙栧伓鏁颁釜鏁版嵁 + if (listExtra.size() % 2 != 0) { + listExtra.remove(listExtra.size() - 1); + } + + if (listQuality.size() % 2 != 0) { + listQuality.remove(listQuality.size() - 1); + } + + JSONObject data = new JSONObject(); + data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listExtra)); + data.put("listGuess", JsonUtil.getApiCommonGson().toJson(listQuality)); + out.print(JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + JSONObject data = new JSONObject(); + data.put("listQuality", new JSONArray()); + data.put("listGuess", new JSONArray()); + out.print(JsonUtil.loadTrueResult(data)); + } } /** @@ -1060,10 +1078,11 @@ return; } - String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(id, PinDuoDuoApiUtil.PID_FANLI + "", uid + ""); + PDDPromotionUrl convertUrl = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_FANLI + "", uid + ""); JSONObject data = new JSONObject(); data.put("native", true); - data.put("jumpLink", jumpLink); + data.put("jumpLink", convertUrl.getUrl()); + data.put("nativeJumpLink", PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl())); out.print(JsonUtil.loadTrueResult(data)); } -- Gitblit v1.8.0