| | |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | |
| | | @Resource
|
| | | private UserShareGoodsRecordService userShareGoodsRecordService;
|
| | |
|
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | |
|
| | | @Override
|
| | | public void addShareGoodsHistory(UserShareGoodsHistory history) {
|
| | | UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper
|
| | |
| | | } else
|
| | | userShareGoodsHistoryMapper.insertSelective(history);
|
| | |
|
| | | |
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId) throws ShareGoodsException {
|
| | | public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId) throws ShareGoodsException {
|
| | |
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | |
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null) {
|
| | | throw new ShareGoodsException(3, "获取推广位失败");
|
| | | }
|
| | | String appId = tbPid.getPid().split("_")[2];
|
| | | String adzoneId = tbPid.getPid().split("_")[3];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | |
|
| | | TaoKeAppInfo info = new TaoKeAppInfo();
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(tbPid.getPid());
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | String pid = Constant.TAOBAO_RELATION_PID_DEFAULT;
|
| | | String appId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(pid);
|
| | | } else {
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null) {
|
| | | throw new ShareGoodsException(3, "获取推广位失败");
|
| | | }
|
| | | String appId = tbPid.getPid().split("_")[2];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | String adzoneId = tbPid.getPid().split("_")[3];
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(tbPid.getPid());
|
| | | }
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
|
| | |
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, tbPid.getPid(), taoBaoUnionConfig);
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService
|
| | | .getConfigByAppIdCache(info.getPid().split("_")[2]);
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, info.getPid(), taoBaoUnionConfig);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "商品转链失败");
|
| | | }
|
| | | goods.setCouponLink(taoBaoLink.getCouponLink());
|
| | | goods.setAuctionUrl(taoBaoLink.getClickUrl());
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl()))
|
| | | goods.setAuctionUrl(goods.getAuctionUrl() + "&relationId=" + relationId);
|
| | | if (!StringUtil.isNullOrEmpty(goods.getCouponLink()))
|
| | | goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId);
|
| | | }
|
| | |
|
| | | // 保存商品详情
|
| | |
|
| | | // 创建淘口令
|
| | | TaoBaoLink tbLink = new TaoBaoLink();
|
| | |
| | |
|
| | | tbLink.setGoods(goods);
|
| | |
|
| | | // 存储分享商品的信息,用于加快分享网页接口请求速度
|
| | | if (Constant.IS_OUTNET)
|
| | | redisManager.saveTaoBaoGoodsBriefTemp(goods);
|
| | |
|
| | | return tbLink;
|
| | | }
|
| | |
|
| | |
| | | if (tbPid == null) {
|
| | | throw new ShareGoodsException(3, "获取推广位失败");
|
| | | }
|
| | | String appId = tbPid.getPid().split("_")[2];
|
| | | String adzoneId = tbPid.getPid().split("_")[3];
|
| | | return getTaoBaoLink(uid, auctionId, tbPid.getPid());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException {
|
| | |
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (auctionId == null || auctionId <= 0) {
|
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(pid)) {
|
| | | throw new ShareGoodsException(3, "无推广位");
|
| | | }
|
| | |
|
| | | String appId = pid.split("_")[2];
|
| | | String adzoneId = pid.split("_")[3];
|
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | |
|
| | | TaoKeAppInfo info = new TaoKeAppInfo();
|
| | | info.setAdzoneId(adzoneId);
|
| | | info.setAppKey(taoBaoUnionConfig.getAppKey());
|
| | | info.setAppSecret(taoBaoUnionConfig.getAppSecret());
|
| | | info.setPid(tbPid.getPid());
|
| | | info.setPid(pid);
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetailForConvert(auctionId, info);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | throw new ShareGoodsException(4, "商品已下架");
|
| | | } finally {
|
| | |
|
| | | }
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(5, "获取商品详情失败");
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, tbPid.getPid(), taoBaoUnionConfig);
|
| | | TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, pid, taoBaoUnionConfig);
|
| | | if (taoBaoLink == null) {
|
| | | throw new ShareGoodsException(201, "商品转链失败");
|
| | | }
|
| | |
| | | return tbLink;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoLink getTaoBaoLinkForBuyWithSpecial(Long uid, String specialId, Long auctionId)
|
| | | throws ShareGoodsException {
|
| | | if (uid == null || uid <= 0) {
|
| | | throw new ShareGoodsException(1, "用户ID不能为空");
|
| | | }
|
| | |
|
| | | if (auctionId == null || auctionId <= 0) {
|
| | | throw new ShareGoodsException(2, "商品ID不能为空");
|
| | | }
|
| | |
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | | app.setAppKey(Constant.TAOBAO_AUTH_APPKEY);
|
| | | app.setAppSecret(Constant.TAOBAO_AUTH_APPSECRET);
|
| | | app.setPid(Constant.TAOBAO_SPECIAL_PID_DEFAULT);
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, app);
|
| | | if (goods == null) {
|
| | | throw new ShareGoodsException(1, "");
|
| | | }
|
| | |
|
| | | TaoBaoLink taoBaoLink = new TaoBaoLink();
|
| | | taoBaoLink.setAuctionId(auctionId);
|
| | | taoBaoLink.setClickUrl(goods.getAuctionUrl());
|
| | | taoBaoLink.setCouponLink(goods.getCouponLink());
|
| | | taoBaoLink.setGoods(goods);
|
| | |
|
| | | return taoBaoLink;
|
| | | }
|
| | |
|
| | | }
|