yujian
2019-07-31 916cd2d0d5a6d3b3d9659c0037a2151da7cbeb7a
品牌好货
2个文件已修改
242 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/PDDCommonTemplateContentServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java 239 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/PDDCommonTemplateContentServiceImpl.java
@@ -12,6 +12,7 @@
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.service.inter.goods.PDDCommonTemplateContentService;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
@Service
public class PDDCommonTemplateContentServiceImpl implements PDDCommonTemplateContentService {
@@ -34,7 +35,7 @@
                pddfilter.setCatId(catId);
                pddfilter.setOptId(catId);
            }
            return PinDuoDuoApiUtil.searchGoods(pddfilter);
            return PinDuoDuoUtil.getBrandGoods(pddfilter);
        }
        return null;
    }
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.util.pinduoduo;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
@@ -18,19 +19,28 @@
import org.yeshi.utils.BigDecimalUtil;
import org.yeshi.utils.HttpUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
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.JDShopInfo;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class PinDuoDuoUtil {
    /**
     * 商品佣金计算
     *
     * @param goods
     * @param rate
     * @return
@@ -39,26 +49,26 @@
        BigDecimal money = null;
        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));
        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(price, promotionRate), rate);
        } else {
            BigDecimal amount =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred);
            BigDecimal startFree =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponMinOrderAmount()), hundred);
            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(finalPrice, promotionRate),rate);
                money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(finalPrice, promotionRate), rate);
            } else {// 不能用券
                money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(price,promotionRate), rate);
                money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(price, promotionRate), rate);
            }
        }
        return BigDecimalUtil.getWithNoZera(money).setScale(2);
    }
    /**
     * 计算商品券后价,没有券则返回原价
     * 
@@ -67,14 +77,14 @@
     */
    public static BigDecimal getQuanPrice(PDDGoodsDetail goods) {
        BigDecimal hundred = new BigDecimal(100);
        BigDecimal price =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), hundred);
        BigDecimal price = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), hundred);
        Boolean hasCoupon = goods.getHasCoupon();
        if (hasCoupon == null || !hasCoupon) {
            return price.setScale(2);
        }
        BigDecimal amount =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred);
        BigDecimal startFree =  MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponMinOrderAmount()), hundred);
        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.setScale(2);
@@ -82,14 +92,12 @@
            return price.setScale(2);
        }
    }
    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)
                    .userAgent(
                            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36")
            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();
            Elements els = doc.getElementsByTag("script");
            for (int i = 0; i < els.size(); i++) {
@@ -124,44 +132,43 @@
        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() + ""));
        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"));
                    }
        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://jinbao.pinduoduo.com/promotion/brand-promotion");
        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();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 搜索候选词
     *
     * @param key
     * @return
     */
@@ -193,4 +200,146 @@
        return list;
    }
    /**
     * 多多进宝爬取数据-品牌好货
     * @param sf
     * @return
     */
    public static PDDGoodsResult getBrandGoods(PDDSearchFilter sf) {
        JSONObject params = new JSONObject();
        params.put("pageNumber", sf.getPage());
        params.put("pageSize", sf.getPageSize());
        if (sf.getSortType() != null) {
            params.put("sortType", sf.getSortType());
        }
        if (sf.getHasCoupon() != null) {
            params.put("withCoupon", sf.getHasCoupon() ? 1 : 0);
        }
        if (sf.getKw() != null) {
            params.put("keyword", sf.getKw());
        } else {
            params.put("keyword", "");
        }
        if (sf.getOptId() != null) {
            params.put("optId", sf.getOptId());
        }
        if (sf.getCatId() != null) {
            params.put("categoryId", sf.getCatId());
        }
        System.out.println(params.toString());
        HttpClient client = new HttpClient();
        PostMethod pm = new PostMethod("https://jinbao.pinduoduo.com/network/api/common/brand/goodsList");
        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://jinbao.pinduoduo.com/promotion/brand-promotion");
        pm.setRequestBody(params.toString());
        PDDGoodsResult goodsResult = null;
        try {
            client.executeMethod(pm);
            String result = pm.getResponseBodyAsString();
            System.out.println(result);
            JSONObject json = JSONObject.fromObject(result);
            Boolean code = json.optBoolean("success");
            if (code != null && code) {
                JSONObject root = json.optJSONObject("result");
                if (root == null) {
                    return null;
                }
                JSONArray array = root.optJSONArray("goodsList");
                if (array == null) {
                    return null;
                }
                List<PDDGoodsDetail> goodsList = new ArrayList<PDDGoodsDetail>();
                for (int i = 0; i < array.size(); i++) {
                    PDDGoodsDetail parseGoods = parseGoods(array.getJSONObject(i));
                    if (parseGoods != null) {
                        goodsList.add(parseGoods);
                    }
                }
                int totalCount = root.optInt("total");
                goodsResult = new PDDGoodsResult();
                goodsResult.setGoodsList(goodsList);
                goodsResult.setTotalCount(totalCount);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return goodsResult;
    }
    private static PDDGoodsDetail parseGoods(JSONObject json) {
        PDDGoodsDetail goods = new PDDGoodsDetail();
        goods.setMallName(json.optString("mallName"));
        goods.setMerchantType(json.optInt("merchantType"));
        goods.setGoodsId(json.optLong("goodsId"));
        goods.setGoodsName(json.optString("goodsName"));
        goods.setGoodsDesc(json.optString("goodsDesc"));
        goods.setGoodsImageUrl(json.optString("goodsImageUrl"));
        goods.setGoodsThumbnailUrl(json.optString("goodsThumbnailUrl"));
        goods.setSalesTip(json.optString("salesTip"));
        goods.setCategoryName(json.optString("categoryName"));
        goods.setHasCoupon(json.optBoolean("hasCoupon"));
        if (json.optString("minGroupPrice") != null) {
            goods.setMinGroupPrice(json.getLong("minGroupPrice"));
        }
        if (json.optString("categoryId") != null) {
            goods.setCategoryId(json.getLong("categoryId"));
        }
        if (json.optString("couponMinOrderAmount") != null) {
            goods.setCouponMinOrderAmount(json.getLong("couponMinOrderAmount"));
        }
        if (json.optString("couponDiscount") != null) {
            goods.setCouponDiscount(json.getLong("couponDiscount"));
        }
        if (json.optString("couponDiscount") != null) {
            goods.setMinNormalPrice(json.getLong("couponDiscount"));
        }
        if (json.optString("couponTotalQuantity") != null) {
            goods.setCouponTotalQuantity(json.getLong("couponTotalQuantity"));
        }
        if (json.optString("couponRemainQuantity") != null) {
            goods.setCouponRemainQuantity(json.getLong("couponRemainQuantity"));
        }
        if (json.optString("couponStartTime") != null) {
            goods.setCouponStartTime(json.getLong("couponStartTime"));
        }
        if (json.optString("couponEndTime") != null) {
            goods.setCouponEndTime(json.getLong("couponEndTime"));
        }
        if (json.optString("promotionRate") != null) {
            goods.setPromotionRate(json.getLong("promotionRate"));
        }
        if (json.optString("optId") != null) {
            goods.setOptId(json.getLong("optId"));
        }
        return goods;
    }
}