From cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 29 七月 2019 10:46:32 +0800 Subject: [PATCH] 订单商品类型处理 --- fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java | 129 ++++++++++++++++++++++++++++++------------ 1 files changed, 92 insertions(+), 37 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java index ea48da6..66d4442 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java @@ -1,6 +1,8 @@ package com.yeshi.fanli.util.pinduoduo; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; @@ -8,13 +10,17 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.PostMethod; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import org.yeshi.utils.BigDecimalUtil; +import org.yeshi.utils.HttpUtil; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.util.MoneyBigDecimalUtil; +import com.yeshi.fanli.util.StringUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -31,30 +37,25 @@ */ public static BigDecimal getGoodsFanLiMoney(PDDGoodsDetail goods, BigDecimal rate) { BigDecimal money = null; - BigDecimal price = new BigDecimal(goods.getMinNormalPrice()); - BigDecimal promotionRate = new BigDecimal(goods.getPromotionRate()); + BigDecimal hundred = new BigDecimal(100); + rate = MoneyBigDecimalUtil.div(rate, hundred); + BigDecimal price = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), hundred).setScale(2); + BigDecimal promotionRate = MoneyBigDecimalUtil.div(new BigDecimal(goods.getPromotionRate()), new BigDecimal(1000)); Boolean hasCoupon = goods.getHasCoupon(); if (hasCoupon == null || !hasCoupon) { - money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul( - MoneyBigDecimalUtil.mul(price, promotionRate),new BigDecimal("0.001")), - MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); + money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(price, promotionRate), rate); } else { - BigDecimal amount = new BigDecimal(goods.getCouponDiscount()); - BigDecimal startFree = new BigDecimal(goods.getCouponMinOrderAmount()); + BigDecimal amount = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred); + BigDecimal startFree = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponMinOrderAmount()), hundred); if (startFree.compareTo(price) <= 0 && price.compareTo(amount) > 0) { BigDecimal finalPrice = price.subtract(amount); - money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil - .mul(MoneyBigDecimalUtil.mul(finalPrice, promotionRate), new BigDecimal("0.001")), - MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); - + money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(finalPrice, promotionRate),rate); } else {// 涓嶈兘鐢ㄥ埜 - money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul( - MoneyBigDecimalUtil.mul(price,promotionRate), new BigDecimal("0.001")), - MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); + money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(price,promotionRate), rate); } } - return BigDecimalUtil.getWithNoZera(money); + return BigDecimalUtil.getWithNoZera(money).setScale(2); } @@ -65,42 +66,28 @@ * @return */ public static BigDecimal getQuanPrice(PDDGoodsDetail goods) { - BigDecimal price = new BigDecimal(goods.getMinNormalPrice()); + BigDecimal hundred = new BigDecimal(100); + BigDecimal price = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), hundred); Boolean hasCoupon = goods.getHasCoupon(); if (hasCoupon == null || !hasCoupon) { - return price; + return price.setScale(2); } - BigDecimal amount = new BigDecimal(goods.getCouponDiscount()); - BigDecimal startFree = new BigDecimal(goods.getCouponMinOrderAmount()); + BigDecimal amount = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred); + BigDecimal startFree = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponMinOrderAmount()), hundred); if (startFree.compareTo(price) <= 0) { BigDecimal quanPrice = MoneyBigDecimalUtil.sub(price, amount); - return quanPrice; + return quanPrice.setScale(2); } else { - return price; + return price.setScale(2); } } - public static String getSaleCount(long count) { - String salesCountMidea = null; - if (count < 10000) { - salesCountMidea = count + ""; - } else { - double sales = count; - salesCountMidea = String.format("%.1f", sales / 10000); - salesCountMidea = salesCountMidea + "涓�"; - } - return salesCountMidea; - } - - - - public static List<String> getDetailImages(Long id) { List<String> imgList = new ArrayList<>(); try { - Document doc = Jsoup.connect("http://yangkeduo.com/goods.html?goods_id="+id) + Document doc = Jsoup.connect("http://yangkeduo.com/goods.html?goods_id=" + id) .userAgent( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36") .get(); @@ -137,5 +124,73 @@ return imgList; } + + + + public static List<Long> getRecommendGoodsId(Long id) { + List<Long> list = new ArrayList<Long>(); + JSONObject params = new JSONObject(); + params.put("pageNo", 1); + params.put("show_tags", 1); + params.put("goods_id", id); + params.put("app_name", "goods_detail"); + params.put("list_id", "goods_detail_HgfiMc"); + params.put("pdduid", StringUtil.Md5(System.currentTimeMillis() + "")); + + HttpClient client = new HttpClient(); + PostMethod pm = new PostMethod("https://mobile.yangkeduo.com/proxy/api/api/tesla/query"); + 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); + JSONArray array = json.optJSONArray("data"); + if (array != null) { + for (int i = 0; i < array.size(); i++) { + list.add(array.optJSONObject(i).optLong("goods_id")); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return list; + } + + /** + * 鎼滅储鍊欓�夎瘝 + * @param key + * @return + */ + public static List<String> suggestSearch(String key) { + List<String> list = new ArrayList<>(); + if (StringUtil.isNullOrEmpty(key)) + return list; + String url = null; + try { + url = String.format("http://apiv3.yangkeduo.com/search_suggest?query=%s&pdduid=0", + URLEncoder.encode(key, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + if (url == null) + return list; + try { + String result = HttpUtil.get(url); + JSONObject dataJSON = JSONObject.fromObject(result); + JSONArray array = dataJSON.optJSONArray("suggest_list"); + for (int i = 0; i < array.size(); i++) { + String sk = array.optJSONObject(i).optJSONObject("item_data").optString("suggestion"); + if (!StringUtil.isNullOrEmpty(sk)) + list.add(sk); + } + } catch (Exception e) { + } + return list; + } } -- Gitblit v1.8.0