From 2147d023563a7c9d05d97547c00d6b0162c0644c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 09 十一月 2020 18:37:24 +0800
Subject: [PATCH] 刷单风险规则优化

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java |  193 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 128 insertions(+), 65 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 f5e9fa4..bc854bf 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
@@ -1,28 +1,12 @@
 package com.yeshi.fanli.util.taobao;
 
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-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.common.entity.PageEntity;
+import com.yeshi.common.entity.taobao.TaoBaoShopInfo;
+import com.yeshi.common.entity.taobao.TaoKeAppInfo;
 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;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.fanli.entity.taobao.TaoBaoHead;
-import com.yeshi.fanli.entity.taobao.TaoBaoProvince;
-import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
-import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
-import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo;
-import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
+import com.yeshi.fanli.entity.taobao.*;
 import com.yeshi.fanli.exception.taobao.TaoBaoAuthException;
 import com.yeshi.fanli.exception.taobao.TaoBaoTokenParseException;
 import com.yeshi.fanli.exception.taobao.TaoKeApiException;
@@ -31,14 +15,20 @@
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.log.TLJLogHelper;
 import com.yeshi.fanli.log.TaoKeLogHelper;
-import com.yeshi.fanli.tag.PageEntity;
-import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TaoBaoConstant;
-import com.yeshi.fanli.util.TimeUtil;
-
+import com.yeshi.goods.facade.dto.taobao.TaoBaoShopInfoDTO;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoHead;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
+import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.MoneyBigDecimalUtil;
+import org.yeshi.utils.TimeUtil;
+import org.yeshi.utils.taobao.TbImgUtil;
+
+import java.math.BigDecimal;
+import java.util.*;
 
 //娣樺疂瀹PI鎺ュ彛
 public class TaoKeApiUtil {
@@ -260,8 +250,9 @@
     /**
      * 鑾峰彇鍟嗗搧璇︽儏锛岀畝鐗�
      *
-     * @param id
+     * @param ids
      * @return
+     * @throws TaobaoGoodsDownException
      */
     public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids) throws TaobaoGoodsDownException {
         List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
@@ -314,8 +305,10 @@
     /**
      * 鑾峰彇鍟嗗搧璇︽儏锛岀畝鐗�
      *
-     * @param id
+     * @param ids
+     * @param ip
      * @return
+     * @throws TaobaoGoodsDownException
      */
     public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids, String ip) throws TaobaoGoodsDownException {
         Map<String, String> map = new HashMap<>();
@@ -356,7 +349,7 @@
      * @return
      * @throws TaobaoGoodsDownException
      */
-    public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaobaoGoodsDownException {
+    public static TaoBaoGoodsBrief searchGoodsDetail(Long id, String specialId, String relationId) throws TaobaoGoodsDownException {
         TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
         if (goods == null)
             return null;
@@ -365,7 +358,7 @@
         filter.setPage(1);
         filter.setPageSize(50);
         TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
-                goods.getUserType());
+                goods.getUserType(), specialId, relationId);
         if (result != null && result.getTaoBaoGoodsBriefs() != null)
             for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                 System.out.println(goods.getAuctionId() + ":" + g.getAuctionId());
@@ -381,7 +374,7 @@
         // 浠庤浆閾炬悳绱�
         TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                 new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
-                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
+                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, relationId);
 
         if (newGoods != null) {
             goods.setTkRate(newGoods.getTkRate());
@@ -411,6 +404,10 @@
 
     }
 
+    public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaobaoGoodsDownException {
+        return searchGoodsDetail(id, null, null);
+    }
+
     /**
      * 鎼滅储鍟嗗搧璇︽儏-璇︾粏
      *
@@ -427,7 +424,7 @@
         filter.setPage(1);
         filter.setPageSize(50);
         TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
-                goods.getUserType(), app);
+                goods.getUserType(), app, null, null);
         if (result != null && result.getTaoBaoGoodsBriefs() != null)
             for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                 if (goods.getAuctionId().longValue() == g.getAuctionId()) {
@@ -458,10 +455,12 @@
         // 浠庤浆閾炬悳绱�
         TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                 new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
-                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
+                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), null, null);
 
         if (newGoods != null) {
             goods.setTkRate(newGoods.getTkRate());
+            goods.setAuctionUrl(newGoods.getAuctionUrl());
+            goods.setCouponLink(newGoods.getCouponLink());
             if (!StringUtil.isNullOrEmpty(newGoods.getCouponInfo())) {
                 List<BigDecimal> couponInfo = TaoBaoCouponUtil.getCouponInfo(newGoods.getCouponInfo());
                 if (couponInfo != null && couponInfo.size() > 1) {
@@ -495,7 +494,7 @@
      * @return
      * @throws TaobaoGoodsDownException
      */
-    public static TaoBaoGoodsBrief searchGoodsDetailForConvert(Long id, TaoKeAppInfo app)
+    public static TaoBaoGoodsBrief searchGoodsDetailForConvert(Long id, TaoKeAppInfo app, String specialId, String relationId)
             throws TaobaoGoodsDownException {
         TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
         if (goods == null)
@@ -505,7 +504,7 @@
         filter.setPage(1);
         filter.setPageSize(50);
         TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
-                goods.getUserType(), app);
+                goods.getUserType(), app, specialId, relationId);
         if (result != null && result.getTaoBaoGoodsBriefs() != null)
             for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                 if (goods.getAuctionId().longValue() == g.getAuctionId()) {
@@ -546,7 +545,7 @@
             filter.setPage(1);
             filter.setPageSize(50);
             TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
-                    goods.getUserType());
+                    goods.getUserType(), null, null);
             if (result != null && result.getTaoBaoGoodsBriefs() != null)
                 for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                     if (goods.getAuctionId().longValue() == g.getAuctionId()) {
@@ -622,9 +621,11 @@
      * 鍟嗗搧鐗╂枡鎼滅储
      *
      * @param filter
+     * @param specialId
+     * @param relationId
      * @return
      */
-    public static TaoBaoSearchResult searchWuLiao(SearchFilter filter) {
+    public static TaoBaoSearchResult searchWuLiao(SearchFilter filter, String specialId, String relationId) {
 
         if (filter.getKey() != null && filter.getKey().trim().equalsIgnoreCase(""))
             return null;
@@ -638,6 +639,14 @@
         map.put("method", "taobao.tbk.dg.material.optional");
         map.put("page_size", filter.getPageSize() == 0 ? "20" : filter.getPageSize() + "");
         map.put("page_no", (filter.getPage() <= 0 ? 1 : filter.getPage()) + "");
+        if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
+            map.put("special_id", specialId);
+        } else if (!StringUtil.isNullOrEmpty(specialId)) {
+            map.put("special_id", specialId);
+        } else if (!StringUtil.isNullOrEmpty(relationId)) {
+            map.put("relation_id", relationId);
+        }
+
         // map.put("material_id", "3756");
 
         pageEntity.setPageIndex(filter.getPage());
@@ -807,11 +816,16 @@
     /**
      * 鍟嗗搧鐗╂枡鎼滅储
      *
-     * @param filter
+     * @param title
+     * @param zkPrice
+     * @param provcity
+     * @param userType
+     * @param specialId
+     * @param relationId
      * @return
      */
     public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
-                                                           int userType) {
+                                                           int userType, String specialId, String relationId) {
         if (provcity.trim().contains(" "))
             provcity = provcity.split(" ")[provcity.split(" ").length - 1];
         TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
@@ -824,6 +838,14 @@
         map.put("is_tmall", (userType == 1) + "");
         map.put("q", title);
         map.put("itemloc", provcity);
+
+        if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
+            map.put("special_id", specialId);
+        } else if (!StringUtil.isNullOrEmpty(specialId)) {
+            map.put("special_id", specialId);
+        } else if (!StringUtil.isNullOrEmpty(relationId)) {
+            map.put("relation_id", relationId);
+        }
 
         String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
         System.out.println(resultStr);
@@ -858,11 +880,17 @@
     /**
      * 鍟嗗搧鐗╂枡鎼滅储
      *
-     * @param filter
+     * @param title
+     * @param zkPrice
+     * @param provcity
+     * @param userType
+     * @param app
+     * @param specialId
+     * @param relationId
      * @return
      */
     public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
-                                                           int userType, TaoKeAppInfo app) {
+                                                           int userType, TaoKeAppInfo app, String specialId, String relationId) {
         if (provcity.trim().contains(" "))
             provcity = provcity.split(" ")[provcity.split(" ").length - 1];
         TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
@@ -875,6 +903,13 @@
         map.put("is_tmall", (userType == 1) + "");
         map.put("q", title);
         map.put("itemloc", provcity);
+        if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
+            map.put("special_id", specialId);
+        } else if (!StringUtil.isNullOrEmpty(specialId)) {
+            map.put("special_id", specialId);
+        } else if (!StringUtil.isNullOrEmpty(relationId)) {
+            map.put("relation_id", relationId);
+        }
 
         String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, app);
         JSONObject data = JSONObject.fromObject(resultStr);
@@ -1027,6 +1062,34 @@
         return null;
     }
 
+    public static String getTKToken(String logo, String text, String url, boolean simpleToken) {
+        if (simpleToken) {
+            return getSimpleTKToken(logo, text, url);
+        } else {
+            return getTKToken(logo, text, url);
+        }
+    }
+
+
+    public static String getSimpleTKToken(String logo, String text, String url) {
+        if (text == null)
+            return null;
+        if (text.length() < 5)
+            text = "濂借揣锛�" + text;
+
+        Map<String, String> map = new HashMap<>();
+        map.put("method", "taobao.tbk.tpwd.create");
+        map.put("url", url);
+        map.put("text", text);
+        map.put("logo", logo);
+        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
+
+        JSONObject data = JSONObject.fromObject(resultStr);
+        if (data.optJSONObject("tbk_tpwd_create_response").optJSONObject("data") != null)
+            return data.optJSONObject("tbk_tpwd_create_response").optJSONObject("data").optString("password_simple");
+        return null;
+    }
+
     /**
      * 鑾峰彇鍒歌缁嗕俊鎭�
      *
@@ -1035,7 +1098,7 @@
      * @return
      */
     public static QuanInfo getQuanInfo(Long auctionId, String activityId) {
-        QuanInfo info = new QuanInfo();
+        QuanInfo info = new TaoKeApiUtil.QuanInfo();
         Map<String, String> map = new HashMap<>();
         map.put("method", "taobao.tbk.coupon.get");
         map.put("item_id", auctionId + "");
@@ -1234,10 +1297,7 @@
     }
 
     /**
-     * 搴楅摵鎼滅储
-     *
-     * @param key  -搴楅摵鍚嶇О
-     * @param page -椤电爜
+     * @param filter
      * @return
      */
     public static List<TaoBaoShopInfo> searchShop(SearchShopFilter filter) {
@@ -1678,23 +1738,26 @@
         }
     }
 
-    public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId, String specialId,String relationId, TaoKeAppInfo app) {
+    public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId, TaoKeAppInfo app, String specialId, String relationId) {
         String pid = app.getPid();
         String[] sts = pid.split("_");
         Map<String, String> map = new HashMap<>();
         map.put("method", "taobao.tbk.coupon.convert");
         map.put("item_id", auctionId + "");
         map.put("adzone_id", sts[3]);
-        if (!StringUtil.isNullOrEmpty(specialId)) {
-            map.put("special_id", specialId);
-        }
-        if (!StringUtil.isNullOrEmpty(relationId)) {
-            map.put("relation_id", specialId);
+
+        if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2020-07-22", "yyyy-MM-dd")) {
+            if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
+                map.put("special_id", specialId);
+            } else if (!StringUtil.isNullOrEmpty(specialId)) {
+                map.put("special_id", specialId);
+            } else if (!StringUtil.isNullOrEmpty(relationId)) {
+                map.put("relation_id", relationId);
+            }
         }
 
         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");
@@ -1718,6 +1781,10 @@
 
             }
             String tkRate = resultJSON.optString("max_commission_rate");
+            if (StringUtil.isNullOrEmpty(tkRate)) {
+                tkRate = resultJSON.optString("min_commission_rate");
+            }
+
             if (!StringUtil.isNullOrEmpty(tkRate)) {
                 goods.setTkRate(new BigDecimal(tkRate));
             }
@@ -1726,13 +1793,7 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
-
         return null;
-    }
-
-
-    public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId, TaoKeAppInfo app) {
-        return specialConvertCoupon(auctionId, null,null, app);
     }
 
     public static void juHuaSuan() {
@@ -2259,13 +2320,15 @@
         return null;
     }
 
+    public static class QuanInfo {
+        public String coupon_start_time;// 寮�濮嬫椂闂�
+        public String coupon_end_time; // 鍒哥粨鏉熸椂闂�
+        public BigDecimal coupon_amount;// 鍒搁噾棰�
+        public int coupon_total_count;// 鍒告�绘暟閲�
+        public int coupon_remain_count;// 鍒稿墿浣欐暟閲�
+        public BigDecimal coupon_start_fee;// 鍒歌捣濮嬮噾棰�
+    }
+
 }
 
-class QuanInfo {
-    public String coupon_start_time;// 寮�濮嬫椂闂�
-    public String coupon_end_time; // 鍒哥粨鏉熸椂闂�
-    public BigDecimal coupon_amount;// 鍒搁噾棰�
-    public int coupon_total_count;// 鍒告�绘暟閲�
-    public int coupon_remain_count;// 鍒稿墿浣欐暟閲�
-    public BigDecimal coupon_start_fee;// 鍒歌捣濮嬮噾棰�
-}
+

--
Gitblit v1.8.0