| | |
| | |
|
| | | 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;
|
| | |
| | | import com.yeshi.fanli.dto.jd.JDFilter;
|
| | | import com.yeshi.fanli.dto.jd.JDOrderResult;
|
| | | import com.yeshi.fanli.dto.jd.JDPingouInfo;
|
| | | 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.jd.JDOrder;
|
| | | import com.yeshi.fanli.tag.PageEntity;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
| | |
|
| | | 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;// 下单时间
|
| | |
| | | *
|
| | | * @return
|
| | | */
|
| | | public static String convertLink(String materialId, String couponUrl, String pid) {
|
| | | public static String convertLink(String materialId, String couponUrl, String positionId, String ext1) {
|
| | | JSONObject json = new JSONObject();
|
| | | json.put("materialId", materialId);
|
| | | json.put("siteId", APP_ID);
|
| | | if (couponUrl != null)
|
| | | json.put("positionId", positionId);
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(couponUrl))
|
| | | json.put("couponUrl", couponUrl);
|
| | | // json.put("ext1", "437032_12");
|
| | | json.put("pid", pid);
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(ext1))
|
| | | json.put("ext1", ext1);
|
| | |
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("promotionCodeReq", json);
|
| | |
|
| | | String result = baseRequest("jd.union.open.promotion.common.get", null, json);
|
| | | String result = baseRequest("jd.union.open.promotion.common.get", null, root);
|
| | | |
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | result = resultJson.optJSONObject("jd_union_open_promotion_common_get_response").optString("result");
|
| | | if (result == null) {
|
| | | return null;
|
| | | }
|
| | | |
| | | 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;
|
| | | }
|
| | |
|
| | |
|
| | |
| | | filter.setPageIndex(1);
|
| | | filter.setPageSize(20);
|
| | | filter.setListId(skuIdList);
|
| | | List<JDGoods> list = queryByKey(filter);
|
| | | if (list != null && list.size() > 0)
|
| | | return list.get(0);
|
| | | JDSearchResult searchResult = queryByKey(filter);
|
| | | if (searchResult != null) {
|
| | | List<JDGoods> list = searchResult.getGoodsList();
|
| | | if (list != null && list.size() > 0)
|
| | | return list.get(0);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | * @param skuIdList
|
| | | * @return
|
| | | */
|
| | | public static List<JDGoods> queryByKey(JDFilter filter) {
|
| | | public static JDSearchResult queryByKey(JDFilter filter) {
|
| | | JDSearchResult searchResult = new JDSearchResult();
|
| | | |
| | | List<JDGoods> list = new ArrayList<>();
|
| | | JSONObject json = new JSONObject();
|
| | | json.put("pageIndex", filter.getPageIndex());
|
| | |
| | | if (filter.getIsPG() != null)
|
| | | json.put("isPG", filter.getIsPG());
|
| | |
|
| | | if (filter.getIsCoupon() != null)
|
| | | json.put("isCoupon", filter.getIsCoupon());
|
| | |
|
| | | if (filter.getPingouPriceStart() != null)
|
| | | json.put("pingouPriceStart", filter.getPingouPriceStart());
|
| | |
|
| | |
| | |
|
| | | if (filter.getShopId() != null)
|
| | | json.put("shopId", filter.getShopId());
|
| | | |
| | | if (filter.getOwner() != null)
|
| | | json.put("owner", filter.getOwner());
|
| | | |
| | | System.out.println(json.toString());
|
| | |
|
| | | JSONObject jsonDTO = new JSONObject();
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | long totalCount = resultJson.optLong("totalCount");
|
| | | PageEntity pageEntity = new PageEntity();
|
| | | pageEntity.setTotalCount(totalCount);
|
| | | |
| | | searchResult.setPageEntity(pageEntity);
|
| | | }
|
| | | return list;
|
| | | searchResult.setGoodsList(list);
|
| | | return searchResult;
|
| | | }
|
| | |
|
| | |
|
| | |
| | |
|
| | | private static JDGoods parseJDGoods(JSONObject json) {
|
| | | JDGoods goods = new JDGoods();
|
| | | |
| | | // 佣金信息
|
| | | Object commission = json.get("commissionInfo");
|
| | | JSONObject commissionJson = JSONObject.fromObject(commission);
|
| | | BigDecimal commissionShare = new BigDecimal(commissionJson.optString("commissionShare"));
|
| | | if (commissionShare.compareTo(new BigDecimal(0)) > 0) {
|
| | | JDCommissionInfo commissionInfo = new JDCommissionInfo();
|
| | | commissionInfo.setCommission(new BigDecimal(commissionJson.optString("commission")));
|
| | | commissionInfo.setCommissionShare(commissionShare);
|
| | | goods.setCommissionInfo(commissionInfo);
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | | |
| | | goods.setComments(json.optLong("comments"));
|
| | | goods.setBrandCode(json.optString("brandCode"));
|
| | | goods.setBrandName(json.optString("brandName"));
|
| | |
| | | // 价格信息
|
| | | 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");
|
| | |
| | | goods.setCategoryInfo(categoryInfo);
|
| | |
|
| | |
|
| | | // 佣金信息
|
| | | Object commission = json.get("commissionInfo");
|
| | | JSONObject commissionJson = JSONObject.fromObject(commission);
|
| | | JDCommissionInfo commissionInfo = new JDCommissionInfo();
|
| | | commissionInfo.setCommission(new BigDecimal(commissionJson.optString("commission")));
|
| | | 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");
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | if (resultJson.optInt("code") == 0) {
|
| | | result = resultJson.optString("result");
|
| | | resultJson = JSONObject.fromObject(result);
|
| | | System.out.println(resultJson);
|
| | | JSONArray array = resultJson.optJSONArray("data");
|
| | | if (array != null)
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | |
| | |
|
| | | private static JDGoods parseSimpleJDGoods(JSONObject json) {
|
| | | JDGoods goods = new JDGoods();
|
| | | goods.setPrice(StringUtil.isNullOrEmpty(json.optString("wlUnitPrice"))
|
| | | ? new BigDecimal(json.optString("unitPrice")) : new BigDecimal(json.optString("wlUnitPrice")));
|
| | |
|
| | | |
| | | BigDecimal commisionRatioWl = new BigDecimal(json.optString("commisionRatioWl"));
|
| | | if (commisionRatioWl.compareTo(new BigDecimal(0)) > 0) {
|
| | | JDCommissionInfo commissionInfo = new JDCommissionInfo();
|
| | | commissionInfo.setCommissionShare(new BigDecimal(json.optString("commisionRatioWl")));
|
| | | commissionInfo.setCommission(MoneyBigDecimalUtil
|
| | | .div(goods.getPrice().multiply(commissionInfo.getCommissionShare()), new BigDecimal(100)));
|
| | | goods.setCommissionInfo(commissionInfo);
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | | |
| | | JDCategoryInfo categoryInfo = new JDCategoryInfo();
|
| | | categoryInfo.setCid1(json.optLong("cid1"));
|
| | | categoryInfo.setCid1Name(json.optString("cid1Name"));
|
| | |
| | |
|
| | | goods.setCategoryInfo(categoryInfo);
|
| | | goods.setComments(null);
|
| | | goods.setPrice(StringUtil.isNullOrEmpty(json.optString("wlUnitPrice"))
|
| | | ? new BigDecimal(json.optString("unitPrice")) : new BigDecimal(json.optString("wlUnitPrice")));
|
| | |
|
| | | JDCommissionInfo commissionInfo = new JDCommissionInfo();
|
| | | commissionInfo.setCommissionShare(new BigDecimal(json.optString("commisionRatioWl")));
|
| | | commissionInfo.setCommission(MoneyBigDecimalUtil
|
| | | .div(goods.getPrice().multiply(commissionInfo.getCommissionShare()), new BigDecimal(100)));
|
| | |
|
| | | goods.setCommissionInfo(commissionInfo);
|
| | | String isFreeShipping = json.optString("isFreeShipping");
|
| | | if (!StringUtil.isNullOrEmpty(isFreeShipping)) {
|
| | | goods.setIsFreeShipping(Integer.parseInt(isFreeShipping));
|
| | | }
|
| | | |
| | | goods.setCouponInfo(null);
|
| | | goods.setGoodCommentsShare(null);
|
| | | List<String> imageList = new ArrayList<>();
|
| | |
| | |
|
| | | 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<>();
|