From 9429c1deecd200b1cf1dc6e4bec4829d0171969c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 15 五月 2019 09:08:12 +0800
Subject: [PATCH] 推荐增加大淘客相关推荐
---
fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java | 329 ++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 303 insertions(+), 26 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
index 18f825a..c2d92e7 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
@@ -9,43 +9,61 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
+import org.springframework.core.task.TaskExecutor;
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.HttpUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.taobao.TbImgUtil;
+import com.yeshi.fanli.dto.share.ShareInfoDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord;
+import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
+import com.yeshi.fanli.entity.dynamic.DynamicInfo;
+import com.yeshi.fanli.entity.dynamic.GoodsPicture;
+import com.yeshi.fanli.entity.system.BusinessSystem;
+import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoLink;
+import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.exception.ShareGoodsException;
import com.yeshi.fanli.exception.goods.ShareGoodsTextTemplateException;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
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.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.monitor.MonitorService;
+import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
+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.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.account.UserUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.MonitorFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
+import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -54,6 +72,9 @@
@RequestMapping("api/v1/share")
public class ShareController {
+ @Resource(name = "taskExecutor")
+ private TaskExecutor executor;
+
@Resource
private ShareGoodsService shareGoodsService;
@@ -89,6 +110,19 @@
@Resource
private ShareGoodsTextTemplateService shareGoodsTextTemplateService;
+
+ @Resource
+ private SystemClientParamsService systemClientParamsService;
+
+ @Resource
+ private DynamicInfoService dynamicInfoService;
+
+ @Resource
+ private UserInfoExtraService userInfoExtraService;
+
+ @Resource
+ private SpreadUserImgService spreadUserImgService;
+
// 鑾峰彇鍟嗗搧鍒嗕韩閾炬帴
@RequestMapping(value = "getGoodsShareUrl")
@@ -158,7 +192,7 @@
if (StringUtil.isNullOrEmpty(text))
text = configService.get("goods_share_text_nocoupon");
shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle()).replace("{鍟嗗搧鍘熶环}",
- taoBaoLink.getGoods().getZkPrice() + "");
+ MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
} else// 鏈夊埜
{
String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
@@ -166,9 +200,9 @@
text = configService.get("goods_share_text_coupon");
shareText = text.replace("{鏍囬}", taoBaoLink.getGoods().getTitle())
- .replace("{鍟嗗搧鍘熶环}", taoBaoLink.getGoods().getZkPrice() + "")
+ .replace("{鍟嗗搧鍘熶环}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
.replace("{浼樻儬鍒搁潰棰潁",
- BigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
+ MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
.replace("{浼樻儬鍒镐环}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + "");
}
shareText = shareText.replace("{搴楅摵绫诲瀷}", shopType)
@@ -189,36 +223,40 @@
// 娣诲姞鍒嗕韩璁板綍
BigDecimal rate = hongBaoManageService.getShareRate();
- UserShareGoodsHistory history = new UserShareGoodsHistory();
- history.setTkCode(taoBaoLink.getTaoToken());
- history.setLink(taoBaoLink.getClickUrl());
- history.setQuanLink(taoBaoLink.getCouponLink());
-
- history.setCreateTime(new Date());
- history.setGoodsId(taoBaoLink.getGoods().getAuctionId());
- history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
- history.setHongbao(TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate));
- List<String> imgList = taoBaoLink.getGoods().getImgList();
- if (imgList == null) {
- imgList = new ArrayList<>();
- }
- history.setPictures(JsonUtil.getGson().toJson(imgList));
- history.setUser(new UserInfo(uid));
- history.setPostPicture(taoBaoLink.getGoods().getPictUrl());
-
- data.put("shareMoney", "楼" + history.getHongbao().toString());
-
+ BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
+
+ data.put("shareMoney", "楼" + shareMoney.toString());
+ data.put("shareId", userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId));
out.print(JsonUtil.loadTrueResult(data));
// 寮傛鎿嶄綔
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(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 (UserShareGoodsRecordException e) {
+ out.print(JsonUtil.loadFalseResult(e.getMsg()));
+ e.printStackTrace();
} catch (ShareGoodsException e) {
try {
monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "鍒嗕韩鍑洪敊"));
@@ -441,7 +479,31 @@
}
}
- String content = shareGoodsTextTemplateService.createContentByTemplate(template, uid, goods, hasCoupon);
+ // 鏌ヨ鏄惁鏈夊垎浜�
+ UserShareGoodsHistory userShareHistory = shareGoodsService.getShareGoodsHistory(uid, goods.getAuctionId());
+ String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
+ Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
+ goods.getAuctionId() + "");
+ String shortLink = HttpUtil.getShortLink(url);
+ 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.createContentByTemplate(template, uid, goods, token, shortLink,
+ hasCoupon);
JSONObject data = new JSONObject();
data.put("content", content);
out.print(JsonUtil.loadTrueResult(data));
@@ -499,7 +561,8 @@
* @param out
*/
@RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST)
- public void resetShareTextTemplate(AcceptData acceptData, Long uid, Boolean hasCoupon, PrintWriter out) {
+ public void resetShareTextTemplate(AcceptData acceptData, Long uid, Long goodsId, Boolean hasCoupon,
+ PrintWriter out) {
if (uid == null) {
out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
return;
@@ -508,6 +571,11 @@
shareGoodsTextTemplateService.resetCouponTemplate(uid);
} else {
shareGoodsTextTemplateService.resetCommonTemplate(uid);
+ }
+
+ if (goodsId != null) {
+ preViewShareTextTemplate(acceptData, uid, null, goodsId, hasCoupon, out);
+ return;
}
out.print(JsonUtil.loadTrueResult(""));
@@ -557,4 +625,213 @@
out.print(JsonUtil.loadTrueResult(configService.get("share_goods_template_rules")));
}
+
+
+ /**
+ * 鏌ヨ椤堕儴鍒嗙被
+ * @param acceptData
+ * @param page
+ * @param cid
+ * @param out
+ */
+ @RequestMapping(value = "shareDynamic", method = RequestMethod.POST)
+ public void shareDynamic(AcceptData acceptData, String id, Long uid, PrintWriter out) {
+ try {
+
+ if (uid == null || uid <= 0) {
+ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+
+ if (StringUtil.isNullOrEmpty(id)) {
+ out.print(JsonUtil.loadFalseResult("鍙傛暟涓嶈兘涓虹┖"));
+ return;
+ }
+
+ DynamicInfo dynamicInfo = dynamicInfoService.getById(id);
+ if (dynamicInfo == null) {
+ out.print(JsonUtil.loadFalseResult("璇ュ姩鎬佷俊鎭凡涓嶅瓨鍦�"));
+ return;
+ }
+
+
+
+ JSONObject data = new JSONObject();
+ // 鍒嗙被id
+ long cid = dynamicInfo.getClassId();
+
+ if (cid == 1) { // 鐑攢鍗曞搧
+ // 鏂囧瓧鍐呭
+ String title ="";
+ List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
+ if (listTitle != null && listTitle.size() > 0) {
+ for (ClientTextStyleVO textStyleVO : listTitle) {
+ title += textStyleVO.getContent();
+ }
+ }
+ data.put("title", title);
+ data.put("content", "鎴戝湪杩斿埄鍒稿彂鐜颁簡涓�涓緢濂界殑鍟嗗搧锛屽揩鏉ョ湅鐪媬");
+
+ // 鍒嗕韩濂栭噾
+ ClientTextStyleVO desc = dynamicInfo.getDesc();
+ String content = desc.getContent();
+ int index = content.indexOf("楼");
+ data.put("shareMoney", new BigDecimal(content.substring(index + 1, content.length())));
+
+ // 鍟嗗搧鍒嗕韩閾炬帴
+ List<GoodsPicture> imgs2 = dynamicInfo.getImgs();
+ GoodsPicture goodsPicture = imgs2.get(0);
+ Long auctionId = goodsPicture.getGoods().getAuctionId();
+ String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
+ Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
+ auctionId + "");
+ String shortLink = HttpUtil.getShortLink(url);
+ if (!StringUtil.isNullOrEmpty(shortLink)) {
+ url = shortLink;
+ }
+ data.put("clickUrl", url);
+
+ // 鍒嗕韩鎻愮ず鍥剧墖
+ String imgs = configService.get("goods_share_notify_imgs");
+ JSONArray array = JSONArray.fromObject(imgs);
+ int p = (int) (array.size() * Math.random());
+ if (p < array.size()) {
+ data.put("notifyPicture", array.optString(p));
+ }
+
+
+ UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
+ String relationId = null;
+ if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
+ && extraInfo.getRelationValid() == true) {
+ relationId = extraInfo.getRelationId();
+ }
+ TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId);
+
+ data.put("pictUrl", TbImgUtil.getTBSizeImg(goodsPicture.getUrl(), 500));
+ // 娣樺疂鍙d护
+ data.put("token", taoBaoLink.getTaoToken());
+ // 甯姪閾炬帴
+ data.put("helpLink","http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
+ // 鍒嗕韩鎻愰啋
+ data.put("notifyDesc", configService.get("goods_share_notify"));
+ // 鍒嗕韩璁板綍id
+ data.put("shareId", userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId));
+
+ } else if (cid == 2) { // 鎺ㄨ崘濂借揣
+
+ String picUrl = null;
+ List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
+ List<GoodsPicture> listImgs = dynamicInfo.getImgs();
+ for (GoodsPicture goodsPicture: listImgs) {
+ TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
+ listGoods.add(goods);
+
+ if (picUrl == null) {
+ picUrl = goodsPicture.getUrl();
+ }
+ }
+
+ // 鏂囧瓧鍐呭
+ String title ="";
+ List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
+ if (listTitle != null && listTitle.size() > 0) {
+ for (ClientTextStyleVO textStyleVO : listTitle) {
+ title += textStyleVO.getContent();
+ }
+ }
+ data.put("title", title);
+ data.put("content", "鎴戝湪杩斿埄鍒稿彂鐜颁簡涓�涓緢濂界殑鍟嗗搧锛屽揩鏉ョ湅鐪媬");
+
+ // 鍒嗕韩濂栭噾
+ ClientTextStyleVO desc = dynamicInfo.getDesc();
+ String content = desc.getContent();
+ int index = content.indexOf("楼");
+ data.put("shareMoney", new BigDecimal(content.substring(index + 1 , content.length())));
+
+ // 鍒嗕韩閾炬帴
+ ShareInfoDTO shareInfo = userShareGoodsRecordService.saveShareRecord(uid,
+ ShareSourceTypeEnum.activity, title, listGoods);
+ data.put("shareId", shareInfo.getShareId());
+ data.put("clickUrl", shareInfo.getCodeUrl());
+ data.put("pictUrl", TbImgUtil.getTBSizeImg(picUrl, 500));
+ // 甯姪閾炬帴
+ data.put("helpLink","http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
+ // 鍒嗕韩鎻愰啋
+ data.put("notifyDesc", configService.get("goods_share_notify"));
+ // 鍒嗕韩鎻愰啋璇�
+ String notifyImgs = configService.get("goods_share_notify_imgs");
+ JSONArray array = JSONArray.fromObject(notifyImgs);
+ int p = (int) (array.size() * Math.random());
+ if (p < array.size()) {
+ data.put("notifyPicture", array.optString(p));
+ }
+
+ } else if (cid == 4) { // 閭�璇峰垎浜�
+
+ String inviteCode = null;
+ UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+ if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) {
+ inviteCode = userInfoExtra.getInviteCode();
+ } else {
+ out.print(JsonUtil.loadFalseResult(9001, "閭�璇风爜鏈縺娲�"));
+ return;
+ }
+
+ Integer showType = dynamicInfo.getShowType();
+ if (showType == 0) { // 鏃犲浘鍒嗕韩
+ String title ="";
+ List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
+ if (listTitle != null && listTitle.size() > 0) {
+ for (ClientTextStyleVO textStyleVO : listTitle) {
+ title += textStyleVO.getContent();
+ }
+ }
+ title = title.replace("銆愰個璇风爜銆�", inviteCode);
+ title = title.replace("銆愰個璇烽摼鎺ャ��", UserUtil.getInviteShortLink(uid));
+ data.put("title", title);
+
+ } else { // 鏈夊浘鍒嗕韩
+
+ // 閭�璇烽摼鎺�
+ String shortLink = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
+ + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
+ data.put("inviteLink", shortLink);
+ data.put("inviteCode", inviteCode);
+
+ // 閭�璇峰浘鐗�
+ List<GoodsPicture> imgs = dynamicInfo.getImgs();
+ String imgLink = spreadUserImgService.getInviteImg(uid, imgs.get(0).getUrl(), inviteCode);
+ data.put("imgLink", imgLink);
+
+ // 閭�璇疯鍒�
+ BusinessSystem system = new BusinessSystem();
+ system.setCreatetime(java.lang.System.currentTimeMillis());
+ system.setPlatform(1);
+ system.setId(4L);
+ String key = "inviteRules"; // key鍊�
+ SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, key);
+ String valueN = values.getValue();
+ String valueBr = valueN.replace("\n", "<br><br>");
+ data.put("inviteRules", valueBr);
+ }
+ }
+ out.print(JsonUtil.loadTrueResult(data));
+
+ // 鏇存柊鍒嗕韩娆℃暟
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ Integer shareCount = dynamicInfo.getShareCount();
+ dynamicInfo.setShareCount(shareCount + 1);
+ dynamicInfoService.updateShareCount(dynamicInfo);
+ }
+ });
+
+ } catch (Exception e) {
+ out.print(JsonUtil.loadFalseResult("鍒嗕韩璁板綍澶辫触"));
+ e.printStackTrace();
+ }
+ }
+
}
--
Gitblit v1.8.0