From 81a2c8e297787cc7dc405d6db4972cb917cd80b5 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 17 一月 2020 16:50:57 +0800 Subject: [PATCH] 无用代码删除,单品分享接口修改 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java | 370 +++++++++++++++++++++++++++++----------------------- 1 files changed, 208 insertions(+), 162 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 2b9deb2..40e69b7 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 @@ -73,7 +73,6 @@ import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil; import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; -import com.yeshi.fanli.util.factory.MonitorFactory; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; @@ -83,6 +82,7 @@ import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.util.taobao.TaoLiJinUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; +import com.yeshi.fanli.vo.goods.ShareGoodsCommentChoiceInfo; import com.yeshi.fanli.vo.goods.ShareInfoVO; import net.sf.json.JSONArray; @@ -157,6 +157,28 @@ @Resource private UserTaoLiJinRecordService userTaoLiJinRecordService; + + private List<ShareGoodsCommentChoiceInfo> getCommentChoiceList(String token, String link, String inviteCode, + BigDecimal fanliMoney) { + List<ShareGoodsCommentChoiceInfo> list = new ArrayList<>(); + if (!StringUtil.isNullOrEmpty(token)) + list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_TOKEN, "娣樺彛浠�", token, true, false)); + if (!StringUtil.isNullOrEmpty(link)) { + list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_LINK, "閾炬帴",link, true, false)); + } + if (!StringUtil.isNullOrEmpty(inviteCode)) { + list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_INVITE_CODE, "閭�璇风爜", inviteCode, false, + true)); + } + + list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_DOWNLOAD_LINK, "涓嬭浇閾炬帴", "http://www.baidu.com", false, + true)); + + list.add( + new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_FANLI_MONEY, "杩斿埄閲戦", "楼 "+fanliMoney, false, true)); + + return list; + } /** * @@ -261,169 +283,13 @@ } // 娣樼ぜ閲戝垱寤哄垎浜� - if (source != null && "taolijin".equals(source)) { + if (source != null && "taolijin".equals(source)) {// 娣樼ぜ閲戝垎浜垱寤� createTaoLijin(uid, goodsId, totalNum, relationId, request, out); return; - } - - try { - ShareInfoVO shareInfo = new ShareInfoVO(); - - // 娴嬭瘯 - - TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, goodsId, relationId); - - if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) { - ConfigParamsDTO dto = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(), - acceptData.getVersion()); - - GoodsDetailVO goodsInfo = GoodsDetailVOFactory.convertTaoBao(taoBaoLink.getGoods(), dto); - shareInfo.setGoodsInfo(goodsInfo); - } - - String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(), - Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - goodsId + ""); - - String shortLink = HttpUtil.getShortLink(url); - if (!StringUtil.isNullOrEmpty(shortLink)) { - url = shortLink; - } - - shareInfo.setClickUrl(url); - shareInfo.setToken(TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); - shareInfo.setRule(configService.get(ConfigKeyEnum.shareSingleGoodsRule.getKey())); - shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500)); - - String commentTextStr = configService.get(ConfigKeyEnum.shareSingleGoodsCommentText.getKey()); - List<String> commentTexts = new ArrayList<>(); - if (!StringUtil.isNullOrEmpty(commentTextStr)) { - JSONArray array = JSONArray.fromObject(commentTextStr); - for (int i = 0; i < array.size(); i++) { - if (StringUtil.isNullOrEmpty(inviteCode)) { - if (array.optString(i).contains("[閭�璇风爜]")) { - continue; - } - } - if (StringUtil.isNullOrEmpty(inviteCode)) - commentTexts.add(array.optString(i).replace("[涓嬭浇閾炬帴]", Constant.YINGYONGBAO_LINK) - .replace("[娣樺彛浠", shareInfo.getToken())); - else - commentTexts.add(array.optString(i).replace("[涓嬭浇閾炬帴]", Constant.YINGYONGBAO_LINK) - .replace("[閭�璇风爜]", inviteCode).replace("[娣樺彛浠", shareInfo.getToken())); - } - } - shareInfo.setCommentTexts(commentTexts); - - String shareText = ""; - // 鏃犲埜 - String shopType = taoBaoLink.getGoods().getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO - : TaoBaoConstant.SHARE_PRICE_TM; - - if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { - String text = shareGoodsTextTemplateService.getCommonTemplate(uid); - if (StringUtil.isNullOrEmpty(text)) - text = configService.get(ConfigKeyEnum.goodsShareTextNoCoupon.getKey()); - shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()).replace("{鍟嗗搧鍘熶环}", - MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + ""); - } else// 鏈夊埜 - { - String text = shareGoodsTextTemplateService.geteCouponTemplate(uid); - if (StringUtil.isNullOrEmpty(text)) - text = configService.get(ConfigKeyEnum.goodsShareTextCoupon.getKey()); - - shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()) - .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "") - .replace("{浼樻儬鍒搁潰棰潁", - MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString()) - .replace("{浼樻儬鍒镐环}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + ""); - } - - shareText = shareText.replace("{搴楅摵绫诲瀷}", shopType) - .replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day())) - .replace("{棰嗗埜鐭摼}", shortLink).replace("{娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); - - shareInfo.setShareText(shareText); - - String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim(); - if (descText.startsWith("\\r\\n")) { - descText = descText.substring(0); - } - shareInfo.setDescText(descText); - // 娴嬭瘯 - // 2.0.2涔嬪墠 - if (!VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(), acceptData.getVersion())) - shareInfo.setClickUrl(getERCodeContent(configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()), - taoBaoLink.getGoods(), shareInfo.getToken())); - - shareInfo.setWxErCode(getERCodeContent(configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()), taoBaoLink.getGoods(), - shareInfo.getToken())); - - // 鎻愮ず鍥炬枃鍐呭 - String imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs.getKey()); - JSONArray array = JSONArray.fromObject(imgs); - int p = (int) (array.size() * Math.random()); - if (p < array.size()) { - shareInfo.setNotifyPicture(array.optString(p)); - } - shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotify.getKey())); - - // 鍒嗕韩閲戦 - BigDecimal rate = hongBaoManageService.getShareRate(); - BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate); - shareInfo.setShareMoney("楼" + shareMoney.toString()); - - // 鍒嗕韩id - try { - ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, - Constant.SOURCE_TYPE_TAOBAO, false); - shareInfo.setShareId(shareRecord.getRedisKey()); - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - - out.print(JsonUtil.loadTrueResult( - JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); - - final TaoBaoLink taobaoLink = taoBaoLink; - // 寮傛鎿嶄綔 - 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(UserShareGoodsHistory.TYPE_TAOBAO); - history.setTkCode(TaoBaoUtil.filterTaoToken(taobaoLink.getTaoToken())); - history.setLink(taobaoLink.getClickUrl()); - history.setQuanLink(taobaoLink.getCouponLink()); - history.setGoodsId(taobaoLink.getGoods().getAuctionId()); - history.setPostPicture(taobaoLink.getGoods().getPictUrl()); - history.setShareImg(taobaoLink.getClickUrl()); - List<String> imgList = taobaoLink.getGoods().getImgList(); - if (imgList == null) { - imgList = new ArrayList<>(); - } - history.setPictures(JsonUtil.getGson().toJson(imgList)); - shareGoodsService.addShareGoodsHistory(history); - } - }); + } else {// 鏅�氬垎浜垱寤� + createCommonTaoBaoShare(acceptData.getPlatform(), acceptData.getVersion(), goodsId, inviteCode, uid, + needGoods, relationId, out); return; - } catch (ShareGoodsException e) { - LogHelper.errorDetailInfo(e, "鍒嗕韩鍑洪敊:uid:" + uid + " goodsId:" + goodsId, ""); - // 鍒嗕韩鍑洪敊鎶ヨ - try { - monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "鍒嗕韩鍑洪敊")); - } catch (Exception e1) { - } - out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); - businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(goodsId + "")); } } @@ -603,6 +469,166 @@ } } + public void createCommonTaoBaoShare(String platform, String version, Long goodsId, String inviteCode, Long uid, + boolean needGoods, String relationId, PrintWriter out) { + try { + ShareInfoVO shareInfo = new ShareInfoVO(); + + TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, goodsId, relationId); + + if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) { + ConfigParamsDTO dto = hongBaoManageService.getShowComputeRate(platform, version); + GoodsDetailVO goodsInfo = GoodsDetailVOFactory.convertTaoBao(taoBaoLink.getGoods(), dto); + shareInfo.setGoodsInfo(goodsInfo); + } + + String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(), + Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + goodsId + ""); + + String shortLink = HttpUtil.getShortLink(url); + if (!StringUtil.isNullOrEmpty(shortLink)) { + url = shortLink; + } + + shareInfo.setClickUrl(url); + shareInfo.setToken(TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); + shareInfo.setRule(configService.get(ConfigKeyEnum.shareSingleGoodsRule.getKey())); + shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500)); + + String commentTextStr = configService.get(ConfigKeyEnum.shareSingleGoodsCommentText.getKey()); + List<String> commentTexts = new ArrayList<>(); + if (!StringUtil.isNullOrEmpty(commentTextStr)) { + JSONArray array = JSONArray.fromObject(commentTextStr); + for (int i = 0; i < array.size(); i++) { + if (StringUtil.isNullOrEmpty(inviteCode)) { + if (array.optString(i).contains("[閭�璇风爜]")) { + continue; + } + } + if (StringUtil.isNullOrEmpty(inviteCode)) + commentTexts.add(array.optString(i).replace("[涓嬭浇閾炬帴]", Constant.YINGYONGBAO_LINK) + .replace("[娣樺彛浠", shareInfo.getToken())); + else + commentTexts.add(array.optString(i).replace("[涓嬭浇閾炬帴]", Constant.YINGYONGBAO_LINK) + .replace("[閭�璇风爜]", inviteCode).replace("[娣樺彛浠", shareInfo.getToken())); + } + } + shareInfo.setCommentTexts(commentTexts); + + String shareText = ""; + // 鏃犲埜 + String shopType = taoBaoLink.getGoods().getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO + : TaoBaoConstant.SHARE_PRICE_TM; + + if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { + String text = shareGoodsTextTemplateService.getCommonTemplate(uid); + if (StringUtil.isNullOrEmpty(text)) + text = configService.get(ConfigKeyEnum.goodsShareTextNoCoupon.getKey()); + shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()).replace("{鍟嗗搧鍘熶环}", + MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + ""); + } else// 鏈夊埜 + { + String text = shareGoodsTextTemplateService.geteCouponTemplate(uid); + if (StringUtil.isNullOrEmpty(text)) + text = configService.get(ConfigKeyEnum.goodsShareTextCoupon.getKey()); + + shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()) + .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "") + .replace("{浼樻儬鍒搁潰棰潁", + MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString()) + .replace("{浼樻儬鍒镐环}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + ""); + } + + shareText = shareText.replace("{搴楅摵绫诲瀷}", shopType) + .replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day())) + .replace("{棰嗗埜鐭摼}", shortLink).replace("{娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); + + shareInfo.setShareText(shareText); + + String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim(); + if (descText.startsWith("\\r\\n")) { + descText = descText.substring(0); + } + shareInfo.setDescText(descText); + // 娴嬭瘯 + // 2.0.2涔嬪墠 + if (!VersionUtil.greaterThan_2_0_2(platform, version)) + shareInfo.setClickUrl(getERCodeContent(configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()), + taoBaoLink.getGoods(), shareInfo.getToken())); + + shareInfo.setWxErCode(getERCodeContent(configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()), + taoBaoLink.getGoods(), shareInfo.getToken())); + + // 鎻愮ず鍥炬枃鍐呭 + String imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs.getKey()); + JSONArray array = JSONArray.fromObject(imgs); + int p = (int) (array.size() * Math.random()); + if (p < array.size()) { + shareInfo.setNotifyPicture(array.optString(p)); + } + shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotify.getKey())); + + // 鍒嗕韩閲戦 + BigDecimal rate = hongBaoManageService.getShareRate(); + BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); + + // 鍒嗕韩id + try { + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, + Constant.SOURCE_TYPE_TAOBAO, false); + shareInfo.setShareId(shareRecord.getRedisKey()); + } catch (Exception e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(shareInfo.getToken(), null, inviteCode, + TaoBaoUtil.getGoodsHongBaoMoney(taoBaoLink.getGoods(), hongBaoManageService.getFanLiRate()))); + + shareInfo.setCommentText(shareInfo.getShareText()); + shareInfo.setRecommendText(shareInfo.getDescText()); + + out.print(JsonUtil.loadTrueResult( + JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); + + final TaoBaoLink taobaoLink = taoBaoLink; + // 寮傛鎿嶄綔 + 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(UserShareGoodsHistory.TYPE_TAOBAO); + history.setTkCode(TaoBaoUtil.filterTaoToken(taobaoLink.getTaoToken())); + history.setLink(taobaoLink.getClickUrl()); + history.setQuanLink(taobaoLink.getCouponLink()); + history.setGoodsId(taobaoLink.getGoods().getAuctionId()); + history.setPostPicture(taobaoLink.getGoods().getPictUrl()); + List<String> imgList = taobaoLink.getGoods().getImgList(); + if (imgList == null) { + imgList = new ArrayList<>(); + } + history.setPictures(JsonUtil.getGson().toJson(imgList)); + shareGoodsService.addShareGoodsHistory(history); + } + }); + return; + } catch (ShareGoodsException e) { + LogHelper.errorDetailInfo(e, "鍒嗕韩鍑洪敊:uid:" + uid + " goodsId:" + goodsId, ""); + out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); + businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(goodsId + "")); + } + } + /** * 浜笢鍒涘缓鍒嗕韩 * @@ -700,6 +726,16 @@ e1.printStackTrace(); } } + + String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getClickUrl(), inviteCode, + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getFanLiRate()))); + + shareInfo.setCommentText(shareInfo.getShareText()); + shareInfo.setRecommendText(shareInfo.getDescText()); + out.print(JsonUtil.loadTrueResult( JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); @@ -720,7 +756,7 @@ history.setGoodsId(goodsId); history.setPostPicture(goods.getPicUrl()); history.setShareImg(jumpLink); - + List<String> imgList = goods.getImageList(); if (imgList == null) { imgList = new ArrayList<>(); @@ -827,6 +863,16 @@ e1.printStackTrace(); } } + + String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getClickUrl(), inviteCode, + PinDuoDuoUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate()))); + + shareInfo.setCommentText(shareInfo.getShareText()); + shareInfo.setRecommendText(shareInfo.getDescText()); + out.print(JsonUtil.loadTrueResult( JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); -- Gitblit v1.8.0