From 51a4ff5d777028d52a19c314a99f796334cb7b51 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 23 十一月 2019 18:30:01 +0800 Subject: [PATCH] 配置文件修改 --- fanli/src/main/java/com/yeshi/fanli/util/jd/JDUtil.java | 204 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 195 insertions(+), 9 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 9ec8560..4140021 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 @@ -8,6 +8,8 @@ import java.math.BigDecimal; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +28,7 @@ import org.yeshi.utils.BigDecimalUtil; import org.yeshi.utils.HttpUtil; +import com.yeshi.fanli.dto.GoodsClassDTO; import com.yeshi.fanli.dto.jd.JDCommissionInfo; import com.yeshi.fanli.dto.jd.JDCouponInfo; import com.yeshi.fanli.dto.jd.JDPingouInfo; @@ -33,7 +36,6 @@ import com.yeshi.fanli.dto.jd.JDSearchResult; import com.yeshi.fanli.dto.jd.JDShopInfo; import com.yeshi.fanli.entity.jd.JDGoods; -import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; @@ -330,11 +332,13 @@ BigDecimal finalPriceDecimal = new BigDecimal(json.optString("finalPrice")); if (finalPriceDecimal != null && json.optString("hasCoupon") != null && json.optInt("hasCoupon") == 1 && json.optInt("couponRemainCnt") > 0) { + List<JDCouponInfo> couponList = new ArrayList<>(); 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); + couponList.add(coupon); + goods.setCouponInfoList(couponList); } } @@ -364,7 +368,7 @@ price = pinGouInfo.getPingouPrice(); } - JDCouponInfo couponInfo = goods.getCouponInfo(); + JDCouponInfo couponInfo = getShowCouponInfo(goods.getCouponInfoList(), price); if (couponInfo == null) { money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil .mul(MoneyBigDecimalUtil.mul(price, commissionInfo.getCommissionShare()), new BigDecimal("0.01")), @@ -391,18 +395,59 @@ } /** + * 鍟嗗搧浣i噾璁$畻 + * + * @param goods + * @param rate + * @return + */ + public static BigDecimal getGoodsFanLiMoneyPlus(JDGoods goods, BigDecimal rate) { + BigDecimal money = new BigDecimal(0); + BigDecimal commissionPlus = goods.getCommissionPlus(); + if (commissionPlus == null) { + return money; + } + + BigDecimal price = null; + JDPingouInfo pinGouInfo = goods.getPinGouInfo(); + if (pinGouInfo == null) { + price = goods.getPrice(); + } else { + price = pinGouInfo.getPingouPrice(); + } + + JDCouponInfo couponInfo = getShowCouponInfo(goods.getCouponInfoList(), price); + if (couponInfo == null) { + money = MoneyBigDecimalUtil.mul( + MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(price, commissionPlus), new BigDecimal("0.01")), + MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); + } else { + BigDecimal quota = couponInfo.getQuota(); + BigDecimal discount = couponInfo.getDiscount(); + if (quota.compareTo(price) <= 0 && price.compareTo(discount) > 0) { + + BigDecimal finalPrice = price.subtract(discount); + money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil + .mul(MoneyBigDecimalUtil.mul(finalPrice, commissionPlus), new BigDecimal("0.01")), + MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); + + } else {// 涓嶈兘鐢ㄥ埜 + money = MoneyBigDecimalUtil.mul( + MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(price, commissionPlus), new BigDecimal("0.01")), + MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); + } + } + // 杩斿埄姣斾緥涓哄師鏉ョ殑90% + return BigDecimalUtil.getWithNoZera(MoneyBigDecimalUtil.mul(money, new BigDecimal("0.9"))); + } + + /** * 璁$畻鍟嗗搧鍒稿悗浠凤紝娌℃湁鍒稿垯杩斿洖鍘熶环 * * @param goodsBrief * @return */ public static BigDecimal getQuanPrice(JDGoods jdGoods) { - JDCouponInfo couponInfo = jdGoods.getCouponInfo(); - if (couponInfo == null) { - return jdGoods.getPrice(); - } - - BigDecimal discount = couponInfo.getDiscount(); BigDecimal price = null; JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo(); if (pinGouInfo == null) { @@ -410,6 +455,12 @@ } else { price = pinGouInfo.getPingouPrice(); } + JDCouponInfo couponInfo = getShowCouponInfo(jdGoods.getCouponInfoList(), price); + if (couponInfo == null) { + return jdGoods.getPrice(); + } + + BigDecimal discount = couponInfo.getDiscount(); // 璁$畻鍒稿悗浠� BigDecimal sub = price.subtract(couponInfo.getQuota()); if (sub.compareTo(BigDecimal.valueOf(0)) >= 0) { @@ -629,4 +680,139 @@ return jdGoods; } + /** + * 鑾峰彇绫荤洰 + * + * @param level + * 绛夌骇 + * @param parentId + * 涓婄骇id + * @return + */ + public static List<GoodsClassDTO> getCategoryList(int level, int parentId) { + try { + // 璇锋眰鍦板潃 + String requestUrl = "https://union.jd.com/api/help/getCategoryList?level=%s&parentId=%s"; + // 鎵ц璇锋眰 + String result = HttpUtil.get(String.format(requestUrl, level, parentId)); + + if (!StringUtil.isNullOrEmpty(result)) { + JSONObject json = JSONObject.fromObject(result); + JSONArray jsonArray = json.getJSONArray("data"); + if (jsonArray != null && jsonArray.size() > 0) { + List<GoodsClassDTO> list = new ArrayList<GoodsClassDTO>(); + for (int i = 0; i < jsonArray.size(); i++) { + Object object = jsonArray.get(i); + if (object == null) + continue; + JSONObject jsonClass = JSONObject.fromObject(object); + + GoodsClassDTO goodsClass = new GoodsClassDTO(); + goodsClass.setId(jsonClass.optString("id")); + goodsClass.setName(jsonClass.optString("categoryName")); + list.add(goodsClass); + } + return list; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 鑾峰彇绫荤洰 + * + * @param level + * 绛夌骇 + * @param parentId + * 涓婄骇id + * @return + */ + public static List<GoodsClassDTO> getCategoryCommiPlus(int level, int parentId) { + try { + // 璇锋眰鍦板潃 + String requestUrl = "https://union.jd.com/api/help/getCategoryCommiPlus?level=%s&parentId=%s"; + // 鎵ц璇锋眰 + String result = HttpUtil.get(String.format(requestUrl, level, parentId)); + + if (!StringUtil.isNullOrEmpty(result)) { + JSONObject json = JSONObject.fromObject(result); + JSONArray jsonArray = json.getJSONArray("data"); + if (jsonArray != null && jsonArray.size() > 0) { + List<GoodsClassDTO> list = new ArrayList<GoodsClassDTO>(); + for (int i = 0; i < jsonArray.size(); i++) { + Object object = jsonArray.get(i); + if (object == null) + continue; + JSONObject jsonClass = JSONObject.fromObject(object); + + GoodsClassDTO goodsClass = new GoodsClassDTO(); + goodsClass.setId(jsonClass.optString("id")); + goodsClass.setName(jsonClass.optString("name")); + + String selfMobileComm = jsonClass.optString("selfMobileComm"); + if (!StringUtil.isNullOrEmpty(selfMobileComm)) + goodsClass.setSelfComm(new BigDecimal(selfMobileComm)); + + String popMobileComm = jsonClass.optString("popMobileComm"); + if (!StringUtil.isNullOrEmpty(popMobileComm)) + goodsClass.setPopComm(new BigDecimal(popMobileComm)); + + list.add(goodsClass); + } + return list; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 鑾峰彇闇�瑕佸睍绀虹殑鍒� + * + * @param couponInfoList + * 鍒稿垪琛� + * @param price + * 鍟嗗搧浠锋牸 + * @return + */ + public static JDCouponInfo getShowCouponInfo(List<JDCouponInfo> couponInfoList, BigDecimal price) { + if (couponInfoList != null && couponInfoList.size() > 0) { + // 鏍规嵁娑堣垂鏉′欢鎺掑簭 + Comparator<JDCouponInfo> cm = new Comparator<JDCouponInfo>() { + @Override + public int compare(JDCouponInfo o1, JDCouponInfo o2) { + return o1.getQuota().compareTo(o2.getQuota()); + } + }; + Collections.sort(couponInfoList, cm); + + // 璁剧疆鍒镐俊鎭负鏈�鎺ヨ繎鐨勪竴涓� + for (int i = couponInfoList.size() - 1; i >= 0; i--) { + if (couponInfoList.get(i).getQuota().compareTo(price) <= 0) { + return couponInfoList.get(i); + } + } + return couponInfoList.get(0); + } + return null; + } + + public static JDCouponInfo getShowCouponInfo(JDGoods goods) { + if (goods == null) + return null; + BigDecimal price = null; + JDPingouInfo pinGouInfo = goods.getPinGouInfo(); + if (pinGouInfo == null) { + price = goods.getPrice(); + } else { + price = pinGouInfo.getPingouPrice(); + } + return getShowCouponInfo(goods.getCouponInfoList(), price); + } + } -- Gitblit v1.8.0