From a7454d8a6325566753358b37ffabfae2faa0ca7f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 28 四月 2021 19:46:49 +0800
Subject: [PATCH] 拼多多授权调整,支持小程序跳转
---
fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java | 1965 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 983 insertions(+), 982 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java b/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java
index 0e708d4..c669d15 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/wxmp/v1/GoodsController.java
@@ -1,982 +1,983 @@
-package com.yeshi.fanli.controller.wxmp.v1;
-
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.math.BigDecimal;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import com.yeshi.fanli.entity.SystemEnum;
-import com.yeshi.fanli.util.*;
-import org.json.simple.JSONArray;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.yeshi.utils.HttpUtil;
-import org.yeshi.utils.JsonUtil;
-import org.yeshi.utils.entity.FileUploadResult;
-import org.yeshi.utils.wx.WXUtil;
-import org.yeshi.utils.wx.WXXCXUtil;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.yeshi.fanli.dto.ConfigParamsDTO;
-import com.yeshi.fanli.dto.WXMPAcceptData;
-import com.yeshi.fanli.dto.jd.JDCategoryInfo;
-import com.yeshi.fanli.dto.jd.JDCouponInfo;
-import com.yeshi.fanli.dto.jd.JDFilter;
-import com.yeshi.fanli.dto.jd.JDSearchResult;
-import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
-import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
-import com.yeshi.fanli.dto.pdd.PDDPromotionUrl;
-import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
-import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
-import com.yeshi.fanli.entity.bus.user.ShamUser;
-import com.yeshi.fanli.entity.bus.user.UserInfo;
-import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
-import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
-import com.yeshi.fanli.entity.jd.JDGoods;
-import com.yeshi.fanli.entity.jd.JDGoodsClass;
-import com.yeshi.fanli.entity.system.ConfigKeyEnum;
-import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
-import com.yeshi.fanli.exception.user.UserInfoExtraException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
-import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
-import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
-import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service;
-import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
-import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
-import com.yeshi.fanli.service.inter.jd.JDGoodsClassService;
-import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
-import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
-import com.yeshi.fanli.service.inter.user.QrCodeService;
-import com.yeshi.fanli.service.inter.user.ShamUserService;
-import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
-import com.yeshi.fanli.service.inter.user.UserInfoService;
-import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
-import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
-import com.yeshi.fanli.tag.PageEntity;
-import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
-import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
-import com.yeshi.fanli.util.factory.CommonGoodsFactory;
-import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
-import com.yeshi.fanli.util.jd.JDApiUtil;
-import com.yeshi.fanli.util.jd.JDUtil;
-import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
-import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
-import com.yeshi.fanli.vo.goods.CouponInfoVO;
-import com.yeshi.fanli.vo.goods.GoodsDetailExtraVO;
-import com.yeshi.fanli.vo.goods.GoodsDetailVO;
-import com.yeshi.fanli.vo.goods.MoneyInfoVO;
-import com.yeshi.fanli.vo.goods.OtherInfo;
-import com.yeshi.fanli.vo.goods.RewardCouponVO;
-import com.yeshi.fanli.vo.goods.ShareVO;
-import com.yeshi.fanli.vo.goods.ShopInfoVO;
-import com.yeshi.fanli.vo.homemodule.BannerVO;
-
-import net.sf.json.JSONObject;
-
-@Controller("WXMPGoodsController")
-@RequestMapping("/wxmp/api/v1/goods")
-public class GoodsController {
-
- @Resource
- private ConfigService configService;
-
- @Resource
- private ShamUserService shamUserService;
-
- @Resource
- private CollectionGoodsV2Service collectionGoodsV2Service;
-
- @Resource
- private HongBaoManageService hongBaoManageService;
-
- @Resource
- private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
-
- @Resource
- private UserInfoExtraService userInfoExtraService;
-
- @Resource
- private ScanHistoryV2Service scanHistoryV2Service;
-
- @Resource
- private UserInfoService userInfoService;
-
- @Resource
- private JDGoodsCacheUtil jdGoodsCacheUtil;
-
- @Resource
- private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
-
- @Resource
- private JumpDetailV2Service jumpDetailV2Service;
-
- @Resource
- private JDGoodsClassService jdGoodsClassService;
-
- @Resource
- private UserVIPInfoService userVIPInfoService;
-
- @Resource
- private QrCodeService qrCodeService;
-
- @Resource
- private ShareGoodsService shareGoodsService;
-
- @Resource
- private UserShareGoodsRecordService userShareGoodsRecordService;
-
- @Resource
- private SwiperPictureService swiperPictureService;
-
- @Resource
- private HongBaoV2CountService hongBaoV2CountService;
-
- /**
- * 涓�绾у垎绫�
- *
- * @param acceptData
- * @param out
- */
- @RequestMapping(value = "getTopCategory", method = RequestMethod.POST)
- public void getTopCategory(WXMPAcceptData acceptData, Long uid, PrintWriter out) {
-
- SystemEnum system= SystemInfoUtil.getSystemByWXCXCAppId(acceptData.getAppId());
- JSONObject data = new JSONObject();
- data.put("list", configService.getValue(ConfigKeyEnum.jdWXMPClass.getKey(),system));
-
- String tips = null;
- if (uid == null || uid <= 0) {
- tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(),system);
- } else {
- long rebateOrder = hongBaoV2CountService.countRebateOrder(uid);
- long shareOrInviteOrder = hongBaoV2CountService.countShareOrInviteOrder(uid);
- if (rebateOrder + shareOrInviteOrder >= 3) {
- // 鐔熷鐗�
- } else if (rebateOrder <= 0 && shareOrInviteOrder <= 0) {
- // 鏂颁汉鐗�
- tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(),system);
- } else if (rebateOrder > 0 && shareOrInviteOrder <= 0) {
- // 鐪侀挶鐗�
- tips = configService.getValue(ConfigKeyEnum.tipGuideSaveMoney.getKey(),system);
- } else {
- // 璧氶挶鐗�
- tips = configService.getValue(ConfigKeyEnum.tipGuideShareInvite.getKey(),system);
- }
- }
-
- if (!StringUtil.isNullOrEmpty(tips)) {
- JSONObject tipData = JSONObject.fromObject(tips);
- data.put("tipData", tipData);
- }
-
- out.print(JsonUtil.loadTrueResult(data));
- }
-
- /**
- * 涓�绾у垎绫诲晢鍝�
- *
- * @param acceptData
- * @param out
- */
- @RequestMapping(value = "getCategoryRecommend", method = RequestMethod.POST)
- public void getCategoryRecommend(WXMPAcceptData acceptData, Long cid, Integer page, PrintWriter out) {
- if (cid == null) {
- out.print(JsonUtil.loadFalseResult("鍒嗙被ID涓虹┖"));
- return;
- }
-
- JSONObject data = new JSONObject();
- if (page == 1) {
- // 杞挱鍥�
- String platform = acceptData.getPlatform();
- int version = Integer.parseInt(acceptData.getVersion());
- List<BannerVO> picList = swiperPictureService.getByBannerCardAndVersion("index_top", platform,
- version,acceptData.getSystem());
- if (picList == null) {
- picList = new ArrayList<>();
- }
-
- for (BannerVO swiper : picList) {
- JSONObject params = null;
- if (StringUtil.isNullOrEmpty(swiper.getParams())) {
- params = JSONObject.fromObject(swiper.getParams());
- }
- swiper.setJumpDetail(JumpDetailUtil.getWXMPJumDetail(swiper.getJumpDetail()));
- }
- data.put("bannerList", JsonUtil.getApiCommonGson().toJson(picList));
- }
-
- JDFilter filterAPI = new JDFilter();
- filterAPI.setPageIndex(page);
- filterAPI.setPageSize(Constant.PAGE_SIZE);
- filterAPI.setIsCoupon(1); // 鏈夊埜
- filterAPI.setIsHot(1); // 鐖嗘
- filterAPI.setCid1(cid);
- JDSearchResult result = JDApiUtil.queryByKey(filterAPI);
-
- long count = 0;
- JSONArray array = new JSONArray();
- if (result != null) {
- PageEntity pageEntity = result.getPageEntity();
- if (pageEntity != null) {
- count = pageEntity.getTotalCount();
- }
-
- List<JDGoods> goodsList = result.getGoodsList();
- if (goodsList != null && goodsList.size() > 0) {
- Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
- .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
- acceptData.getVersion(),acceptData.getSystem());
- for (JDGoods goods : goodsList) {
- GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO);
- if (goodsDetailVO.isHasCoupon()) {
- array.add(gson.toJson(goodsDetailVO));
- }
- }
- }
- }
-
- data.put("count", count);
- data.put("list", array);
- out.print(JsonUtil.loadTrueResult(data));
- }
-
- /**
- * 鑾峰彇鍟嗗搧璇︽儏
- *
- * @param acceptData
- * @param goodsId
- * 鍟嗗搧id
- * @param uid
- * 閭�璇风爜
- * @param goodsType
- * 鍟嗗搧绫诲瀷
- * @param from
- * 椤甸潰鏉ユ簮
- * @param out
- */
- @RequestMapping(value = "getGoodsDetial")
- public void getGoodsDetial(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Long uid,
- PrintWriter out) {
- if (goodsType == null || goodsType < 2 || goodsType > 3) {
- out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�"));
- return;
- }
-
- /*--------- 浜笢鍟嗗搧 -------*/
- if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
- getDetialJD(acceptData, goodsId, uid, from, out);
- return;
- }
-
- /*-------- 鎷煎澶氬晢鍝� -------*/
- if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
- getDetialPDD(acceptData, goodsId, uid, from, out);
- return;
- }
- }
-
- /**
- * 浜笢鍟嗗搧璇︽儏
- *
- * @param acceptData
- * @param id
- * @param uid
- * @param from
- * @param out
- */
- private void getDetialJD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
- JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id); // 楂樼骇鎺ュ彛
- if (jdGoods == null) {
- jdGoods = JDUtil.getGoodsDetail(id); // 鐖彇缃戦〉
- // jdGoods = JDApiUtil.getGoodsDetail(id); // 鏅�氭帴鍙�
- }
-
- if (jdGoods == null) {
- out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧涓嶅瓨鍦�"));
- return;
- }
-
- List<String> imageList = jdGoods.getImageList();
- if (imageList == null) {
- imageList = new ArrayList<String>();
- imageList.add(jdGoods.getPicUrl());
- }
-
- // 淇濆瓨缂撳瓨
- jdGoodsCacheUtil.saveGoodsInfo(jdGoods);
-
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
- acceptData.getVersion(),acceptData.getSystem());
- paramsDTO.setMaxRewardRate(null);
- GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
- if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
- goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
- goodsDetail.getMoneyInfo()
- .setShareMoney("楼" + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP,acceptData.getSystem())));
- goodsDetail.getMoneyInfo().setRateInfo(goodsDetail.getMoneyInfo().getMaxRateInfo());
- goodsDetail.getMoneyInfo().setCompositionInfo(goodsDetail.getMoneyInfo().getMaxCompositionInfo());
- }
-
- goodsDetail.getMoneyInfo()
- .setRateInfoHelpUrl(configService.getValue(ConfigKeyEnum.goodsDetailFanliRateHelpUrl.getKey(),acceptData.getSystem()));
-
- // 闄勫姞淇℃伅
- OtherInfo otherInfo = new OtherInfo();
-
- // 浜笢plus杩斿埄
- String maxMoneyPlus = null;
- JDCategoryInfo categoryInfo = jdGoods.getCategoryInfo();
- if (categoryInfo != null && categoryInfo.getCid3() != null && jdGoods.getCommissionInfo() != null) {
- Long cid3 = categoryInfo.getCid3();
- JDGoodsClass threeClass = jdGoodsClassService.getThreeClassByCid(Integer.parseInt(cid3.toString()));
- if (threeClass != null && threeClass.getSelfComm() != null
- && threeClass.getSelfComm().compareTo(new BigDecimal(0)) > 0) {
- BigDecimal commissionShare = jdGoods.getCommissionInfo().getCommissionShare();
- // plus姣斾緥 灏忎簬姝e父姣斾緥
- if (commissionShare != null && commissionShare.compareTo(threeClass.getSelfComm()) > 0) {
- jdGoods.setCommissionPlus(threeClass.getSelfComm());
- // plus杩斿埄
- BigDecimal fanliMoneyPlus = JDUtil.getGoodsFanLiMoneyPlus(jdGoods,
- hongBaoManageService.getFanLiRate(acceptData.getSystem()));
- otherInfo.setFanliMoneyPlus("浜笢plus杩斅�" + fanliMoneyPlus);
- // 浣跨敤濂栧姳鍒告渶楂樿繑
-
- maxMoneyPlus = "锛堜含涓減lus杩斅�"
- + JDUtil.getGoodsFanLiMoneyPlus(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP,acceptData.getSystem())) + "锛�";
-
- }
- }
- }
-
- // 濂栧姳鍒歌繑鍒�
- RewardCouponVO rewardCoupon = new RewardCouponVO();
- rewardCoupon.setMaxMoneyPlus(maxMoneyPlus);
-
- rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
- rewardCoupon.setDesc("杩�");
- otherInfo.setRewardCoupon(rewardCoupon);
- goodsDetail.setOtherInfo(otherInfo);
-
- CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
- if (couponInfo != null) {
- // 鍒搁摼鎺ュ鐞�
- String materialId = "https://item.jd.com/" + id + ".html";
- String url = JDApiUtil.convertLinkWithSubUnionId(materialId, couponInfo.getLink(),
- JDApiUtil.POSITION_COUPON + "", null);
- couponInfo.setLink(url);
- }
-
- ShopInfoVO shopInfo = goodsDetail.getShopInfo();
- if (shopInfo != null) {
- if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
- || shopInfo.getScoreSeller() == null) {
- goodsDetail.setShopInfo(null);
- }
- }
-
- GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
- extraVO.setIsNative(false);
- // IOS鏄惁姝e湪涓婄嚎
- if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
- String version = acceptData.getVersion();
- extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version),acceptData.getSystem()));
- }
-
- Long inOrderCount30Days = jdGoods.getInOrderCount30Days();
- List<ShamUser> listShareUser = new ArrayList<ShamUser>();
-
- // 浜笢寮�鍚垎浜�
- String open = configService.getValue(ConfigKeyEnum.shareOpenJD.getKey(),acceptData.getSystem());
- if ("1".equals(open.trim())) {
- extraVO.setShareValid(true);
- MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
- if (moneyInfo != null) {
- String shareMoney = moneyInfo.getShareMoney().replaceAll("楼", "");
- if (Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
- listShareUser.addAll(shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5));
- }
- }
- }
-
- extraVO.setListShareUser(listShareUser);
-
- // 棰嗗埜浜哄垪琛�
- List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
- if (goodsDetail.isHasCoupon() && Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
- listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
- }
- extraVO.setListCouponUser(listCouponUser);
-
- if (uid != null) {
- // 鏄惁鍔犲叆鏀惰棌
- CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
- Constant.SOURCE_TYPE_JD);
- extraVO.setCollected(collectionGoods != null ? true : false);
- }
-
- // 鍥炬枃璇︽儏
- extraVO.setDetailUrl("https://in.m.jd.com/product/jieshao/video/" + id + ".html");
-
- // 鍟嗗搧閾炬帴
- String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
- Constant.systemCommonConfig.getShareGoodsPagePathJD(), "", id + "");
- try {
- extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
- } catch (Exception e) {
- extraVO.setH5Url(h5Url);
- }
-
- String helpLink = null;
- extraVO.setFanliValid(true);
-
- if (StringUtil.isNullOrEmpty(helpLink)) {
- helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(),acceptData.getSystem());
- }
-
- ShareVO shareInfoVO = new ShareVO();
- shareInfoVO.setHelpLink(helpLink);
- extraVO.setShare(shareInfoVO);
-
- // 鍒ゆ柇vip
- if (uid != null) {
- extraVO.setVip(userVIPInfoService.isVIP(uid));
- }
- JSONObject object = new JSONObject();
- object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
- object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
- out.print(JsonUtil.loadTrueResult(object.toString()));
-
- final JDGoods goods = jdGoods;
- ThreadUtil.run(new Runnable() {
- public void run() {
- // 娣诲姞娴忚璁板綍
- try {
- scanHistoryV2Service.addJDScanHistory(uid, acceptData.getDevice(), goods);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- /**
- * 鎷煎澶氬晢鍝佽鎯�
- *
- * @param acceptData
- * @param id
- * @param uid
- * @param from
- * @param out
- */
- private void getDetialPDD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
- PDDGoodsDetail pddGoods =null; //PinDuoDuoApiUtil.getGoodsDetail(id);
- if (pddGoods == null) {
- out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧涓嶅瓨鍦�"));
- return;
- }
-
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
- acceptData.getVersion(),acceptData.getSystem());
- paramsDTO.setMaxRewardRate(null);
- GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
- if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
- goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
- goodsDetail.getMoneyInfo().setShareMoney(
- "楼" + PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP,acceptData.getSystem())));
- }
-
- if (goodsDetail.getCouponInfo() != null) {
- List<CouponInfoVO> list = new ArrayList<>();
- list.add(goodsDetail.getCouponInfo());
- goodsDetail.setCouponInfoList(list);
- }
-
- // 濂栧姳鍒歌繑鍒�
- RewardCouponVO rewardCoupon = new RewardCouponVO();
-
- rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
- rewardCoupon.setDesc("杩�");
-
- OtherInfo otherInfo = new OtherInfo();
- otherInfo.setRewardCoupon(rewardCoupon);
- goodsDetail.setOtherInfo(otherInfo);
-
- CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
- PDDPromotionUrl convertUrl = null;
- if (couponInfo != null) {
- convertUrl = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_COUPON + "", null);
- if (convertUrl != null)
- couponInfo.setLink(convertUrl.getUrl());
- }
-
- ShopInfoVO shopInfo = goodsDetail.getShopInfo();
- if (shopInfo != null) {
- if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
- || shopInfo.getScoreSeller() == null) {
- goodsDetail.setShopInfo(null);
- }
- }
-
- GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
- extraVO.setDetailUrl("http://apph5.banliapp.com/apppage/goods_img_pdd.html?id=" + id);
-
- String salesTip = pddGoods.getSalesTip();
- if (!StringUtil.isNullOrEmpty(salesTip)) {
- int indexOf = salesTip.indexOf("+");
- if (indexOf > 0) {
- salesTip = salesTip.substring(0, indexOf);
- }
-
- int totalSales = 0;
- if (salesTip.contains("涓�")) {
- salesTip = salesTip.substring(0, salesTip.indexOf("涓�"));
- totalSales = (int) (Float.parseFloat(salesTip) * 10000);
- } else {
- totalSales = Integer.parseInt(salesTip);
- }
-
- List<ShamUser> listShareUser = new ArrayList<ShamUser>();
- MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
- if (moneyInfo != null) {
- String shareMoney = moneyInfo.getShareMoney().replaceAll("楼", "");
- if (totalSales >= 50000) {
- listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5);
- }
- }
- extraVO.setListShareUser(listShareUser);
-
- // 棰嗗埜浜哄垪琛�
- List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
- if (goodsDetail.isHasCoupon() && totalSales >= 50000) {
- listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
- }
- extraVO.setListCouponUser(listCouponUser);
- }
-
- if (uid != null) {
- // 鏄惁鍔犲叆鏀惰棌
- CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
- Constant.SOURCE_TYPE_PDD);
- extraVO.setCollected(collectionGoods != null ? true : false);
- }
-
- // 鍒嗕韩璺緞
- String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
- Constant.systemCommonConfig.getShareGoodsPagePathPDD(), "", id + "");
- try {
- extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
- } catch (Exception e) {
- extraVO.setH5Url(h5Url);
- }
-
- String helpLink = null;
- extraVO.setFanliValid(true);
- extraVO.setShareValid(true);
-
- if (StringUtil.isNullOrEmpty(helpLink)) {
- helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(),acceptData.getSystem());
- }
-
- ShareVO shareInfoVO = new ShareVO();
- shareInfoVO.setHelpLink(helpLink);
- extraVO.setShare(shareInfoVO);
-
- // 鍒ゆ柇vip
- if (uid != null) {
- extraVO.setVip(userVIPInfoService.isVIP(uid));
- }
-
- if (convertUrl != null) {
- extraVO.setCouponJumpLink(convertUrl.getUrl());
- extraVO.setNativeCouponJumpLink(PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl()));
- }
-
- JSONObject object = new JSONObject();
- object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
- object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
- out.print(JsonUtil.loadTrueResult(object.toString()));
-
- ThreadUtil.run(new Runnable() {
- public void run() {
- try {
- scanHistoryV2Service.addPDDScanHistory(uid, acceptData.getDevice(), pddGoods);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- /**
- * 鍟嗗搧璇︽儏鎺ㄨ崘锛堢寽浣犲枩娆� + 鎺ㄨ崘锛�
- *
- * @param acceptData
- * @param id
- * @param out
- */
- @RequestMapping(value = "getRecommendGoods", method = RequestMethod.POST)
- public void getRecommendGoods(WXMPAcceptData acceptData, long id, Integer goodsType, PrintWriter out) {
- if (goodsType == null || goodsType < 2 || goodsType > 3) {
- out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�"));
- return;
- }
-
- try {
- // 浜笢
- if (goodsType == Constant.SOURCE_TYPE_JD) {
- JSONObject data = new JSONObject();
- data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
-
- List<JDGoods> list = JDUtil.getRecommendGoodsById(id);
- if (list == null) {
- list = new ArrayList<JDGoods>();
- } else if (list.size() > 10) {
- list = list.subList(0, 10);
- }
-
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
- acceptData.getVersion(),acceptData.getSystem());
- List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
-
- for (JDGoods goods : list) {
- listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO));
- }
-
- // 鍙栧伓鏁颁釜鏁版嵁
- if (listDetailVO.size() % 2 != 0) {
- listDetailVO.remove(listDetailVO.size() - 1);
- }
-
- data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
- out.print(JsonUtil.loadTrueResult(data));
- return;
- }
-
- // 鎷煎澶�
- if (goodsType == Constant.SOURCE_TYPE_PDD) {
- JSONObject data = new JSONObject();
- data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
-
- List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
-
- List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id);
- if (goodsIdList != null && goodsIdList.size() > 0) {
- PDDSearchFilter pddfilter = new PDDSearchFilter();
- pddfilter.setPage(1);
- pddfilter.setPageSize(Constant.PAGE_SIZE);
- Long[] strings = new Long[goodsIdList.size()];
- pddfilter.setGoodsIdList(goodsIdList.toArray(strings));
-
- PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter);
- if (result != null) {
- List<PDDGoodsDetail> goodsList = result.getGoodsList();
- if (goodsList != null && goodsList.size() > 0) {
-
- if (goodsList.size() > 10) {
- goodsList = goodsList.subList(0, 10);
- }
-
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService
- .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(),acceptData.getSystem());
- for (PDDGoodsDetail goods : goodsList) {
- listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO));
- }
- }
- }
- }
-
- // 鍙栧伓鏁颁釜鏁版嵁
- if (listDetailVO.size() % 2 != 0) {
- listDetailVO.remove(listDetailVO.size() - 1);
- }
-
- data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
- out.print(JsonUtil.loadTrueResult(data));
- return;
- }
- } catch (Exception e) {
- LogHelper.errorDetailInfo(e);
- JSONObject data = new JSONObject();
- data.put("listQuality", new JSONArray());
- data.put("listGuess", new JSONArray());
- out.print(JsonUtil.loadTrueResult(data));
- }
- }
-
- /**
- * 鑾峰彇鍟嗗搧璇︽儏
- *
- * @param acceptData
- * @param goodsId
- * 鍟嗗搧id
- * @param uid
- * 閭�璇风爜
- * @param goodsType
- * 鍟嗗搧绫诲瀷
- * @param from
- * 椤甸潰鏉ユ簮
- * @param out
- */
- @RequestMapping(value = "getBuyLink", method = RequestMethod.POST)
- public void getBuyLink(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, String couponUrl,
- Long uid, String inviteCode, PrintWriter out) {
- if (goodsId == null || goodsType == null) {
- out.print(JsonUtil.loadFalseResult(1, "鍟嗗搧淇℃伅浼犻�掗敊璇�"));
- return;
- }
-
- // 鍒ゆ柇鏄嚜璐� 杩樻槸鏍规嵁閭�璇风爜
- boolean share = false;
-
- String subUnionId = "";
- if (uid != null) {
- 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;
- }
- subUnionId = uid.toString();
- } else if ((uid == null || uid < 1) && !StringUtil.isNullOrEmpty(inviteCode)) {
- try {
- UserInfo user = userInfoExtraService.getUserByInviteCode(inviteCode);
- if (user != null && user.getState() == UserInfo.STATE_NORMAL) {
- share = true;
- subUnionId = user.getId().toString();
- }
- } catch (UserInfoExtraException e) {
- e.printStackTrace();
- }
- }
-
- String jumpLink = null;
- if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 浜笢
- JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
- if (goods == null) {
- out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
- return;
- }
-
- String materialId = "https://item.jd.com/" + goodsId + ".html";
- if (StringUtil.isNullOrEmpty(couponUrl)) {
- JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods.getCouponInfoList(), goods.getPrice());
- if (couponInfo != null) {
- couponUrl = couponInfo.getLink();
- }
- }
-
- long position = JDApiUtil.POSITION_FANLI;
- if (share) {
- position = JDApiUtil.POSITION_SHARE;
- }
- String jdLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, position + "", subUnionId);
- try {
- jumpLink = "/pages/union/proxy/proxy?spreadUrl=" + URLEncoder.encode(jdLink, "UTF-8");
- } catch (Exception e) {
- LogHelper.errorDetailInfo(e);
- }
- } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 鎷煎澶�
- PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
- if (goods == null) {
- out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
- return;
- }
-
- String position = PinDuoDuoApiUtil.PID_FANLI;
- if (share) {
- position = PinDuoDuoApiUtil.PID_SHARE;
- }
- jumpLink = PinDuoDuoApiUtil.convertWXMP(goodsId, position, subUnionId);
- } else {
- out.print(JsonUtil.loadFalseResult(1, "鍙傛暟浼犻�掗敊璇�"));
- return;
- }
-
- if (StringUtil.isNullOrEmpty(jumpLink)) {
- out.print(JsonUtil.loadFalseResult(1, "鍒涘缓璐拱淇℃伅澶辫触"));
- return;
- }
-
- JSONObject data = new JSONObject();
- data.put("goodsType", goodsType);
- data.put("jumpLink", jumpLink);
- out.print(JsonUtil.loadTrueResult(data));
- }
-
- /**
- * 鍒嗕韩鍟嗗搧娴锋姤
- *
- * @param acceptData
- * @param goodsId
- * @param goodsType
- * @param from
- * @param type
- * @param uid
- * @param out
- */
- @RequestMapping(value = "sharePoster", method = RequestMethod.POST)
- public void sharePoster(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
- Long uid, PrintWriter out) {
- if (uid == null || uid < 1) {
- out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
- return;
- }
-
- if (goodsId == null || goodsType == null) {
- out.print(JsonUtil.loadFalseResult(1, "鍟嗗搧淇℃伅浼犻�掗敊璇�"));
- return;
- }
-
- if (type == null || type < 1 || type > 2) {
- out.print(JsonUtil.loadFalseResult(1, "鍒嗕韩绫诲瀷閿欒"));
- 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;
- }
-
- String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
- if (StringUtil.isNullOrEmpty(inviteCode)) {
- out.print(JsonUtil.loadFalseResult(1, "閭�璇风爜鏈縺娲�"));
- return;
- }
-
- if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 浜笢
- createPosterJD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
- } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 鎷煎澶�
- createPosterPDD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
- } else {
- out.print(JsonUtil.loadFalseResult(1, "鍙傛暟浼犻�掗敊璇�"));
- }
- }
-
- /**
- * 鍒涘缓浜笢鍒嗕韩娴锋姤
- */
- private void createPosterJD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
- UserInfo user, String inviteCode, PrintWriter out) {
- JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
- if (jdGoods == null) {
- out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
- return;
- }
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
- acceptData.getVersion(),acceptData.getSystem());
- GoodsDetailVO goods = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
-
- String scene = goodsType + "#" + goodsId + "#" + inviteCode;
- FileUploadResult uploadResult = null;
- if (type == 1) {
- String erCodeUrl = "https://wxmp.banliapp.com/goods?i=" + scene;
- uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
- } else {
- String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
- Constant.WXMP_APP_INFO.getAppSecret());
- InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
- uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
- }
-
- try {
- userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(jdGoods));
- } catch (UserShareGoodsRecordException e) {
- e.printStackTrace();
- }
- String posterLink = uploadResult.getUrl();
-
- JSONObject data = new JSONObject();
- data.put("posterLink", posterLink);
- 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(user.getId()));
- history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("楼", "")));
- 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.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
- history.setShareImg(posterLink);
- shareGoodsService.addShareGoodsHistory(history);
- }
- });
- }
-
- /**
- * 鍒涘缓鎷煎澶氬垎浜捣鎶�
- */
- private void createPosterPDD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
- UserInfo user, String inviteCode, PrintWriter out) {
- PDDGoodsDetail pddGoods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
- if (pddGoods == null) {
- out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
- return;
- }
- ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
- acceptData.getVersion(),acceptData.getSystem());
- GoodsDetailVO goods = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
-
- String scene = goodsType + "#" + goodsId + "#" + inviteCode;
- FileUploadResult uploadResult = null;
- if (type == 1) {
- String erCodeUrl = "https://wxmp.banliapp.com/goods?info=" + scene;
- uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
- } else {
- String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
- Constant.WXMP_APP_INFO.getAppSecret());
- InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
- uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
- }
-
- try {
- userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(pddGoods));
- } catch (UserShareGoodsRecordException e) {
- e.printStackTrace();
- }
- String posterLink = uploadResult.getUrl();
-
- JSONObject data = new JSONObject();
- data.put("posterLink", posterLink);
- 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(user.getId()));
- history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("楼", "")));
- 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.getPicUrl());
- history.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
- history.setShareImg(posterLink);
- shareGoodsService.addShareGoodsHistory(history);
- }
- });
- }
-}
+package com.yeshi.fanli.controller.wxmp.v1;
+
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.math.BigDecimal;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import com.yeshi.fanli.util.*;
+import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO;
+import org.json.simple.JSONArray;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.yeshi.utils.HttpUtil;
+import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.entity.FileUploadResult;
+import org.yeshi.utils.wx.WXUtil;
+import org.yeshi.utils.wx.WXXCXUtil;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.yeshi.fanli.dto.ConfigParamsDTO;
+import com.yeshi.fanli.dto.WXMPAcceptData;
+import com.yeshi.fanli.dto.jd.JDCategoryInfo;
+import com.yeshi.fanli.dto.jd.JDCouponInfo;
+import com.yeshi.fanli.dto.jd.JDFilter;
+import com.yeshi.fanli.dto.jd.JDSearchResult;
+import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
+import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
+import com.yeshi.fanli.dto.pdd.PDDPromotionUrl;
+import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
+import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
+import com.yeshi.fanli.entity.bus.user.ShamUser;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
+import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
+import com.yeshi.fanli.entity.jd.JDGoods;
+import com.yeshi.fanli.entity.jd.JDGoodsClass;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
+import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
+import com.yeshi.fanli.exception.user.UserInfoExtraException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
+import com.yeshi.fanli.service.inter.config.ConfigService;
+import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
+import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
+import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service;
+import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
+import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
+import com.yeshi.fanli.service.inter.jd.JDGoodsClassService;
+import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
+import com.yeshi.fanli.service.inter.user.QrCodeService;
+import com.yeshi.fanli.service.inter.user.ShamUserService;
+import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
+import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
+import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
+import com.yeshi.common.entity.PageEntity;
+import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
+import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
+import com.yeshi.fanli.util.factory.CommonGoodsFactory;
+import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
+import com.yeshi.fanli.util.jd.JDApiUtil;
+import com.yeshi.fanli.util.jd.JDUtil;
+import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
+import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
+import com.yeshi.fanli.vo.goods.CouponInfoVO;
+import com.yeshi.fanli.vo.goods.GoodsDetailExtraVO;
+import com.yeshi.fanli.vo.goods.GoodsDetailVO;
+import com.yeshi.fanli.vo.goods.MoneyInfoVO;
+import com.yeshi.fanli.vo.goods.OtherInfo;
+import com.yeshi.fanli.vo.goods.RewardCouponVO;
+import com.yeshi.fanli.vo.goods.ShareVO;
+import com.yeshi.fanli.vo.goods.ShopInfoVO;
+import com.yeshi.fanli.vo.homemodule.BannerVO;
+
+import net.sf.json.JSONObject;
+
+@Controller("WXMPGoodsController")
+@RequestMapping("/wxmp/api/v1/goods")
+public class GoodsController {
+
+ @Resource
+ private ConfigService configService;
+
+ @Resource
+ private ShamUserService shamUserService;
+
+ @Resource
+ private CollectionGoodsV2Service collectionGoodsV2Service;
+
+ @Resource
+ private HongBaoManageService hongBaoManageService;
+
+ @Resource
+ private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
+
+ @Resource
+ private UserInfoExtraService userInfoExtraService;
+
+ @Resource
+ private ScanHistoryV2Service scanHistoryV2Service;
+
+ @Resource
+ private UserInfoService userInfoService;
+
+ @Resource
+ private JDGoodsCacheUtil jdGoodsCacheUtil;
+
+ @Resource
+ private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
+
+ @Resource
+ private JumpDetailV2Service jumpDetailV2Service;
+
+ @Resource
+ private JDGoodsClassService jdGoodsClassService;
+
+ @Resource
+ private UserVIPInfoService userVIPInfoService;
+
+ @Resource
+ private QrCodeService qrCodeService;
+
+ @Resource
+ private ShareGoodsService shareGoodsService;
+
+ @Resource
+ private UserShareGoodsRecordService userShareGoodsRecordService;
+
+ @Resource
+ private SwiperPictureService swiperPictureService;
+
+ @Resource
+ private HongBaoV2CountService hongBaoV2CountService;
+
+ /**
+ * 涓�绾у垎绫�
+ *
+ * @param acceptData
+ * @param out
+ */
+ @RequestMapping(value = "getTopCategory", method = RequestMethod.POST)
+ public void getTopCategory(WXMPAcceptData acceptData, Long uid, PrintWriter out) {
+
+ SystemEnum system= SystemInfoUtil.getSystemByWXCXCAppId(acceptData.getAppId());
+ JSONObject data = new JSONObject();
+ data.put("list", configService.getValue(ConfigKeyEnum.jdWXMPClass.getKey(),system));
+
+ String tips = null;
+ if (uid == null || uid <= 0) {
+ tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(),system);
+ } else {
+ long rebateOrder = hongBaoV2CountService.countRebateOrder(uid);
+ long shareOrInviteOrder = hongBaoV2CountService.countShareOrInviteOrder(uid);
+ if (rebateOrder + shareOrInviteOrder >= 3) {
+ // 鐔熷鐗�
+ } else if (rebateOrder <= 0 && shareOrInviteOrder <= 0) {
+ // 鏂颁汉鐗�
+ tips = configService.getValue(ConfigKeyEnum.tipGuideNewUser.getKey(),system);
+ } else if (rebateOrder > 0 && shareOrInviteOrder <= 0) {
+ // 鐪侀挶鐗�
+ tips = configService.getValue(ConfigKeyEnum.tipGuideSaveMoney.getKey(),system);
+ } else {
+ // 璧氶挶鐗�
+ tips = configService.getValue(ConfigKeyEnum.tipGuideShareInvite.getKey(),system);
+ }
+ }
+
+ if (!StringUtil.isNullOrEmpty(tips)) {
+ JSONObject tipData = JSONObject.fromObject(tips);
+ data.put("tipData", tipData);
+ }
+
+ out.print(JsonUtil.loadTrueResult(data));
+ }
+
+ /**
+ * 涓�绾у垎绫诲晢鍝�
+ *
+ * @param acceptData
+ * @param out
+ */
+ @RequestMapping(value = "getCategoryRecommend", method = RequestMethod.POST)
+ public void getCategoryRecommend(WXMPAcceptData acceptData, Long cid, Integer page, PrintWriter out) {
+ if (cid == null) {
+ out.print(JsonUtil.loadFalseResult("鍒嗙被ID涓虹┖"));
+ return;
+ }
+
+ JSONObject data = new JSONObject();
+ if (page == 1) {
+ // 杞挱鍥�
+ String platform = acceptData.getPlatform();
+ int version = Integer.parseInt(acceptData.getVersion());
+ List<BannerVO> picList = swiperPictureService.getByBannerCardAndVersion("index_top", platform,
+ version,acceptData.getSystem());
+ if (picList == null) {
+ picList = new ArrayList<>();
+ }
+
+ for (BannerVO swiper : picList) {
+ JSONObject params = null;
+ if (StringUtil.isNullOrEmpty(swiper.getParams())) {
+ params = JSONObject.fromObject(swiper.getParams());
+ }
+ swiper.setJumpDetail(JumpDetailUtil.getWXMPJumDetail(swiper.getJumpDetail()));
+ }
+ data.put("bannerList", JsonUtil.getApiCommonGson().toJson(picList));
+ }
+
+ JDFilter filterAPI = new JDFilter();
+ filterAPI.setPageIndex(page);
+ filterAPI.setPageSize(Constant.PAGE_SIZE);
+ filterAPI.setIsCoupon(1); // 鏈夊埜
+ filterAPI.setIsHot(1); // 鐖嗘
+ filterAPI.setCid1(cid);
+ JDSearchResult result = JDApiUtil.queryByKey(filterAPI);
+
+ long count = 0;
+ JSONArray array = new JSONArray();
+ if (result != null) {
+ PageEntity pageEntity = result.getPageEntity();
+ if (pageEntity != null) {
+ count = pageEntity.getTotalCount();
+ }
+
+ List<JDGoods> goodsList = result.getGoodsList();
+ if (goodsList != null && goodsList.size() > 0) {
+ Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
+ .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion(),acceptData.getSystem());
+ for (JDGoods goods : goodsList) {
+ GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO);
+ if (goodsDetailVO.isHasCoupon()) {
+ array.add(gson.toJson(goodsDetailVO));
+ }
+ }
+ }
+ }
+
+ data.put("count", count);
+ data.put("list", array);
+ out.print(JsonUtil.loadTrueResult(data));
+ }
+
+ /**
+ * 鑾峰彇鍟嗗搧璇︽儏
+ *
+ * @param acceptData
+ * @param goodsId
+ * 鍟嗗搧id
+ * @param uid
+ * 閭�璇风爜
+ * @param goodsType
+ * 鍟嗗搧绫诲瀷
+ * @param from
+ * 椤甸潰鏉ユ簮
+ * @param out
+ */
+ @RequestMapping(value = "getGoodsDetial")
+ public void getGoodsDetial(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Long uid,
+ PrintWriter out) {
+ if (goodsType == null || goodsType < 2 || goodsType > 3) {
+ out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�"));
+ return;
+ }
+
+ /*--------- 浜笢鍟嗗搧 -------*/
+ if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
+ getDetialJD(acceptData, goodsId, uid, from, out);
+ return;
+ }
+
+ /*-------- 鎷煎澶氬晢鍝� -------*/
+ if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
+ getDetialPDD(acceptData, goodsId, uid, from, out);
+ return;
+ }
+ }
+
+ /**
+ * 浜笢鍟嗗搧璇︽儏
+ *
+ * @param acceptData
+ * @param id
+ * @param uid
+ * @param from
+ * @param out
+ */
+ private void getDetialJD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
+ JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id); // 楂樼骇鎺ュ彛
+ if (jdGoods == null) {
+ jdGoods = JDUtil.getGoodsDetail(id); // 鐖彇缃戦〉
+ // jdGoods = JDApiUtil.getGoodsDetail(id); // 鏅�氭帴鍙�
+ }
+
+ if (jdGoods == null) {
+ out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧涓嶅瓨鍦�"));
+ return;
+ }
+
+ List<String> imageList = jdGoods.getImageList();
+ if (imageList == null) {
+ imageList = new ArrayList<String>();
+ imageList.add(jdGoods.getPicUrl());
+ }
+
+ // 淇濆瓨缂撳瓨
+ jdGoodsCacheUtil.saveGoodsInfo(jdGoods);
+
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion(),acceptData.getSystem());
+ paramsDTO.setMaxRewardRate(null);
+ GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
+ if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
+ goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
+ goodsDetail.getMoneyInfo()
+ .setShareMoney("楼" + JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP,acceptData.getSystem())));
+ goodsDetail.getMoneyInfo().setRateInfo(goodsDetail.getMoneyInfo().getMaxRateInfo());
+ goodsDetail.getMoneyInfo().setCompositionInfo(goodsDetail.getMoneyInfo().getMaxCompositionInfo());
+ }
+
+ goodsDetail.getMoneyInfo()
+ .setRateInfoHelpUrl(configService.getValue(ConfigKeyEnum.goodsDetailFanliRateHelpUrl.getKey(),acceptData.getSystem()));
+
+ // 闄勫姞淇℃伅
+ OtherInfo otherInfo = new OtherInfo();
+
+ // 浜笢plus杩斿埄
+ String maxMoneyPlus = null;
+ JDCategoryInfo categoryInfo = jdGoods.getCategoryInfo();
+ if (categoryInfo != null && categoryInfo.getCid3() != null && jdGoods.getCommissionInfo() != null) {
+ Long cid3 = categoryInfo.getCid3();
+ JDGoodsClass threeClass = jdGoodsClassService.getThreeClassByCid(Integer.parseInt(cid3.toString()));
+ if (threeClass != null && threeClass.getSelfComm() != null
+ && threeClass.getSelfComm().compareTo(new BigDecimal(0)) > 0) {
+ BigDecimal commissionShare = jdGoods.getCommissionInfo().getCommissionShare();
+ // plus姣斾緥 灏忎簬姝e父姣斾緥
+ if (commissionShare != null && commissionShare.compareTo(threeClass.getSelfComm()) > 0) {
+ jdGoods.setCommissionPlus(threeClass.getSelfComm());
+ // plus杩斿埄
+ BigDecimal fanliMoneyPlus = JDUtil.getGoodsFanLiMoneyPlus(jdGoods,
+ hongBaoManageService.getFanLiRate(acceptData.getSystem()));
+ otherInfo.setFanliMoneyPlus("浜笢plus杩斅�" + fanliMoneyPlus);
+ // 浣跨敤濂栧姳鍒告渶楂樿繑
+
+ maxMoneyPlus = "锛堜含涓減lus杩斅�"
+ + JDUtil.getGoodsFanLiMoneyPlus(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP,acceptData.getSystem())) + "锛�";
+
+ }
+ }
+ }
+
+ // 濂栧姳鍒歌繑鍒�
+ RewardCouponVO rewardCoupon = new RewardCouponVO();
+ rewardCoupon.setMaxMoneyPlus(maxMoneyPlus);
+
+ rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
+ rewardCoupon.setDesc("杩�");
+ otherInfo.setRewardCoupon(rewardCoupon);
+ goodsDetail.setOtherInfo(otherInfo);
+
+ CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
+ if (couponInfo != null) {
+ // 鍒搁摼鎺ュ鐞�
+ String materialId = "https://item.jd.com/" + id + ".html";
+ String url = JDApiUtil.convertLinkWithSubUnionId(materialId, couponInfo.getLink(),
+ null,JDApiUtil.POSITION_COUPON + "", null);
+ couponInfo.setLink(url);
+ }
+
+ ShopInfoVO shopInfo = goodsDetail.getShopInfo();
+ if (shopInfo != null) {
+ if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
+ || shopInfo.getScoreSeller() == null) {
+ goodsDetail.setShopInfo(null);
+ }
+ }
+
+ GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
+ extraVO.setIsNative(false);
+ // IOS鏄惁姝e湪涓婄嚎
+ if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
+ String version = acceptData.getVersion();
+ extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version),acceptData.getSystem()));
+ }
+
+ Long inOrderCount30Days = jdGoods.getInOrderCount30Days();
+ List<ShamUser> listShareUser = new ArrayList<ShamUser>();
+
+ // 浜笢寮�鍚垎浜�
+ String open = configService.getValue(ConfigKeyEnum.shareOpenJD.getKey(),acceptData.getSystem());
+ if ("1".equals(open.trim())) {
+ extraVO.setShareValid(true);
+ MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
+ if (moneyInfo != null) {
+ String shareMoney = moneyInfo.getShareMoney().replaceAll("楼", "");
+ if (Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
+ listShareUser.addAll(shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5));
+ }
+ }
+ }
+
+ extraVO.setListShareUser(listShareUser);
+
+ // 棰嗗埜浜哄垪琛�
+ List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
+ if (goodsDetail.isHasCoupon() && Integer.parseInt(inOrderCount30Days.toString()) >= 1000) {
+ listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
+ }
+ extraVO.setListCouponUser(listCouponUser);
+
+ if (uid != null) {
+ // 鏄惁鍔犲叆鏀惰棌
+ CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
+ Constant.SOURCE_TYPE_JD);
+ extraVO.setCollected(collectionGoods != null ? true : false);
+ }
+
+ // 鍥炬枃璇︽儏
+ extraVO.setDetailUrl("https://in.m.jd.com/product/jieshao/video/" + id + ".html");
+
+ // 鍟嗗搧閾炬帴
+ String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
+ Constant.systemCommonConfig.getShareGoodsPagePathJD(), "", id + "");
+ try {
+ extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
+ } catch (Exception e) {
+ extraVO.setH5Url(h5Url);
+ }
+
+ String helpLink = null;
+ extraVO.setFanliValid(true);
+
+ if (StringUtil.isNullOrEmpty(helpLink)) {
+ helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(),acceptData.getSystem());
+ }
+
+ ShareVO shareInfoVO = new ShareVO();
+ shareInfoVO.setHelpLink(helpLink);
+ extraVO.setShare(shareInfoVO);
+
+ // 鍒ゆ柇vip
+ if (uid != null) {
+ extraVO.setVip(userVIPInfoService.isVIP(uid));
+ }
+ JSONObject object = new JSONObject();
+ object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
+ object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
+ out.print(JsonUtil.loadTrueResult(object.toString()));
+
+ final JDGoods goods = jdGoods;
+ ThreadUtil.run(new Runnable() {
+ public void run() {
+ // 娣诲姞娴忚璁板綍
+ try {
+ scanHistoryV2Service.addJDScanHistory(uid, acceptData.getDevice(), goods);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ /**
+ * 鎷煎澶氬晢鍝佽鎯�
+ *
+ * @param acceptData
+ * @param id
+ * @param uid
+ * @param from
+ * @param out
+ */
+ private void getDetialPDD(WXMPAcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
+ PDDGoodsDetail pddGoods =null; //PinDuoDuoApiUtil.getGoodsDetail(id);
+ if (pddGoods == null) {
+ out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧涓嶅瓨鍦�"));
+ return;
+ }
+
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion(),acceptData.getSystem());
+ paramsDTO.setMaxRewardRate(null);
+ GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
+ if (goodsDetail != null && goodsDetail.getMoneyInfo() != null && userVIPInfoService.isVIP(uid)) {
+ goodsDetail.getMoneyInfo().setFanliMoney(goodsDetail.getMoneyInfo().getMaxMoney());
+ goodsDetail.getMoneyInfo().setShareMoney(
+ "楼" + PinDuoDuoUtil.getGoodsFanLiMoney(pddGoods, hongBaoManageService.getShareRate(UserLevelEnum.superVIP,acceptData.getSystem())));
+ }
+
+ if (goodsDetail.getCouponInfo() != null) {
+ List<CouponInfoVO> list = new ArrayList<>();
+ list.add(goodsDetail.getCouponInfo());
+ goodsDetail.setCouponInfoList(list);
+ }
+
+ // 濂栧姳鍒歌繑鍒�
+ RewardCouponVO rewardCoupon = new RewardCouponVO();
+
+ rewardCoupon.setMaxMoney(goodsDetail.getMoneyInfo().getMaxMoney());
+ rewardCoupon.setDesc("杩�");
+
+ OtherInfo otherInfo = new OtherInfo();
+ otherInfo.setRewardCoupon(rewardCoupon);
+ goodsDetail.setOtherInfo(otherInfo);
+
+ CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
+ PDDConvertLinkResultVO convertUrl = null;
+ if (couponInfo != null) {
+ convertUrl = PinDuoDuoApiUtil.convert(pddGoods.getGoodsSign(), PinDuoDuoApiUtil.PID_COUPON + "", null,false);
+ if (convertUrl != null)
+ couponInfo.setLink(convertUrl.getUrl());
+ }
+
+ ShopInfoVO shopInfo = goodsDetail.getShopInfo();
+ if (shopInfo != null) {
+ if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
+ || shopInfo.getScoreSeller() == null) {
+ goodsDetail.setShopInfo(null);
+ }
+ }
+
+ GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
+ extraVO.setDetailUrl("http://apph5.banliapp.com/apppage/goods_img_pdd.html?id=" + id);
+
+ String salesTip = pddGoods.getSalesTip();
+ if (!StringUtil.isNullOrEmpty(salesTip)) {
+ int indexOf = salesTip.indexOf("+");
+ if (indexOf > 0) {
+ salesTip = salesTip.substring(0, indexOf);
+ }
+
+ int totalSales = 0;
+ if (salesTip.contains("涓�")) {
+ salesTip = salesTip.substring(0, salesTip.indexOf("涓�"));
+ totalSales = (int) (Float.parseFloat(salesTip) * 10000);
+ } else {
+ totalSales = Integer.parseInt(salesTip);
+ }
+
+ List<ShamUser> listShareUser = new ArrayList<ShamUser>();
+ MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
+ if (moneyInfo != null) {
+ String shareMoney = moneyInfo.getShareMoney().replaceAll("楼", "");
+ if (totalSales >= 50000) {
+ listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5);
+ }
+ }
+ extraVO.setListShareUser(listShareUser);
+
+ // 棰嗗埜浜哄垪琛�
+ List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
+ if (goodsDetail.isHasCoupon() && totalSales >= 50000) {
+ listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
+ }
+ extraVO.setListCouponUser(listCouponUser);
+ }
+
+ if (uid != null) {
+ // 鏄惁鍔犲叆鏀惰棌
+ CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
+ Constant.SOURCE_TYPE_PDD);
+ extraVO.setCollected(collectionGoods != null ? true : false);
+ }
+
+ // 鍒嗕韩璺緞
+ String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(acceptData.getSystem()),
+ Constant.systemCommonConfig.getShareGoodsPagePathPDD(), "", id + "");
+ try {
+ extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
+ } catch (Exception e) {
+ extraVO.setH5Url(h5Url);
+ }
+
+ String helpLink = null;
+ extraVO.setFanliValid(true);
+ extraVO.setShareValid(true);
+
+ if (StringUtil.isNullOrEmpty(helpLink)) {
+ helpLink = configService.getValue(ConfigKeyEnum.noRebateHelpLink.getKey(),acceptData.getSystem());
+ }
+
+ ShareVO shareInfoVO = new ShareVO();
+ shareInfoVO.setHelpLink(helpLink);
+ extraVO.setShare(shareInfoVO);
+
+ // 鍒ゆ柇vip
+ if (uid != null) {
+ extraVO.setVip(userVIPInfoService.isVIP(uid));
+ }
+
+ if (convertUrl != null) {
+ extraVO.setCouponJumpLink(convertUrl.getUrl());
+ extraVO.setNativeCouponJumpLink(PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl()));
+ }
+
+ JSONObject object = new JSONObject();
+ object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
+ object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
+ out.print(JsonUtil.loadTrueResult(object.toString()));
+
+ ThreadUtil.run(new Runnable() {
+ public void run() {
+ try {
+ scanHistoryV2Service.addPDDScanHistory(uid, acceptData.getDevice(), pddGoods);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ /**
+ * 鍟嗗搧璇︽儏鎺ㄨ崘锛堢寽浣犲枩娆� + 鎺ㄨ崘锛�
+ *
+ * @param acceptData
+ * @param id
+ * @param out
+ */
+ @RequestMapping(value = "getRecommendGoods", method = RequestMethod.POST)
+ public void getRecommendGoods(WXMPAcceptData acceptData, long id, Integer goodsType, PrintWriter out) {
+ if (goodsType == null || goodsType < 2 || goodsType > 3) {
+ out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�"));
+ return;
+ }
+
+ try {
+ // 浜笢
+ if (goodsType == Constant.SOURCE_TYPE_JD) {
+ JSONObject data = new JSONObject();
+ data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
+
+ List<JDGoods> list = JDUtil.getRecommendGoodsById(id);
+ if (list == null) {
+ list = new ArrayList<JDGoods>();
+ } else if (list.size() > 10) {
+ list = list.subList(0, 10);
+ }
+
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion(),acceptData.getSystem());
+ List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
+
+ for (JDGoods goods : list) {
+ listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO));
+ }
+
+ // 鍙栧伓鏁颁釜鏁版嵁
+ if (listDetailVO.size() % 2 != 0) {
+ listDetailVO.remove(listDetailVO.size() - 1);
+ }
+
+ data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
+ out.print(JsonUtil.loadTrueResult(data));
+ return;
+ }
+
+ // 鎷煎澶�
+ if (goodsType == Constant.SOURCE_TYPE_PDD) {
+ JSONObject data = new JSONObject();
+ data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
+
+ List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
+
+ List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id);
+ if (goodsIdList != null && goodsIdList.size() > 0) {
+ PDDSearchFilter pddfilter = new PDDSearchFilter();
+ pddfilter.setPage(1);
+ pddfilter.setPageSize(Constant.PAGE_SIZE);
+ Long[] strings = new Long[goodsIdList.size()];
+ pddfilter.setGoodsIdList(goodsIdList.toArray(strings));
+
+ PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter,Constant.PDD_SEARCH_CUSTOMER_PARAMS);
+ if (result != null) {
+ List<PDDGoodsDetail> goodsList = result.getGoodsList();
+ if (goodsList != null && goodsList.size() > 0) {
+
+ if (goodsList.size() > 10) {
+ goodsList = goodsList.subList(0, 10);
+ }
+
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService
+ .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion(),acceptData.getSystem());
+ for (PDDGoodsDetail goods : goodsList) {
+ listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO));
+ }
+ }
+ }
+ }
+
+ // 鍙栧伓鏁颁釜鏁版嵁
+ if (listDetailVO.size() % 2 != 0) {
+ listDetailVO.remove(listDetailVO.size() - 1);
+ }
+
+ data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
+ out.print(JsonUtil.loadTrueResult(data));
+ return;
+ }
+ } catch (Exception e) {
+ LogHelper.errorDetailInfo(e);
+ JSONObject data = new JSONObject();
+ data.put("listQuality", new JSONArray());
+ data.put("listGuess", new JSONArray());
+ out.print(JsonUtil.loadTrueResult(data));
+ }
+ }
+
+ /**
+ * 鑾峰彇鍟嗗搧璇︽儏
+ *
+ * @param acceptData
+ * @param goodsId
+ * 鍟嗗搧id
+ * @param uid
+ * 閭�璇风爜
+ * @param goodsType
+ * 鍟嗗搧绫诲瀷
+ * @param from
+ * 椤甸潰鏉ユ簮
+ * @param out
+ */
+ @RequestMapping(value = "getBuyLink", method = RequestMethod.POST)
+ public void getBuyLink(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, String couponUrl,
+ Long uid, String inviteCode, PrintWriter out) {
+ if (goodsId == null || goodsType == null) {
+ out.print(JsonUtil.loadFalseResult(1, "鍟嗗搧淇℃伅浼犻�掗敊璇�"));
+ return;
+ }
+
+ // 鍒ゆ柇鏄嚜璐� 杩樻槸鏍规嵁閭�璇风爜
+ boolean share = false;
+
+ String subUnionId = "";
+ if (uid != null) {
+ 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;
+ }
+ subUnionId = uid.toString();
+ } else if ((uid == null || uid < 1) && !StringUtil.isNullOrEmpty(inviteCode)) {
+ try {
+ UserInfo user = userInfoExtraService.getUserByInviteCode(inviteCode);
+ if (user != null && user.getState() == UserInfo.STATE_NORMAL) {
+ share = true;
+ subUnionId = user.getId().toString();
+ }
+ } catch (UserInfoExtraException e) {
+ e.printStackTrace();
+ }
+ }
+
+ String jumpLink = null;
+ if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 浜笢
+ JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
+ if (goods == null) {
+ out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
+ return;
+ }
+
+ String materialId = "https://item.jd.com/" + goodsId + ".html";
+ if (StringUtil.isNullOrEmpty(couponUrl)) {
+ JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods.getCouponInfoList(), goods.getPrice());
+ if (couponInfo != null) {
+ couponUrl = couponInfo.getLink();
+ }
+ }
+
+ long position = JDApiUtil.POSITION_FANLI;
+ if (share) {
+ position = JDApiUtil.POSITION_SHARE;
+ }
+ String jdLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null,position + "", subUnionId);
+ try {
+ jumpLink = "/pages/union/proxy/proxy?spreadUrl=" + URLEncoder.encode(jdLink, "UTF-8");
+ } catch (Exception e) {
+ LogHelper.errorDetailInfo(e);
+ }
+ } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 鎷煎澶�
+ PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
+ if (goods == null) {
+ out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
+ return;
+ }
+
+ String position = PinDuoDuoApiUtil.PID_FANLI;
+ if (share) {
+ position = PinDuoDuoApiUtil.PID_SHARE;
+ }
+ jumpLink = PinDuoDuoApiUtil.convertWXMP(goodsId, position, subUnionId);
+ } else {
+ out.print(JsonUtil.loadFalseResult(1, "鍙傛暟浼犻�掗敊璇�"));
+ return;
+ }
+
+ if (StringUtil.isNullOrEmpty(jumpLink)) {
+ out.print(JsonUtil.loadFalseResult(1, "鍒涘缓璐拱淇℃伅澶辫触"));
+ return;
+ }
+
+ JSONObject data = new JSONObject();
+ data.put("goodsType", goodsType);
+ data.put("jumpLink", jumpLink);
+ out.print(JsonUtil.loadTrueResult(data));
+ }
+
+ /**
+ * 鍒嗕韩鍟嗗搧娴锋姤
+ *
+ * @param acceptData
+ * @param goodsId
+ * @param goodsType
+ * @param from
+ * @param type
+ * @param uid
+ * @param out
+ */
+ @RequestMapping(value = "sharePoster", method = RequestMethod.POST)
+ public void sharePoster(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
+ Long uid, PrintWriter out) {
+ if (uid == null || uid < 1) {
+ out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+ return;
+ }
+
+ if (goodsId == null || goodsType == null) {
+ out.print(JsonUtil.loadFalseResult(1, "鍟嗗搧淇℃伅浼犻�掗敊璇�"));
+ return;
+ }
+
+ if (type == null || type < 1 || type > 2) {
+ out.print(JsonUtil.loadFalseResult(1, "鍒嗕韩绫诲瀷閿欒"));
+ 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;
+ }
+
+ String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
+ if (StringUtil.isNullOrEmpty(inviteCode)) {
+ out.print(JsonUtil.loadFalseResult(1, "閭�璇风爜鏈縺娲�"));
+ return;
+ }
+
+ if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) { // 浜笢
+ createPosterJD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
+ } else if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) { // 鎷煎澶�
+ createPosterPDD(acceptData, goodsId, goodsType, from, type, user, inviteCode, out);
+ } else {
+ out.print(JsonUtil.loadFalseResult(1, "鍙傛暟浼犻�掗敊璇�"));
+ }
+ }
+
+ /**
+ * 鍒涘缓浜笢鍒嗕韩娴锋姤
+ */
+ private void createPosterJD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
+ UserInfo user, String inviteCode, PrintWriter out) {
+ JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
+ if (jdGoods == null) {
+ out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
+ return;
+ }
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion(),acceptData.getSystem());
+ GoodsDetailVO goods = GoodsDetailVOFactory.convertJDGoods(jdGoods, paramsDTO);
+
+ String scene = goodsType + "#" + goodsId + "#" + inviteCode;
+ FileUploadResult uploadResult = null;
+ if (type == 1) {
+ String erCodeUrl = "https://wxmp.banliapp.com/goods?i=" + scene;
+ uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
+ } else {
+ String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
+ Constant.WXMP_APP_INFO.getAppSecret());
+ InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
+ uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
+ }
+
+ try {
+ userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(jdGoods));
+ } catch (UserShareGoodsRecordException e) {
+ e.printStackTrace();
+ }
+ String posterLink = uploadResult.getUrl();
+
+ JSONObject data = new JSONObject();
+ data.put("posterLink", posterLink);
+ 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(user.getId()));
+ history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("楼", "")));
+ 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.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
+ history.setShareImg(posterLink);
+ shareGoodsService.addShareGoodsHistory(history);
+ }
+ });
+ }
+
+ /**
+ * 鍒涘缓鎷煎澶氬垎浜捣鎶�
+ */
+ private void createPosterPDD(WXMPAcceptData acceptData, Long goodsId, Integer goodsType, String from, Integer type,
+ UserInfo user, String inviteCode, PrintWriter out) {
+ PDDGoodsDetail pddGoods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
+ if (pddGoods == null) {
+ out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧宸蹭笅鏋�"));
+ return;
+ }
+ ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion(),acceptData.getSystem());
+ GoodsDetailVO goods = GoodsDetailVOFactory.convertPDDGoods(pddGoods, paramsDTO);
+
+ String scene = goodsType + "#" + goodsId + "#" + inviteCode;
+ FileUploadResult uploadResult = null;
+ if (type == 1) {
+ String erCodeUrl = "https://wxmp.banliapp.com/goods?info=" + scene;
+ uploadResult = qrCodeService.drawGoodsPoster(erCodeUrl, user.getPortrait(), goods);
+ } else {
+ String acessToken = WXUtil.getAcessToken(Constant.WXMP_APP_INFO.getAppId(),
+ Constant.WXMP_APP_INFO.getAppSecret());
+ InputStream xcxCode = WXXCXUtil.getXCXCode(acessToken, "/pages/goods/goods", scene);
+ uploadResult = qrCodeService.drawGoodsPosterXCX(xcxCode, user, goods);
+ }
+
+ try {
+ userShareGoodsRecordService.saveShareRecord(user.getId(), CommonGoodsFactory.create(pddGoods));
+ } catch (UserShareGoodsRecordException e) {
+ e.printStackTrace();
+ }
+ String posterLink = uploadResult.getUrl();
+
+ JSONObject data = new JSONObject();
+ data.put("posterLink", posterLink);
+ 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(user.getId()));
+ history.setHongbao(new BigDecimal(goods.getMoneyInfo().getShareMoney().replace("楼", "")));
+ 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.getPicUrl());
+ history.setPictures(JsonUtil.getGson().toJson(goods.getImgList()));
+ history.setShareImg(posterLink);
+ shareGoodsService.addShareGoodsHistory(history);
+ }
+ });
+ }
+}
--
Gitblit v1.8.0