| | |
| | | package com.yeshi.fanli.service.manger.goods; |
| | | |
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.entity.taobao.PidUser; |
| | | import com.yeshi.fanli.entity.taobao.TBPid; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoLink; |
| | |
| | | import com.yeshi.fanli.service.inter.redpack.UserTaoLiJinNewbiesService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; |
| | | import com.yeshi.fanli.service.inter.user.TBPidService; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.util.*; |
| | | import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | |
| | | @Resource |
| | | private TaoBaoCouponCacheService taoBaoCouponCacheService; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | |
| | | /** |
| | | * 获取淘宝购买链接 |
| | | * 只领券 |
| | | * |
| | | * @param uid |
| | | * @param auctionId |
| | | * @param specialId |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public TaoBaoLink getTaoBaoLinkForBuy(Long uid, Long auctionId, String specialId, String pid) throws TaoBaoConvertLinkException { |
| | | if (uid == null || uid <= 0) { |
| | | throw new TaoBaoConvertLinkException(1, "用户ID不能为空"); |
| | | } |
| | | |
| | | if (auctionId == null || auctionId <= 0) { |
| | | public TaoBaoLink getTaoBaoLinkForRecieveCoupon(SystemEnum system, String auctionId, String specialId, String pid) throws TaoBaoConvertLinkException { |
| | | if (StringUtil.isNullOrEmpty(auctionId)) { |
| | | throw new TaoBaoConvertLinkException(2, "商品ID不能为空"); |
| | | } |
| | | |
| | | TaoKeAppInfo app = new TaoKeAppInfo(); |
| | | app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); |
| | | app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); |
| | | app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT); |
| | | if (pid == null) |
| | | app.setPid(pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli)); |
| | | else |
| | | app.setPid(pid); |
| | | |
| | | TaoBaoLink taoBaoLink = new TaoBaoLink(); |
| | | taoBaoLink.setAuctionId(auctionId); |
| | |
| | | |
| | | String link = null; |
| | | try { |
| | | link = DaTaoKeApiUtil.convertLink(auctionId, app.getPid()); |
| | | link = DaTaoKeApiUtil.convertLink(auctionId, app.getPid(),false); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | |
| | | return taoBaoLink; |
| | | } |
| | | |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, app, specialId, null); |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCouponV2(auctionId, app, specialId, null); |
| | | if (goods == null) { |
| | | throw new TaoBaoConvertLinkException(1, ""); |
| | | } |
| | |
| | | goods.setCouponLink(taoBaoLink.getCouponLink()); |
| | | cacheCouponInfo(auctionId, taoBaoLink.getCouponLink(), app.getPid()); |
| | | return taoBaoLink; |
| | | } |
| | | |
| | | /** |
| | | * 获取淘宝购买链接 |
| | | * |
| | | * @param uid |
| | | * @param auctionId |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public TaoBaoLink getTaoBaoLinkForBuy(SystemEnum system, Long uid, String auctionId, String specialId, String pid) throws TaoBaoConvertLinkException { |
| | | if (uid == null || uid <= 0) { |
| | | throw new TaoBaoConvertLinkException(1, "用户ID不能为空"); |
| | | } |
| | | return getTaoBaoLinkForRecieveCoupon(system, auctionId, specialId, pid); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | private void cacheCouponInfo(Long auctionId, String link, String pid) { |
| | | private void cacheCouponInfo(String auctionId, String link, String pid) { |
| | | String activityId = TaoBaoUtil.getActivityIdFromCouponLink(link); |
| | | if (StringUtil.isNullOrEmpty(activityId)) |
| | | return; |
| | |
| | | return; |
| | | |
| | | try { |
| | | TaoBaoCouponCache cache = TaoBaoCouponCacheFactory.create(goods.getAuctionId(), goods.getCouponActivityId(), goods.getCouponAmount(), goods.getCouponStartFee(), new Date(TimeUtil.convertToTimeTemp(goods.getCouponEffectiveStartTime(), "yyyy-MM-dd")), new Date(TimeUtil.convertToTimeTemp(goods.getCouponEffectiveEndTime(), "yyyy-MM-dd")+1000*60*60*24L), pid, goods.getCouponLink()); |
| | | TaoBaoCouponCache cache = TaoBaoCouponCacheFactory.create(goods.getAuctionId(), goods.getCouponActivityId(), goods.getCouponAmount(), goods.getCouponStartFee(), new Date(TimeUtil.convertToTimeTemp(goods.getCouponEffectiveStartTime(), "yyyy-MM-dd")), new Date(TimeUtil.convertToTimeTemp(goods.getCouponEffectiveEndTime(), "yyyy-MM-dd") + 1000 * 60 * 60 * 24L), pid, goods.getCouponLink()); |
| | | if (cache != null) { |
| | | taoBaoCouponCacheService.save(cache); |
| | | } |
| | |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId, String pid) throws |
| | | public TaoBaoLink getTaoBaoLinkForShare(SystemEnum system, Long uid, String auctionId, String relationId, String pid) throws |
| | | TaoBaoConvertLinkException { |
| | | if (uid == null || uid <= 0) { |
| | | throw new TaoBaoConvertLinkException(1, "用户ID不能为空"); |
| | | } |
| | | |
| | | if (auctionId == null || auctionId <= 0) { |
| | | if (StringUtil.isNullOrEmpty(auctionId)) { |
| | | throw new TaoBaoConvertLinkException(2, "商品ID不能为空"); |
| | | } |
| | | |
| | |
| | | |
| | | if (!StringUtil.isNullOrEmpty(relationId)) { |
| | | if (StringUtil.isNullOrEmpty(pid)) |
| | | pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT; |
| | | pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share); |
| | | String appId = pid.split("_")[2]; |
| | | String adzoneId = pid.split("_")[3]; |
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); |
| | |
| | | |
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { |
| | | |
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info, null, relationId); |
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCouponV2(auctionId, info, null, relationId); |
| | | if (taoBaoLink == null) { |
| | | throw new TaoBaoConvertLinkException(201, "商品转链失败"); |
| | | } |
| | |
| | | DaTaoKeFilterResult result = daTaoKeGoodsDetailV2Service.filterTaoBaoGoods(goods); |
| | | if (result.getFilterType() == DaTaoKeFilterResult.FILTER_TYPE_COUPON |
| | | || result.getFilterType() == DaTaoKeFilterResult.FILTER_TYPE_PRICE_AND_COUPON) { |
| | | link = DaTaoKeApiUtil.convertLink(auctionId, info.getPid()); |
| | | link = DaTaoKeApiUtil.convertLink(auctionId, info.getPid(),true); |
| | | } else if (goods.getCouponAmount() != null && goods.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {// 有券 |
| | | link = DaTaoKeApiUtil.convertLink(auctionId, info.getPid()); |
| | | |
| | | link = DaTaoKeApiUtil.convertLink(auctionId, info.getPid(),true); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(link)) { |
| | |
| | | //保存券链接 |
| | | cacheCouponInfo(goods, info.getPid()); |
| | | } else { |
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info, null, relationId); |
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCouponV2(auctionId, info, null, relationId); |
| | | if (taoBaoLink == null) { |
| | | throw new TaoBaoConvertLinkException(201, "商品转链失败"); |
| | | } |
| | |
| | | |
| | | if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功 |
| | | String quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), |
| | | tbLink.getCouponLink()); |
| | | tbLink.getCouponLink(), false); |
| | | if (!StringUtil.isNullOrEmpty(quanToken)) { |
| | | tbLink.setTaoToken(quanToken); |
| | | } |
| | | } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) { |
| | | String quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), |
| | | tbLink.getClickUrl()); |
| | | tbLink.getClickUrl(), false); |
| | | if (!StringUtil.isNullOrEmpty(quanToken)) { |
| | | tbLink.setTaoToken(quanToken); |
| | | } |
| | |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, Long auctionId, String pid) throws TaoBaoConvertLinkException { |
| | | public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String auctionId, String pid) throws TaoBaoConvertLinkException { |
| | | if (uid == null || uid <= 0) |
| | | throw new TaoBaoConvertLinkException(1, "用户ID不能为空"); |
| | | |
| | | if (auctionId == null || auctionId <= 0) |
| | | if (StringUtil.isNullOrEmpty(auctionId)) |
| | | throw new TaoBaoConvertLinkException(1, "商品ID不能为空"); |
| | | |
| | | TaoBaoGoodsBrief goods = null; |
| | |
| | | * @param pid |
| | | * @return |
| | | */ |
| | | public TaoBaoLink getTaoLiJinLinkForShare(Long uid, Long auctionId, String relationId, String pid) throws |
| | | public TaoBaoLink getTaoLiJinLinkForShare(SystemEnum system, Long uid, String auctionId, String relationId, String pid) throws |
| | | TaoBaoConvertLinkException { |
| | | if (uid == null || uid <= 0) { |
| | | throw new TaoBaoConvertLinkException(1, "用户ID不能为空"); |
| | | } |
| | | |
| | | if (auctionId == null || auctionId <= 0) { |
| | | if (StringUtil.isNullOrEmpty(auctionId)) { |
| | | throw new TaoBaoConvertLinkException(2, "商品ID不能为空"); |
| | | } |
| | | |
| | |
| | | |
| | | if (!StringUtil.isNullOrEmpty(relationId)) { |
| | | if (StringUtil.isNullOrEmpty(pid)) |
| | | pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT; |
| | | pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share); |
| | | String appId = pid.split("_")[2]; |
| | | String adzoneId = pid.split("_")[3]; |
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); |
| | |
| | | if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { |
| | | TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService |
| | | .getConfigByAppIdCache(info.getPid().split("_")[2]); |
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info, null, relationId); |
| | | TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCouponV2(auctionId, info, null, relationId); |
| | | if (taoBaoLink == null) { |
| | | throw new TaoBaoConvertLinkException(201, "商品转链失败"); |
| | | } |