From fe879975a3e8a0a1aa280fb839e02d159bfbcff8 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 27 八月 2019 18:04:38 +0800 Subject: [PATCH] 金币任务多次获取bug修改 --- fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 45 insertions(+), 10 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java index e7f417b..9e17cc5 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java @@ -28,6 +28,7 @@ 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.entity.jd.JDOrderItem; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; @@ -37,21 +38,19 @@ import net.sf.json.JSONObject; public class JDApiUtil { - public static String APP_ID = "1774659094"; - public static String APP_KEY = "7ba8e06b7d6fde3d6bd5db4b0026ecd7"; - public static String SECRET_KEY = "fb49bc6ecac5458ba5394fc2969d7c56"; + public static String APP_ID = "1864778416"; + public static String APP_KEY = "388f5133d13a5ea290aa5c44f3ebcc00"; + public static String SECRET_KEY = "e22367fc866746d98b50d47b4c521781"; private static String SERVER_URL = "https://router.jd.com/api"; - public static long POSITION_FANLI = 1834339426L; - public static long POSITION_SHARE = 1834289924L; - public static long POSITION_COUPON = 1859510742L; + public static long POSITION_FANLI = 1869704794L; + public static long POSITION_SHARE = 1869542990L; + public static long POSITION_COUPON = 1869704796L; // 璁㈠崟鏌ヨ绫诲瀷 public static int ORDER_TYPE_CREATETIME = 1;// 涓嬪崟鏃堕棿 public static int ORDER_TYPE_FINISHTIME = 2;// 瀹屾垚鏃堕棿 public static int ORDER_TYPE_UPDATETIME = 3;// 鏇存柊鏃堕棿 - - private static String post2(String url, Map<String, String> params) { String baseUrl = url; @@ -133,6 +132,7 @@ JSONObject resultJson = JSONObject.fromObject(result); result = resultJson.optJSONObject("jd_union_open_promotion_common_get_response").optString("result"); + System.out.println(result); if (result == null) { return null; } @@ -172,6 +172,19 @@ return list.get(0); } return null; + } + + /** + * 閫氳繃鍟嗗搧鎼滅储鎺ュ彛鎵归噺鑾峰彇璇︽儏 + * + * @param skuIds + * @return + */ + public static List<JDGoods> listGoodsDetail(List<Long> skuIds) { + JDFilter filter = new JDFilter(); + filter.setListId(skuIds); + JDSearchResult result = queryByKey(filter); + return result.getGoodsList(); } /** @@ -606,24 +619,46 @@ json.put("orderReq", orderReq); String result = baseRequest2("jd.union.open.order.query", null, json); + System.out.println(result); JSONObject root = JSONObject.fromObject(result).optJSONObject("jd_union_open_order_query_response"); if (root.optInt("code") == 0) { boolean hasMore = root.optBoolean("hasMore"); root = JSONObject.fromObject(root.optString("result")); - if (root.optInt("code") == 200&&root.optJSONArray("data")!=null) { - + if (root.optInt("code") == 200 && root.optJSONArray("data") != null) { + String date = root.optJSONArray("data").toString(); Type typeToken = new TypeToken<List<JDOrder>>() { }.getType(); List<JDOrder> orderList = new Gson().fromJson(date, typeToken); if (orderList != null) for (JDOrder order : orderList) { + Map<Long, List<JDOrderItem>> map = new HashMap<>(); for (int i = 0; i < order.getOrderItemList().size(); i++) { + JDOrderItem orderItem = order.getOrderItemList().get(i); + if (map.get(orderItem.getSkuId()) == null) + map.put(orderItem.getSkuId(), new ArrayList<>()); + map.get(orderItem.getSkuId()).add(orderItem); + order.getOrderItemList().get(i) .setTradeId(order.getOrderId() + "-" + order.getOrderItemList().get(i).getSkuId()); order.getOrderItemList().get(i).setOrderId(order.getOrderId()); order.getOrderItemList().get(i).setOrderBy(i + 1); } + // 鏌ヨ鍟嗗搧ID鐩稿悓鐨勫瓙璁㈠崟 + for (Iterator<Long> its = map.keySet().iterator(); its.hasNext();) { + Long skuId = its.next(); + if (map.get(skuId).size() > 1) { + int skuOrderBy = 1; + for (int i = 0; i < order.getOrderItemList().size(); i++) { + JDOrderItem orderItem = order.getOrderItemList().get(i); + if (orderItem.getSkuId().longValue() == skuId) { + order.getOrderItemList().get(i).setTradeId(order.getOrderId() + "-" + + order.getOrderItemList().get(i).getSkuId() + "-" + skuOrderBy++); + } + } + } + } + } return new JDOrderResult(hasMore, orderList); } -- Gitblit v1.8.0