From d99f45a1c358282ab0d4333232da25f03560778f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 29 五月 2020 18:49:31 +0800
Subject: [PATCH] 苏宁,唯品会接口修改

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java |  187 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 171 insertions(+), 16 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 7088861..55d3eea 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
@@ -27,6 +27,9 @@
 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;
@@ -82,6 +85,8 @@
 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;
@@ -205,7 +210,7 @@
 	 * @param out
 	 */
 	@RequestMapping(value = "createShareInfo")
-	public void createShareInfo(AcceptData acceptData, Long uid, Long goodsId, String source, Integer totalNum,
+	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涓嶈兘涓虹┖"));
@@ -228,32 +233,38 @@
 			return;
 		}
 
-		if (goodsId == null || goodsId <= 0) {
+		if (goodsId == null ) {
 			out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧ID涓嶈兘涓虹┖"));
 			return;
 		}
 
 		// 娣樺疂
 		if (goodsType == null || goodsType == Constant.SOURCE_TYPE_TAOBAO) {
-			createTaoBaoShare(acceptData, uid, goodsId, totalNum, source, needGoods, request, out);
+			createTaoBaoShare(acceptData, uid,Long.parseLong(goodsId), totalNum, source, needGoods, request, out);
 			return;
 		}
 
 		// 浜笢
 		if (goodsType == Constant.SOURCE_TYPE_JD) {
-			createJDShare(acceptData, uid, goodsId, source, needGoods, out);
+			createJDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out);
 			return;
 		}
 
 		// 鎷煎澶�
 		if (goodsType == Constant.SOURCE_TYPE_PDD) {
-			createPDDShare(acceptData, uid, goodsId, source, needGoods, out);
+			createPDDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out);
 			return;
 		}
 
 		// 鍞搧浼�
 		if (goodsType == Constant.SOURCE_TYPE_VIP) {
-			createPDDShare(acceptData, uid, goodsId, source, needGoods, out);
+			createVIPShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out);
+			return;
+		}
+
+		// 鑻忓畞
+		if (goodsType == Constant.SOURCE_TYPE_SUNING) {
+			createSuningShare(acceptData, uid, goodsId, source, needGoods, out);
 			return;
 		}
 
@@ -1048,13 +1059,17 @@
 	}
 
 	/**
-	 * 鎷煎澶氬垎浜�
-	 * 
+	 * 鍞搧浼氬垎浜�
+	 * @Title: createVIPShare
+	 * @Description: 
 	 * @param acceptData
 	 * @param uid
 	 * @param goodsId
 	 * @param source
-	 * @param out
+	 * @param needGoods
+	 * @param out 
+	 * void 杩斿洖绫诲瀷
+	 * @throws
 	 */
 	public void createVIPShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods,
 			PrintWriter out) {
@@ -1064,11 +1079,11 @@
 			return;
 		}
 
-		String jumpLink = VipShopApiUtil.convertLink(goodsId + "", VipShopUtil.getShareChanTag(uid));
+		VIPConvertResultDTO jumpLink = VipShopApiUtil.convertLink(goodsId + "", VipShopUtil.getShareChanTag(uid));
 
 		ShareInfoVO shareInfo = new ShareInfoVO();
-		shareInfo.setClickUrl(jumpLink);
-		shareInfo.setWxErCode(jumpLink);
+		shareInfo.setClickUrl(jumpLink.getUrl());
+		shareInfo.setWxErCode(jumpLink.getUrl());
 		shareInfo.setCommentTexts(new ArrayList<>());
 		shareInfo.setRule(configService.get(ConfigKeyEnum.shareRuleLinkVIP.getKey()));
 		shareInfo.setPictUrl(goods.getGoodsThumbUrl());
@@ -1081,7 +1096,7 @@
 		}
 
 		String template = shareGoodsTextTemplateService.getTextTemplateByVIP(uid);
-		String shareText = shareGoodsTextTemplateService.createContentVIP(template, goods, jumpLink);
+		String shareText = shareGoodsTextTemplateService.createContentVIP(template, goods, jumpLink.getUrl());
 		shareInfo.setShareText(shareText);
 
 		String descText = shareText.replace(goods.getGoodsName(), "").trim();
@@ -1132,7 +1147,7 @@
 
 		String quickCommentText = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
 		commentText = quickCommentText.replace("[鍘熶环]", goods.getMarketPrice());
-		commentText = commentText.replace("[閾炬帴]", jumpLink);
+		commentText = commentText.replace("[閾炬帴]", jumpLink.getUrl());
 
 		commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘");
 		commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", "");
@@ -1163,10 +1178,150 @@
 				history.setQuanLink(null);
 				history.setGoodsId(goodsId);
 				history.setPostPicture(goods.getGoodsThumbUrl());
-				history.setShareImg(jumpLink);
+				history.setShareImg(jumpLink.getUrl());
 				List<String> imgList = goods.getGoodsDetailPictures();
 				if (imgList == null) {
 					imgList = new ArrayList<>();
+				}
+				history.setPictures(JsonUtil.getGson().toJson(imgList));
+				shareGoodsService.addShareGoodsHistory(history);
+			}
+		});
+	}
+
+	/**
+	 * 鑻忓畞鏄撹喘鍒嗕韩
+	 * @Title: createSuningShare
+	 * @Description: 
+	 * @param acceptData
+	 * @param uid
+	 * @param goodsId
+	 * @param source
+	 * @param needGoods
+	 * @param out 
+	 * void 杩斿洖绫诲瀷
+	 * @throws
+	 */
+	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;
+		}
+
+		String couponLink = goods.getCouponInfo().getCouponUrl();
+
+		String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sts[0], sts[1]),
+				StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, uid + "");
+
+		ShareInfoVO shareInfo = new ShareInfoVO();
+		shareInfo.setClickUrl(jumpLink);
+		shareInfo.setWxErCode(jumpLink);
+		shareInfo.setCommentTexts(new ArrayList<>());
+		shareInfo.setRule(configService.get(ConfigKeyEnum.shareRuleLinkSuning.getKey()));
+		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 ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
+									hongBaoManageService.getShareRate(), Constant.MAX_REWARD_RATE,
+									hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
+		}
+
+		String template = shareGoodsTextTemplateService.getTextTemplateByVIP(uid);
+		String shareText = shareGoodsTextTemplateService.createContentSuning(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()));
+		JSONArray array = JSONArray.fromObject(imgs);
+
+		shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0));
+
+		// 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.goodsShareNotifySuning.getKey()));
+
+		// 娣诲姞鍒嗕韩璁板綍
+		BigDecimal shareRate = hongBaoManageService.getShareRate();
+		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 commentText = "";
+		String recommendText = "";
+		String qtemplate = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey());
+		recommendText = qtemplate.replace("[鍟嗗搧鏍囬]", goods.getCommodityInfo().getCommodityName());
+
+		recommendText = recommendText.replace("鎺ㄨ崘鐞嗙敱:[鎺ㄨ崘璇璢", "");
+
+		String quickCommentText = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
+		commentText = quickCommentText.replace("[鍘熶环]", goods.getCommodityInfo().getCommodityPrice());
+		commentText = commentText.replace("[閾炬帴]", jumpLink);
+
+		commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘");
+		commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", "");
+		recommendText = recommendText.replace("浼樻儬鍒�:[鍒搁潰棰漖鍏�", "");
+
+		shareInfo.setRecommendText(deleteBlankLine(recommendText));
+		shareInfo.setCommentText(deleteBlankLine(commentText));
+
+		// 璁剧疆璇勮鏂囨湰閫夐」
+		shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode,
+				SuningUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
+
+		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(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);
@@ -1543,7 +1698,7 @@
 
 		JSONArray array = new JSONArray();
 		JSONObject data = new JSONObject();
-		
+
 		boolean notBackSuVip = false;
 		if (!VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion()))
 			notBackSuVip = true;

--
Gitblit v1.8.0