admin
2023-04-12 651f2856e9ae10aacbfb8327d967aacbb6d58333
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("[口令]", 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) {