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/ShareControllerV2.java |  235 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 226 insertions(+), 9 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
index bc8fcec..8bbff8a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -22,6 +22,10 @@
 import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
 import com.yeshi.fanli.util.*;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.goods.douyin.CSJCPSApiUtil;
+import com.yeshi.fanli.util.goods.douyin.DYUtil;
+import com.yeshi.fanli.util.goods.douyin.vo.DYConvertResult;
+import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
@@ -257,6 +261,12 @@
         // 鑻忓畞
         if (goodsType == Constant.SOURCE_TYPE_SUNING) {
             createSuningShare(acceptData, uid, goodsId, source, needGoods, out);
+            return;
+        }
+
+        // 鎶栭煶
+        if (goodsType == Constant.SOURCE_TYPE_DY) {
+            createDYShare(acceptData, uid,Long.parseLong( goodsId), source, needGoods, out);
             return;
         }
 
@@ -832,7 +842,7 @@
         BigDecimal shareMoney = JDUtil.getGoodsFanLiMoney(jdGoods, shareRate);
         shareInfo.setShareMoney("楼" + shareMoney.toString());
         try {
-            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId+"",
+            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId + "",
                     Constant.SOURCE_TYPE_JD, false);
             shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
@@ -908,7 +918,7 @@
                 history.setTkCode(null);
                 history.setLink(null);
                 history.setQuanLink(null);
-                history.setGoodsId(goodsId+"");
+                history.setGoodsId(goodsId + "");
                 history.setPostPicture(goods.getPicUrl());
                 history.setShareImg(jumpLinkNew);
 
@@ -1022,7 +1032,7 @@
         shareInfo.setShareMoney("楼" + shareMoney.toString());
 
         try {
-            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId+"",
+            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId + "",
                     Constant.SOURCE_TYPE_PDD, false);
             shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
@@ -1097,7 +1107,7 @@
                 history.setTkCode(null);
                 history.setLink(null);
                 history.setQuanLink(null);
-                history.setGoodsId(goodsId+"");
+                history.setGoodsId(goodsId + "");
                 history.setPostPicture(goods.getGoodsImageUrl());
                 history.setShareImg(jumpLink);
                 List<String> imgList = null;
@@ -1177,7 +1187,7 @@
         shareInfo.setShareMoney("楼" + shareMoney.toString());
 
         try {
-            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId+"",
+            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId + "",
                     Constant.SOURCE_TYPE_VIP, false);
             shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
@@ -1226,7 +1236,7 @@
                 history.setTkCode(null);
                 history.setLink(null);
                 history.setQuanLink(null);
-                history.setGoodsId(goodsId+"");
+                history.setGoodsId(goodsId + "");
                 history.setPostPicture(goods.getGoodsThumbUrl());
                 history.setShareImg(jumpLink.getUrl());
                 List<String> imgList = goods.getGoodsDetailPictures();
@@ -1321,7 +1331,7 @@
 
         try {
             ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid,
-                    Long.parseLong(sts[1])+"", Constant.SOURCE_TYPE_SUNING, false);
+                    Long.parseLong(sts[1]) + "", Constant.SOURCE_TYPE_SUNING, false);
             shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
             try {
@@ -1407,7 +1417,7 @@
                 history.setTkCode(null);
                 history.setLink(null);
                 history.setQuanLink(null);
-                history.setGoodsId(Long.parseLong(sts[1])+"");
+                history.setGoodsId(Long.parseLong(sts[1]) + "");
                 if (goods.getCommodityInfo().getPictureUrl() != null
                         && goods.getCommodityInfo().getPictureUrl().size() > 0)
                     history.setPostPicture(goods.getCommodityInfo().getPictureUrl().get(0).getPicUrl());
@@ -1417,6 +1427,161 @@
                 if (pictureList != null) {
                     for (SuningGoodsImg gi : pictureList)
                         imgList.add(gi.getPicUrl());
+                }
+                history.setPictures(JsonUtil.getGson().toJson(imgList));
+                shareGoodsService.addShareGoodsHistory(history);
+            }
+        });
+    }
+
+
+    /**
+     * 鎶栭煶鍒嗕韩
+     *
+     * @param acceptData
+     * @param uid
+     * @param goodsId
+     * @param source
+     * @param needGoods
+     * @param out        void 杩斿洖绫诲瀷
+     * @throws
+     * @Title: createSuningShare
+     * @Description:
+     */
+    public void createDYShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods,
+                              PrintWriter out) {
+        DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(goodsId);
+        if (goods == null) {
+            out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦"));
+            return;
+        }
+
+        SystemEnum system = SystemInfoUtil.getSystem(acceptData);
+
+
+        DYConvertResult convertResult = CSJCPSApiUtil.goodsConvert(goods.getDetail_url(), DYUtil.createShareExtraInfo(uid), "");
+
+        ShareInfoVO shareInfo = new ShareInfoVO();
+        shareInfo.setClickUrl(convertResult.getQrCode());
+        shareInfo.setWxErCode(convertResult.getQrCode());
+        shareInfo.setCommentTexts(new ArrayList<>());
+        shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareRuleLinkDY.getKey(), system));
+        shareInfo.setPictUrl(goods.getCover());
+        if (needGoods) {
+            shareInfo
+                    .setGoodsInfo(GoodsDetailVOFactory.convertDYGoods(goods,
+                            new GoodsMoneyConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()),
+                                    hongBaoManageService.getShareRate(acceptData.getSystem()), Constant.MAX_REWARD_RATE,
+                                    hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem()))));
+        }
+
+        String template = shareGoodsTextTemplateService.getTextTemplateBySuNing(uid);
+        String shareText =  shareGoodsTextTemplateService.createCommonShareTextDY(template, goods, convertResult.getDeeplink());
+        shareInfo.setShareText(shareText);
+
+        String descText = shareText.replace(goods.getTitle(), "").trim();
+        if (descText.startsWith("\\r\\n")) {
+            descText = descText.substring(0);
+        }
+        shareInfo.setDescText(descText);
+
+        //
+        String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getPlatform(),
+                Integer.parseInt(acceptData.getVersion()), system);
+        JSONArray array = JSONArray.fromObject(imgs);
+
+        shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0));
+
+        // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖
+        imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs207.getKey(), system);
+        array = JSONArray.fromObject(imgs);
+        shareInfo.setNotifyPictureNew(array.size() > 1 ? array.optString(1) : array.optString(0));
+
+        shareInfo.setNotifyDesc(configService.getValue(ConfigKeyEnum.goodsShareNotifyDY.getKey(), system));
+
+        // 娣诲姞鍒嗕韩璁板綍
+        BigDecimal shareRate = hongBaoManageService.getShareRate(acceptData.getSystem());
+        BigDecimal shareMoney = DYUtil.getGoodsFanLiMoney(goods, shareRate);
+        shareInfo.setShareMoney("楼" + shareMoney.toString());
+
+        try {
+            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid,
+                    goodsId + "", Constant.SOURCE_TYPE_DY, false);
+            shareInfo.setShareId(shareRecord.getRedisKey());
+        } catch (Exception e) {
+            try {
+                LogHelper.errorDetailInfo(e);
+            } catch (Exception e1) {
+                e1.printStackTrace();
+            }
+        }
+
+        String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
+
+
+        String commentText = "";
+        String recommendText = "";
+        String qtemplate = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), system);
+        recommendText = qtemplate.replace("[鍟嗗搧鏍囬]", goods.getTitle());
+
+        recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", "");
+
+
+        String quickCommentText = configService.getValue(ConfigKeyEnum.quickShareDYCommentText.getKey(), system);
+
+        commentText = quickCommentText.replace("[鍘熶环]", BigDecimalUtil.getWithNoZera(DYUtil.getPrice(goods.getPrice())).toString());
+        //commentText = commentText.replace("[閾炬帴]", jumpLink);
+        commentText = commentText.replace("[鍙d护]", convertResult.getPassword());
+
+
+        String salesCountMidea = "";
+        Integer count = goods.getSales();
+        if (count < 10000) {
+            salesCountMidea = count + "";
+        } else {
+            double sales = count;
+            salesCountMidea = String.format("%.1f", sales / 10000);
+            salesCountMidea = salesCountMidea + "涓�";
+        }
+        if (StringUtil.isNullOrEmpty(salesCountMidea) || salesCountMidea.equals("0")) {
+            recommendText = recommendText.replace("閿�閲�:[閿�閲廬", "");
+        } else {
+            recommendText = recommendText.replace("[閿�閲廬", salesCountMidea.replace("涓�", "w"));
+        }
+
+        commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘").replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", "");
+        recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", "");
+
+        shareInfo.setRecommendText(deleteBlankLine(recommendText));
+        shareInfo.setCommentText(deleteBlankLine(commentText));
+
+        // 璁剧疆璇勮鏂囨湰閫夐」
+        shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode,
+                DYUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem()))));
+
+        out.print(JsonUtil.loadTrueResult(
+                JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo)));
+
+        // 寮傛鎿嶄綔
+        com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
+            @Override
+            public void run() {
+                // 寮傛鎿嶄綔 娣诲姞鍒嗕韩璁板綍
+                UserShareGoodsHistory history = new UserShareGoodsHistory();
+                history.setUser(new UserInfo(uid));
+                history.setHongbao(shareMoney);
+                history.setCreateTime(new Date());
+                history.setGoodsType(Constant.SOURCE_TYPE_DY);
+                history.setTkCode(null);
+                history.setLink(null);
+                history.setQuanLink(null);
+                history.setGoodsId(goodsId + "");
+                history.setPostPicture(goods.getCover());
+                history.setShareImg(convertResult.getQrCode());
+                List<String> imgList = new ArrayList<>();
+                if (goods.getImgs() != null) {
+                    for (String gi : goods.getImgs())
+                        imgList.add(gi);
                 }
                 history.setPictures(JsonUtil.getGson().toJson(imgList));
                 shareGoodsService.addShareGoodsHistory(history);
@@ -1469,6 +1634,11 @@
 
         if (goodsType == Constant.SOURCE_TYPE_SUNING) {
             createSuNingViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, hasCoupon, out);
+            return;
+        }
+
+        if (goodsType == Constant.SOURCE_TYPE_DY) {
+            createDYViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, hasCoupon, out);
             return;
         }
     }
@@ -1712,6 +1882,40 @@
         out.print(JsonUtil.loadTrueResult(data));
     }
 
+
+    private void createDYViewText(SystemEnum system, Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon,
+                                      PrintWriter out) {
+
+        DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(goodsId));
+        if (goods == null) {
+            out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�"));
+            return;
+        }
+
+        if (StringUtil.isNullOrEmpty(template)) {
+            template = getShareTemplate(goodsType, uid, hasCoupon, null);
+        }
+
+        // 鏍¢獙鍒告ā鏉挎槸鍚︽纭�
+        try {
+            shareGoodsTextTemplateService.verifyRightDY(template);
+        } catch (ShareGoodsTextTemplateException e) {
+            out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
+            return;
+        }
+
+        DYConvertResult convertResult = CSJCPSApiUtil.goodsConvert(goods.getDetail_url(),DYUtil.createShareExtraInfo(uid),"");
+
+
+        // 鐢熸垚鏅�氬垎浜唴瀹�
+        String content = shareGoodsTextTemplateService.createCommonShareTextDY(template, goods, convertResult.getPassword());
+
+        JSONObject data = new JSONObject();
+        data.put("content", content);
+        out.print(JsonUtil.loadTrueResult(data));
+    }
+
+
     /**
      * 鑾峰彇鍒嗕韩妯℃澘
      *
@@ -1732,6 +1936,8 @@
             template = shareGoodsTextTemplateService.getTextTemplateByVIP(uid);
         } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
             template = shareGoodsTextTemplateService.getTextTemplateBySuNing(uid);
+        }else if (goodsType == Constant.SOURCE_TYPE_DY) {
+            template = shareGoodsTextTemplateService.getTextTemplateByDY(uid);
         }
         return template;
     }
@@ -1786,6 +1992,8 @@
             out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRulesVIP.getKey(), system)));
         } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
             out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRulesSuNing.getKey(), system)));
+        }else if (goodsType == Constant.SOURCE_TYPE_DY) {
+            out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRulesDY.getKey(), system)));
         }
     }
 
@@ -1817,6 +2025,8 @@
                 shareGoodsTextTemplateService.saveTemplateVIP(uid, template);
             } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
                 shareGoodsTextTemplateService.saveTemplateSuNing(uid, template);
+            } else if (goodsType == Constant.SOURCE_TYPE_DY) {
+                shareGoodsTextTemplateService.saveTemplateDY(uid, template);
             }
         } catch (ShareGoodsTextTemplateException e) {
             out.print(JsonUtil.loadFalseResult(5, e.getMsg()));
@@ -1851,6 +2061,8 @@
             shareGoodsTextTemplateService.resetCommonTemplateVIP(uid);
         } else if (goodsType == Constant.SOURCE_TYPE_SUNING) {
             shareGoodsTextTemplateService.resetCommonTemplateSuNing(uid);
+        }else if (goodsType == Constant.SOURCE_TYPE_DY) {
+            shareGoodsTextTemplateService.resetCommonTemplateDY(uid);
         }
 
         if (goodsId != null) {
@@ -1935,7 +2147,7 @@
                 String goodsId = commonGoods.getGoodsId();
                 for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
                     String auctionId = taoKeGoods.getAuctionId();
-                    if (TaoBaoUtil.isEqual(goodsId , auctionId)) {
+                    if (TaoBaoUtil.isEqual(goodsId, auctionId)) {
                         state = 0; // 鍦ㄥ敭
                         break;
                     }
@@ -2025,6 +2237,11 @@
             if (goods != null) {
                 goodsDetail = GoodsDetailVOFactory.convertSuningGoods(goods, paramsDTO);
             }
+        }else if (goodsType == Constant.SOURCE_TYPE_DY) {
+            DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(goodsId));
+            if (goods != null) {
+                goodsDetail = GoodsDetailVOFactory.convertDYGoods(goods, paramsDTO);
+            }
         }
 
         if (goodsDetail == null) {

--
Gitblit v1.8.0