From f4548a3ee46afe45da4ee2a42dc169c575deee9f Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 31 七月 2019 11:57:36 +0800
Subject: [PATCH] 动态v2兼容

---
 fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java |  162 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 132 insertions(+), 30 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java
index b443d07..1b454ed 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java
@@ -20,6 +20,7 @@
 
 import com.yeshi.fanli.dto.jd.JDCommissionInfo;
 import com.yeshi.fanli.dto.jd.JDCouponInfo;
+import com.yeshi.fanli.dto.jd.JDPingouInfo;
 import com.yeshi.fanli.dto.jd.JDSearchFilter;
 import com.yeshi.fanli.dto.jd.JDSearchResult;
 import com.yeshi.fanli.dto.jd.JDShopInfo;
@@ -100,6 +101,12 @@
 		System.out.println(result);
 	}
 
+	
+	/**
+	 * 鎼滅储缃戦〉
+	 * @param searchFilter
+	 * @return
+	 */
 	@SuppressWarnings("deprecation")
 	public static JDSearchResult searchByKey(JDSearchFilter searchFilter) {
 
@@ -132,6 +139,7 @@
 	
 		String key = searchFilter.getKey();
 		if (StringUtil.isNullOrEmpty(key)) {
+			data.put("key", "");
 			data.put("keywordType", "kt0");
 			data.put("searchType", "st3");
 		} else {
@@ -176,20 +184,79 @@
 					JSONArray array = json.optJSONObject("data").optJSONArray("unionGoods");
 					if (array != null) {
 						for (int i = 0; i < array.size(); i++) {
-							goodsList.add(parseGoods(array.optJSONArray(i).optJSONObject(0).toString()));
+							JDGoods parseGoods = parseGoods(array.optJSONArray(i).optJSONObject(0).toString());
+							if (parseGoods != null) {
+								goodsList.add(parseGoods);
+							}
 						}
 					}
 				}
-				json.optJSONObject("data").optJSONArray("unionGoods");
 			}
-
-			System.out.println(result);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 
 		searchResult.setGoodsList(goodsList);
 		return searchResult;
+	}
+	
+	
+	/**
+	 * 鎼滅储缃戦〉
+	 * @param searchFilter
+	 * @return
+	 */
+	@SuppressWarnings("deprecation")
+	public static List<JDGoods> getRecommendGoodsById(Long skuId) {
+		List<JDGoods> goodsList = new ArrayList<>();
+		JSONObject params = new JSONObject();
+		params.put("pageNo", 1);
+		params.put("pageSize", 60);
+		params.put("searchUUID", StringUtil.Md5(System.currentTimeMillis() + ""));
+		
+		JSONObject data = new JSONObject();
+		data.put("lock", "0");
+		data.put("deliveryType", 0);
+		data.put("hasCoupon",0);
+		data.put("isCare", 0);
+		data.put("isPinGou", 0);
+		data.put("isZY", 0);
+		data.put("orientationFlag", 0);
+		
+		data.put("key", skuId);
+		data.put("keywordType", "kt0");
+		data.put("searchType", "st2");
+		params.put("data", data);
+		
+		HttpClient client = new HttpClient();
+		PostMethod pm = new PostMethod("https://union.jd.com/api/goods/search");
+		pm.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
+		pm.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
+		pm.setRequestHeader("Referer", "https://union.jd.com/proManager/index?pageNo=1&keywords=%E9%9E%8B%E5%AD%90");
+		pm.setRequestBody(params.toString());
+		try {
+			client.executeMethod(pm);
+			String result = pm.getResponseBodyAsString();
+			JSONObject json = JSONObject.fromObject(result);
+			if (json.optInt("code") == 200) {
+				if (json.optJSONObject("data") != null) {
+					JSONArray array = json.optJSONObject("data").optJSONArray("unionRecommendGoods");
+					if (array != null) {
+						for (int i = 0; i < array.size(); i++) {
+							JDGoods parseGoods = parseGoods(array.optJSONArray(i).optJSONObject(0).toString());
+							if (parseGoods != null) {
+								goodsList.add(parseGoods);
+							}
+						}
+					}
+				}
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		return goodsList;
 	}
 
 	public static JDGoods getGoodsDetail(Long skuId) {
@@ -203,23 +270,30 @@
 		return null;
 	}
 
+	
 	private static JDGoods parseGoods(String data) {
 		JDGoods goods = new JDGoods();
 		JSONObject json = JSONObject.fromObject(data);
+		
+		BigDecimal wlCommissionRatio = new BigDecimal(json.optString("wlCommissionRatio"));
+		if (wlCommissionRatio.compareTo(new BigDecimal(0)) > 0) {
+			JDCommissionInfo commission = new JDCommissionInfo();
+			commission.setCommission(new BigDecimal(json.optString("wlCommission")));
+			commission.setCommissionShare(wlCommissionRatio);
+			goods.setCommissionInfo(commission);
+		} else {
+			return null; // 杩囨护鏃犺繑鍒╁晢鍝�
+		}
+		
 		goods.setSkuId(json.optLong("skuId"));
 		goods.setSkuName(json.optString("skuName"));
-		
 		
 		JDShopInfo shopInfo = new JDShopInfo();
 		shopInfo.setShopId(json.optInt("shopId"));
 		shopInfo.setShopName(json.optString("shopName"));
 		goods.setShopInfo(shopInfo);
-
-		if (!StringUtil.isNullOrEmpty(json.optString("wlPrice")))
-			goods.setPrice(new BigDecimal(json.optString("wlPrice")));
-		else
-			goods.setPrice(new BigDecimal(json.optString("finalPrice")));
-		
+		goods.setPrice(new BigDecimal(json.optString("wlPrice")));
+	
 		goods.setInOrderCount30Days(json.optLong("inOrderCount30Days"));
 		
 		if (json.optInt("isZY") == 1)
@@ -229,23 +303,33 @@
 		
 		goods.setMaterialUrl("https://item.jd.com/"+ json.optLong("skuId") +".html");
 		goods.setPicUrl("http://img14.360buyimg.com/n1/" + json.optString("materialUrl"));
-		JDCommissionInfo commission = new JDCommissionInfo();
-		commission.setCommission(new BigDecimal(json.optString("wlCommission")));
-		commission.setCommissionShare(new BigDecimal(json.optString("wlCommissionRatio")));
-		goods.setCommissionInfo(commission);
+		
 		goods.setGoodCommentsShare(new BigDecimal(json.optString("goodCommentsShare")));
 
-		if (json.optString("hasCoupon") != null && json.optInt("hasCoupon") == 1
-				&& json.optInt("couponRemainCnt") > 0) {
-			// 鏈夊埜
-			JDCouponInfo coupon = new JDCouponInfo();
-			coupon.setDiscount(new BigDecimal(json.optString("couponDiscount")));
-			coupon.setQuota(new BigDecimal(json.optString("couponQuota")));
-			coupon.setLink("https:" + json.optString("couponLink"));
-			goods.setCouponInfo(coupon);
-		} else {
-			// 鏃犲埜
+		// 鍥㈣喘淇℃伅
+		if (json.optString("isPinGou") != null && json.optInt("isPinGou") == 1) {
+			JDPingouInfo jdPinGouInfo = new JDPingouInfo();
+			jdPinGouInfo.setPingouPrice(new BigDecimal(json.optString("pingouPrice")));
+			jdPinGouInfo.setPingouTmCount(json.optLong("pingouTmCount"));
+			goods.setPinGouInfo(jdPinGouInfo);
+		} 
+		
+		
+		String finalPrice = json.optString("finalPrice");
+		if (!StringUtil.isNullOrEmpty(finalPrice)) {
+			// 鍒镐俊鎭�
+			BigDecimal finalPriceDecimal = new BigDecimal(json.optString("finalPrice"));
+			if (finalPriceDecimal != null && json.optString("hasCoupon") != null && json.optInt("hasCoupon") == 1
+					&& json.optInt("couponRemainCnt") > 0) {
+				JDCouponInfo coupon = new JDCouponInfo();
+				coupon.setDiscount(new BigDecimal(json.optString("couponDiscount")));
+				coupon.setQuota(new BigDecimal(json.optString("couponQuota")));
+				coupon.setLink("https:" + json.optString("couponLink"));
+				goods.setCouponInfo(coupon);
+			} 
 		}
+		
+		
 		return goods;
 	}
 	
@@ -264,13 +348,20 @@
 			return money;
 		}
 		
+		BigDecimal price = null;
+		JDPingouInfo pinGouInfo = goods.getPinGouInfo();
+		if (pinGouInfo == null) {
+			 price =  goods.getPrice();
+		} else {
+			 price =  pinGouInfo.getPingouPrice();
+		}
+		
 		JDCouponInfo couponInfo = goods.getCouponInfo();
 		if (couponInfo == null) {
-			// 浣i噾
-			BigDecimal commission = commissionInfo.getCommission();
-			return MoneyBigDecimalUtil.mul(commission, MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
+			money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
+					MoneyBigDecimalUtil.mul(price,commissionInfo.getCommissionShare()),
+					new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
 		} else {
-			BigDecimal price = goods.getPrice();
 			BigDecimal quota = couponInfo.getQuota();
 			BigDecimal discount = couponInfo.getDiscount();
 			if (quota.compareTo(price) <= 0 && price.compareTo(discount) > 0) {
@@ -304,7 +395,13 @@
 		} 
 		
 		BigDecimal discount = couponInfo.getDiscount();
-		BigDecimal price = jdGoods.getPrice();
+		BigDecimal price = null;
+		JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo();
+		if (pinGouInfo == null) {
+			 price =  jdGoods.getPrice();
+		} else {
+			 price =  pinGouInfo.getPingouPrice();
+		}
 		// 璁$畻鍒稿悗浠�
 		BigDecimal sub = price.subtract(couponInfo.getQuota());
 		if (sub.compareTo(BigDecimal.valueOf(0)) >= 0) {
@@ -333,6 +430,11 @@
 		return salesCountMidea;
 	}
 	
+	/** 
+	 * 鎼滅储鍊欓�夎瘝
+	 * @param key
+	 * @return
+	 */
 	public static List<String> suggestSearch(String key) {
 		List<String> list = new ArrayList<>();
 		if (StringUtil.isNullOrEmpty(key))

--
Gitblit v1.8.0