From 1be32ab61d7ed248f190eead478bdd7f8b83edbe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 29 七月 2019 18:26:19 +0800 Subject: [PATCH] 添加判断京东/拼多多是否参与推广 --- fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java | 217 +++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 167 insertions(+), 50 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java index 01b0b1c..ef93756 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java @@ -13,6 +13,7 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; +import org.yeshi.utils.HttpUtil; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -42,6 +43,7 @@ public static Long POSITION_FANLI = 1834339426L; public static Long POSITION_SHARE = 1834289924L; + public static Long POSITION_COUPON = 1859510742L; // 璁㈠崟鏌ヨ绫诲瀷 public static int ORDER_TYPE_CREATETIME = 1;// 涓嬪崟鏃堕棿 @@ -171,6 +173,22 @@ result = resultJson.optJSONObject("jd_union_open_promotion_common_get_response").optString("result"); resultJson = JSONObject.fromObject(result); return resultJson.optJSONObject("data").optString("clickURL"); + } + + /** + * 杞摼鎺�-鐭繛鎺� + * @param materialId + * @param couponUrl + * @param positionId + * @param ext1 + * @return + */ + public static String convertShortLink(String materialId, String couponUrl, String positionId, String ext1) { + String url = convertLink(materialId, couponUrl, positionId, ext1); + if (!StringUtil.isNullOrEmpty(url)) { + url = HttpUtil.getShortLink(url); + } + return url; } @@ -315,8 +333,7 @@ // 浠锋牸淇℃伅 Object priceInfo = json.get("priceInfo"); JSONObject priceInfoJson = JSONObject.fromObject(priceInfo); - BigDecimal price = new BigDecimal(priceInfoJson.optString("price")); - goods.setPrice(price); + goods.setPrice(new BigDecimal(priceInfoJson.optString("price"))); // 搴楅摵淇℃伅 Object shopInfo = json.get("shopInfo"); @@ -348,53 +365,6 @@ commissionInfo.setCommissionShare(new BigDecimal(commissionJson.optString("commissionShare"))); goods.setCommissionInfo(commissionInfo); - - // 鍒镐俊鎭� - Object coupon = json.get("couponInfo"); - if (coupon != null) { - JSONObject couponJson = JSONObject.fromObject(coupon); - JSONArray couponArray = couponJson.optJSONArray("couponList"); - if (couponArray != null) { - BigDecimal gap = null; - JDCouponInfo couponInfo = null; - for (int i = 0; i < couponArray.size(); i++) { - boolean add = false; - JSONObject jdcoupon = couponArray.optJSONObject(i); - if (couponInfo == null) { - couponInfo = new JDCouponInfo(); - add = true; - } - - BigDecimal quota = new BigDecimal(jdcoupon.optString("quota")); - BigDecimal sub = MoneyBigDecimalUtil.sub(price, quota); - if (gap == null) { - gap = sub; - } else if (sub.compareTo(gap) == 0) { - BigDecimal discount = new BigDecimal(jdcoupon.optString("discount")); - if (discount.compareTo(couponInfo.getDiscount()) > 0) { - add = true; - } - } else if (sub.compareTo(gap) > 0) { - add = true; - } - - if (add) { - couponInfo.setBindType(jdcoupon.optInt("bindType")); - couponInfo.setDiscount(new BigDecimal(jdcoupon.optString("discount"))); - couponInfo.setQuota(new BigDecimal(jdcoupon.optString("quota"))); - couponInfo.setPlatformType(jdcoupon.optInt("platformType")); - couponInfo.setGetEndTime(jdcoupon.optLong("getEndTime")); - couponInfo.setGetStartTime(jdcoupon.optLong("getStartTime")); - couponInfo.setUseEndTime(jdcoupon.optLong("useEndTime")); - couponInfo.setUseStartTime(jdcoupon.optLong("useStartTime")); - couponInfo.setLink(jdcoupon.optString("link")); - } - } - goods.setCouponInfo(couponInfo); - } - } - - // 鍥剧墖淇℃伅 List<String> imageList = new ArrayList<String>(); Object images = json.get("imageInfo"); @@ -409,20 +379,75 @@ goods.setPicUrl(imageList.get(0)); } + BigDecimal price = new BigDecimal(priceInfoJson.optString("price")); // 鎷艰喘淇℃伅 Object pinGouInfo = json.get("pinGouInfo"); if (pinGouInfo != null) { JSONObject pinGouInfoJson = JSONObject.fromObject(pinGouInfo); if (!pinGouInfoJson.isEmpty()) { JDPingouInfo jdPinGouInfo = new JDPingouInfo(); - jdPinGouInfo.setPingouPrice(new BigDecimal(pinGouInfoJson.optString("pingouPrice"))); + price = new BigDecimal(pinGouInfoJson.optString("pingouPrice")); + jdPinGouInfo.setPingouPrice(price); jdPinGouInfo.setPingouTmCount(pinGouInfoJson.optLong("pingouTmCount")); jdPinGouInfo.setPingouUrl(pinGouInfoJson.optString("pingouUrl")); jdPinGouInfo.setTotalCount(pinGouInfoJson.optLong("totalCount")); jdPinGouInfo.setPingouEndTime(pinGouInfoJson.optLong("pingouEndTime")); jdPinGouInfo.setPingouStartTime(pinGouInfoJson.optLong("pingouStartTime")); + goods.setPinGouInfo(jdPinGouInfo); } } + + + + // 鍒镐俊鎭� + Object coupon = json.get("couponInfo"); + if (coupon != null) { + JSONObject couponJson = JSONObject.fromObject(coupon); + JSONArray couponArray = couponJson.optJSONArray("couponList"); + if (couponArray != null) { + BigDecimal discount_temp = null; + JDCouponInfo couponInfo = null; + for (int i = 0; i < couponArray.size(); i++) { + boolean add = false; + JSONObject jdcoupon = couponArray.optJSONObject(i); + + BigDecimal quota = new BigDecimal(jdcoupon.optString("quota")); + BigDecimal sub = MoneyBigDecimalUtil.sub(price, quota); + if (sub.compareTo(new BigDecimal(0)) < 0) { + continue; // 鍟嗗搧浠锋牸灏忎簬浼樻儬鍒镐环鏍奸檺鍒� + } + + // 鍒搁潰棰� + BigDecimal discount = new BigDecimal(jdcoupon.optString("discount")); + if (discount_temp == null) { + add = true; + discount_temp = discount; + } else if (discount_temp.compareTo(discount) > 0) { // 鍒搁潰棰濆ぇ + add = true; + } + + if (add) { + if (couponInfo == null) { + couponInfo = new JDCouponInfo(); + } + + couponInfo.setBindType(jdcoupon.optInt("bindType")); + couponInfo.setDiscount(new BigDecimal(jdcoupon.optString("discount"))); + couponInfo.setQuota(new BigDecimal(jdcoupon.optString("quota"))); + couponInfo.setPlatformType(jdcoupon.optInt("platformType")); + couponInfo.setGetEndTime(jdcoupon.optLong("getEndTime")); + couponInfo.setGetStartTime(jdcoupon.optLong("getStartTime")); + couponInfo.setUseEndTime(jdcoupon.optLong("useEndTime")); + couponInfo.setUseStartTime(jdcoupon.optLong("useStartTime")); + couponInfo.setLink(jdcoupon.optString("link")); + } + } + + goods.setCouponInfo(couponInfo); + } + } + + return goods; } @@ -476,6 +501,12 @@ commissionInfo.setCommission(MoneyBigDecimalUtil .div(goods.getPrice().multiply(commissionInfo.getCommissionShare()), new BigDecimal(100))); + String isFreeShipping = json.optString("isFreeShipping"); + if (!StringUtil.isNullOrEmpty(isFreeShipping)) { + goods.setIsFreeShipping(Integer.parseInt(isFreeShipping)); + } + + goods.setCommissionInfo(commissionInfo); goods.setCouponInfo(null); goods.setGoodCommentsShare(null); @@ -499,6 +530,92 @@ return goods; } + + + public static JDSearchResult getJingFenGoods(int pageIndex, int eliteId) { + JDSearchResult searchResult = new JDSearchResult(); + List<JDGoods> list = new ArrayList<>(); + JSONObject json = new JSONObject(); + json.put("pageIndex", pageIndex); + json.put("pageSize", 20); + json.put("sortName", "inOrderCount30DaysSku"); + json.put("sort", "desc"); + json.put("eliteId", eliteId); + + JSONObject jsonDTO = new JSONObject(); + jsonDTO.put("goodsReq", json); + + + String result = baseRequest2("jd.union.open.goods.jingfen.query", null, jsonDTO); + System.out.println(result); + JSONObject resultJson = JSONObject.fromObject(result); + resultJson = resultJson.optJSONObject("jd_union_open_goods_jingfen_query_response"); + if (resultJson.optInt("code") == 0) { + result = resultJson.optString("result"); + resultJson = JSONObject.fromObject(result); + String message = resultJson.optString("message"); + if ("SUCCESS".equalsIgnoreCase(message)) { + JSONArray array = resultJson.optJSONArray("data"); + if (array != null) { + for (int i = 0; i < array.size(); i++) { + JDGoods goods = parseJDGoods(array.optJSONObject(i)); + if (goods != null) + list.add(goods); + } + } + } + + long totalCount = resultJson.optLong("totalCount"); + PageEntity pageEntity = new PageEntity(); + pageEntity.setTotalCount(totalCount); + + searchResult.setPageEntity(pageEntity); + } + searchResult.setGoodsList(list); + return searchResult; + } + + + public static JDSearchResult getGoodsClass() { + JDSearchResult searchResult = new JDSearchResult(); + List<JDGoods> list = new ArrayList<>(); + JSONObject json = new JSONObject(); + json.put("parentId", 0); + json.put("grade", 0); + + JSONObject jsonDTO = new JSONObject(); + jsonDTO.put("req", json); + + + String result = baseRequest2("jd.union.open.category.goods.get", null, jsonDTO); + System.out.println(result); + JSONObject resultJson = JSONObject.fromObject(result); + resultJson = resultJson.optJSONObject("jd_union_open_goods_jingfen_query_response"); + if (resultJson.optInt("code") == 0) { + result = resultJson.optString("result"); + resultJson = JSONObject.fromObject(result); + String message = resultJson.optString("message"); + if ("SUCCESS".equalsIgnoreCase(message)) { + JSONArray array = resultJson.optJSONArray("data"); + if (array != null) { + for (int i = 0; i < array.size(); i++) { + JDGoods goods = parseJDGoods(array.optJSONObject(i)); + if (goods != null) + list.add(goods); + } + } + } + + long totalCount = resultJson.optLong("totalCount"); + PageEntity pageEntity = new PageEntity(); + pageEntity.setTotalCount(totalCount); + + searchResult.setPageEntity(pageEntity); + } + searchResult.setGoodsList(list); + return searchResult; + } + public static JDGoods getGoodsDetail(Long skuId) { List<Long> skuIdList = new ArrayList<>(); -- Gitblit v1.8.0