From af66f9797b42ae81f831d1fbf91a59463a569956 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 17 十一月 2022 19:29:36 +0800
Subject: [PATCH] 拼多多接口修改

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java |  152 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 139 insertions(+), 13 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
index f84c61f..7c9be00 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -21,6 +21,7 @@
 import com.yeshi.fanli.entity.accept.AcceptData;
 import com.yeshi.fanli.entity.bus.help.AppPageNotification;
 import com.yeshi.fanli.entity.bus.search.HistorySearch;
+import com.yeshi.fanli.entity.goods.BaseGoodsInfo;
 import com.yeshi.fanli.entity.goods.CommonGoods;
 import com.yeshi.fanli.entity.jd.JDGoods;
 import com.yeshi.fanli.entity.system.ConfigKeyEnum;
@@ -54,6 +55,12 @@
 import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
 import com.yeshi.fanli.util.factory.CommonGoodsFactory;
 import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
+import com.yeshi.fanli.util.goods.douyin.CSJCPSApiUtil;
+import com.yeshi.fanli.util.goods.douyin.DYUtil;
+import com.yeshi.fanli.util.goods.douyin.vo.DYGoods;
+import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail;
+import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsSearchFilter;
+import com.yeshi.fanli.util.goods.douyin.vo.ListResult;
 import com.yeshi.fanli.util.jd.JDApiUtil;
 import com.yeshi.fanli.util.jd.JDUtil;
 import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
@@ -282,7 +289,7 @@
                                         TaoBaoGoodsBrief goodsBrief = null;
                                         String specialId = userExtraTaoBaoInfoService.getSpecialIdByUid(uid);
                                         try {
-                                            goodsBrief = TaoKeApiUtil.searchGoodsDetail(StringUtil.isNullOrEmpty(goods.getGoodsSign())? goods.getGoodsId():goods.getGoodsSign(), specialId, null);
+                                            goodsBrief = TaoKeApiUtil.searchGoodsDetail(StringUtil.isNullOrEmpty(goods.getGoodsSign()) ? goods.getGoodsId() : goods.getGoodsSign(), specialId, null);
                                         } catch (TaobaoGoodsDownException e) {
                                             e.printStackTrace();
                                         }
@@ -422,7 +429,7 @@
         switch (goods.getGoodsType()) {
             case Constant.SOURCE_TYPE_TAOBAO:
                 type = "goodsdetail";
-                if(!StringUtil.isNullOrEmpty(goods.getGoodsSign())) {
+                if (!StringUtil.isNullOrEmpty(goods.getGoodsSign())) {
                     params.put("id", goods.getGoodsSign() + "");
                 }
                 break;
@@ -437,6 +444,9 @@
                 break;
             case Constant.SOURCE_TYPE_SUNING:
                 type = "goodsdetail_suning";
+                break;
+            case Constant.SOURCE_TYPE_DY:
+                type = "goodsdetail_dy";
                 break;
 
         }
@@ -533,7 +543,7 @@
     public void searchGoods(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter,
                             Integer order, Long uid, String notifyType, HttpSession session, HttpServletRequest request, PrintWriter out) {
 
-        if (goodsType == null || goodsType < 1 || goodsType > 5) {
+        if (goodsType == null || goodsType < 1 || goodsType > 7) {
             out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�"));
             return;
         }
@@ -629,6 +639,13 @@
             return;
         }
 
+
+        /*-------- 鎶栭煶鍟嗗搧 ------*/
+        if (goodsType.intValue() == Constant.SOURCE_TYPE_DY) {
+            searchDYGoods(acceptData, uid, searchkey, page, filter, order, ap, out);
+            return;
+        }
+
         /*-------- 娣樺疂鍟嗗搧  -------*/
         searchTaoBaoGoods(acceptData, uid, searchkey, page, filter, order, ap, out);
 
@@ -711,6 +728,14 @@
             return;
         }
 
+
+        /*-------- 鎶栭煶鍟嗗搧 ------*/
+        if (goodsType.intValue() == Constant.SOURCE_TYPE_DY) {
+            searchDYGoods(acceptData, uid, searchkey, page, filter, order, ap, out);
+            return;
+        }
+
+
         /*-------- 娣樺疂鍟嗗搧  -------*/
         searchTaoBaoGoods(acceptData, uid, searchkey, page, filter, order, ap, out);
 
@@ -741,14 +766,14 @@
                     goodsId = id;
                 }
                 if (goodsId == null) {
-                try {
-                    TaoKeApiUtil.TokenConvertResult result = TaoKeApiUtil.tokenConvert(key);
-                    if (result != null) {
-                        goodsId = result.getNum_iid();
+                    try {
+                        TaoKeApiUtil.TokenConvertResult result = TaoKeApiUtil.tokenConvert(key);
+                        if (result != null) {
+                            goodsId = result.getNum_iid();
+                        }
+                    } catch (TaoBaoTokenParseException e) {
+                        e.printStackTrace();
                     }
-                } catch (TaoBaoTokenParseException e) {
-                    e.printStackTrace();
-                }
 
 
                 }
@@ -770,8 +795,8 @@
                     String[] ks = key.trim().split("  ");
                     if (ks.length > 1)
                         key = ks[1].trim();
-                }else{
-                    key=title;
+                } else {
+                    key = title;
                 }
             }
         }
@@ -1280,7 +1305,7 @@
     }
 
     /**
-     * 鎼滅储鍞搧浼氬晢鍝�
+     * 鎼滅储鎶栭煶鍟嗗搧
      *
      * @param acceptData
      * @param key
@@ -1292,6 +1317,107 @@
      * @Title: searchVIPGoods
      * @Description:
      */
+    private void searchDYGoods(AcceptData acceptData, Long uid, String key, Integer page, String filter, Integer order,
+                               AppPageNotification ap, PrintWriter out) {
+        String goodsId = null;
+        if (page == 1) {
+            List<String> linkList = HttpUtil.getUrlListFromText(key);
+            if (linkList != null && linkList.size() > 0) {
+                String productId = DYUtil.parseProdectIdFromLink(linkList.get(0));
+                if (!StringUtil.isNullOrEmpty(productId)) {
+                    goodsId = productId;
+                }
+            }
+        }
+
+
+        long count = 0;
+        List<BaseGoodsInfo> goodsList = new ArrayList<>();
+        if (goodsId != null) {
+            DYGoodsDetail goodsInfo = CSJCPSApiUtil.goodsDetail(Long.parseLong(goodsId));
+            if (goodsInfo != null) {
+                goodsList.add(goodsInfo);
+                count = 1;
+            }
+        } else {
+            DYGoodsSearchFilter searchFilter = new DYGoodsSearchFilter();
+            searchFilter.setTitle(key);
+            searchFilter.setPage(page);
+            searchFilter.setPageSize(Constant.PAGE_SIZE);
+
+            if (order != null) {
+                int sort = order.intValue();
+                switch (sort) {
+                    case 1: // 閿�閲� desc
+                        searchFilter.setSearch_type(1);
+                        searchFilter.setOrder_type(1);
+                        break;
+                    case 2: // 浠锋牸鈥攄esc
+                        searchFilter.setSearch_type(2);
+                        searchFilter.setOrder_type(1);
+                        break;
+                    case 3: // 浠锋牸鈥攁sc
+                        searchFilter.setSearch_type(2);
+                        searchFilter.setOrder_type(0);
+                        break;
+                    case 4: // 杩斿埄姣�
+                        searchFilter.setSearch_type(4);
+                        searchFilter.setOrder_type(1);
+                        break;
+                    default: // 缁煎悎鎺掑簭
+                        searchFilter.setSearch_type(0);
+                        searchFilter.setOrder_type(0);
+                        break;
+                }
+            }
+
+            if (!StringUtil.isNullOrEmpty(filter)) {
+                JSONObject jsonfilter = JSONObject.fromObject(filter);
+                String minPrice = jsonfilter.optString("minPrice");
+                if (!StringUtil.isNullOrEmpty(minPrice)) {
+                    searchFilter.setPrice_min(new BigDecimal(minPrice).min(new BigDecimal(100)).intValue());
+                }
+
+                String maxPrice = jsonfilter.optString("maxPrice");
+                if (!StringUtil.isNullOrEmpty(maxPrice)) {
+                    searchFilter.setPrice_max(new BigDecimal(maxPrice).min(new BigDecimal(100)).intValue());
+                }
+            }
+
+
+            ListResult result = CSJCPSApiUtil.searchGoods(searchFilter);
+            if (result != null) {
+                count = result.getCount();
+                List<Object> tempList = result.getDataList();
+                if (tempList != null) {
+                    for (Object o : tempList) {
+                        goodsList.add((DYGoods) o);
+                    }
+                }
+
+            }
+        }
+
+        JSONObject data = new JSONObject();
+        JSONArray array = new JSONArray();
+
+        if (goodsList != null && goodsList.size() > 0) {
+            Gson gson = JsonUtil.getApiCommonGson();
+            GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+                    acceptData.getVersion(), acceptData.getSystem());
+
+            List<GoodsDetailVO> voList = goodsLijinMnager.loadOtherMoneyInfo(acceptData.getSystem(), uid, goodsList, paramsDTO);
+            for (GoodsDetailVO goodsDetailVO : voList) {
+                array.add(gson.toJson(goodsDetailVO));
+            }
+        }
+
+        data.put("result", array);
+        data.put("count", count);
+        out.print(JsonUtil.loadTrueResult(buildSearchResult(data, ap)));
+    }
+
+
     private void searchVIPGoods(AcceptData acceptData, Long uid, String key, Integer page, String filter, Integer order,
                                 AppPageNotification ap, PrintWriter out) {
         String goodsId = null;

--
Gitblit v1.8.0