From ec60e757d358636dcac1589c44a66f3e276fe58c Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 29 六月 2020 14:41:42 +0800 Subject: [PATCH] 拉新 --- fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java | 251 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 205 insertions(+), 46 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java index 326ec76..ab4371c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java @@ -7,10 +7,12 @@ import java.util.List; import java.util.Map; +import org.yeshi.utils.JsonUtil; import org.yeshi.utils.taobao.TbImgUtil; import com.yeshi.fanli.dto.taobao.TaoBaoShopInfoDTO; import com.yeshi.fanli.dto.taobao.TaoLiJinDTO; +import com.yeshi.fanli.dto.taobao.api.TaoKeOfficialActivityConvertResultDTO; import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinReport; import com.yeshi.fanli.entity.taobao.SearchFilter; import com.yeshi.fanli.entity.taobao.SearchShopFilter; @@ -208,6 +210,9 @@ } else goods.setMaterialLibType(0); + goods.setRootCategoryName(item.optString("cat_name")); + goods.setLeafName(item.optString("cat_leaf_name")); + goods = loadYuShouInfo(goods, item); return goods; } @@ -261,10 +266,10 @@ */ public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids) throws TaobaoGoodsDownException { List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); - Map<String, String> map = new HashMap<>(); map.put("method", "taobao.tbk.item.info.get"); map.put("num_iids", ids + ""); + String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true); JSONObject data = JSONObject.fromObject(resultStr); // 鍟嗗搧涓嬫灦 @@ -276,6 +281,63 @@ if (data.optJSONObject("tbk_item_info_get_response") == null) return null; + JSONArray array = data.optJSONObject("tbk_item_info_get_response").optJSONObject("results") + .optJSONArray("n_tbk_item"); + if (array != null && array.size() > 0) { + + for (int i = 0; i < array.size(); i++) { + JSONObject item = array.optJSONObject(i); + goodsList.add(parseSimpleGoodsInfo(item)); + } + } + return goodsList; + } + + + public static List<TaoBaoGoodsBrief> getBatchGoodsInfo(List<Long> listId, String ip ) + throws TaoKeApiException, TaobaoGoodsDownException { + if (listId == null || listId.size() == 0) { + throw new TaobaoGoodsDownException(1, "娣樺疂鍟嗗搧ID涓嶈兘涓虹┖"); + } + + if (listId.size() > 40) { + throw new TaobaoGoodsDownException(1, "娣樺疂鍟嗗搧ID涓嶈兘瓒呰繃40涓�"); + } + + StringBuffer ids = new StringBuffer(); + for (Long id : listId) { + ids.append(id + ","); + } + + return getBatchGoodsInfos(ids.substring(0, ids.length() - 1), ip); + } + + /** + * 鑾峰彇鍟嗗搧璇︽儏锛岀畝鐗� + * + * @param id + * @return + */ + public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids, String ip) throws TaobaoGoodsDownException { + Map<String, String> map = new HashMap<>(); + map.put("method", "taobao.tbk.item.info.get"); + map.put("num_iids", ids + ""); + if (!StringUtil.isNullOrEmpty(ip)) { + map.put("ip", ip); + } + + String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true); + JSONObject data = JSONObject.fromObject(resultStr); + // 鍟嗗搧涓嬫灦 + if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 15 + && data.optJSONObject("error_response").optInt("sub_code") == 50001) { + throw new TaobaoGoodsDownException(data.optJSONObject("error_response").optInt("code"), "鍟嗗搧涓嬫灦"); + } + + if (data.optJSONObject("tbk_item_info_get_response") == null) + return null; + List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); + JSONArray array = data.optJSONObject("tbk_item_info_get_response").optJSONObject("results") .optJSONArray("n_tbk_item"); if (array != null && array.size() > 0) { @@ -317,29 +379,37 @@ } } - // 鍐嶄粠娣樺疂鑱旂洘缃戦〉鎼滅储 - filter.setKey(goods.getAuctionUrl()); - TaoBaoSearchResult searchResult = TaoBaoUtil.searchFromAlimamaWeb(filter, null); - if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null - && searchResult.getTaoBaoGoodsBriefs().size() > 0) { - for (TaoBaoGoodsBrief g : searchResult.getTaoBaoGoodsBriefs()) { - if (g.getAuctionId().longValue() == goods.getAuctionId()) { - g.setImgList(goods.getImgList()); - goods = g; - if ("鏃�".equalsIgnoreCase(goods.getCouponInfo())) - goods.setCouponInfo(null); - return goods; + // 浠庤浆閾炬悳绱� + TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(), + new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, + TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT)); + + if (newGoods != null) { + goods.setTkRate(newGoods.getTkRate()); + if (!StringUtil.isNullOrEmpty(newGoods.getCouponInfo())) { + List<BigDecimal> couponInfo = TaoBaoCouponUtil.getCouponInfo(newGoods.getCouponInfo()); + if (couponInfo != null && couponInfo.size() > 1) { + goods.setCouponStartFee(couponInfo.get(0)); + goods.setCouponAmount(couponInfo.get(1)); + goods.setCouponEffectiveStartTime(newGoods.getCouponEffectiveStartTime()); + goods.setCouponEffectiveEndTime(newGoods.getCouponEffectiveEndTime()); + goods.setCouponLeftCount(newGoods.getCouponLeftCount()); + goods.setCouponTotalCount(newGoods.getCouponTotalCount()); + goods.setCouponInfo(newGoods.getCouponInfo()); } } + + return goods; + + } else { + goods.setCouponAmount(new BigDecimal("0")); + goods.setTkMktStatus("1"); + goods.setTkRate(new BigDecimal("0")); + goods.setReservePrice(new BigDecimal(0)); + goods.setTkCommFee(new BigDecimal(0)); + return goods; } - TaoKeLogHelper.error(null, "娌℃湁鎼滅储鍒拌鎯�:" + id); - goods.setCouponAmount(new BigDecimal("0")); - goods.setTkMktStatus("1"); - goods.setTkRate(new BigDecimal("0")); - goods.setReservePrice(new BigDecimal(0)); - goods.setTkCommFee(new BigDecimal(0)); - return goods; } /** @@ -386,29 +456,36 @@ } } - // 鍐嶄粠娣樺疂鑱旂洘缃戦〉鎼滅储 - filter.setKey(goods.getAuctionUrl()); - TaoBaoSearchResult searchResult = TaoBaoUtil.searchFromAlimamaWeb(filter, null); - if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null - && searchResult.getTaoBaoGoodsBriefs().size() > 0) { - for (TaoBaoGoodsBrief g : searchResult.getTaoBaoGoodsBriefs()) { - if (g.getAuctionId().longValue() == goods.getAuctionId()) { - g.setImgList(goods.getImgList()); - goods = g; - if ("鏃�".equalsIgnoreCase(goods.getCouponInfo())) - goods.setCouponInfo(null); - return goods; + // 浠庤浆閾炬悳绱� + TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(), + new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, + TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT)); + + if (newGoods != null) { + goods.setTkRate(newGoods.getTkRate()); + if (!StringUtil.isNullOrEmpty(newGoods.getCouponInfo())) { + List<BigDecimal> couponInfo = TaoBaoCouponUtil.getCouponInfo(newGoods.getCouponInfo()); + if (couponInfo != null && couponInfo.size() > 1) { + goods.setCouponStartFee(couponInfo.get(0)); + goods.setCouponAmount(couponInfo.get(1)); + goods.setCouponEffectiveStartTime(newGoods.getCouponEffectiveStartTime()); + goods.setCouponEffectiveEndTime(newGoods.getCouponEffectiveEndTime()); + goods.setCouponLeftCount(newGoods.getCouponLeftCount()); + goods.setCouponTotalCount(newGoods.getCouponTotalCount()); + goods.setCouponInfo(newGoods.getCouponInfo()); } } - } - TaoKeLogHelper.error(null, "娌℃湁鎼滅储鍒拌鎯�:" + id); - goods.setCouponAmount(new BigDecimal("0")); - goods.setTkMktStatus("1"); - goods.setTkRate(new BigDecimal("0")); - goods.setReservePrice(new BigDecimal(0)); - goods.setTkCommFee(new BigDecimal(0)); - return goods; + return goods; + + } else { + goods.setCouponAmount(new BigDecimal("0")); + goods.setTkMktStatus("1"); + goods.setTkRate(new BigDecimal("0")); + goods.setReservePrice(new BigDecimal(0)); + goods.setTkCommFee(new BigDecimal(0)); + return goods; + } } /** @@ -1623,6 +1700,7 @@ map.put("adzone_id", sts[3]); try { String result = TaoKeBaseUtil.baseRequestForThreeTimes(map, app); + System.out.println(result); JSONObject json = JSONObject.fromObject(result); JSONObject resultJSON = json.optJSONObject("tbk_coupon_convert_response").optJSONObject("result") .optJSONObject("results"); @@ -1633,6 +1711,17 @@ if (!StringUtil.isNullOrEmpty(resultJSON.optString("coupon_info"))) { goods.setCouponLink(couponLink); goods.setCouponInfo(resultJSON.optString("coupon_info")); + if (!StringUtil.isNullOrEmpty(resultJSON.optString("coupon_total_count"))) { + goods.setCouponTotalCount(Integer.parseInt(resultJSON.optString("coupon_total_count"))); + } + + if (!StringUtil.isNullOrEmpty(resultJSON.optString("coupon_remain_count"))) { + goods.setCouponLeftCount(Integer.parseInt(resultJSON.optString("coupon_remain_count"))); + } + + goods.setCouponEffectiveStartTime(resultJSON.optString("coupon_start_time")); + goods.setCouponEffectiveEndTime(resultJSON.optString("coupon_end_time")); + } String tkRate = resultJSON.optString("max_commission_rate"); if (!StringUtil.isNullOrEmpty(tkRate)) { @@ -2046,11 +2135,12 @@ * -娓犻亾ID * @return */ - public static String officialActivityConvert(String adZoneId, String promotionSceneId, String relationId) { + public static TaoKeOfficialActivityConvertResultDTO officialActivityConvert(String adZoneId, + String promotionSceneId, String relationId) { Map<String, String> map = new HashMap<>(); - map.put("method", "taobao.tbk.activitylink.get"); + map.put("method", "taobao.tbk.activity.info.get"); map.put("adzone_id", adZoneId); - map.put("promotion_scene_id", promotionSceneId); + map.put("activity_material_id", promotionSceneId); if (relationId != null) map.put("relation_id", relationId); TaoKeAppInfo app = new TaoKeAppInfo(); @@ -2058,11 +2148,13 @@ app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); try { String result = TaoKeBaseUtil.baseRequestForThreeTimes(map, app); + System.out.println(result); JSONObject json = JSONObject.fromObject(result); if (json != null) { - json = json.optJSONObject("tbk_activitylink_get_response"); - if (json.optInt("result_code") == 200) { - return json.optString("data"); + json = json.optJSONObject("tbk_activity_info_get_response"); + if (json.optJSONObject("data") != null) { + return JsonUtil.getSimpleGson().fromJson(json.optJSONObject("data").toString(), + TaoKeOfficialActivityConvertResultDTO.class); } } } catch (Exception e) { @@ -2103,6 +2195,73 @@ return goodsList; } + + public static List<TaoBaoGoodsBrief> getCouponListByItemId(Long auctionId) { + Map<String, String> map = new HashMap<>(); + map.put("method", "taobao.tbk.itemid.coupon.get"); + map.put("platform", auctionId + ""); + map.put("num_iids", auctionId + ""); + map.put("pid", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT); + + List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); + JSONObject resultJSON = null; + try { + resultJSON = TaoKeBaseUtil.baseRequest(map, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, + TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT)); + + JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response"); + if (response != null && response.optJSONObject("result_list") != null) { + JSONArray array = response.optJSONObject("result_list").optJSONArray("map_data"); + if (array != null) { + + for (int i = 0; i < array.size(); i++) { + JSONObject item = array.optJSONObject(i); + TaoBaoGoodsBrief goods = parseWuLiaoItemFromMaterialId(item); + if (goods != null) + goodsList.add(goods); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return goodsList; + } + + /** + * 娣樺疂瀹�-鎺ㄥ箍鑰�-瀹樻柟娲诲姩淇℃伅鑾峰彇 + * @Title: getActivityInfo + * @Description: + * @param activityMaterialId + * @param pid + * @param relationId + * @return + * String 杩斿洖绫诲瀷 + * @throws + */ + public static String getActivityInfo(String activityMaterialId, String pid, String relationId) { + Map<String, String> map = new HashMap<>(); + map.put("method", "taobao.tbk.activity.info.get"); + map.put("activity_material_id", activityMaterialId); + map.put("adzone_id", pid.split("_")[3] + ""); + map.put("relation_id", relationId); + + JSONObject resultJSON = null; + try { + resultJSON = TaoKeBaseUtil.baseRequest(map, + new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid)); + JSONObject response = resultJSON.optJSONObject("tbk_activity_info_get_response"); + if (response != null && response.optJSONObject("data") != null) { + return response.optJSONObject("data").optString("click_url"); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + } class QuanInfo { -- Gitblit v1.8.0