From d8359ddb48dab5cc797a9d552e11fde571f4920c Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期二, 27 八月 2019 12:32:46 +0800 Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java | 196 ++++++++++++++++++++++++++---------------------- 1 files changed, 106 insertions(+), 90 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 bb251d5..55ad6fc 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 @@ -71,6 +71,7 @@ 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; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; @@ -157,8 +158,9 @@ * 鑾峰彇娣樺疂鐨勫垎浜摼鎺� * * @param acceptData - * @param uid -鐢ㄦ埛ID - * @param auctionId-鍟嗗搧ID + * @param uid + * -鐢ㄦ埛ID + * @param auctionId-鍟嗗搧ID * @param out */ @RequestMapping(value = "createShareInfo") @@ -302,7 +304,7 @@ // 鍒嗕韩id try { ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, - Constant.SOURCE_TYPE_TAOBAO); + Constant.SOURCE_TYPE_TAOBAO, false); shareInfo.setShareId(shareRecord.getRedisKey()); } catch (Exception e) { try { @@ -366,12 +368,21 @@ public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, HttpServletRequest request, PrintWriter out) { try { - TaoBaoLink taoBaoLink = shareGoodsService.getTaoLiJinLinkForShare(uid, auctionId, relationId); + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, + TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT)); + } catch (TaobaoGoodsDownException e2) { + e2.printStackTrace(); + } - TaoBaoGoodsBrief goods = taoBaoLink.getGoods(); + if (goods == null) { + out.print(JsonUtil.loadFalseResult("鍟嗗搧宸蹭笅鏋�")); + return; + } // 璁$畻鎺ㄥ箍绾㈠寘 - String warningRate = configTaoLiJinService.getValueByKey("warning_value"); + String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date()); BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods); // 鎺ㄥ箍绾㈠寘 涓嶈兘灏忎簬1 @@ -405,53 +416,50 @@ } shareInfo.setClickUrl(url); + TaoBaoLink taoBaoLink = new TaoBaoLink(); + taoBaoLink.setCouponLink(taoLiJinLink); + taoBaoLink.setClickUrl(taoLiJinLink); + // 鍒涘缓娣樺彛浠� if (!StringUtil.isNullOrEmpty(taoLiJinLink)) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoLiJinLink); if (!StringUtil.isNullOrEmpty(quanToken)) { taoBaoLink.setTaoToken(quanToken); } - } else if (!StringUtil.isNullOrEmpty(taoBaoLink.getClickUrl())) { - String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), - taoBaoLink.getClickUrl()); - if (!StringUtil.isNullOrEmpty(quanToken)) { - taoBaoLink.setTaoToken(quanToken); - } } shareInfo.setToken(taoBaoLink.getTaoToken()); shareInfo.setRule(configService.get("share_single_goods_rule")); - shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500)); + shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(goods.getPictUrl(), 500)); // 鏃犲埜 - String shopType = taoBaoLink.getGoods().getUserType() == 0 ? "娣樺疂浠�" : "澶╃尗浠�"; + String shopType = goods.getUserType() == 0 ? "娣樺疂浠�" : "澶╃尗浠�"; String shareText = ""; - if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { + if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) { String text = shareGoodsTextTemplateService.getCommonTemplate(uid); if (StringUtil.isNullOrEmpty(text)) text = configService.get("goods_share_text_nocoupon"); - shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()).replace("{鍟嗗搧鍘熶环}", - MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + ""); + shareText = text.replace("{鏍囬}", goods.getTitle()).replace("{鍟嗗搧鍘熶环}", + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()) + ""); } else// 鏈夊埜 { String text = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid); if (StringUtil.isNullOrEmpty(text)) - text = configTaoLiJinService.getValueByKey("goods_share_text"); + text = configTaoLiJinService.getValueByKey("goods_share_text", new Date()); - shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()) - .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "") - .replace("{浼樻儬鍒搁潰棰潁", - MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString()) + shareText = text.replace("{鏍囬}", goods.getTitle()) + .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()) + "") + .replace("{浼樻儬鍒搁潰棰潁", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString()) .replace("{娣樼ぜ閲戦潰棰潁", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString()) - .replace("{浼樻儬鍒镐环}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + ""); + .replace("{浼樻儬鍒镐环}", TaoBaoUtil.getAfterUseCouplePrice(goods) + ""); } shareText = shareText.replace("{搴楅摵绫诲瀷}", shopType) - .replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day())) - .replace("{棰嗗埜鐭摼}", shortLink).replace("{娣樺彛浠", taoBaoLink.getTaoToken()); + .replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{棰嗗埜鐭摼}", shortLink) + .replace("{娣樺彛浠", taoBaoLink.getTaoToken()); shareInfo.setShareText(shareText); - String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim(); + String descText = shareText.replace(goods.getTitle(), "").trim(); if (descText.startsWith("\\r\\n")) descText = descText.substring(0); @@ -467,11 +475,11 @@ // 娣诲姞鍒嗕韩璁板綍 BigDecimal rate = hongBaoManageService.getShareRate(); - BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate); + BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate); shareInfo.setShareMoney("楼" + shareMoney.toString()); try { ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId, - Constant.SOURCE_TYPE_TAOBAO); + Constant.SOURCE_TYPE_TAOBAO, true); shareInfo.setShareId(shareRecord.getRedisKey()); } catch (Exception e) { try { @@ -483,6 +491,7 @@ out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(shareInfo))); final TaoBaoLink taobaoLink = taoBaoLink; + final TaoBaoGoodsBrief finalGoods=goods; // 寮傛鎿嶄綔 com.yeshi.fanli.util.ThreadUtil.run(new Runnable() { @Override @@ -496,10 +505,10 @@ history.setTkCode(taobaoLink.getTaoToken()); history.setLink(taobaoLink.getClickUrl()); history.setQuanLink(taobaoLink.getCouponLink()); - history.setGoodsId(taobaoLink.getGoods().getAuctionId()); - history.setPostPicture(taobaoLink.getGoods().getPictUrl()); + history.setGoodsId(finalGoods.getAuctionId()); + history.setPostPicture(finalGoods.getPictUrl()); - List<String> imgList = taobaoLink.getGoods().getImgList(); + List<String> imgList = finalGoods.getImgList(); if (imgList == null) { imgList = new ArrayList<>(); } @@ -508,14 +517,9 @@ } }); return; - } catch (ShareGoodsException e) { + } catch (Exception e) { LogHelper.errorDetailInfo(e, "鍒嗕韩鍑洪敊:uid:" + uid + "auctionId:" + auctionId, ""); - // 鍒嗕韩鍑洪敊鎶ヨ - try { - monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "鍒嗕韩鍑洪敊")); - } catch (Exception e1) { - } - out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); + out.print(JsonUtil.loadFalseResult("鍒涘缓鍒嗕韩鍑洪敊")); businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + "")); } } @@ -538,41 +542,46 @@ return; } - String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(), - Constant.systemCommonConfig.getShareGoodsPagePathJD(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - goodsId + ""); + // String url = String.format("http://%s%s?uid=%s&id=%s", + // configService.getH5Host(), + // Constant.systemCommonConfig.getShareGoodsPagePathJD(), + // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + // goodsId + ""); - // 鍒哥煭杩炴帴 - String shortLink = HttpUtil.getShortLink(url); - if (!StringUtil.isNullOrEmpty(shortLink)) { - url = shortLink; + String couponUrl = null; + JDCouponInfo couponInfo = jdGoods.getCouponInfo(); + if (couponInfo != null) { + couponUrl = couponInfo.getLink(); } + String materialId = "https://item.jd.com/" + goodsId + ".html"; + String jumpLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", uid + ""); ShareInfoVO shareInfo = new ShareInfoVO(); - shareInfo.setClickUrl(url); + shareInfo.setClickUrl(jumpLink); shareInfo.setRule(configService.get("share_rule_link_jd")); shareInfo.setPictUrl(jdGoods.getPicUrl()); String shareText = ""; boolean hasCoupon = false; + // 鍒嗕韩妯℃澘 - JDCouponInfo couponInfo = jdGoods.getCouponInfo(); ShareGoodsTextTemplate textTemplate = shareGoodsTextTemplateService.getShareGoodsTextTemplate(uid); if (couponInfo == null) { // 鏃犲埜妯℃澘 - if (textTemplate != null) + if (textTemplate != null) shareText = textTemplate.getShareJDTextTemplate(); - + if (StringUtil.isNullOrEmpty(shareText)) shareText = configService.get("goods_share_text_nocoupon_jd"); } else { // 鏈夊埜妯℃澘 hasCoupon = true; if (textTemplate != null) shareText = textTemplate.getShareJDTextTemplateCoupon(); - + if (StringUtil.isNullOrEmpty(shareText)) shareText = configService.get("goods_share_text_coupon_jd"); } - shareText = shareGoodsTextTemplateService.createContentByTemplateJD(shareText, uid, jdGoods, shortLink, hasCoupon); + shareText = shareGoodsTextTemplateService.createContentByTemplateJD(shareText, uid, jdGoods, jumpLink, + hasCoupon); shareInfo.setShareText(shareText); String descText = shareText.replace(jdGoods.getSkuName(), "").trim(); @@ -595,7 +604,7 @@ shareInfo.setShareMoney("楼" + shareMoney.toString()); try { ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, - Constant.SOURCE_TYPE_JD); + Constant.SOURCE_TYPE_JD, false); shareInfo.setShareId(shareRecord.getRedisKey()); } catch (Exception e) { try { @@ -649,17 +658,16 @@ return; } - String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(), - Constant.systemCommonConfig.getShareGoodsPagePathPDD(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - goodsId + ""); + // String url = String.format("http://%s%s?uid=%s&id=%s", + // configService.getH5Host(), + // Constant.systemCommonConfig.getShareGoodsPagePathPDD(), + // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + // goodsId + ""); - String shortLink = HttpUtil.getShortLink(url); - if (!StringUtil.isNullOrEmpty(shortLink)) { - url = shortLink; - } - + String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", uid + ""); + ShareInfoVO shareInfo = new ShareInfoVO(); - shareInfo.setClickUrl(url); + shareInfo.setClickUrl(jumpLink); shareInfo.setRule(configService.get("share_rule_link_pdd")); shareInfo.setPictUrl(goods.getGoodsImageUrl()); @@ -676,17 +684,17 @@ hasCoupon = true; if (textTemplate != null) template = textTemplate.getSharePDDTextTemplateCoupon(); - + if (StringUtil.isNullOrEmpty(template)) template = configService.get("goods_share_text_coupon_pdd"); } // 鍒涘缓鍙d护 String token = PinDuoDuoApiUtil.createGenerate(goodsId); - + // 鐢熸垚鍒嗕韩鍐呭 - String shareText = shareGoodsTextTemplateService.createContentByTemplatePDD(template, uid, goods, shortLink, - hasCoupon, token); + String shareText = shareGoodsTextTemplateService.createContentByTemplatePDD(template, uid, goods, jumpLink, + hasCoupon, token); shareInfo.setShareText(shareText); String descText = shareText.replace(goods.getGoodsName(), "").trim(); @@ -711,7 +719,7 @@ try { ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, - Constant.SOURCE_TYPE_JD); + Constant.SOURCE_TYPE_PDD, false); shareInfo.setShareId(shareRecord.getRedisKey()); } catch (Exception e) { try { @@ -731,7 +739,7 @@ history.setUser(new UserInfo(uid)); history.setHongbao(shareMoney); history.setCreateTime(new Date()); - history.setGoodsType(Constant.SOURCE_TYPE_JD); + history.setGoodsType(Constant.SOURCE_TYPE_PDD); history.setTkCode(null); history.setLink(null); history.setQuanLink(null); @@ -785,12 +793,12 @@ return; } - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + if (goodsType == Constant.SOURCE_TYPE_JD) { createJDViewText(goodsType, uid, template, goodsId, hasCoupon, out); return; } - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + if (goodsType == Constant.SOURCE_TYPE_PDD) { createPDDViewText(goodsType, uid, template, goodsId, hasCoupon, out); return; } @@ -939,10 +947,13 @@ } } - 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); + String couponUrl = null; + JDCouponInfo couponInfo = goods.getCouponInfo(); + if (couponInfo != null) { + couponUrl = couponInfo.getLink(); + } + String materialId = "https://item.jd.com/" + goodsId + ".html"; + String shortLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", uid + ""); String content = shareGoodsTextTemplateService.createContentByTemplateJD(template, uid, goods, shortLink, hasCoupon); @@ -952,7 +963,7 @@ } /** - * 鍒涘缓浜笢鍒嗕韩妯℃澘 + * 鍒涘缓鎷煎澶氬垎浜ā鏉� * * @param uid * @param template @@ -994,11 +1005,15 @@ } } - // 鍒涘缓h5杩炴帴 - 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); + // // 鍒涘缓h5杩炴帴 + // 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); + + String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", uid + ""); // 鍒涘缓鍙d护 String token = PinDuoDuoApiUtil.createGenerate(goodsId); @@ -1027,7 +1042,7 @@ if (tljId != null) { template = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid); if (StringUtil.isNullOrEmpty(template)) - template = configTaoLiJinService.getValueByKey("goods_share_text"); + template = configTaoLiJinService.getValueByKey("goods_share_text", new Date()); } else { template = shareGoodsTextTemplateService.geteCouponTemplate(uid); if (StringUtil.isNullOrEmpty(template)) @@ -1120,7 +1135,8 @@ if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { if (tljId != null) { - out.print(JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules"))); + out.print( + JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules", new Date()))); } else { out.print(JsonUtil.loadTrueResult(configService.get("share_goods_template_rules"))); } @@ -1201,7 +1217,8 @@ * * @param acceptData * @param uid - * @param hasCoupon -鏄惁鏈夊埜 + * @param hasCoupon + * -鏄惁鏈夊埜 * @param out */ @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST) @@ -1217,7 +1234,7 @@ return; } - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { if (hasCoupon) { if (tljId != null) { shareGoodsTextTemplateService.resetTaoLijinTemplate(uid); @@ -1227,21 +1244,20 @@ } else { shareGoodsTextTemplateService.resetCommonTemplate(uid); } - } else if (goodsType == Constant.SOURCE_TYPE_JD) { - if (hasCoupon) { + } else if (goodsType == Constant.SOURCE_TYPE_JD) { + if (hasCoupon) { shareGoodsTextTemplateService.resetCouponTemplateJD(uid); } else { shareGoodsTextTemplateService.resetCommonTemplateJD(uid); } - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - if (hasCoupon) { + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + if (hasCoupon) { shareGoodsTextTemplateService.resetCouponTemplatePDD(uid); } else { shareGoodsTextTemplateService.resetCommonTemplatePDD(uid); } - } - - + } + if (goodsId != null) { viewShareTextTemplate(acceptData, uid, null, goodsType, goodsId, tljId, hasCoupon, out); return; -- Gitblit v1.8.0