From 62a447d89331aee1feae7724c7616aa1bb2cfe79 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 16 十月 2024 14:28:37 +0800 Subject: [PATCH] 将CMQ替换为rabbitmq --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java | 396 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 342 insertions(+), 54 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 ae201d0..f8e13ff 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 @@ -1,7 +1,9 @@ package com.yeshi.fanli.controller.client.v2; import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -11,11 +13,22 @@ import javax.servlet.http.HttpServletRequest; import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.entity.SystemFunction; +import com.yeshi.fanli.entity.SystemPIDInfo; import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException; import com.yeshi.fanli.service.inter.pdd.PDDAuthService; +import com.yeshi.fanli.service.inter.user.*; +import com.yeshi.fanli.service.manger.PIDManager; 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 kafka.utils.Json; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -24,7 +37,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.yeshi.fanli.dto.ConfigParamsDTO; +import com.yeshi.fanli.dto.GoodsMoneyConfigParamsDTO; import com.yeshi.fanli.dto.jd.JDCouponInfo; import com.yeshi.fanli.dto.jd.JDPingouInfo; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; @@ -61,10 +74,6 @@ import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService; -import com.yeshi.fanli.service.inter.user.UserInfoExtraService; -import com.yeshi.fanli.service.inter.user.UserInfoService; -import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService; -import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil; @@ -91,6 +100,9 @@ @Controller @RequestMapping("api/v2/share") public class ShareControllerV2 { + + Logger logger = LoggerFactory.getLogger(ShareControllerV2.class); + @Resource private ShareGoodsService shareGoodsService; @@ -148,6 +160,12 @@ @Resource private PDDAuthService pddAuthService; + + @Resource + private PIDManager pidManager; + + @Resource + private UserFunctionsLimitService userFunctionsLimitService; private List<ShareGoodsCommentChoiceInfo> getCommentChoiceList(String token, String link, String inviteCode, BigDecimal fanliMoney) { @@ -212,9 +230,14 @@ return; } + if (userFunctionsLimitService.isLimit(uid, SystemFunction.share, new Date())) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ姛鑳介檺鍒朵娇鐢�")); + return; + } + // 娣樺疂 if (goodsType == null || goodsType == Constant.SOURCE_TYPE_TAOBAO) { - createTaoBaoShare(acceptData, uid, Long.parseLong(goodsId), totalNum, source, needGoods, request, out); + createTaoBaoShare(acceptData, uid, goodsId, totalNum, source, needGoods, request, out); return; } @@ -226,7 +249,7 @@ // 鎷煎澶� if (goodsType == Constant.SOURCE_TYPE_PDD) { - createPDDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out); + createPDDShare(acceptData, uid, goodsId, source, needGoods, out); return; } @@ -242,11 +265,39 @@ return; } + // 鎶栭煶 + if (goodsType == Constant.SOURCE_TYPE_DY) { + try { + createDYShare(acceptData, uid,Long.parseLong( goodsId), source, needGoods, out); + } catch (Exception e) { + out.print(JsonUtil.loadFalseResult("杞摼澶辫触")); + e.printStackTrace(); + } + return; + } + } public static String getERCodeContentNew(String template, TaoBaoGoodsBrief goods, String token) { + String tempToken = ""; + String[] sts = token.split(" "); + if (sts.length > 1) { + for (int i = 0; i < sts.length - 1; i++) { + tempToken += sts[i] + " "; + } + } else { + tempToken = token; + } + tempToken = tempToken.trim(); + + try { + tempToken = URLEncoder.encode(tempToken, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + String commentText = template.replace("[鍘熶环]", goods.getZkPrice().toString()); - commentText = commentText.replace("[娣樺彛浠", token); + commentText = commentText.replace("[娣樺彛浠", tempToken); if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) { commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); @@ -276,7 +327,7 @@ * @param request * @param out */ - public void createTaoBaoShare(AcceptData acceptData, Long uid, Long goodsId, Integer totalNum, String source, + public void createTaoBaoShare(AcceptData acceptData, Long uid, String goodsId, Integer totalNum, String source, Boolean needGoods, HttpServletRequest request, PrintWriter out) { if (needGoods == null) needGoods = false; @@ -306,6 +357,10 @@ createTaoLijin(uid, goodsId, totalNum, relationId, acceptData, request, out); return; } else {// 鏅�氬垎浜垱寤� + if("鐚滀綘鍠滄".equalsIgnoreCase(source)){ + out.print(JsonUtil.loadFalseResult(4, "鏆備笉鏀寔鍒嗕韩")); + return; + } createCommonTaoBaoShare(acceptData.getPlatform(), acceptData.getVersion(), goodsId, inviteCode, uid, needGoods, relationId, acceptData, out); return; @@ -323,7 +378,7 @@ * @param request * @param out */ - public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, AcceptData acceptData, HttpServletRequest request, + public void createTaoLijin(Long uid, String auctionId, int totalNum, String relationId, AcceptData acceptData, HttpServletRequest request, PrintWriter out) { try { TaoBaoGoodsBrief goods = null; @@ -494,17 +549,17 @@ } } - public void createCommonTaoBaoShare(String platform, String version, Long goodsId, String inviteCode, Long uid, + public void createCommonTaoBaoShare(String platform, String version, String goodsId, String inviteCode, Long uid, boolean needGoods, String relationId, AcceptData acceptData, PrintWriter out) { SystemEnum system = SystemInfoUtil.getSystem(acceptData); try { ShareInfoVO shareInfo = new ShareInfoVO(); - TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(uid, goodsId, relationId, null); + TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, goodsId, relationId, null); if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) { - ConfigParamsDTO dto = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version, acceptData.getSystem()); + GoodsMoneyConfigParamsDTO dto = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version, acceptData.getSystem()); GoodsDetailVO goodsInfo = GoodsDetailVOFactory.convertTaoBao(taoBaoLink.getGoods(), dto); shareInfo.setGoodsInfo(goodsInfo); } @@ -738,9 +793,19 @@ couponUrl = couponInfo.getLink(); } String materialId = "https://item.jd.com/" + goodsId + ".html"; - String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_SHARE + "", uid + ""); + String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share); + String jumpLink = null; + try { + jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pid, uid + ""); + } catch (Exception e) { + logger.warn(String.format("浜笢杞摼鍑洪敊锛歮aterialId-%s couponUrl-%s", materialId, couponUrl), e); + } if (StringUtil.isNullOrEmpty(jumpLink)) { - jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, JDApiUtil.POSITION_SHARE + "", uid + ""); + try { + jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, null, null, pid, uid + ""); + } catch (Exception e) { + logger.warn(String.format("浜笢杞摼鍑洪敊锛歮aterialId-%s couponUrl-%s", materialId, couponUrl), e); + } } ShareInfoVO shareInfo = new ShareInfoVO(); @@ -787,7 +852,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) { @@ -863,7 +928,7 @@ history.setTkCode(null); history.setLink(null); history.setQuanLink(null); - history.setGoodsId(goodsId); + history.setGoodsId(goodsId + ""); history.setPostPicture(goods.getPicUrl()); history.setShareImg(jumpLinkNew); @@ -890,18 +955,20 @@ * @param source * @param out */ - public void createPDDShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods, + public void createPDDShare(AcceptData acceptData, Long uid, String goodsId, String source, boolean needGoods, PrintWriter out) { //鏌ヨ褰撳墠鐢ㄦ埛鏄惁鎺堟潈 + String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share); + if (VersionUtil.greaterThan_2_1_5(acceptData.getPlatform(), acceptData.getVersion())) { - if (!PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_SHARE, pddAuthService.getFanliCustomParams(uid))) { + if (!PinDuoDuoApiUtil.isAuth(pid, pddAuthService.getFanliCustomParams(uid))) { out.print(JsonUtil.loadFalseResult(20001, "灏氭湭澶囨,璇峰厛澶囨")); return; } } else { - if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2021-05-01", "yyyy-MM-dd") && !PinDuoDuoApiUtil.isAuth(PinDuoDuoApiUtil.PID_SHARE, pddAuthService.getFanliCustomParams(uid))) { + if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2021-05-01", "yyyy-MM-dd") && !PinDuoDuoApiUtil.isAuth(pid, pddAuthService.getFanliCustomParams(uid))) { out.print(JsonUtil.loadFalseResult(20001, "璇峰崌绾у埌鏈�鏂扮増")); return; } @@ -920,7 +987,7 @@ // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), // goodsId + ""); - String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", uid + ""); + String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pid, pddAuthService.getFanliCustomParams(uid) + ""); SystemEnum system = SystemInfoUtil.getSystem(acceptData); @@ -933,7 +1000,7 @@ if (needGoods) { shareInfo .setGoodsInfo(GoodsDetailVOFactory.convertPDDGoods(goods, - new ConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), + new GoodsMoneyConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), hongBaoManageService.getShareRate(acceptData.getSystem()), Constant.MAX_REWARD_RATE, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); } @@ -975,7 +1042,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) { @@ -1050,7 +1117,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; @@ -1101,7 +1168,7 @@ if (needGoods) { shareInfo .setGoodsInfo(GoodsDetailVOFactory.convertVIPGoods(goods, - new ConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), + new GoodsMoneyConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), hongBaoManageService.getShareRate(acceptData.getSystem()), Constant.MAX_REWARD_RATE, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); } @@ -1130,7 +1197,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) { @@ -1179,7 +1246,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(); @@ -1224,7 +1291,7 @@ String couponLink = goods.getCouponInfo().getCouponUrl(); String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sts[0], sts[1]), - StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, uid + ""); + StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), uid + ""); ShareInfoVO shareInfo = new ShareInfoVO(); shareInfo.setClickUrl(jumpLink); @@ -1236,7 +1303,7 @@ if (needGoods) { shareInfo .setGoodsInfo(GoodsDetailVOFactory.convertSuningGoods(goods, - new ConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), + new GoodsMoneyConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), hongBaoManageService.getShareRate(acceptData.getSystem()), Constant.MAX_REWARD_RATE, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); } @@ -1274,7 +1341,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 { @@ -1360,7 +1427,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()); @@ -1370,6 +1437,162 @@ 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) throws Exception { + 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.getZlink()); + shareInfo.setWxErCode(convertResult.getZlink()); + 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); @@ -1401,17 +1624,17 @@ } if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - createTaoBaoViewText(goodsType, uid, template, Long.parseLong(goodsId), tljId, hasCoupon, out); + createTaoBaoViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, tljId, hasCoupon, out); return; } if (goodsType == Constant.SOURCE_TYPE_JD) { - createJDViewText(goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out); + createJDViewText(acceptData.getSystem(), goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out); return; } if (goodsType == Constant.SOURCE_TYPE_PDD) { - createPDDViewText(goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out); + createPDDViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, hasCoupon, out); return; } @@ -1421,7 +1644,12 @@ } if (goodsType == Constant.SOURCE_TYPE_SUNING) { - createSuNingViewText(goodsType, uid, template, goodsId, hasCoupon, out); + 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; } } @@ -1437,7 +1665,7 @@ * @param hasCoupon * @param out */ - private void createTaoBaoViewText(Integer goodsType, Long uid, String template, Long goodsId, Long tljId, + private void createTaoBaoViewText(SystemEnum system, Integer goodsType, Long uid, String template, String goodsId, Long tljId, Boolean hasCoupon, PrintWriter out) { TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId); if (goods == null) @@ -1472,11 +1700,12 @@ } if (StringUtil.isNullOrEmpty(token)) { + String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share); TaoKeAppInfo app = new TaoKeAppInfo(); - app.setAdzoneId(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]); + app.setAdzoneId(pid.split("_")[3]); app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); - app.setPid(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT); + app.setPid(pid); TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app, null, null); if (goodsLink != null) token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), @@ -1499,7 +1728,7 @@ * @param hasCoupon * @param out */ - private void createJDViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, + private void createJDViewText(SystemEnum system, Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, PrintWriter out) { JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId); if (goods == null) { @@ -1525,8 +1754,13 @@ couponUrl = couponInfo.getLink(); } String materialId = "https://item.jd.com/" + goodsId + ".html"; - String shortLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, JDApiUtil.POSITION_SHARE + "", - uid + ""); + String shortLink = null; + try { + shortLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share), + uid + ""); + } catch (Exception e) { + logger.warn(String.format("浜笢杞摼鍑洪敊锛歮aterialId-%s couponUrl-%s", materialId, couponUrl), e); + } String content = shareGoodsTextTemplateService.createContentJD(template, goods, shortLink, hasCoupon); JSONObject data = new JSONObject(); @@ -1544,7 +1778,7 @@ * @param hasCoupon * @param out */ - private void createPDDViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, + private void createPDDViewText(SystemEnum system, Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon, PrintWriter out) { PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); if (goods == null) { @@ -1572,7 +1806,7 @@ // goodsId + ""); // String shortLink = HttpUtil.getShortLink(url); - String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), PinDuoDuoApiUtil.PID_SHARE + "", uid + ""); + String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), uid + ""); // // 鍒涘缓鍙d护 // String token = PinDuoDuoApiUtil.createGenerate(goodsId); @@ -1626,7 +1860,7 @@ } - private void createSuNingViewText(Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon, + private void createSuNingViewText(SystemEnum system, Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon, PrintWriter out) { String[] ids = SuningUtil.getGoodsIdDetail(goodsId); SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(ids[1], ids[0]); @@ -1649,7 +1883,7 @@ String couponLink = goods.getCouponInfo().getCouponUrl(); String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(ids[0], ids[1]), - StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, uid + ""); + StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(system, Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), uid + ""); // 鐢熸垚鏅�氬垎浜唴瀹� String content = shareGoodsTextTemplateService.createCommonShareTextSuNing(template, goods, jumpLink); @@ -1658,6 +1892,46 @@ data.put("content", content); 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 = null; + try { + convertResult = CSJCPSApiUtil.goodsConvert(goods.getDetail_url(), DYUtil.createShareExtraInfo(uid),""); + } catch (Exception e) { + out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧杞摼澶辫触")); + return; + } + + + // 鐢熸垚鏅�氬垎浜唴瀹� + String content = shareGoodsTextTemplateService.createCommonShareTextDY(template, goods, convertResult.getPassword()); + + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } + /** * 鑾峰彇鍒嗕韩妯℃澘 @@ -1679,6 +1953,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; } @@ -1733,6 +2009,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))); } } @@ -1764,6 +2042,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())); @@ -1798,6 +2078,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) { @@ -1840,7 +2122,7 @@ // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭 List<TaoBaoGoodsBrief> listTaoKeGoods = null; - List<Long> listGid = new ArrayList<Long>(); + List<String> listGid = new ArrayList<>(); for (UserShareGoodsGroup goodsGroup : list) { CommonGoods commonGoods = goodsGroup.getCommonGoods(); Integer goodsType = commonGoods.getGoodsType(); @@ -1862,7 +2144,7 @@ } } - ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), + GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(), acceptData.getSystem()); Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) @@ -1879,10 +2161,10 @@ if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 && goodsType != null && goodsType == Constant.SOURCE_TYPE_TAOBAO) { int state = 1; // 榛樿鍋滃敭 - Long goodsId = commonGoods.getGoodsId(); + String goodsId = commonGoods.getGoodsId(); for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { - Long auctionId = taoKeGoods.getAuctionId(); - if (goodsId == auctionId || goodsId.equals(auctionId)) { + String auctionId = taoKeGoods.getAuctionId(); + if (TaoBaoUtil.isEqual(goodsId, auctionId)) { state = 0; // 鍦ㄥ敭 break; } @@ -1904,6 +2186,7 @@ dataObject.put("totalMoney", "楼" + goodsGroup.getTotalMoney()); GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, paramsDTO); + detailVO.setCreatetime(null); detailVO.setId(commonGoods.getId()); dataObject.put("goods", gson.toJson(detailVO)); array.add(dataObject); @@ -1934,15 +2217,15 @@ } GoodsDetailVO goodsDetail = null; - ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), + GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(), acceptData.getSystem()); paramsDTO.setBaseFanliRate(hongBaoManageService.getBaseFanliRate(acceptData.getSystem())); if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(Long.parseLong(goodsId)); + TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId); if (goods == null) { try { - goods = redisManager.getTaoBaoGoodsBrief(Long.parseLong(goodsId)); + goods = redisManager.getTaoBaoGoodsBrief(goodsId); } catch (TaobaoGoodsDownException e) { goods = null; } @@ -1956,7 +2239,7 @@ goodsDetail = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO); } } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(Long.parseLong(goodsId)); + PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); if (goods != null) { goodsDetail = GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO); } @@ -1971,6 +2254,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