From 81da61b828e29b7745e1382dfbbaeb685dc083ef Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 23 一月 2024 17:17:55 +0800 Subject: [PATCH] 抖音转链修改 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java | 3325 ++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 2,027 insertions(+), 1,298 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 6aabcbc..813870a 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; @@ -10,23 +12,40 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import org.springframework.core.task.TaskExecutor; +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; -import org.yeshi.utils.BigDecimalUtil; -import org.yeshi.utils.DateUtil; -import org.yeshi.utils.HttpUtil; -import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.*; import org.yeshi.utils.taobao.TbImgUtil; 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; import com.yeshi.fanli.dto.share.ShareGoodsRecordDTO; +import com.yeshi.fanli.dto.suning.SuningGoodsImg; +import com.yeshi.fanli.dto.suning.SuningGoodsInfo; +import com.yeshi.fanli.dto.vip.VIPConvertResultDTO; +import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup; import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory; @@ -39,40 +58,23 @@ import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.system.ConfigKeyEnum; -import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; +import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoLink; -import com.yeshi.fanli.entity.taobao.TaoKeAppInfo; +import com.yeshi.common.entity.taobao.TaoKeAppInfo; import com.yeshi.fanli.exception.goods.ShareGoodsTextTemplateException; -import com.yeshi.fanli.exception.share.ShareGoodsException; import com.yeshi.fanli.exception.taobao.TaoKeApiException; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.config.SystemClientParamsService; -import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService; -import com.yeshi.fanli.service.inter.goods.CommonGoodsService; import com.yeshi.fanli.service.inter.goods.ShareGoodsService; import com.yeshi.fanli.service.inter.goods.ShareGoodsTextTemplateService; import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service; -import com.yeshi.fanli.service.inter.monitor.MonitorService; import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService; 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.SpreadUserImgService; -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.AESUtil; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.MoneyBigDecimalUtil; -import com.yeshi.fanli.util.RedisManager; -import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.TaoBaoConstant; -import com.yeshi.fanli.util.VersionUtil; import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil; import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; @@ -81,9 +83,13 @@ import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; +import com.yeshi.fanli.util.suning.SuningApiUtil; +import com.yeshi.fanli.util.suning.SuningUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.util.taobao.TaoLiJinUtil; +import com.yeshi.fanli.util.vipshop.VipShopApiUtil; +import com.yeshi.fanli.util.vipshop.VipShopUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; import com.yeshi.fanli.vo.goods.ShareGoodsCommentChoiceInfo; import com.yeshi.fanli.vo.goods.ShareInfoVO; @@ -95,1467 +101,2190 @@ @RequestMapping("api/v2/share") public class ShareControllerV2 { - @Resource(name = "taskExecutor") - private TaskExecutor executor; + Logger logger = LoggerFactory.getLogger(ShareControllerV2.class); - @Resource - private ShareGoodsService shareGoodsService; + @Resource + private ShareGoodsService shareGoodsService; - @Resource - private ConfigService configService; + @Resource + private TaoBaoLinkManager taoBaoLinkManager; - @Resource - private HongBaoManageService hongBaoManageService; - - @Resource - private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; + @Resource + private ConfigService configService; - @Resource - private MonitorService monitorService; + @Resource + private HongBaoManageService hongBaoManageService; - @Resource - private UserShareGoodsRecordService userShareGoodsRecordService; + @Resource + private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; - @Resource - private UserShareGoodsGroupService userShareGoodsGroupService; + @Resource + private UserShareGoodsRecordService userShareGoodsRecordService; - @Resource - private CommonGoodsService commonGoodsService; + @Resource + private UserShareGoodsGroupService userShareGoodsGroupService; - @Resource - private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; - @Resource - private UserInfoService userInfoService; + @Resource + private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; - @Resource - private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; + @Resource + private UserInfoService userInfoService; - @Resource - private JDGoodsCacheUtil jdGoodsCacheUtil; + @Resource + private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; - @Resource - private PinDuoDuoCacheUtil pinDuoDuoCacheUtil; + @Resource + private JDGoodsCacheUtil jdGoodsCacheUtil; - @Resource - private RedisManager redisManager; + @Resource + private PinDuoDuoCacheUtil pinDuoDuoCacheUtil; - @Resource - private ShareGoodsTextTemplateService shareGoodsTextTemplateService; + @Resource + private RedisManager redisManager; - @Resource - private SystemClientParamsService systemClientParamsService; + @Resource + private ShareGoodsTextTemplateService shareGoodsTextTemplateService; - @Resource - private DynamicInfoService dynamicInfoService; + @Resource + private UserInfoExtraService userInfoExtraService; - @Resource - private UserInfoExtraService userInfoExtraService; + @Resource + private BusinessEmergent110Service businessEmergent110Service; - @Resource - private SpreadUserImgService spreadUserImgService; + @Resource + private ConfigTaoLiJinService configTaoLiJinService; - @Resource - private BusinessEmergent110Service businessEmergent110Service; + @Resource + private UserTaoLiJinRecordService userTaoLiJinRecordService; - @Resource - private ConfigTaoLiJinService configTaoLiJinService; + @Resource + private PDDAuthService pddAuthService; - @Resource - private UserTaoLiJinRecordService userTaoLiJinRecordService; + @Resource + private PIDManager pidManager; - 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)); - } + @Resource + private UserFunctionsLimitService userFunctionsLimitService; - list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_DOWNLOAD_LINK, "涓嬭浇閾炬帴", - "涓嬭浇閾炬帴锛�" + Constant.YINGYONGBAO_LINK, false, true)); + 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_FANLI_MONEY, "杩斿埄閲戦", - String.format("銆愯仈绯绘垜涓嬭浇APP銆戞渶楂樺彲杩旇繕%s鍏�", fanliMoney + ""), false, true)); + list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_DOWNLOAD_LINK, "涓嬭浇閾炬帴", + "涓嬭浇閾炬帴锛�" + Constant.YINGYONGBAO_LINK, false, true)); - return list; - } + list.add(new ShareGoodsCommentChoiceInfo(ShareGoodsCommentChoiceInfo.TYPE_FANLI_MONEY, "杩斿埄閲戦", + String.format("銆愯仈绯绘垜涓嬭浇APP銆戞渶楂樺彲杩旇繕%s鍏�", fanliMoney + ""), false, true)); - /** - * - * @param acceptData - * @param uid - * -鐢ㄦ埛ID - * @param goodsId-鍟嗗搧ID - * @param source - * @param totalNum - * @param goodsType - * @param needGoods - * -鏄惁闇�瑕佸晢鍝佷俊鎭� - * @param request - * @param out - */ - @RequestMapping(value = "createShareInfo") - public void createShareInfo(AcceptData acceptData, Long uid, Long goodsId, String source, Integer totalNum, - Integer goodsType, Boolean needGoods, HttpServletRequest request, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛ID涓嶈兘涓虹┖")); - return; - } + return list; + } - if (needGoods == null) - needGoods = false; - try { - // 鏃ュ織璁板綍 - String info = String.format("type=share&uid=%s&goodsId=%s&source=%s&goodsType=%s", uid, goodsId, source, - goodsType); - LogHelper.orderInfo(info); - } catch (Exception e) { - } + /** + * @param acceptData + * @param uid -鐢ㄦ埛ID + * @param goodsId-鍟嗗搧ID + * @param source + * @param totalNum + * @param goodsType + * @param needGoods -鏄惁闇�瑕佸晢鍝佷俊鎭� + * @param request + * @param out + */ + @RequestMapping(value = "createShareInfo") + public void createShareInfo(AcceptData acceptData, Long uid, String goodsId, String source, Integer totalNum, + Integer goodsType, Boolean needGoods, HttpServletRequest request, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛ID涓嶈兘涓虹┖")); + return; + } - UserInfo user = userInfoService.getUserByIdWithMybatis(uid); - if (user != null && user.getState() != UserInfo.STATE_NORMAL) { - out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); - return; - } + if (needGoods == null) + needGoods = false; + try { + // 鏃ュ織璁板綍 + String info = String.format("type=share&uid=%s&goodsId=%s&source=%s&goodsType=%s", uid, goodsId, source, + goodsType); + LogHelper.orderInfo(info); + } catch (Exception e) { + } - if (goodsId == null || goodsId <= 0) { - out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧ID涓嶈兘涓虹┖")); - return; - } + UserInfo user = userInfoService.getUserByIdWithMybatis(uid); + if (user != null && user.getState() != UserInfo.STATE_NORMAL) { + out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); + return; + } - // 娣樺疂 - if (goodsType == null || goodsType == Constant.SOURCE_TYPE_TAOBAO) { - createTaoBaoShare(acceptData, uid, goodsId, totalNum, source, needGoods, request, out); - return; - } + if (goodsId == null) { + out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧ID涓嶈兘涓虹┖")); + return; + } - // 浜笢 - if (goodsType == Constant.SOURCE_TYPE_JD) { - createJDShare(acceptData, uid, goodsId, source, needGoods, out); - return; - } + if (userFunctionsLimitService.isLimit(uid, SystemFunction.share, new Date())) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ姛鑳介檺鍒朵娇鐢�")); + return; + } - // 鎷煎澶� - if (goodsType == Constant.SOURCE_TYPE_PDD) { - createPDDShare(acceptData, uid, goodsId, source, needGoods, out); - return; - } - } + // 娣樺疂 + if (goodsType == null || goodsType == Constant.SOURCE_TYPE_TAOBAO) { + createTaoBaoShare(acceptData, uid, goodsId, totalNum, source, needGoods, request, out); + return; + } - public static String getERCodeContentNew(String template, TaoBaoGoodsBrief goods, String token) { - String commentText = template.replace("[鍘熶环]", goods.getZkPrice().toString()); - commentText = commentText.replace("[娣樺彛浠", token); - if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) { - commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); - commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); - } else { - commentText = commentText.replace("[鍒稿悗浠穄", TaoBaoUtil.getAfterUseCouplePrice(goods) + ""); - } + // 浜笢 + if (goodsType == Constant.SOURCE_TYPE_JD) { + createJDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out); + return; + } - commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n"); - return commentText; - } + // 鎷煎澶� + if (goodsType == Constant.SOURCE_TYPE_PDD) { + createPDDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out); + return; + } - /** - * 鍒涘缓娣樺疂鍒嗕韩淇℃伅 - * - * @param acceptData - * @param uid - * @param goodsId - * @param totalNum - * @param source - * @param request - * @param out - */ - public void createTaoBaoShare(AcceptData acceptData, Long uid, Long goodsId, Integer totalNum, String source, - Boolean needGoods, HttpServletRequest request, PrintWriter out) { - if (needGoods == null) - needGoods = false; + // 鍞搧浼� + if (goodsType == Constant.SOURCE_TYPE_VIP) { + createVIPShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out); + return; + } - UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid); - UserInfoExtra userExtraInfo = userInfoExtraService.getUserInfoExtra(uid); - String inviteCode = null; - if (userExtraInfo != null) { - if (!StringUtil.isNullOrEmpty(userExtraInfo.getInviteCodeVip())) { - inviteCode = userExtraInfo.getInviteCodeVip(); - } else { - inviteCode = userExtraInfo.getInviteCode(); - } - } - String relationId = null; - if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null - && extraInfo.getRelationValid() == true) - relationId = extraInfo.getRelationId(); + // 鑻忓畞 + if (goodsType == Constant.SOURCE_TYPE_SUNING) { + createSuningShare(acceptData, uid, goodsId, source, needGoods, out); + return; + } - if (StringUtil.isNullOrEmpty(relationId)) { - out.print(JsonUtil.loadFalseResult(3, "娣樺疂鏈巿鏉冿紝璇峰墠寰�\"鎴戠殑\"缁戝畾娣樺疂璐﹀彿")); - 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; + } - // 娣樼ぜ閲戝垱寤哄垎浜� - if (source != null && "taolijin".equals(source)) {// 娣樼ぜ閲戝垎浜垱寤� - createTaoLijin(uid, goodsId, totalNum, relationId, request, out); - return; - } else {// 鏅�氬垎浜垱寤� - createCommonTaoBaoShare(acceptData.getPlatform(), acceptData.getVersion(), goodsId, inviteCode, uid, - needGoods, relationId, out); - 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(); - /** - * 娣樼ぜ閲戝垱寤哄垎浜� - * - * @param uid - * @param auctionId - * @param totalNum - * @param relationId - * @param request - * @param out - */ - public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, HttpServletRequest request, - PrintWriter out) { - try { - TaoBaoGoodsBrief goods = null; - try { - goods = TaoKeApiUtil.searchGoodsDetail(auctionId); - } catch (TaobaoGoodsDownException e2) { - e2.printStackTrace(); - } + try { + tempToken = URLEncoder.encode(tempToken, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } - if (goods == null) { - out.print(JsonUtil.loadFalseResult("鍟嗗搧宸蹭笅鏋�")); - return; - } + String commentText = template.replace("[鍘熶环]", goods.getZkPrice().toString()); + commentText = commentText.replace("[娣樺彛浠", tempToken); + if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) { + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); + commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + } else { + commentText = commentText.replace("[鍒稿悗浠穄", TaoBaoUtil.getCouponPrice(goods) + ""); + } - if (goods.getTkRate() == null || goods.getTkRate().compareTo(new BigDecimal(0)) <= 0) { - // TaoKeApiUtil.specialConvertCoupon(auctionId, app); + commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n"); + return commentText; + } - } + // 娣樺疂鍒嗕韩娲诲姩 + public static String getTaoBaoActiivtyERCodeContentNew(String template, String token) { + String commentText = template.replace("[娣樺彛浠", token); + commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n"); + return commentText; + } - // 璁$畻鎺ㄥ箍绾㈠寘 - String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date()); - LogHelper.error("鎺ㄥ箍绾㈠寘姣斾緥:" + warningRate); - BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods); - LogHelper.error("鎺ㄥ箍绾㈠寘:" + spreadMoney); - // 鎺ㄥ箍绾㈠寘 涓嶈兘灏忎簬1 - if (spreadMoney.compareTo(new BigDecimal(1.1)) < 0) { - out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佹窐绀奸噾涓嶈冻")); - return; - } + /** + * 鍒涘缓娣樺疂鍒嗕韩淇℃伅 + * + * @param acceptData + * @param uid + * @param goodsId + * @param totalNum + * @param source + * @param request + * @param out + */ + public void createTaoBaoShare(AcceptData acceptData, Long uid, String goodsId, Integer totalNum, String source, + Boolean needGoods, HttpServletRequest request, PrintWriter out) { + if (needGoods == null) + needGoods = false; - ShareInfoVO shareInfo = new ShareInfoVO(); - shareInfo.setSpreadMoney(" 楼" + spreadMoney.toString()); + UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid); + UserInfoExtra userExtraInfo = userInfoExtraService.getUserInfoExtra(uid); + String inviteCode = null; + if (userExtraInfo != null) { + if (!StringUtil.isNullOrEmpty(userExtraInfo.getInviteCodeVip())) { + inviteCode = userExtraInfo.getInviteCodeVip(); + } else { + inviteCode = userExtraInfo.getInviteCode(); + } + } + String relationId = null; + if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null + && extraInfo.getRelationValid() == true) + relationId = extraInfo.getRelationId(); - String taoLiJinLink = null; - Long tljId = null; - try { - UserTaoLiJinRecord record = userTaoLiJinRecordService.createShareTaoLiJin(uid, totalNum, goods); - tljId = record.getId(); - taoLiJinLink = record.getSendUrl(); - shareInfo.setTljId(tljId.toString()); - shareInfo.setSurplusMoney(record.getSurplusMoney().toString()); - } catch (UserTaoLiJinRecordException e) { - out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); - return; - } + if (StringUtil.isNullOrEmpty(relationId)) { + out.print(JsonUtil.loadFalseResult(3, "娣樺疂鏈巿鏉冿紝璇峰墠寰�\"鎴戠殑\"缁戝畾娣樺疂璐﹀彿")); + return; + } - String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&tid=%s", configService.getH5Host(), - Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - auctionId + "", AESUtil.encrypt(tljId + "", Constant.UIDAESKEY)); - String shortLink = HttpUtil.getShortLink(url); - if (!StringUtil.isNullOrEmpty(shortLink)) { - url = shortLink; - } - shareInfo.setClickUrl(url); + // 娣樼ぜ閲戝垱寤哄垎浜� + if (source != null && "taolijin".equals(source)) {// 娣樼ぜ閲戝垎浜垱寤� + 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; + } - 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); - } - } - shareInfo.setToken(TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); - shareInfo.setRule(configService.get(ConfigKeyEnum.shareSingleGoodsRule.getKey())); - shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(goods.getPictUrl(), 500)); + /** + * 娣樼ぜ閲戝垱寤哄垎浜� + * + * @param uid + * @param auctionId + * @param totalNum + * @param relationId + * @param request + * @param out + */ + public void createTaoLijin(Long uid, String auctionId, int totalNum, String relationId, AcceptData acceptData, HttpServletRequest request, + PrintWriter out) { + try { + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId); + } catch (TaobaoGoodsDownException e2) { + e2.printStackTrace(); + } - // 鏃犲埜 - String shopType = goods.getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO - : TaoBaoConstant.SHARE_PRICE_TM; - String shareText = ""; + if (goods == null) { + out.print(JsonUtil.loadFalseResult("鍟嗗搧宸蹭笅鏋�")); + return; + } - if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) { - String text = shareGoodsTextTemplateService.getCommonTemplate(uid); - if (StringUtil.isNullOrEmpty(text)) - text = configService.get(ConfigKeyEnum.goodsShareTextNoCoupon.getKey()); - 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", new Date()); + if (goods.getTkRate() == null || goods.getTkRate().compareTo(new BigDecimal(0)) <= 0) { + // TaoKeApiUtil.specialConvertCoupon(auctionId, app); - shareText = text.replace("{鏍囬}", goods.getTitle()) - .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()) + "") - .replace("{浼樻儬鍒搁潰棰潁", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString()) - .replace("{娣樼ぜ閲戦潰棰潁", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString()) - .replace("{浼樻儬鍒镐环}", TaoBaoUtil.getAfterUseCouplePrice(goods) + ""); - } + } - shareText = shareText.replace("{搴楅摵绫诲瀷}", shopType) - .replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{棰嗗埜鐭摼}", shortLink) - .replace("{娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); - shareInfo.setShareText(shareText); + // 璁$畻鎺ㄥ箍绾㈠寘 + String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date()); + LogHelper.error("鎺ㄥ箍绾㈠寘姣斾緥:" + warningRate); + BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods); + LogHelper.error("鎺ㄥ箍绾㈠寘:" + spreadMoney); + // 鎺ㄥ箍绾㈠寘 涓嶈兘灏忎簬1 + if (spreadMoney.compareTo(new BigDecimal(1.1)) < 0) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佹窐绀奸噾涓嶈冻")); + return; + } - String descText = shareText.replace(goods.getTitle(), "").trim(); - if (descText.startsWith("\\r\\n")) - descText = descText.substring(0); + ShareInfoVO shareInfo = new ShareInfoVO(); + shareInfo.setSpreadMoney(" 楼" + spreadMoney.toString()); - shareInfo.setDescText(descText); + String taoLiJinLink = null; + Long tljId = null; + try { + UserTaoLiJinRecord record = userTaoLiJinRecordService.createShareTaoLiJin(uid, totalNum, goods); + tljId = record.getId(); + taoLiJinLink = record.getSendUrl(); + shareInfo.setTljId(tljId.toString()); + shareInfo.setSurplusMoney(record.getSurplusMoney().toString()); + } catch (UserTaoLiJinRecordException e) { + out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); + return; + } - String imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs.getKey()); - JSONArray array = JSONArray.fromObject(imgs); - shareInfo.setNotifyPicture(array.optString(0)); + String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&tid=%s", configService.getH5Host(SystemInfoUtil.getSystem(acceptData)), + Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + auctionId + "", AESUtil.encrypt(tljId + "", Constant.UIDAESKEY)); + String shortLink = HttpUtil.getShortLink(url); + if (!StringUtil.isNullOrEmpty(shortLink)) { + url = shortLink; + } + shareInfo.setClickUrl(url); - // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖 - imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs207.getKey()); - array = JSONArray.fromObject(imgs); - shareInfo.setNotifyPictureNew(array.optString(0)); + TaoBaoLink taoBaoLink = new TaoBaoLink(); + taoBaoLink.setCouponLink(taoLiJinLink); + taoBaoLink.setClickUrl(taoLiJinLink); - shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotify.getKey())); + // 鍒涘缓娣樺彛浠� + if (!StringUtil.isNullOrEmpty(taoLiJinLink)) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� + String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoLiJinLink); + if (!StringUtil.isNullOrEmpty(quanToken)) { + taoBaoLink.setTaoToken(quanToken); + } + } - // 娣诲姞鍒嗕韩璁板綍 - BigDecimal rate = hongBaoManageService.getShareRate(); - BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate); - shareInfo.setShareMoney("楼" + shareMoney.toString()); - try { - ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId, - Constant.SOURCE_TYPE_TAOBAO, true); - shareInfo.setShareId(shareRecord.getRedisKey()); - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(shareInfo))); + SystemEnum system = SystemInfoUtil.getSystem(acceptData); - final TaoBaoLink taobaoLink = taoBaoLink; - final TaoBaoGoodsBrief finalGoods = goods; - // 寮傛鎿嶄綔 - 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(finalGoods.getAuctionId()); - history.setPostPicture(finalGoods.getPictUrl()); - history.setShareImg(taobaoLink.getClickUrl()); - List<String> imgList = finalGoods.getImgList(); - if (imgList == null) { - imgList = new ArrayList<>(); - } - history.setPictures(JsonUtil.getGson().toJson(imgList)); - shareGoodsService.addShareGoodsHistory(history); - } - }); - return; - } catch (Exception e) { - LogHelper.errorDetailInfo(e, "鍒嗕韩鍑洪敊:uid:" + uid + "auctionId:" + auctionId, ""); - out.print(JsonUtil.loadFalseResult("鍒涘缓鍒嗕韩鍑洪敊")); - businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + "")); - } - } + shareInfo.setToken(TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); + shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareSingleGoodsRule.getKey(), system)); + shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(goods.getPictUrl(), 500)); - public void createCommonTaoBaoShare(String platform, String version, Long goodsId, String inviteCode, Long uid, - boolean needGoods, String relationId, PrintWriter out) { - try { - ShareInfoVO shareInfo = new ShareInfoVO(); + // 鏃犲埜 + String shopType = goods.getUserType() == 0 ? TaoBaoConstant.SHARE_PRICE_TAOBAO + : TaoBaoConstant.SHARE_PRICE_TM; + String shareText = ""; - TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, goodsId, relationId); + if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) { + String text = shareGoodsTextTemplateService.getCommonTemplate(uid); + if (StringUtil.isNullOrEmpty(text)) + text = configService.getValue(ConfigKeyEnum.goodsShareTextNoCoupon.getKey(), system); + 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", new Date()); - if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) { - ConfigParamsDTO dto = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version); - GoodsDetailVO goodsInfo = GoodsDetailVOFactory.convertTaoBao(taoBaoLink.getGoods(), dto); - shareInfo.setGoodsInfo(goodsInfo); - } + shareText = text.replace("{鏍囬}", goods.getTitle()) + .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()) + "") + .replace("{浼樻儬鍒搁潰棰潁", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString()) + .replace("{娣樼ぜ閲戦潰棰潁", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString()) + .replace("{浼樻儬鍒镐环}", TaoBaoUtil.getCouponPrice(goods) + ""); + } - String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(), - Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - goodsId + ""); + shareText = shareText.replace("{搴楅摵绫诲瀷}", shopType) + .replace("{鏈堥攢閲弣", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{棰嗗埜鐭摼}", shortLink) + .replace("{娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); + shareInfo.setShareText(shareText); - String shortLink = HttpUtil.getShortLink(url); - if (!StringUtil.isNullOrEmpty(shortLink)) { - url = shortLink; - } + String descText = shareText.replace(goods.getTitle(), "").trim(); + if (descText.startsWith("\\r\\n")) + descText = descText.substring(0); - shareInfo.setClickUrl(url); - shareInfo.setToken(TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); - shareInfo.setRule(configService.get(ConfigKeyEnum.shareSingleGoodsRule.getKey())); - shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500)); + shareInfo.setDescText(descText); - 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 imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), system); + JSONArray array = JSONArray.fromObject(imgs); + shareInfo.setNotifyPicture(array.optString(0)); - TaoBaoGoodsBrief goods = taoBaoLink.getGoods(); + // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖 + imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs207.getKey(), system); + array = JSONArray.fromObject(imgs); + shareInfo.setNotifyPictureNew(array.optString(0)); - boolean coupon = false; - if (!StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { - coupon = true; - } + shareInfo.setNotifyDesc(configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(), system)); - String template = shareGoodsTextTemplateService.getTextTemplateByTB(uid); - String shareText = shareGoodsTextTemplateService.createContentTB(template, goods, taoBaoLink.getTaoToken(), - coupon); - shareInfo.setShareText(shareText); + // 娣诲姞鍒嗕韩璁板綍 + BigDecimal rate = hongBaoManageService.getShareRate(acceptData.getSystem()); + BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); + try { + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId, + Constant.SOURCE_TYPE_TAOBAO, true); + shareInfo.setShareId(shareRecord.getRedisKey()); + } catch (Exception e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(shareInfo))); - String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim(); - if (descText.startsWith("\\r\\n")) { - descText = descText.substring(0); - } - shareInfo.setDescText(deleteBlankLine(descText)); + final TaoBaoLink taobaoLink = taoBaoLink; + final TaoBaoGoodsBrief finalGoods = goods; + // 寮傛鎿嶄綔 + 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(finalGoods.getAuctionId()); + history.setPostPicture(finalGoods.getPictUrl()); + history.setShareImg(taobaoLink.getClickUrl()); + List<String> imgList = finalGoods.getImgList(); + if (imgList == null) { + imgList = new ArrayList<>(); + } + history.setPictures(JsonUtil.getGson().toJson(imgList)); + shareGoodsService.addShareGoodsHistory(history); + } + }); + return; + } catch (Exception e) { + LogHelper.errorDetailInfo(e, "鍒嗕韩鍑洪敊:uid:" + uid + "auctionId:" + auctionId, ""); + out.print(JsonUtil.loadFalseResult("鍒涘缓鍒嗕韩鍑洪敊")); + businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""), SystemInfoUtil.getSystem(acceptData)); + } + } - // 娴嬭瘯 - // 2.0.2涔嬪墠 - if (VersionUtil.greaterThan_2_0_7(platform, version)) { - shareInfo.setClickUrl( - getERCodeContentNew(configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()), - taoBaoLink.getGoods(), shareInfo.getToken())); - } else if (!VersionUtil.greaterThan_2_0_2(platform, version)) { - shareInfo.setClickUrl( - getERCodeContentNew(configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()), - taoBaoLink.getGoods(), shareInfo.getToken())); - } + public void createCommonTaoBaoShare(String platform, String version, String goodsId, String inviteCode, Long uid, + boolean needGoods, String relationId, AcceptData acceptData, PrintWriter out) { - // if (VersionUtil.greaterThan_2_0_7(platform, version)) { - // shareInfo.setWxErCode( - // getERCodeContentNew(configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()), - // taoBaoLink.getGoods(), shareInfo.getToken())); - // } else { - shareInfo.setWxErCode(getERCodeContentNew(configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()), - taoBaoLink.getGoods(), shareInfo.getToken())); - // } + SystemEnum system = SystemInfoUtil.getSystem(acceptData); + try { + ShareInfoVO shareInfo = new ShareInfoVO(); - // 鎻愮ず鍥炬枃鍐呭 - String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), platform, - Integer.parseInt(version)); - JSONArray array = JSONArray.fromObject(imgs); + TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, goodsId, relationId, null); + + if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) { + GoodsMoneyConfigParamsDTO dto = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version, acceptData.getSystem()); + 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(SystemInfoUtil.getSystem(acceptData)), + Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + goodsId + ""); + + String shortLink = HttpUtil.getShortLink(url); + if (!StringUtil.isNullOrEmpty(shortLink)) { + url = shortLink; + } + + shareInfo.setClickUrl(url); + if ("android".equalsIgnoreCase(platform)) { + shareInfo.setToken(TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); + } else { + shareInfo.setToken(taoBaoLink.getTaoToken()); + } + + shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareSingleGoodsRule.getKey(), system)); + shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500)); + + String commentTextStr = configService.getValue(ConfigKeyEnum.shareSingleGoodsCommentText.getKey(), system); + 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); + + TaoBaoGoodsBrief goods = taoBaoLink.getGoods(); + + boolean coupon = false; + if (!StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { + coupon = true; + } + + String template = shareGoodsTextTemplateService.getTextTemplateByTB(uid); + String shareText = shareGoodsTextTemplateService.createContentTB(template, goods, taoBaoLink.getTaoToken(), + coupon); + shareInfo.setShareText(shareText); + + String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim(); + if (descText.startsWith("\\r\\n")) { + descText = descText.substring(0); + } + shareInfo.setDescText(deleteBlankLine(descText)); + + // 娴嬭瘯 + // 2.0.2涔嬪墠 + if (VersionUtil.greaterThan_2_0_7(platform, version)) { + shareInfo.setClickUrl( + getERCodeContentNew(configService.getValue(ConfigKeyEnum.quickShareTBCommentText.getKey(), system), + taoBaoLink.getGoods(), shareInfo.getToken())); + } else if (!VersionUtil.greaterThan_2_0_2(platform, version)) { + shareInfo.setClickUrl( + getERCodeContentNew(configService.getValue(ConfigKeyEnum.taobaoShareQrcodeText.getKey(), system), + taoBaoLink.getGoods(), shareInfo.getToken())); + } + + // if (VersionUtil.greaterThan_2_0_7(platform, version)) { + // shareInfo.setWxErCode( + // getERCodeContentNew(configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()), + // taoBaoLink.getGoods(), shareInfo.getToken())); + // } else { + shareInfo.setWxErCode(getERCodeContentNew(configService.getValue(ConfigKeyEnum.taobaoShareQrcodeText.getKey(), system), + taoBaoLink.getGoods(), shareInfo.getToken())); + // } + + // 鎻愮ず鍥炬枃鍐呭 + String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), platform, + Integer.parseInt(version), system); + JSONArray array = JSONArray.fromObject(imgs); + + shareInfo.setNotifyPicture(array.optString(0)); + + // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖 + imgs = configService.getValue(ConfigKeyEnum.goodsShareNotifyImgs207.getKey(), system); + array = JSONArray.fromObject(imgs); + shareInfo.setNotifyPictureNew(array.optString(0)); + + shareInfo.setNotifyDesc(configService.getValue(ConfigKeyEnum.goodsShareNotify.getKey(), system)); + + // 鍒嗕韩閲戦 + BigDecimal rate = hongBaoManageService.getShareRate(acceptData.getSystem()); + 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(); + } + } + + String commentText = ""; + String recommendText = ""; + if (VersionUtil.greaterThan_2_0_7(platform, version)) { + String template2 = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), system); + recommendText = template2.replace("[鍟嗗搧鏍囬]", goods.getTitle()); + if (!coupon) { + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + } else { + if (!StringUtil.isNullOrEmpty(goods.getDescription())) { + recommendText = recommendText.replace("[鎺ㄨ崘璇璢", goods.getDescription()); + } else { + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + } + } + + String sales = TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()); + if (sales.equals("0")) { + recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); + } else { + recommendText = recommendText.replace("[閿�閲廬", sales.replace("涓�", "w")); + } + + String quickCommentText = configService.getValue(ConfigKeyEnum.quickShareTBCommentText.getKey(), system); + commentText = quickCommentText.replace("[鍘熶环]", goods.getZkPrice().toString()); + commentText = commentText.replace("[娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); + if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); + commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + } else { + commentText = commentText.replace("[鍒稿悗浠穄", + TaoBaoUtil.getCouponPrice(taoBaoLink.getGoods()) + ""); + } + + if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { + recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); + } else { + recommendText = recommendText.replace("[鍒搁潰棰漖", + MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString()); + } + } else { + commentText = shareInfo.getShareText(); + recommendText = shareInfo.getDescText(); + } + + if ("ios".equalsIgnoreCase(platform)) { + shareInfo.setCommentText(taoBaoLink.getTaoToken()); + } else + shareInfo.setCommentText(deleteBlankLine(commentText)); + shareInfo.setRecommendText(deleteBlankLine(recommendText)); + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList( + getCommentChoiceList(shareInfo.getCommentText(), null, inviteCode, TaoBaoUtil.getGoodsHongBaoMoney( + taoBaoLink.getGoods(), hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem()), false))); + + 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 (TaoBaoConvertLinkException e) { + LogHelper.errorDetailInfo(e, "鍒嗕韩鍑洪敊:uid:" + uid + " goodsId:" + goodsId, ""); + out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); + businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(goodsId + ""), SystemInfoUtil.getSystem(acceptData)); + } + } + + /** + * 浜笢鍒涘缓鍒嗕韩 + * + * @param acceptData + * @param uid + * @param goodsId + * @param source + * @param out + */ + public void createJDShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods, + PrintWriter out) { + JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId); + if (jdGoods == null) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); + return; + } + + // String url = String.format("http://%s%s?uid=%s&id=%s", + // configService.getH5Host(), + // Constant.systemCommonConfig.getShareGoodsPagePathJD(), + // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + // goodsId + ""); + + String couponUrl = null; + JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods); + if (couponInfo != null) { + couponUrl = couponInfo.getLink(); + } + String materialId = "https://item.jd.com/" + goodsId + ".html"; + 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)) { + 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(); + shareInfo.setClickUrl(jumpLink); + shareInfo.setWxErCode(jumpLink); + shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareRuleLinkJD.getKey(), SystemInfoUtil.getSystem(acceptData))); + shareInfo.setPictUrl(jdGoods.getPicUrl()); + shareInfo.setCommentTexts(new ArrayList<>()); + + if (needGoods) + shareInfo.setGoodsInfo(GoodsDetailVOFactory.convertJDGoods(jdGoods, orderHongBaoMoneyComputeService + .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(), acceptData.getSystem()))); + + boolean hasCoupon = false; + if (couponInfo != null) { + hasCoupon = true; + } + + String template = shareGoodsTextTemplateService.getTextTemplateByJD(uid); + String shareText = shareGoodsTextTemplateService.createContentJD(template, jdGoods, jumpLink, hasCoupon); + shareInfo.setShareText(shareText); + + String descText = shareText.replace(jdGoods.getSkuName(), "").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()), SystemInfoUtil.getSystem(acceptData)); + 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(), SystemInfoUtil.getSystem(acceptData)); + array = JSONArray.fromObject(imgs); + shareInfo.setNotifyPictureNew(array.size() > 1 ? array.optString(1) : array.optString(0)); + + shareInfo.setNotifyDesc(configService.getValue(ConfigKeyEnum.goodsShareNotifyJD.getKey(), SystemInfoUtil.getSystem(acceptData))); + + // 娣诲姞鍒嗕韩璁板綍 + BigDecimal shareRate = hongBaoManageService.getShareRate(acceptData.getSystem()); + BigDecimal shareMoney = JDUtil.getGoodsFanLiMoney(jdGoods, shareRate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); + try { + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId + "", + Constant.SOURCE_TYPE_JD, 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 = ""; + if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) { + String template2 = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), SystemInfoUtil.getSystem(acceptData)); + recommendText = template2.replace("[鍟嗗搧鏍囬]", jdGoods.getSkuName()); + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + String sales = JDUtil.getSaleCount(jdGoods.getInOrderCount30Days()); + if (sales.equals("0")) { + recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); + } else { + recommendText = recommendText.replace("[閿�閲廬", sales.replace("涓�", "w")); + } + + BigDecimal price = jdGoods.getPrice(); + JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo(); + if (pinGouInfo != null) { + price = pinGouInfo.getPingouPrice(); + } + + String template3 = configService.getValue(ConfigKeyEnum.quickShareJDCommentText.getKey(), SystemInfoUtil.getSystem(acceptData)); + commentText = template3.replace("[鍘熶环]", BigDecimalUtil.getWithNoZera(price).toString()); + if (!hasCoupon) { + recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); + commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); + } else { + recommendText = recommendText.replace("[鍒搁潰棰漖", + BigDecimalUtil.getWithNoZera(couponInfo.getDiscount()).toString()); + commentText = commentText.replace("[鍒稿悗浠穄", + BigDecimalUtil.getWithNoZera(JDUtil.getCouponPrice(jdGoods)).toString()); + } + commentText = commentText.replace("[閾炬帴]", jumpLink); + } else { + commentText = shareInfo.getShareText(); + recommendText = shareInfo.getDescText(); + } + shareInfo.setCommentText(deleteBlankLine(commentText)); + shareInfo.setRecommendText(deleteBlankLine(recommendText)); + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode, + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); + + out.print(JsonUtil.loadTrueResult( + JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); + + + final String jumpLinkNew = jumpLink; + + // 寮傛鎿嶄綔 + final JDGoods goods = jdGoods; + 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_JD); + history.setTkCode(null); + history.setLink(null); + history.setQuanLink(null); + history.setGoodsId(goodsId + ""); + history.setPostPicture(goods.getPicUrl()); + history.setShareImg(jumpLinkNew); + + List<String> imgList = goods.getImageList(); + if (imgList == null) { + imgList = new ArrayList<>(); + } + history.setPictures(JsonUtil.getGson().toJson(imgList)); + shareGoodsService.addShareGoodsHistory(history); + } + }); + } + + private String deleteBlankLine(String st) { + return st.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n"); + } + + /** + * 鎷煎澶氬垎浜� + * + * @param acceptData + * @param uid + * @param goodsId + * @param source + * @param out + */ + public void createPDDShare(AcceptData acceptData, Long uid, Long 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(pid, pddAuthService.getFanliCustomParams(uid))) { + out.print(JsonUtil.loadFalseResult(20001, "灏氭湭澶囨,璇峰厛澶囨")); + return; + } + } else { + if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2021-05-01", "yyyy-MM-dd") && !PinDuoDuoApiUtil.isAuth(pid, pddAuthService.getFanliCustomParams(uid))) { + out.print(JsonUtil.loadFalseResult(20001, "璇峰崌绾у埌鏈�鏂扮増")); + return; + } + } + + + PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); + return; + } + + // String url = String.format("http://%s%s?uid=%s&id=%s", + // configService.getH5Host(), + // Constant.systemCommonConfig.getShareGoodsPagePathPDD(), + // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + // goodsId + ""); + + String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pid, pddAuthService.getFanliCustomParams(uid) + ""); + + SystemEnum system = SystemInfoUtil.getSystem(acceptData); + + ShareInfoVO shareInfo = new ShareInfoVO(); + shareInfo.setClickUrl(jumpLink); + shareInfo.setWxErCode(jumpLink); + shareInfo.setCommentTexts(new ArrayList<>()); + shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareRuleLinkPDD.getKey(), SystemInfoUtil.getSystem(acceptData))); + shareInfo.setPictUrl(goods.getGoodsImageUrl()); + if (needGoods) { + shareInfo + .setGoodsInfo(GoodsDetailVOFactory.convertPDDGoods(goods, + new GoodsMoneyConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), + hongBaoManageService.getShareRate(acceptData.getSystem()), Constant.MAX_REWARD_RATE, + hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); + } + + // 鍒涘缓鍙d护 + // String token = PinDuoDuoApiUtil.createGenerate(goodsId); + + boolean hasCoupon = true; + if (goods.getHasCoupon() == null || !goods.getHasCoupon()) { + hasCoupon = false; + } + String template = shareGoodsTextTemplateService.getTextTemplateByPDD(uid); + String shareText = shareGoodsTextTemplateService.createContentPDD(template, goods, jumpLink, hasCoupon); + shareInfo.setShareText(shareText); + + String descText = shareText.replace(goods.getGoodsName(), "").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.goodsShareNotifyPDD.getKey(), system)); + + // 娣诲姞鍒嗕韩璁板綍 + BigDecimal shareRate = hongBaoManageService.getShareRate(acceptData.getSystem()); + BigDecimal shareMoney = PinDuoDuoUtil.getGoodsFanLiMoney(goods, shareRate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); + + try { + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId + "", + Constant.SOURCE_TYPE_PDD, 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 = ""; + if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) { + String qtemplate = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), system); + recommendText = qtemplate.replace("[鍟嗗搧鏍囬]", goods.getGoodsName()); + + // 鎬婚攢閲� + String salesTip = goods.getSalesTip(); + if (StringUtil.isNullOrEmpty(salesTip)) { + salesTip = "0"; + } + if (salesTip.equals("0")) { + recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); + } else { + recommendText = recommendText.replace("[閿�閲廬", salesTip.replace("涓�", "w")); + recommendText = recommendText.replace("閿�閲�", "鎬婚攢閲�"); + } + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + + String quickCommentText = configService.getValue(ConfigKeyEnum.quickSharePDDCommentText.getKey(), system); + commentText = quickCommentText.replace("[鍘熶环]", MoneyBigDecimalUtil + .div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)).setScale(2).toString()); + commentText = commentText.replace("[閾炬帴]", jumpLink); + if (!hasCoupon) { + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); + commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); + } else { + commentText = commentText.replace("[鍒稿悗浠穄", + BigDecimalUtil.getWithNoZera(PinDuoDuoUtil.getCouponPrice(goods)).toString()); + + BigDecimal hundred = new BigDecimal(100); + BigDecimal amount = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred); + recommendText = recommendText.replace("[鍒搁潰棰漖", BigDecimalUtil.getWithNoZera(amount).toString()); + } + } else { + commentText = shareInfo.getShareText(); + recommendText = shareInfo.getDescText(); + } + shareInfo.setRecommendText(deleteBlankLine(recommendText)); + shareInfo.setCommentText(deleteBlankLine(commentText)); + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode, + PinDuoDuoUtil.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_PDD); + history.setTkCode(null); + history.setLink(null); + history.setQuanLink(null); + history.setGoodsId(goodsId + ""); + history.setPostPicture(goods.getGoodsImageUrl()); + history.setShareImg(jumpLink); + List<String> imgList = null; + String[] goodsGalleryUrls = goods.getGoodsGalleryUrls(); + if (goodsGalleryUrls != null) { + imgList = Arrays.asList(goodsGalleryUrls); + } + if (imgList == null) { + imgList = new ArrayList<>(); + } + history.setPictures(JsonUtil.getGson().toJson(imgList)); + shareGoodsService.addShareGoodsHistory(history); + } + }); + } + + /** + * 鍞搧浼氬垎浜� + * + * @param acceptData + * @param uid + * @param goodsId + * @param source + * @param needGoods + * @param out void 杩斿洖绫诲瀷 + * @throws + * @Title: createVIPShare + * @Description: + */ + public void createVIPShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods, + PrintWriter out) { + VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId + ""); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); + return; + } + + SystemEnum system = SystemInfoUtil.getSystem(acceptData); + + VIPConvertResultDTO jumpLink = VipShopApiUtil.convertLink(goodsId + "", VipShopUtil.getShareChanTag(uid)); + + ShareInfoVO shareInfo = new ShareInfoVO(); + shareInfo.setClickUrl(jumpLink.getUrl()); + shareInfo.setWxErCode(jumpLink.getUrl()); + shareInfo.setCommentTexts(new ArrayList<>()); + shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareRuleLinkVIP.getKey(), system)); + shareInfo.setPictUrl(goods.getGoodsThumbUrl()); + if (needGoods) { + shareInfo + .setGoodsInfo(GoodsDetailVOFactory.convertVIPGoods(goods, + new GoodsMoneyConfigParamsDTO(hongBaoManageService.getFanLiRate(acceptData.getSystem()), + hongBaoManageService.getShareRate(acceptData.getSystem()), Constant.MAX_REWARD_RATE, + hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); + } + + String template = shareGoodsTextTemplateService.getTextTemplateByVIP(uid); + String shareText = shareGoodsTextTemplateService.createContentVIP(template, goods, jumpLink.getUrl()); + shareInfo.setShareText(shareText); + + String descText = shareText.replace(goods.getGoodsName(), "").trim(); + if (descText.startsWith("\\r\\n")) { + descText = descText.substring(0); + } + shareInfo.setDescText(descText); + + // + String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgsVIP.getKey(), acceptData.getPlatform(), + Integer.parseInt(acceptData.getVersion()), system); + shareInfo.setNotifyPicture(imgs); + shareInfo.setNotifyPictureNew(imgs); + + shareInfo.setNotifyDesc(configService.getValue(ConfigKeyEnum.goodsShareNotifyVIP.getKey(), system)); + + // 娣诲姞鍒嗕韩璁板綍 + BigDecimal shareRate = hongBaoManageService.getShareRate(acceptData.getSystem()); + BigDecimal shareMoney = VipShopUtil.getGoodsFanLiMoney(goods, shareRate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); + + try { + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId + "", + Constant.SOURCE_TYPE_VIP, 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.getGoodsName()); + recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); + + String quickCommentText = configService.getValue(ConfigKeyEnum.quickShareVIPCommentText.getKey(), system); + commentText = quickCommentText.replace("[鍦ㄥ敭浠穄", BigDecimalUtil.getWithNoZera(new BigDecimal(goods.getMarketPrice())).toString()); + commentText = commentText.replace("[閾炬帴]", jumpLink.getUrl()); + commentText = commentText.replace("[鎶樻墸浠穄", "" + MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(goods.getVipPrice()))); + + shareInfo.setRecommendText(deleteBlankLine(recommendText)); + shareInfo.setCommentText(deleteBlankLine(commentText)); + + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode, + VipShopUtil.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_VIP); + history.setTkCode(null); + history.setLink(null); + history.setQuanLink(null); + history.setGoodsId(goodsId + ""); + history.setPostPicture(goods.getGoodsThumbUrl()); + history.setShareImg(jumpLink.getUrl()); + List<String> imgList = goods.getGoodsDetailPictures(); + if (imgList == null) { + imgList = new ArrayList<>(); + } + + if (imgList.size() > 10) { + imgList = imgList.subList(0, 9); + } + + 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 createSuningShare(AcceptData acceptData, Long uid, String goodsId, String source, boolean needGoods, + PrintWriter out) { + String[] sts = SuningUtil.getGoodsIdDetail(goodsId); + SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(sts[1], sts[0]); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); + return; + } + + SystemEnum system = SystemInfoUtil.getSystem(acceptData); + + String couponLink = goods.getCouponInfo().getCouponUrl(); + + String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sts[0], sts[1]), + StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), uid + ""); + + ShareInfoVO shareInfo = new ShareInfoVO(); + shareInfo.setClickUrl(jumpLink); + shareInfo.setWxErCode(jumpLink); + shareInfo.setCommentTexts(new ArrayList<>()); + shareInfo.setRule(configService.getValue(ConfigKeyEnum.shareRuleLinkSuning.getKey(), system)); + if (goods.getCommodityInfo().getPictureUrl() != null && goods.getCommodityInfo().getPictureUrl().size() > 0) + shareInfo.setPictUrl(goods.getCommodityInfo().getPictureUrl().get(0).getPicUrl()); + if (needGoods) { + shareInfo + .setGoodsInfo(GoodsDetailVOFactory.convertSuningGoods(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.createQuickShareTextSuNing(template, goods, jumpLink); + + String shareText = shareGoodsTextTemplateService.createCommonShareTextSuNing(template, goods, jumpLink); + shareInfo.setShareText(shareText); + + String descText = shareText.replace(goods.getCommodityInfo().getCommodityName(), "").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.goodsShareNotifySuning.getKey(), system)); + + // 娣诲姞鍒嗕韩璁板綍 + BigDecimal shareRate = hongBaoManageService.getShareRate(acceptData.getSystem()); + BigDecimal shareMoney = SuningUtil.getGoodsFanLiMoney(goods, shareRate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); + + try { + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, + Long.parseLong(sts[1]) + "", Constant.SOURCE_TYPE_SUNING, false); + shareInfo.setShareId(shareRecord.getRedisKey()); + } catch (Exception e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); + + String commodityPrice = goods.getCommodityInfo().getCommodityPrice(); + if (StringUtil.isNullOrEmpty(commodityPrice)) { + commodityPrice = goods.getCommodityInfo().getSnPrice(); + } + + String commentText = ""; + String recommendText = ""; + String qtemplate = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), system); + recommendText = qtemplate.replace("[鍟嗗搧鏍囬]", goods.getCommodityInfo().getCommodityName()); + + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + + + String quickCommentText = configService.getValue(ConfigKeyEnum.quickShareSuNingCommentText.getKey(), system); + commentText = quickCommentText.replace("[鍘熶环]", BigDecimalUtil.getWithNoZera(new BigDecimal(commodityPrice)).toString()); + commentText = commentText.replace("[閾炬帴]", jumpLink); + + + String salesCountMidea = ""; + Integer count = Integer.parseInt(goods.getCommodityInfo().getMonthSales()); + 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")); + } + + + if (goods.getCouponInfo() != null && !StringUtil.isNullOrEmpty(goods.getCouponInfo().getCouponUrl())) {// 鏈夊埜 + BigDecimal amount = new BigDecimal(goods.getCouponInfo().getCouponValue()); + BigDecimal startFee = new BigDecimal(goods.getCouponInfo().getBounsLimit()); + BigDecimal zkPrice = new BigDecimal(commodityPrice); + BigDecimal couponPrice = zkPrice; + if (zkPrice.compareTo(startFee) >= 0) { + couponPrice = zkPrice.subtract(amount); + } + recommendText = recommendText.replace("[鍒搁潰棰漖", + BigDecimalUtil.getWithNoZera(new BigDecimal(goods.getCouponInfo().getCouponValue())).toString()); + commentText = commentText.replace("[鍒稿悗浠穄", BigDecimalUtil.getWithNoZera(couponPrice).toString()); + } else { + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); + commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); + } + + shareInfo.setRecommendText(deleteBlankLine(recommendText)); + shareInfo.setCommentText(deleteBlankLine(commentText)); - shareInfo.setNotifyPicture(array.optString(0)); + // 璁剧疆璇勮鏂囨湰閫夐」 + shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode, + SuningUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP, acceptData.getSystem())))); - // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖 - imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs207.getKey()); - array = JSONArray.fromObject(imgs); - shareInfo.setNotifyPictureNew(array.optString(0)); + out.print(JsonUtil.loadTrueResult( + JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); - shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotify.getKey())); + // 寮傛鎿嶄綔 + 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_VIP); + history.setTkCode(null); + history.setLink(null); + history.setQuanLink(null); + history.setGoodsId(Long.parseLong(sts[1]) + ""); + if (goods.getCommodityInfo().getPictureUrl() != null + && goods.getCommodityInfo().getPictureUrl().size() > 0) + history.setPostPicture(goods.getCommodityInfo().getPictureUrl().get(0).getPicUrl()); + history.setShareImg(jumpLink); + List<SuningGoodsImg> pictureList = goods.getCommodityInfo().getPictureUrl(); + List<String> imgList = new ArrayList<>(); + if (pictureList != null) { + for (SuningGoodsImg gi : pictureList) + imgList.add(gi.getPicUrl()); + } + history.setPictures(JsonUtil.getGson().toJson(imgList)); + shareGoodsService.addShareGoodsHistory(history); + } + }); + } - // 鍒嗕韩閲戦 - 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(); - } - } + /** + * 鎶栭煶鍒嗕韩 + * + * @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; + } - String commentText = ""; - String recommendText = ""; - if (VersionUtil.greaterThan_2_0_7(platform, version)) { - String template2 = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey()); - recommendText = template2.replace("[鍟嗗搧鏍囬]", goods.getTitle()); - if (!coupon) { - recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); - } else { - if (!StringUtil.isNullOrEmpty(goods.getDescription())) { - recommendText = recommendText.replace("[鎺ㄨ崘璇璢", goods.getDescription()); - } else { - recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); - } - } + SystemEnum system = SystemInfoUtil.getSystem(acceptData); - String sales = TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()); - if (sales.equals("0")) { - recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); - } else { - recommendText = recommendText.replace("[閿�閲廬", sales.replace("涓�", "w")); - } - String quickCommentText = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()); - commentText = quickCommentText.replace("[鍘熶环]", goods.getZkPrice().toString()); - commentText = commentText.replace("[娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); - if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { - commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); - commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); - } else { - commentText = commentText.replace("[鍒稿悗浠穄", - TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + ""); - } + DYConvertResult convertResult = CSJCPSApiUtil.goodsConvert(goods.getDetail_url(), DYUtil.createShareExtraInfo(uid), ""); - if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) { - recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); - } else { - recommendText = recommendText.replace("[鍒搁潰棰漖", - MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString()); - } - } else { - commentText = shareInfo.getShareText(); - recommendText = shareInfo.getDescText(); - } - shareInfo.setCommentText(deleteBlankLine(commentText)); - shareInfo.setRecommendText(deleteBlankLine(recommendText)); - // 璁剧疆璇勮鏂囨湰閫夐」 - shareInfo.setCommentTextChoiceList(getCommentChoiceList(shareInfo.getCommentText(), null, inviteCode, - TaoBaoUtil.getGoodsHongBaoMoney(taoBaoLink.getGoods(), hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP)))); + 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())))); + } - out.print(JsonUtil.loadTrueResult( - JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); + String template = shareGoodsTextTemplateService.getTextTemplateBySuNing(uid); + String shareText = shareGoodsTextTemplateService.createCommonShareTextDY(template, goods, convertResult.getDeeplink()); + shareInfo.setShareText(shareText); - 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 + "")); - } - } + String descText = shareText.replace(goods.getTitle(), "").trim(); + if (descText.startsWith("\\r\\n")) { + descText = descText.substring(0); + } + shareInfo.setDescText(descText); - /** - * 浜笢鍒涘缓鍒嗕韩 - * - * @param acceptData - * @param uid - * @param goodsId - * @param source - * @param goodsType - * @param request - * @param out - */ - public void createJDShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods, - PrintWriter out) { - JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId); - if (jdGoods == null) { - out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); - return; - } + // + String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getPlatform(), + Integer.parseInt(acceptData.getVersion()), system); + JSONArray array = JSONArray.fromObject(imgs); - // String url = String.format("http://%s%s?uid=%s&id=%s", - // configService.getH5Host(), - // Constant.systemCommonConfig.getShareGoodsPagePathJD(), - // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - // goodsId + ""); + shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0)); - String couponUrl = null; - JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods); - if (couponInfo != null) { - couponUrl = couponInfo.getLink(); - } - String materialId = "https://item.jd.com/" + goodsId + ".html"; - String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", - uid + ""); + // 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)); - ShareInfoVO shareInfo = new ShareInfoVO(); - shareInfo.setClickUrl(jumpLink); - shareInfo.setWxErCode(jumpLink); - shareInfo.setRule(configService.get(ConfigKeyEnum.shareRuleLinkJD.getKey())); - shareInfo.setPictUrl(jdGoods.getPicUrl()); - shareInfo.setCommentTexts(new ArrayList<>()); + shareInfo.setNotifyDesc(configService.getValue(ConfigKeyEnum.goodsShareNotifyDY.getKey(), system)); - if (needGoods) - shareInfo.setGoodsInfo(GoodsDetailVOFactory.convertJDGoods(jdGoods, - orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion()))); + // 娣诲姞鍒嗕韩璁板綍 + BigDecimal shareRate = hongBaoManageService.getShareRate(acceptData.getSystem()); + BigDecimal shareMoney = DYUtil.getGoodsFanLiMoney(goods, shareRate); + shareInfo.setShareMoney("楼" + shareMoney.toString()); - boolean hasCoupon = false; - if (couponInfo != null) { - hasCoupon = true; - } + 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 template = shareGoodsTextTemplateService.getTextTemplateByJD(uid); - String shareText = shareGoodsTextTemplateService.createContentJD(template, jdGoods, jumpLink, hasCoupon); - shareInfo.setShareText(shareText); + String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); - String descText = shareText.replace(jdGoods.getSkuName(), "").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())); - JSONArray array = JSONArray.fromObject(imgs); + String commentText = ""; + String recommendText = ""; + String qtemplate = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), system); + recommendText = qtemplate.replace("[鍟嗗搧鏍囬]", goods.getTitle()); - shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0)); + recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); - // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖 - imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs207.getKey()); - array = JSONArray.fromObject(imgs); - shareInfo.setNotifyPictureNew(array.size() > 1 ? array.optString(1) : array.optString(0)); - shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotifyJD.getKey())); + String quickCommentText = configService.getValue(ConfigKeyEnum.quickShareDYCommentText.getKey(), system); - // 娣诲姞鍒嗕韩璁板綍 - BigDecimal shareRate = hongBaoManageService.getShareRate(); - BigDecimal shareMoney = JDUtil.getGoodsFanLiMoney(jdGoods, shareRate); - shareInfo.setShareMoney("楼" + shareMoney.toString()); - try { - ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, - Constant.SOURCE_TYPE_JD, false); - shareInfo.setShareId(shareRecord.getRedisKey()); - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - } + commentText = quickCommentText.replace("[鍘熶环]", BigDecimalUtil.getWithNoZera(DYUtil.getPrice(goods.getPrice())).toString()); + //commentText = commentText.replace("[閾炬帴]", jumpLink); + commentText = commentText.replace("[鍙d护]", convertResult.getPassword()); - String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); - String commentText = ""; - String recommendText = ""; - if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) { - String template2 = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey()); - recommendText = template2.replace("[鍟嗗搧鏍囬]", jdGoods.getSkuName()); - recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); - String sales = JDUtil.getSaleCount(jdGoods.getInOrderCount30Days()); - if (sales.equals("0")) { - recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); - } else { - recommendText = recommendText.replace("[閿�閲廬", sales.replace("涓�", "w")); - } + 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")); + } - BigDecimal price = jdGoods.getPrice(); - JDPingouInfo pinGouInfo = jdGoods.getPinGouInfo(); - if (pinGouInfo != null) { - price = pinGouInfo.getPingouPrice(); - } + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘").replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); - String template3 = configService.get(ConfigKeyEnum.quickShareJDCommentText.getKey()); - commentText = template3.replace("[鍘熶环]", BigDecimalUtil.getWithNoZera(price).toString()); - if (!hasCoupon) { - recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); - commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); - commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); - } else { - recommendText = recommendText.replace("[鍒搁潰棰漖", - BigDecimalUtil.getWithNoZera(couponInfo.getDiscount()).toString()); - commentText = commentText.replace("[鍒稿悗浠穄", - BigDecimalUtil.getWithNoZera(JDUtil.getQuanPrice(jdGoods)).toString()); - } - commentText = commentText.replace("[閾炬帴]", jumpLink); - } else { - commentText = shareInfo.getShareText(); - recommendText = shareInfo.getDescText(); - } - shareInfo.setCommentText(deleteBlankLine(commentText)); - shareInfo.setRecommendText(deleteBlankLine(recommendText)); + shareInfo.setRecommendText(deleteBlankLine(recommendText)); + shareInfo.setCommentText(deleteBlankLine(commentText)); - // 璁剧疆璇勮鏂囨湰閫夐」 - shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode, - JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP)))); + // 璁剧疆璇勮鏂囨湰閫夐」 + 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))); + out.print(JsonUtil.loadTrueResult( + JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); - // 寮傛鎿嶄綔 - final JDGoods goods = jdGoods; - 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_JD); - history.setTkCode(null); - history.setLink(null); - history.setQuanLink(null); - history.setGoodsId(goodsId); - history.setPostPicture(goods.getPicUrl()); - history.setShareImg(jumpLink); + // 寮傛鎿嶄綔 + 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); + } + }); + } - List<String> imgList = goods.getImageList(); - if (imgList == null) { - imgList = new ArrayList<>(); - } - history.setPictures(JsonUtil.getGson().toJson(imgList)); - shareGoodsService.addShareGoodsHistory(history); - } - }); - } + /** + * 棰勮鍒嗕韩妯℃澘 + * + * @param acceptData + * @param uid + * @param template + * @param goodsId + * @param hasCoupon + * @param out + */ + @RequestMapping(value = "viewShareTextTemplate", method = RequestMethod.POST) + public void viewShareTextTemplate(AcceptData acceptData, Long uid, String template, Integer goodsType, String goodsId, + Long tljId, Boolean hasCoupon, PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } - private String deleteBlankLine(String st) { - return st.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n"); - } + if (goodsId == null) { + out.print(JsonUtil.loadFalseResult(3, "鍟嗗搧ID涓嶈兘涓虹┖")); + return; + } - /** - * 鎷煎澶氬垎浜� - * - * @param acceptData - * @param uid - * @param goodsId - * @param source - * @param out - */ - public void createPDDShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods, - PrintWriter out) { - PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); - if (goods == null) { - out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); - return; - } + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + createTaoBaoViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, tljId, hasCoupon, out); + return; + } - // String url = String.format("http://%s%s?uid=%s&id=%s", - // configService.getH5Host(), - // Constant.systemCommonConfig.getShareGoodsPagePathPDD(), - // AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - // goodsId + ""); + if (goodsType == Constant.SOURCE_TYPE_JD) { + createJDViewText(acceptData.getSystem(), goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out); + return; + } - String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", uid + ""); + if (goodsType == Constant.SOURCE_TYPE_PDD) { + createPDDViewText(acceptData.getSystem(), goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out); + return; + } - ShareInfoVO shareInfo = new ShareInfoVO(); - shareInfo.setClickUrl(jumpLink); - shareInfo.setWxErCode(jumpLink); - shareInfo.setCommentTexts(new ArrayList<>()); - shareInfo.setRule(configService.get(ConfigKeyEnum.shareRuleLinkPDD.getKey())); - shareInfo.setPictUrl(goods.getGoodsImageUrl()); - if (needGoods) { - shareInfo - .setGoodsInfo(GoodsDetailVOFactory.convertPDDGoods(goods, - new ConfigParamsDTO(hongBaoManageService.getFanLiRate(), - hongBaoManageService.getShareRate(), Constant.MAX_REWARD_RATE, - hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP)))); - } + if (goodsType == Constant.SOURCE_TYPE_VIP) { + createVIPViewText(goodsType, uid, template, Long.parseLong(goodsId), hasCoupon, out); + return; + } - // 鍒涘缓鍙d护 - // String token = PinDuoDuoApiUtil.createGenerate(goodsId); + if (goodsType == Constant.SOURCE_TYPE_SUNING) { + createSuNingViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, hasCoupon, out); + return; + } - boolean hasCoupon = true; - if (goods.getHasCoupon() == null || !goods.getHasCoupon()) { - hasCoupon = false; - } - String template = shareGoodsTextTemplateService.getTextTemplateByPDD(uid); - String shareText = shareGoodsTextTemplateService.createContentPDD(template, goods, jumpLink, hasCoupon); - shareInfo.setShareText(shareText); + if (goodsType == Constant.SOURCE_TYPE_DY) { + createDYViewText(acceptData.getSystem(), goodsType, uid, template, goodsId, hasCoupon, out); + return; + } + } - String descText = shareText.replace(goods.getGoodsName(), "").trim(); - if (descText.startsWith("\\r\\n")) { - descText = descText.substring(0); - } - shareInfo.setDescText(descText); + /** + * 鍒涘缓娣樺疂鍒嗕韩妯℃澘 + * + * @param uid + * @param template + * @param goodsType + * @param goodsId + * @param tljId + * @param hasCoupon + * @param out + */ + 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) + try { + goods = redisManager.getTaoBaoGoodsBrief(goodsId); + } catch (TaobaoGoodsDownException e) { + goods = null; + } - // - String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getPlatform(), - Integer.parseInt(acceptData.getVersion())); - JSONArray array = JSONArray.fromObject(imgs); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); + return; + } - shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0)); + if (StringUtil.isNullOrEmpty(template)) { + template = getShareTemplate(goodsType, uid, hasCoupon, tljId); + } - // 2.0.7鐗堟湰鍚庣殑鎻愮ず鍥剧墖 - imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs207.getKey()); - array = JSONArray.fromObject(imgs); - shareInfo.setNotifyPictureNew(array.size() > 1 ? array.optString(1) : array.optString(0)); + // 鏍¢獙妯℃澘鏄惁姝g‘ + try { + shareGoodsTextTemplateService.verifyRightTB(template); + } catch (ShareGoodsTextTemplateException e) { + out.print(JsonUtil.loadFalseResult(5, e.getMsg())); + return; + } - shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotifyPDD.getKey())); + // 鏌ヨ鏄惁鏈夊垎浜� + UserShareGoodsHistory userShareHistory = shareGoodsService.getShareGoodsHistory(uid, goods.getAuctionId()); + String token = ""; + if (userShareHistory != null) { + token = userShareHistory.getTkCode(); + } - // 娣诲姞鍒嗕韩璁板綍 - BigDecimal shareRate = hongBaoManageService.getShareRate(); - BigDecimal shareMoney = PinDuoDuoUtil.getGoodsFanLiMoney(goods, shareRate); - shareInfo.setShareMoney("楼" + shareMoney.toString()); + if (StringUtil.isNullOrEmpty(token)) { + String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share); + TaoKeAppInfo app = new TaoKeAppInfo(); + app.setAdzoneId(pid.split("_")[3]); + app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); + app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); + app.setPid(pid); + TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app, null, null); + if (goodsLink != null) + token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), + StringUtil.isNullOrEmpty(goodsLink.getCouponLink()) ? goodsLink.getAuctionUrl() + : goodsLink.getCouponLink()); + } + String content = shareGoodsTextTemplateService.createContentTB(template, goods, token, hasCoupon); + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } - try { - ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, - Constant.SOURCE_TYPE_PDD, false); - shareInfo.setShareId(shareRecord.getRedisKey()); - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - } + /** + * 鍒涘缓浜笢鍒嗕韩妯℃澘 + * + * @param uid + * @param template + * @param goodsType + * @param goodsId + * @param hasCoupon + * @param out + */ + 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) { + out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); + return; + } - String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); + if (StringUtil.isNullOrEmpty(template)) { + template = getShareTemplate(goodsType, uid, hasCoupon, null); + } - String commentText = ""; - String recommendText = ""; - if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) { - String qtemplate = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey()); - recommendText = qtemplate.replace("[鍟嗗搧鏍囬]", goods.getGoodsName()); + // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� + try { + shareGoodsTextTemplateService.verifyRightJD(template); + } catch (ShareGoodsTextTemplateException e) { + out.print(JsonUtil.loadFalseResult(5, e.getMsg())); + return; + } - // 鎬婚攢閲� - String salesTip = goods.getSalesTip(); - if (StringUtil.isNullOrEmpty(salesTip)) { - salesTip = "0"; - } - if (salesTip.equals("0")) { - recommendText = recommendText.replace("閿�閲�:[閿�閲廬", ""); - } else { - recommendText = recommendText.replace("[閿�閲廬", salesTip.replace("涓�", "w")); - recommendText = recommendText.replace("閿�閲�", "鎬婚攢閲�"); - } - recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", ""); + String couponUrl = null; + JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods); + if (couponInfo != null) { + couponUrl = couponInfo.getLink(); + } + String materialId = "https://item.jd.com/" + goodsId + ".html"; + 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 quickCommentText = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey()); - commentText = quickCommentText.replace("[鍘熶环]", MoneyBigDecimalUtil - .div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)).setScale(2).toString()); - commentText = commentText.replace("[閾炬帴]", jumpLink); - if (!hasCoupon) { - commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); - commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); - recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", ""); - } else { - commentText = commentText.replace("[鍒稿悗浠穄", - BigDecimalUtil.getWithNoZera(PinDuoDuoUtil.getQuanPrice(goods)).toString()); + String content = shareGoodsTextTemplateService.createContentJD(template, goods, shortLink, hasCoupon); + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } - BigDecimal hundred = new BigDecimal(100); - BigDecimal amount = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCouponDiscount()), hundred); - recommendText = recommendText.replace("[鍒搁潰棰漖", BigDecimalUtil.getWithNoZera(amount).toString()); - } - } else { - commentText = shareInfo.getShareText(); - recommendText = shareInfo.getDescText(); - } - shareInfo.setRecommendText(deleteBlankLine(recommendText)); - shareInfo.setCommentText(deleteBlankLine(commentText)); + /** + * 鍒涘缓鎷煎澶氬垎浜ā鏉� + * + * @param uid + * @param template + * @param goodsType + * @param goodsId + * @param hasCoupon + * @param out + */ + private void createPDDViewText(SystemEnum system, Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, + PrintWriter out) { + PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); + return; + } - // 璁剧疆璇勮鏂囨湰閫夐」 - shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode, - PinDuoDuoUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP)))); + if (StringUtil.isNullOrEmpty(template)) { + template = getShareTemplate(goodsType, uid, hasCoupon, null); + } - out.print(JsonUtil.loadTrueResult( - JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo))); + // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� + try { + shareGoodsTextTemplateService.verifyRightPDD(template); + } catch (ShareGoodsTextTemplateException e) { + out.print(JsonUtil.loadFalseResult(5, e.getMsg())); + return; + } - // 寮傛鎿嶄綔 - 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_PDD); - history.setTkCode(null); - history.setLink(null); - history.setQuanLink(null); - history.setGoodsId(goodsId); - history.setPostPicture(goods.getGoodsImageUrl()); - history.setShareImg(jumpLink); - List<String> imgList = null; - String[] goodsGalleryUrls = goods.getGoodsGalleryUrls(); - if (goodsGalleryUrls != null) { - imgList = Arrays.asList(goodsGalleryUrls); - } - if (imgList == null) { - imgList = new ArrayList<>(); - } - history.setPictures(JsonUtil.getGson().toJson(imgList)); - shareGoodsService.addShareGoodsHistory(history); - } - }); - } + // // 鍒涘缓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); - /** - * 棰勮鍒嗕韩妯℃澘 - * - * @param acceptData - * @param uid - * @param template - * @param goodsId - * @param hasCoupon - * @param out - */ - @RequestMapping(value = "viewShareTextTemplate", method = RequestMethod.POST) - public void viewShareTextTemplate(AcceptData acceptData, Long uid, String template, Integer goodsType, Long goodsId, - Long tljId, Boolean hasCoupon, PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } + String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goods.getGoodsSign(), pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share), uid + ""); - if (goodsId == null) { - out.print(JsonUtil.loadFalseResult(3, "鍟嗗搧ID涓嶈兘涓虹┖")); - return; - } + // // 鍒涘缓鍙d护 + // String token = PinDuoDuoApiUtil.createGenerate(goodsId); - if (goodsType == null || goodsType > 3 || goodsType < 1) { - out.print(JsonUtil.loadFalseResult(3, "骞冲彴绫诲瀷涓嶆纭�")); - return; - } + // 鐢熸垚鍒嗕韩鍐呭 + String content = shareGoodsTextTemplateService.createContentPDD(template, goods, shortLink, hasCoupon); - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - createTaoBaoViewText(goodsType, uid, template, goodsId, tljId, hasCoupon, out); - return; - } + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } - if (goodsType == Constant.SOURCE_TYPE_JD) { - createJDViewText(goodsType, uid, template, goodsId, hasCoupon, out); - return; - } + /** + * 鍞搧浼氬垎浜� + * + * @param goodsType + * @param uid + * @param template + * @param goodsId + * @param hasCoupon + * @param out + */ + private void createVIPViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, + PrintWriter out) { + VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId + ""); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); + return; + } - if (goodsType == Constant.SOURCE_TYPE_PDD) { - createPDDViewText(goodsType, uid, template, goodsId, hasCoupon, out); - return; - } - } + if (StringUtil.isNullOrEmpty(template)) { + template = getShareTemplate(goodsType, uid, hasCoupon, null); + } - /** - * 鍒涘缓娣樺疂鍒嗕韩妯℃澘 - * - * @param uid - * @param template - * @param goodsType - * @param goodsId - * @param tljId - * @param hasCoupon - * @param out - */ - private void createTaoBaoViewText(Integer goodsType, Long uid, String template, Long goodsId, Long tljId, - Boolean hasCoupon, PrintWriter out) { - TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId); - if (goods == null) - try { - goods = redisManager.getTaoBaoGoodsBrief(goodsId); - } catch (TaobaoGoodsDownException e) { - goods = null; - } + // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� + try { + shareGoodsTextTemplateService.verifyRightVIP(template); + } catch (ShareGoodsTextTemplateException e) { + out.print(JsonUtil.loadFalseResult(5, e.getMsg())); + return; + } - if (goods == null) { - out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); - return; - } + VIPConvertResultDTO jumpLink = VipShopApiUtil.convertLink(goodsId + "", VipShopUtil.getShareChanTag(uid)); - if (StringUtil.isNullOrEmpty(template)) { - template = getShareTemplate(goodsType, uid, hasCoupon, tljId); - } + // 鐢熸垚鍒嗕韩鍐呭 + String content = shareGoodsTextTemplateService.createContentVIP(template, goods, jumpLink.getUrl()); - // 鏍¢獙妯℃澘鏄惁姝g‘ - try { - shareGoodsTextTemplateService.verifyRightTB(template); - } catch (ShareGoodsTextTemplateException e) { - out.print(JsonUtil.loadFalseResult(5, e.getMsg())); - return; - } + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } - // 鏌ヨ鏄惁鏈夊垎浜� - UserShareGoodsHistory userShareHistory = shareGoodsService.getShareGoodsHistory(uid, goods.getAuctionId()); - String token = ""; - if (userShareHistory != null) { - token = userShareHistory.getTkCode(); - } - if (StringUtil.isNullOrEmpty(token)) { - TaoKeAppInfo app = new TaoKeAppInfo(); - app.setAdzoneId(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]); - app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); - app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); - app.setPid(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT); - TaoBaoGoodsBrief goodsLink = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app); - if (goodsLink != null) - token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), - StringUtil.isNullOrEmpty(goodsLink.getCouponLink()) ? goodsLink.getAuctionUrl() - : goodsLink.getCouponLink()); - } - String content = shareGoodsTextTemplateService.createContentTB(template, goods, token, hasCoupon); - JSONObject data = new JSONObject(); - data.put("content", content); - out.print(JsonUtil.loadTrueResult(data)); - } + 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]); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); + return; + } - /** - * 鍒涘缓浜笢鍒嗕韩妯℃澘 - * - * @param uid - * @param template - * @param goodsType - * @param goodsId - * @param tljId - * @param hasCoupon - * @param out - */ - private void createJDViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, - PrintWriter out) { - JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId); - if (goods == null) { - out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); - return; - } + if (StringUtil.isNullOrEmpty(template)) { + template = getShareTemplate(goodsType, uid, hasCoupon, null); + } - if (StringUtil.isNullOrEmpty(template)) { - template = getShareTemplate(goodsType, uid, hasCoupon, null); - } + // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� + try { + shareGoodsTextTemplateService.verifyRightSuNing(template); + } catch (ShareGoodsTextTemplateException e) { + out.print(JsonUtil.loadFalseResult(5, e.getMsg())); + return; + } - // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� - try { - shareGoodsTextTemplateService.verifyRightJD(template); - } catch (ShareGoodsTextTemplateException e) { - out.print(JsonUtil.loadFalseResult(5, e.getMsg())); - return; - } + String couponLink = goods.getCouponInfo().getCouponUrl(); + String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(ids[0], ids[1]), + StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, pidManager.getPidCache(system, Constant.SOURCE_TYPE_SUNING, SystemPIDInfo.PidType.share), uid + ""); - String couponUrl = null; - JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods); - if (couponInfo != null) { - couponUrl = couponInfo.getLink(); - } - String materialId = "https://item.jd.com/" + goodsId + ".html"; - String shortLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", - uid + ""); + // 鐢熸垚鏅�氬垎浜唴瀹� + String content = shareGoodsTextTemplateService.createCommonShareTextSuNing(template, goods, jumpLink); - String content = shareGoodsTextTemplateService.createContentJD(template, goods, shortLink, hasCoupon); - JSONObject data = new JSONObject(); - data.put("content", content); - out.print(JsonUtil.loadTrueResult(data)); - } + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } - /** - * 鍒涘缓鎷煎澶氬垎浜ā鏉� - * - * @param uid - * @param template - * @param goodsType - * @param goodsId - * @param tljId - * @param hasCoupon - * @param out - */ - private void createPDDViewText(Integer goodsType, Long uid, String template, Long goodsId, Boolean hasCoupon, - PrintWriter out) { - PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); - if (goods == null) { - out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); - return; - } - if (StringUtil.isNullOrEmpty(template)) { - template = getShareTemplate(goodsType, uid, hasCoupon, null); - } + private void createDYViewText(SystemEnum system, Integer goodsType, Long uid, String template, String goodsId, Boolean hasCoupon, + PrintWriter out) { - // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� - try { - shareGoodsTextTemplateService.verifyRightPDD(template); - } catch (ShareGoodsTextTemplateException e) { - out.print(JsonUtil.loadFalseResult(5, e.getMsg())); - return; - } + DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(goodsId)); + if (goods == null) { + out.print(JsonUtil.loadFalseResult(4, "鍟嗗搧宸蹭笅鏋�")); + return; + } - // // 鍒涘缓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); + if (StringUtil.isNullOrEmpty(template)) { + template = getShareTemplate(goodsType, uid, hasCoupon, null); + } - String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", uid + ""); + // 鏍¢獙鍒告ā鏉挎槸鍚︽纭� + try { + shareGoodsTextTemplateService.verifyRightDY(template); + } catch (ShareGoodsTextTemplateException e) { + out.print(JsonUtil.loadFalseResult(5, e.getMsg())); + return; + } - // // 鍒涘缓鍙d护 - // String token = PinDuoDuoApiUtil.createGenerate(goodsId); + 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.createContentPDD(template, goods, shortLink, hasCoupon); - JSONObject data = new JSONObject(); - data.put("content", content); - out.print(JsonUtil.loadTrueResult(data)); - } + // 鐢熸垚鏅�氬垎浜唴瀹� + String content = shareGoodsTextTemplateService.createCommonShareTextDY(template, goods, convertResult.getPassword()); - /** - * 鑾峰彇鍒嗕韩妯℃澘 - * - * @param uid - * @param hasCoupon - * @param tljId - * @return - */ - private String getShareTemplate(int goodsType, Long uid, boolean hasCoupon, Long tljId) { - String template = ""; - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - template = shareGoodsTextTemplateService.getTextTemplateByTB(uid); - } else if (goodsType == Constant.SOURCE_TYPE_JD) { - template = shareGoodsTextTemplateService.getTextTemplateByJD(uid); - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - template = shareGoodsTextTemplateService.getTextTemplateByPDD(uid); - } - return template; - } + JSONObject data = new JSONObject(); + data.put("content", content); + out.print(JsonUtil.loadTrueResult(data)); + } - /** - * 鑾峰彇鍒嗕韩妯℃澘 - * - * @param acceptData - * @param uid - * @param hasCoupon - * @param out - */ - @RequestMapping(value = "getShareTextTemplate", method = RequestMethod.POST) - public void getShareTextTemplate(AcceptData acceptData, Integer goodsType, Long uid, Long tljId, Boolean hasCoupon, - PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - if (hasCoupon == null) { - out.print(JsonUtil.loadFalseResult(1, "鏄惁鏈夊埜瀛楁涓虹┖")); - return; - } + /** + * 鑾峰彇鍒嗕韩妯℃澘 + * + * @param uid + * @param hasCoupon + * @param tljId + * @return + */ + private String getShareTemplate(int goodsType, Long uid, boolean hasCoupon, Long tljId) { + String template = ""; + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + template = shareGoodsTextTemplateService.getTextTemplateByTB(uid); + } else if (goodsType == Constant.SOURCE_TYPE_JD) { + template = shareGoodsTextTemplateService.getTextTemplateByJD(uid); + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + template = shareGoodsTextTemplateService.getTextTemplateByPDD(uid); + } else if (goodsType == Constant.SOURCE_TYPE_VIP) { + 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; + } - JSONObject data = new JSONObject(); - data.put("template", getShareTemplate(goodsType, uid, hasCoupon, tljId)); - out.print(JsonUtil.loadTrueResult(data)); - } + /** + * 鑾峰彇鍒嗕韩妯℃澘 + * + * @param acceptData + * @param uid + * @param hasCoupon + * @param out + */ + @RequestMapping(value = "getShareTextTemplate", method = RequestMethod.POST) + public void getShareTextTemplate(AcceptData acceptData, Integer goodsType, Long uid, Long tljId, Boolean hasCoupon, + PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } - /** - * 鑾峰彇鍒嗕韩妯℃澘缂栬緫瑙勫垯 - * - * @param acceptData - * @param out - */ - @RequestMapping(value = "getShareTextTemplateRules", method = RequestMethod.POST) - public void getShareTextTemplateRules(AcceptData acceptData, Integer goodsType, Long tljId, PrintWriter out) { - if (goodsType == null || goodsType > 3 || goodsType < 1) { - out.print(JsonUtil.loadFalseResult(3, "骞冲彴绫诲瀷涓嶆纭�")); - return; - } + if (hasCoupon == null) { + out.print(JsonUtil.loadFalseResult(1, "鏄惁鏈夊埜瀛楁涓虹┖")); + return; + } - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - if (tljId != null) { - out.print( - JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules", new Date()))); - } else { - out.print(JsonUtil.loadTrueResult(configService.get(ConfigKeyEnum.shareGoodsTemplateRules.getKey()))); - } - } else if (goodsType == Constant.SOURCE_TYPE_JD) { - out.print(JsonUtil.loadTrueResult(configService.get(ConfigKeyEnum.shareGoodsTemplateRulesJD.getKey()))); - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - out.print(JsonUtil.loadTrueResult(configService.get(ConfigKeyEnum.shareGoodsTemplateRulesPDD.getKey()))); - } - } + JSONObject data = new JSONObject(); + data.put("template", getShareTemplate(goodsType, uid, hasCoupon, tljId)); + out.print(JsonUtil.loadTrueResult(data)); + } - /** - * 淇濆瓨妯℃澘 - * - * @param acceptData - * @param uid - * @param hasCoupon - * @param template - * @param out - */ - @RequestMapping(value = "saveShareTextTemplate", method = RequestMethod.POST) - public void saveShareTextTemplate(AcceptData acceptData, Integer goodsType, Long uid, Long tljId, Boolean hasCoupon, - String template, PrintWriter out) { - if (StringUtil.isNullOrEmpty(template)) { - out.print(JsonUtil.loadFalseResult(1, "鍒嗕韩妯℃澘涓虹┖")); - return; - } + /** + * 鑾峰彇鍒嗕韩妯℃澘缂栬緫瑙勫垯 + * + * @param acceptData + * @param out + */ + @RequestMapping(value = "getShareTextTemplateRules", method = RequestMethod.POST) + public void getShareTextTemplateRules(AcceptData acceptData, Integer goodsType, Long tljId, PrintWriter out) { + SystemEnum system = SystemInfoUtil.getSystem(acceptData); + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + if (tljId != null) { + out.print( + JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules", new Date()))); + } else { + out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRules.getKey(), system))); + } + } else if (goodsType == Constant.SOURCE_TYPE_JD) { + out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRulesJD.getKey(), system))); + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + out.print(JsonUtil.loadTrueResult(configService.getValue(ConfigKeyEnum.shareGoodsTemplateRulesPDD.getKey(), system))); + } else if (goodsType == Constant.SOURCE_TYPE_VIP) { + 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))); + } + } - if (goodsType == null || goodsType > 3 || goodsType < 1) { - out.print(JsonUtil.loadFalseResult(3, "骞冲彴绫诲瀷涓嶆纭�")); - return; - } + /** + * 淇濆瓨妯℃澘 + * + * @param acceptData + * @param uid + * @param hasCoupon + * @param template + * @param out + */ + @RequestMapping(value = "saveShareTextTemplate", method = RequestMethod.POST) + public void saveShareTextTemplate(AcceptData acceptData, Integer goodsType, Long uid, Long tljId, Boolean hasCoupon, + String template, PrintWriter out) { + if (StringUtil.isNullOrEmpty(template)) { + out.print(JsonUtil.loadFalseResult(1, "鍒嗕韩妯℃澘涓虹┖")); + return; + } - try { - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - shareGoodsTextTemplateService.saveTemplateTB(uid, template); - } else if (goodsType == Constant.SOURCE_TYPE_JD) { - shareGoodsTextTemplateService.saveTemplateJD(uid, template); - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - shareGoodsTextTemplateService.saveTemplatePDD(uid, template); - } - } catch (ShareGoodsTextTemplateException e) { - out.print(JsonUtil.loadFalseResult(5, e.getMsg())); - return; - } - out.print(JsonUtil.loadTrueResult("")); - } + try { + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + shareGoodsTextTemplateService.saveTemplateTB(uid, template); + } else if (goodsType == Constant.SOURCE_TYPE_JD) { + shareGoodsTextTemplateService.saveTemplateJD(uid, template); + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + shareGoodsTextTemplateService.saveTemplatePDD(uid, template); + } else if (goodsType == Constant.SOURCE_TYPE_VIP) { + 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())); + return; + } + out.print(JsonUtil.loadTrueResult("")); + } - /** - * 杩樺師妯℃澘 - * - * @param acceptData - * @param uid - * @param hasCoupon - * -鏄惁鏈夊埜 - * @param out - */ - @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST) - public void resetShareTextTemplate(AcceptData acceptData, Long uid, Long goodsId, Long tljId, Boolean hasCoupon, - Integer goodsType, PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } + /** + * 杩樺師妯℃澘 + * + * @param acceptData + * @param uid + * @param hasCoupon -鏄惁鏈夊埜 + * @param out + */ + @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST) + public void resetShareTextTemplate(AcceptData acceptData, Long uid, String goodsId, Long tljId, Boolean hasCoupon, + Integer goodsType, PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } - if (goodsType == null || goodsType > 3 || goodsType < 1) { - out.print(JsonUtil.loadFalseResult(3, "骞冲彴绫诲瀷涓嶆纭�")); - return; - } + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + shareGoodsTextTemplateService.resetCommonTemplate(uid); + } else if (goodsType == Constant.SOURCE_TYPE_JD) { + shareGoodsTextTemplateService.resetCommonTemplateJD(uid); + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + shareGoodsTextTemplateService.resetCommonTemplatePDD(uid); + } else if (goodsType == Constant.SOURCE_TYPE_VIP) { + shareGoodsTextTemplateService.resetCommonTemplateVIP(uid); + } else if (goodsType == Constant.SOURCE_TYPE_SUNING) { + shareGoodsTextTemplateService.resetCommonTemplateSuNing(uid); + }else if (goodsType == Constant.SOURCE_TYPE_DY) { + shareGoodsTextTemplateService.resetCommonTemplateDY(uid); + } - if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { - shareGoodsTextTemplateService.resetCommonTemplate(uid); - } else if (goodsType == Constant.SOURCE_TYPE_JD) { - shareGoodsTextTemplateService.resetCommonTemplateJD(uid); - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - shareGoodsTextTemplateService.resetCommonTemplatePDD(uid); - } + if (goodsId != null) { + viewShareTextTemplate(acceptData, uid, null, goodsType, goodsId, tljId, hasCoupon, out); + return; + } + out.print(JsonUtil.loadTrueResult("")); + } - if (goodsId != null) { - viewShareTextTemplate(acceptData, uid, null, goodsType, goodsId, tljId, hasCoupon, out); - return; - } - out.print(JsonUtil.loadTrueResult("")); - } + /** + * 鑾峰彇鍒嗕韩璁板綍涓殑鍟嗗搧 鍒嗕韩淇℃伅 + * + * @param acceptData + * @param recordId + * @param out + */ + @RequestMapping(value = "getShareGoods") + public void getShareGoods(AcceptData acceptData, Long recordId, PrintWriter out) { - /** - * 鑾峰彇鍒嗕韩璁板綍涓殑鍟嗗搧 鍒嗕韩淇℃伅 - * - * @param acceptData - * @param recordId - * @param out - */ - @RequestMapping(value = "getShareGoods") - public void getShareGoods(AcceptData acceptData, Long recordId, PrintWriter out) { + if (recordId == null) { + out.print(JsonUtil.loadFalseResult("鍙傛暟涓嶆纭�")); + return; + } - if (recordId == null) { - out.print(JsonUtil.loadFalseResult("鍙傛暟涓嶆纭�")); - return; - } + JSONArray array = new JSONArray(); + JSONObject data = new JSONObject(); - JSONArray array = new JSONArray(); - JSONObject data = new JSONObject(); + boolean notBackSuVip = false; + if (!VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion())) + notBackSuVip = true; - List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId); - if (list == null || list.size() == 0) { - data.put("title", "鍒嗕韩鍟嗗搧"); - data.put("count", 0); - data.put("result_list", array); - out.print(JsonUtil.loadTrueResult(data)); - return; - } + List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId, notBackSuVip); + if (list == null || list.size() == 0) { + data.put("title", "鍒嗕韩鍟嗗搧"); + data.put("count", 0); + data.put("result_list", array); + out.print(JsonUtil.loadTrueResult(data)); + return; + } - // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭 - List<TaoBaoGoodsBrief> listTaoKeGoods = null; - List<Long> listGid = new ArrayList<Long>(); - for (UserShareGoodsGroup goodsGroup : list) { - CommonGoods commonGoods = goodsGroup.getCommonGoods(); - Integer goodsType = commonGoods.getGoodsType(); - if (commonGoods == null || goodsType == null || goodsType != Constant.SOURCE_TYPE_TAOBAO) { - continue; - } - listGid.add(commonGoods.getGoodsId()); - } + // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭 + List<TaoBaoGoodsBrief> listTaoKeGoods = null; + List<String> listGid = new ArrayList<>(); + for (UserShareGoodsGroup goodsGroup : list) { + CommonGoods commonGoods = goodsGroup.getCommonGoods(); + Integer goodsType = commonGoods.getGoodsType(); + if (commonGoods == null || goodsType == null || goodsType != Constant.SOURCE_TYPE_TAOBAO) { + continue; + } + listGid.add(commonGoods.getGoodsId()); + } - if (listGid.size() > 0) { - try { - listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); - } catch (TaoKeApiException e) { - e.printStackTrace(); - } catch (TaobaoGoodsDownException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + if (listGid.size() > 0) { + try { + listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); + } catch (TaoKeApiException e) { + e.printStackTrace(); + } catch (TaobaoGoodsDownException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), - acceptData.getVersion()); + GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), + acceptData.getVersion(), acceptData.getSystem()); - Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) - .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); + Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) + .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); - for (UserShareGoodsGroup goodsGroup : list) { - CommonGoods commonGoods = goodsGroup.getCommonGoods(); - if (commonGoods == null) { - continue; - } + for (UserShareGoodsGroup goodsGroup : list) { + CommonGoods commonGoods = goodsGroup.getCommonGoods(); + if (commonGoods == null) { + continue; + } - // 楠岃瘉娣樺疂鍟嗗搧鏄惁鍦ㄥ敭 - Integer goodsType = commonGoods.getGoodsType(); - if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 && goodsType != null - && goodsType == Constant.SOURCE_TYPE_TAOBAO) { - int state = 1; // 榛樿鍋滃敭 - Long goodsId = commonGoods.getGoodsId(); - for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { - Long auctionId = taoKeGoods.getAuctionId(); - if (goodsId == auctionId || goodsId.equals(auctionId)) { - state = 0; // 鍦ㄥ敭 - break; - } - } - commonGoods.setState(state); - } + // 楠岃瘉娣樺疂鍟嗗搧鏄惁鍦ㄥ敭 + Integer goodsType = commonGoods.getGoodsType(); + if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 && goodsType != null + && goodsType == Constant.SOURCE_TYPE_TAOBAO) { + int state = 1; // 榛樿鍋滃敭 + String goodsId = commonGoods.getGoodsId(); + for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { + String auctionId = taoKeGoods.getAuctionId(); + if (TaoBaoUtil.isEqual(goodsId, auctionId)) { + state = 0; // 鍦ㄥ敭 + break; + } + } + commonGoods.setState(state); + } - // 浠婃棩娴忚璁板綍澶勭悊 - Date date = new Date(); - Date browseTime = goodsGroup.getBrowseTime(); - if (!DateUtil.isSameDay(browseTime, date)) { - goodsGroup.setTodayBrowse(0); // 涓嶆槸鍚屼竴澶╂祻瑙堣褰曡缃�0 - } + // 浠婃棩娴忚璁板綍澶勭悊 + Date date = new Date(); + Date browseTime = goodsGroup.getBrowseTime(); + if (!DateUtil.isSameDay(browseTime, date)) { + goodsGroup.setTodayBrowse(0); // 涓嶆槸鍚屼竴澶╂祻瑙堣褰曡缃�0 + } - JSONObject dataObject = new JSONObject(); - dataObject.put("todayBrowse", goodsGroup.getTodayBrowse()); - dataObject.put("totalBrowse", goodsGroup.getTotalBrowse()); - dataObject.put("totalOrder", goodsGroup.getTotalOrder()); - dataObject.put("totalMoney", "楼" + goodsGroup.getTotalMoney()); + JSONObject dataObject = new JSONObject(); + dataObject.put("todayBrowse", goodsGroup.getTodayBrowse()); + dataObject.put("totalBrowse", goodsGroup.getTotalBrowse()); + dataObject.put("totalOrder", goodsGroup.getTotalOrder()); + dataObject.put("totalMoney", "楼" + goodsGroup.getTotalMoney()); - GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, paramsDTO); - detailVO.setId(commonGoods.getId()); - dataObject.put("goods", gson.toJson(detailVO)); - array.add(dataObject); - } + GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, paramsDTO); + detailVO.setCreatetime(null); + detailVO.setId(commonGoods.getId()); + dataObject.put("goods", gson.toJson(detailVO)); + array.add(dataObject); + } - String title = ""; - UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordService.selectByPrimaryKey(recordId); - if (userShareGoodsRecord != null) { - title = userShareGoodsRecord.getTitle(); - } + String title = ""; + UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordService.selectByPrimaryKey(recordId); + if (userShareGoodsRecord != null) { + title = userShareGoodsRecord.getTitle(); + } - data.put("title", title); - data.put("count", list.size()); - data.put("result_list", array); - out.print(JsonUtil.loadTrueResult(data)); - } + data.put("title", title); + data.put("count", list.size()); + data.put("result_list", array); + out.print(JsonUtil.loadTrueResult(data)); + } - @RequestMapping(value = "getShareTextQuick", method = RequestMethod.POST) - public void getShareTextQuick(AcceptData acceptData, Long goodsId, Integer goodsType, Long uid, PrintWriter out) { - if (uid == null) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } + @RequestMapping(value = "getShareTextQuick", method = RequestMethod.POST) + public void getShareTextQuick(AcceptData acceptData, String goodsId, Integer goodsType, Long uid, PrintWriter out) { + if (uid == null) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } - if (goodsType == null || goodsId == null) { - out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭殑鍟嗗搧淇℃伅")); - return; - } + if (goodsType == null || goodsId == null) { + out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭殑鍟嗗搧淇℃伅")); + return; + } - GoodsDetailVO goodsDetail = null; - ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), - acceptData.getVersion()); - paramsDTO.setBaseFanliRate(hongBaoManageService.getBaseFanliRate()); + GoodsDetailVO goodsDetail = null; + 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(goodsId); - if (goods == null) { - try { - goods = redisManager.getTaoBaoGoodsBrief(goodsId); - } catch (TaobaoGoodsDownException e) { - goods = null; - } - } - if (goods != null) { - goodsDetail = GoodsDetailVOFactory.convertTaoBao(goods, paramsDTO); - } - } else if (goodsType == Constant.SOURCE_TYPE_JD) { - JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId); - if (goods != null) { - goodsDetail = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO); - } - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId); - if (goods != null) { - goodsDetail = GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO); - } - } + if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { + TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goodsId); + if (goods == null) { + try { + goods = redisManager.getTaoBaoGoodsBrief(goodsId); + } catch (TaobaoGoodsDownException e) { + goods = null; + } + } + if (goods != null) { + goodsDetail = GoodsDetailVOFactory.convertTaoBao(goods, paramsDTO); + } + } else if (goodsType == Constant.SOURCE_TYPE_JD) { + JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(Long.parseLong(goodsId)); + if (goods != null) { + goodsDetail = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO); + } + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(Long.parseLong(goodsId)); + if (goods != null) { + goodsDetail = GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO); + } + } else if (goodsType == Constant.SOURCE_TYPE_VIP) { + VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId + ""); + if (goods == null) { + goodsDetail = GoodsDetailVOFactory.convertVIPGoods(goods, paramsDTO); + } + } else if (goodsType == Constant.SOURCE_TYPE_SUNING) { + String[] ids = SuningUtil.getGoodsIdDetail(goodsId); + SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(ids[1], ids[0]); + 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) { - out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); - return; - } + if (goodsDetail == null) { + out.print(JsonUtil.loadFalseResult(1, "璇ュ晢鍝佸凡涓嬫灦")); + return; + } - String template = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey()); - template = template.replace("[鍟嗗搧鏍囬]", goodsDetail.getTitle()).replace("[閿�閲廬", goodsDetail.getSalesCount()); - if (!StringUtil.isNullOrEmpty(goodsDetail.getDescription())) { - template = template.replace("[鎺ㄨ崘璇璢", goodsDetail.getDescription()); - } else { - template = template.replace("鎺ㄨ崘璇�:[鎺ㄨ崘璇璢", ""); - } + String template = configService.getValue(ConfigKeyEnum.quickShareGoodsText.getKey(), SystemInfoUtil.getSystem(acceptData)); + template = template.replace("[鍟嗗搧鏍囬]", goodsDetail.getTitle()).replace("[閿�閲廬", goodsDetail.getSalesCount()); + if (!StringUtil.isNullOrEmpty(goodsDetail.getDescription())) { + template = template.replace("[鎺ㄨ崘璇璢", goodsDetail.getDescription()); + } else { + template = template.replace("鎺ㄨ崘璇�:[鎺ㄨ崘璇璢", ""); + } - if (goodsDetail.isHasCoupon()) { - template = template.replace("[鍒搁潰棰漖", - String.format("婊�%s鍏冨噺%s鍏�", - MoneyBigDecimalUtil.getWithNoZera(goodsDetail.getCouponInfo().getStartFee()).toString(), - MoneyBigDecimalUtil.getWithNoZera(goodsDetail.getCouponInfo().getAmount()).toString())); - } else { - template = template.replace("浼樻儬鍒�:[鍒搁潰棰漖", ""); - } + if (goodsDetail.isHasCoupon()) { + template = template.replace("[鍒搁潰棰漖", + String.format("婊�%s鍏冨噺%s鍏�", + MoneyBigDecimalUtil.getWithNoZera(goodsDetail.getCouponInfo().getStartFee()).toString(), + MoneyBigDecimalUtil.getWithNoZera(goodsDetail.getCouponInfo().getAmount()).toString())); + } else { + template = template.replace("浼樻儬鍒�:[鍒搁潰棰漖", ""); + } - JSONObject data = new JSONObject(); - data.put("description", template); - out.print(JsonUtil.loadTrueResult(data)); - } + JSONObject data = new JSONObject(); + data.put("description", template); + out.print(JsonUtil.loadTrueResult(data)); + } } -- Gitblit v1.8.0