admin
2020-07-14 eec7e789a87863c25d92c10ad5dfc22ad80c448d
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java
@@ -11,6 +11,8 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import org.springframework.stereotype.Service;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
@@ -21,6 +23,7 @@
import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
import com.yeshi.fanli.dao.mybatis.UserShareGoodsHistoryMapper;
import com.yeshi.fanli.dto.taobao.DaTaoKeFilterResult;
import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -31,6 +34,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.entity.taobao.UserTLJBuyHistory;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.fanli.exception.share.ShareGoodsException;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
@@ -47,6 +51,7 @@
import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.taobao.UserTLJBuyHistoryService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserAccountService;
import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
@@ -59,789 +64,463 @@
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
@Service
public class ShareGoodsServiceImpl implements ShareGoodsService {
    @Resource
    private TBPidService tbPidService;
    @Resource
    private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper;
   @Resource
   private TBPidService tbPidService;
    @Resource
    private UserInfoService userInfoService;
   @Resource
   private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper;
    @Resource
    private RedisManager redisManager;
    @Resource
    private ConfigService configService;
   @Resource
   private UserInfoMapper userinfoMapper;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
   @Resource
   private RedisManager redisManager;
    @Resource
    private UserAccountService userAccountService;
   @Resource
   private ConfigService configService;
    @Resource
    private HongBaoManageService hongBaoManageService;
   @Resource
   private TaoBaoUnionConfigService taoBaoUnionConfigService;
    @Resource
    private UserTLJBuyHistoryService userTLJBuyHistoryService;
   @Resource
   private UserAccountService userAccountService;
    @Resource
    private TLJBuyGoodsService tljBuyGoodsService;
   @Resource
   private HongBaoManageService hongBaoManageService;
    @Resource
    private BusinessEmergent110Service businessEmergent110Service;
    @Resource
    private UserTaoLiJinNewbiesService userTaoLiJinNewbiesService;
   @Resource
   private UserTLJBuyHistoryService userTLJBuyHistoryService;
    @Resource
    private ConvertLinkManager convertLinkManager;
   @Resource
   private TLJBuyGoodsService tljBuyGoodsService;
    @Resource
    private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
   @Resource
   private BusinessEmergent110Service businessEmergent110Service;
    @Resource
    private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
   @Resource
   private UserTaoLiJinNewbiesService userTaoLiJinNewbiesService;
   @Resource
   private ConvertLinkManager convertLinkManager;
    @Override
    public void addShareGoodsHistory(UserShareGoodsHistory history) {
        UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper
                .selectByUidAndAuctionId(history.getUser().getId(), history.getGoodsId());
        if (userShareGoodsHistory != null && !StringUtil.isNullOrEmpty(history.getTkCode())) {
            UserShareGoodsHistory update = new UserShareGoodsHistory();
            update.setId(userShareGoodsHistory.getId());
            userShareGoodsHistory.setTkCode(history.getTkCode());
            userShareGoodsHistory.setCreateTime(new Date());
            userShareGoodsHistoryMapper.updateByPrimaryKeySelective(userShareGoodsHistory);
        } else
            userShareGoodsHistoryMapper.insertSelective(history);
    }
   @Override
   public void addShareGoodsHistory(UserShareGoodsHistory history) {
      UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper
            .selectByUidAndAuctionId(history.getUser().getId(), history.getGoodsId());
      if (userShareGoodsHistory != null && !StringUtil.isNullOrEmpty(history.getTkCode())) {
         UserShareGoodsHistory update = new UserShareGoodsHistory();
         update.setId(userShareGoodsHistory.getId());
         userShareGoodsHistory.setTkCode(history.getTkCode());
         userShareGoodsHistory.setCreateTime(new Date());
         userShareGoodsHistoryMapper.updateByPrimaryKeySelective(userShareGoodsHistory);
      } else
         userShareGoodsHistoryMapper.insertSelective(history);
   }
    @Override
    public UserShareGoodsHistory addShareGoodsHistory(Long uid, Long auctionId) throws ShareGoodsException {
        TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
        if (tbPid == null) {
            throw new ShareGoodsException(1, "获取PID失败");
        }
        String appId = tbPid.getPid().split("_")[2];
        String adzoneId = tbPid.getPid().split("_")[3];
        TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
   @Override
   public UserShareGoodsHistory addShareGoodsHistory(Long uid, Long auctionId) throws ShareGoodsException {
      TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
      if (tbPid == null) {
         throw new ShareGoodsException(1, "获取PID失败");
      }
      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());
        TaoBaoGoodsBrief goods = null;
        long startTime = System.currentTimeMillis();
        try {
            goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
        } catch (TaobaoGoodsDownException e) {
            throw new ShareGoodsException(3, "商品已下架");
        } finally {
            LogHelper.test(auctionId + "-获取商品详情耗时为:" + (System.currentTimeMillis() - startTime));
        }
        if (goods == null) {
            throw new ShareGoodsException(3, "商品已下架");
        }
      TaoKeAppInfo info = new TaoKeAppInfo();
      info.setAdzoneId(adzoneId);
      info.setAppKey(taoBaoUnionConfig.getAppKey());
      info.setAppSecret(taoBaoUnionConfig.getAppSecret());
      info.setPid(tbPid.getPid());
      TaoBaoGoodsBrief goods = null;
      long startTime = System.currentTimeMillis();
      try {
         goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info);
      } catch (TaobaoGoodsDownException e) {
         throw new ShareGoodsException(3, "商品已下架");
      } finally {
         LogHelper.test(auctionId + "-获取商品详情耗时为:" + (System.currentTimeMillis() - startTime));
      }
      if (goods == null) {
         throw new ShareGoodsException(3, "商品已下架");
      }
        // 没有获取到转过链的商品详情
        if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
            TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); // TaoBaoUtil.getTbLinkForShare(auctionId,
            // tbPid.getPid(),
            // taoBaoUnionConfig);
            if (taoBaoLink == null) {
                throw new ShareGoodsException(201, "转链失败");
            }
            goods.setCouponLink(taoBaoLink.getCouponLink());
            goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
        }
        return addShareGoodsHistory(uid, goods);
    }
      // 没有获取到转过链的商品详情
      if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
         TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); // TaoBaoUtil.getTbLinkForShare(auctionId,
                                                                        // tbPid.getPid(),
                                                                        // taoBaoUnionConfig);
         if (taoBaoLink == null) {
            throw new ShareGoodsException(201, "转链失败");
         }
         goods.setCouponLink(taoBaoLink.getCouponLink());
         goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
      }
      return addShareGoodsHistory(uid, goods);
   }
    @Override
    public UserShareGoodsHistory addShareGoodsHistory(Long uid, TaoBaoGoodsBrief goods) throws ShareGoodsException {
        if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && StringUtil.isNullOrEmpty(goods.getAuctionUrl())) {
            throw new ShareGoodsException(10, "转链失败");
        }
   @Override
   public UserShareGoodsHistory addShareGoodsHistory(Long uid, TaoBaoGoodsBrief goods) throws ShareGoodsException {
      if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && StringUtil.isNullOrEmpty(goods.getAuctionUrl())) {
         throw new ShareGoodsException(10, "转链失败");
      }
        SystemEnum system = userInfoService.getUserSystem(uid);
        BigDecimal rate = hongBaoManageService.getShareRate(system);
      BigDecimal rate = hongBaoManageService.getShareRate();
        // 创建淘口令
        TaoBaoLink tbLink = new TaoBaoLink(); // TaoBaoUtil.getTbLinkForShare(goods.getAuctionId(),
        // tbPid.getPid(),
        // config.get(0));
        tbLink.setAuctionId(goods.getAuctionId());
        tbLink.setClickUrl(goods.getAuctionUrl());
        tbLink.setCouponLink(goods.getCouponLink());
      // 创建淘口令
      TaoBaoLink tbLink = new TaoBaoLink(); // TaoBaoUtil.getTbLinkForShare(goods.getAuctionId(),
                                    // tbPid.getPid(),
                                    // config.get(0));
      tbLink.setAuctionId(goods.getAuctionId());
      tbLink.setClickUrl(goods.getAuctionUrl());
      tbLink.setCouponLink(goods.getCouponLink());
        if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
            if (!StringUtil.isNullOrEmpty(quanToken)) {
                tbLink.setTaoToken(quanToken);
            }
        } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) {
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
            if (!StringUtil.isNullOrEmpty(quanToken)) {
                tbLink.setTaoToken(quanToken);
            }
        }
      if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
         String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
         if (!StringUtil.isNullOrEmpty(quanToken)) {
            tbLink.setTaoToken(quanToken);
         }
      } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) {
         String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
         if (!StringUtil.isNullOrEmpty(quanToken)) {
            tbLink.setTaoToken(quanToken);
         }
      }
        UserShareGoodsHistory history = new UserShareGoodsHistory();
        history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
        history.setLink(tbLink.getClickUrl());
        history.setQuanLink(tbLink.getCouponLink());
        history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
      UserShareGoodsHistory history = new UserShareGoodsHistory();
      history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
      history.setLink(tbLink.getClickUrl());
      history.setQuanLink(tbLink.getCouponLink());
      history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
        history.setCreateTime(new Date());
        history.setGoodsId(goods.getAuctionId());
        history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
        history.setHongbao(TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate));
        List<String> imgList = goods.getImgList();
        if (imgList == null) {
            imgList = new ArrayList<>();
        }
        history.setPictures(JsonUtil.getGson().toJson(imgList));
        history.setUser(new UserInfo(uid));
        history.setPostPicture(goods.getPictUrl());
        // 生成二维码信息
        // 包含用户ID与商品ID
        // 新版商品分享
      history.setCreateTime(new Date());
      history.setGoodsId(goods.getAuctionId());
      history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
      history.setHongbao(TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate));
      List<String> imgList = goods.getImgList();
      if (imgList == null) {
         imgList = new ArrayList<>();
      }
      history.setPictures(JsonUtil.getGson().toJson(imgList));
      history.setUser(new UserInfo(uid));
      history.setPostPicture(goods.getPictUrl());
      // 生成二维码信息
      // 包含用户ID与商品ID
      // 新版商品分享
      String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(),
            Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
            goods.getAuctionId() + "");
        String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(system),
                Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
                goods.getAuctionId() + "");
      String shortLink = HttpUtil.getShortLink(url);
      if (!StringUtil.isNullOrEmpty(shortLink)) {
         url = shortLink;
      }
      String destPath = FileUtil.getCacheDir() + "/ercode_" + uid + "_" + goods.getAuctionId() + ".jpg";
      String shareImgPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + goods.getAuctionId() + ".png";
      InputStream erCodeInputStream = null;
        String shortLink = HttpUtil.getShortLink(url);
        if (!StringUtil.isNullOrEmpty(shortLink)) {
            url = shortLink;
        }
        String destPath = FileUtil.getCacheDir() + "/ercode_" + uid + "_" + goods.getAuctionId() + ".jpg";
        String shareImgPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + goods.getAuctionId() + ".png";
        InputStream erCodeInputStream = null;
      try {
         try {
            erCodeInputStream = QRCodeUtil.getInstance(500).encode(url);
         } catch (Exception e) {
            e.printStackTrace();
         }
        try {
            try {
                erCodeInputStream = QRCodeUtil.getInstance(500).encode(url);
            } catch (Exception e) {
                e.printStackTrace();
            }
         // if (!new File(destPath).exists()) {
         // throw new ShareGoodsException(4, "生成二维码失败");
         // }
         // 获取到用户的头像
         UserInfo user = userinfoMapper.selectAvailableByPrimaryKey(uid);
         InputStream portrait = null;
         if (!StringUtil.isNullOrEmpty(user.getPortrait())) {
            try {
               portrait = HttpUtil.downLoadImg(user.getPortrait());
            } catch (HttpException e) {
               String portraitUrl = userAccountService.repairPortrait(uid);
               if (StringUtil.isNullOrEmpty(portraitUrl))
                  throw new ShareGoodsException(11, "获取头像出错");
               else {
                  // 再次获取头像
                  try {
                     portrait = HttpUtil.downLoadImg(portraitUrl);
                  } catch (HttpException e1) {
                     throw new ShareGoodsException(11, "获取头像出错");
                  }
               }
            }
         }
            // if (!new File(destPath).exists()) {
            // throw new ShareGoodsException(4, "生成二维码失败");
            // }
            // 获取到用户的头像
            UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
            InputStream portrait = null;
            if (!StringUtil.isNullOrEmpty(user.getPortrait())) {
                try {
                    portrait = HttpUtil.downLoadImg(user.getPortrait());
                } catch (HttpException e) {
                    String portraitUrl = userAccountService.repairPortrait(uid);
                    if (StringUtil.isNullOrEmpty(portraitUrl))
                        throw new ShareGoodsException(11, "获取头像出错");
                    else {
                        // 再次获取头像
                        try {
                            portrait = HttpUtil.downLoadImg(portraitUrl);
                        } catch (HttpException e1) {
                            throw new ShareGoodsException(11, "获取头像出错");
                        }
                    }
                }
            }
         InputStream shareImgInputStream = null;
            InputStream shareImgInputStream = null;
         try {
            // 海草街的分享二维码不一样
            if (Constant.systemCommonConfig.getProjectChineseName().contains("海草街")) {
               try {
                  shareImgInputStream = ImageUtil.drawGoodsShareImgHCJ(new FileInputStream(new File(destPath)),
                        portrait, goods);
               } catch (Exception e) {
                  try {
                     LogHelper.errorDetailInfo(e);
                  } catch (Exception e1) {
                     e1.printStackTrace();
                  }
                  throw new ShareGoodsException(5, "分享图绘制失败");
               }
            } else {
               shareImgInputStream = ImageUtil.drawGoodsShareImg(erCodeInputStream, portrait, goods);
            }
         } catch (Exception e) {
            try {
               LogHelper.errorDetailInfo(e, "", "分享图无法找到");
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
            try {
                // 海草街的分享二维码不一样
                if (Constant.systemCommonConfig.getProjectChineseName().contains("海草街")) {
                    try {
                        shareImgInputStream = ImageUtil.drawGoodsShareImgHCJ(new FileInputStream(new File(destPath)),
                                portrait, goods);
                    } catch (Exception e) {
                        try {
                            LogHelper.errorDetailInfo(e);
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                        throw new ShareGoodsException(5, "分享图绘制失败");
                    }
                } else {
                    shareImgInputStream = ImageUtil.drawGoodsShareImg(erCodeInputStream, portrait, goods);
                }
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e, "", "分享图无法找到");
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
         try {
            if (shareImgInputStream != null && shareImgInputStream.available() <= 0) {
               throw new ShareGoodsException(5, "生成分享图失败");
            }
         } catch (IOException e) {
            throw new ShareGoodsException(5, "读取分享图失败");
         }
            try {
                if (shareImgInputStream != null && shareImgInputStream.available() <= 0) {
                    throw new ShareGoodsException(5, "生成分享图失败");
                }
            } catch (IOException e) {
                throw new ShareGoodsException(5, "读取分享图失败");
            }
         FileUploadResult shareImgResult = COSManager.getInstance().uploadInputStream(shareImgInputStream,
               FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + goods.getAuctionId() + "_"
                     + System.currentTimeMillis() + ".png");
            FileUploadResult shareImgResult = COSManager.getInstance().uploadInputStream(shareImgInputStream,
                    FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + goods.getAuctionId() + "_"
                            + System.currentTimeMillis() + ".png");
         if (shareImgResult == null || StringUtil.isNullOrEmpty(shareImgResult.getUrl())) {
            throw new ShareGoodsException(6, "分享图片保存失败");
         }
            if (shareImgResult == null || StringUtil.isNullOrEmpty(shareImgResult.getUrl())) {
                throw new ShareGoodsException(6, "分享图片保存失败");
            }
         history.setShareImg(shareImgResult.getUrl());
         history.setShareImgMD5(shareImgResult.getMd5());
            history.setShareImg(shareImgResult.getUrl());
            history.setShareImgMD5(shareImgResult.getMd5());
         // 查询之前是否存在,存在就替换掉
            // 查询之前是否存在,存在就替换掉
         UserShareGoodsHistory old = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, history.getGoodsId());
         if (old != null) {
            history.setId(old.getId());
            userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history);
            // 删除原来的图片
            COSManager.getInstance().deleteFile(old.getShareImg());
         } else {
            userShareGoodsHistoryMapper.insertSelective(history);
         }
         history.setLink(url);
         return history;
      } finally {
         if (new File(destPath).exists()) {
            new File(destPath).delete();
         }
         if (new File(shareImgPath).exists()) {
            new File(shareImgPath).delete();
         }
      }
   }
            UserShareGoodsHistory old = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, history.getGoodsId());
            if (old != null) {
                history.setId(old.getId());
                userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history);
                // 删除原来的图片
                COSManager.getInstance().deleteFile(old.getShareImg());
            } else {
                userShareGoodsHistoryMapper.insertSelective(history);
            }
            history.setLink(url);
            return history;
        } finally {
            if (new File(destPath).exists()) {
                new File(destPath).delete();
            }
            if (new File(shareImgPath).exists()) {
                new File(shareImgPath).delete();
            }
        }
    }
   @Override
   public UserShareGoodsHistory getShareGoodsHistoryDetail(Long uid, Long auctionId) throws ShareGoodsException {
      UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid,
            auctionId);
      if (userShareGoodsHistory == null)
         throw new ShareGoodsException(10, "分享不存在");
    @Override
    public UserShareGoodsHistory getShareGoodsHistoryDetail(Long uid, Long auctionId) throws ShareGoodsException {
        UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid,
                auctionId);
        if (userShareGoodsHistory == null)
            throw new ShareGoodsException(10, "分享不存在");
      // 淘口令不存在
      if (StringUtil.isNullOrEmpty(userShareGoodsHistory.getTkCode())) {
         TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
         if (tbPid == null)
            throw new ShareGoodsException(1, "获取PID失败");
        // 淘口令不存在
        if (StringUtil.isNullOrEmpty(userShareGoodsHistory.getTkCode())) {
            TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
            if (tbPid == null)
                throw new ShareGoodsException(1, "获取PID失败");
         List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
         // 创建淘口令
         TaoBaoLink tbLink = TaoBaoUtil.getTbLink(auctionId, tbPid.getPid(), config.get(0));
         if (tbLink == null) {
            TaoBaoGoodsBrief goods = null;
            try {
               goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
            } catch (TaobaoGoodsDownException e) {
               throw new ShareGoodsException(4, "商品已下架");
            }
            tbLink = TaoBaoUtil.getTbLinkWithCoupon(goods.getPictUrl(), goods.getTitle(),
                  goods.getCouponActivityId(), auctionId, tbPid.getPid());
            if (tbLink == null || StringUtil.isNullOrEmpty(tbLink.getTaoToken()))
               throw new ShareGoodsException(2, "获取淘口令失败,请稍后重试");
         }
         // 更新淘口令
            List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
            // 创建淘口令
            TaoBaoLink tbLink = TaoBaoUtil.getTbLink(auctionId, tbPid.getPid(), config.get(0));
            if (tbLink == null) {
                TaoBaoGoodsBrief goods = null;
                try {
                    goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
                } catch (TaobaoGoodsDownException e) {
                    throw new ShareGoodsException(4, "商品已下架");
                }
                tbLink = TaoBaoUtil.getTbLinkWithCoupon(goods.getPictUrl(), goods.getTitle(),
                        goods.getCouponActivityId(), auctionId, tbPid.getPid());
                if (tbLink == null || StringUtil.isNullOrEmpty(tbLink.getTaoToken()))
                    throw new ShareGoodsException(2, "获取淘口令失败,请稍后重试");
            }
            // 更新淘口令
         UserShareGoodsHistory history = new UserShareGoodsHistory();
         history.setId(userShareGoodsHistory.getId());
         history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
         history.setLink(tbLink.getClickUrl());
         history.setQuanLink(tbLink.getCouponLink());
         history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
         userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history);
            UserShareGoodsHistory history = new UserShareGoodsHistory();
            history.setId(userShareGoodsHistory.getId());
            history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
            history.setLink(tbLink.getClickUrl());
            history.setQuanLink(tbLink.getCouponLink());
            history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
            userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history);
         userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
         userShareGoodsHistory.setLink(tbLink.getClickUrl());
         userShareGoodsHistory.setQuanLink(tbLink.getCouponLink());
         userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
      }
            userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
            userShareGoodsHistory.setLink(tbLink.getClickUrl());
            userShareGoodsHistory.setQuanLink(tbLink.getCouponLink());
            userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken()));
        }
      return userShareGoodsHistory;
   }
        return userShareGoodsHistory;
    }
   @Override
   public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId) throws ShareGoodsException {
    @Override
    public String createTaoBaoToken(Long uid, TaoBaoGoodsBrief goods) {
        String quanToken = "";
        if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {// 通过立即推广方式获取淘口令成功
            quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(),
                    goods.getCouponLink());
        } else if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl())) {
            quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(),
                    goods.getAuctionUrl());
        }
        return quanToken;
    }
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
    @Override
    public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException {
      if (auctionId == null || auctionId <= 0) {
         throw new ShareGoodsException(2, "商品ID不能为空");
      }
      TaoKeAppInfo info = new TaoKeAppInfo();
      if (!StringUtil.isNullOrEmpty(relationId)) {
         String pid = TaoBaoConstant.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);
      } 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")) {
         TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
         if (taoBaoLink == null) {
            throw new ShareGoodsException(201, "商品转链失败");
         }
         goods.setCouponLink(taoBaoLink.getCouponLink());
         goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
      }
      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.setAuctionId(goods.getAuctionId());
      tbLink.setClickUrl(goods.getAuctionUrl());
      tbLink.setCouponLink(goods.getCouponLink());
      if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
         String quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
         if (!StringUtil.isNullOrEmpty(quanToken)) {
            tbLink.setTaoToken(quanToken);
         }
      } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) {
         String quanToken = convertLinkManager.createTaoBaoToken(uid,goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
         if (!StringUtil.isNullOrEmpty(quanToken)) {
            tbLink.setTaoToken(quanToken);
         }
      }
      tbLink.setGoods(goods);
      // 存储分享商品的信息,用于加快分享网页接口请求速度
      if (Constant.IS_OUTNET)
         redisManager.saveTaoBaoGoodsBriefTemp(goods);
      LogManager.getLogger(LogType.taobaoTrade)
            .info(String.format("淘宝商品分享\n UID:%s \n 商品ID:%s \n 券链接%s \n商品链接:%s \n 口令:%s ", uid, auctionId,
                  tbLink.getCouponLink(), tbLink.getClickUrl(), tbLink.getTaoToken()));
      return tbLink;
   }
   @Override
   public TaoBaoLink getTaoBaoLinkForBuy(Long uid, Long auctionId, int pidType) throws ShareGoodsException {
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
      if (auctionId == null || auctionId <= 0) {
         throw new ShareGoodsException(2, "商品ID不能为空");
      }
      TBPid tbPid = tbPidService.getTBPid(uid, pidType);
      if (tbPid == null) {
         throw new ShareGoodsException(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(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")) {
         TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
         if (taoBaoLink == null) {
            throw new ShareGoodsException(201, "商品转链失败");
         }
         goods.setCouponLink(taoBaoLink.getCouponLink());
         goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
      }
      // 创建淘口令
      TaoBaoLink tbLink = new TaoBaoLink();
      tbLink.setAuctionId(goods.getAuctionId());
      tbLink.setClickUrl(goods.getAuctionUrl());
      tbLink.setCouponLink(goods.getCouponLink());
      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(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
      app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
      app.setPid(TaoBaoConstant.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());
      if (!StringUtil.isNullOrEmpty(goods.getYsylClickUrl()))
         taoBaoLink.setCouponLink(goods.getYsylClickUrl());
      taoBaoLink.setGoods(goods);
      return taoBaoLink;
   }
   @Override
   public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) {
      return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId);
   }
   @Override
   public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId, String pid)
         throws ShareGoodsException {
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
      if (auctionId == null || auctionId <= 0) {
         throw new ShareGoodsException(2, "商品ID不能为空");
      }
      TaoKeAppInfo info = new TaoKeAppInfo();
      if (!StringUtil.isNullOrEmpty(relationId)) {
         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);
      } 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")) {
         TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
         if (taoBaoLink == null) {
            throw new ShareGoodsException(201, "商品转链失败");
         }
         goods.setCouponLink(taoBaoLink.getCouponLink());
         goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
      }
      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.setAuctionId(goods.getAuctionId());
      tbLink.setClickUrl(goods.getAuctionUrl());
      tbLink.setCouponLink(goods.getCouponLink());
      if (!StringUtil.isNullOrEmpty(goods.getYsylClickUrl()))
         tbLink.setCouponLink(goods.getYsylClickUrl());
      if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 通过立即推广方式获取淘口令成功
         String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink());
         if (!StringUtil.isNullOrEmpty(quanToken)) {
            tbLink.setTaoToken(quanToken);
         }
      } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) {
         String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl());
         if (!StringUtil.isNullOrEmpty(quanToken)) {
            tbLink.setTaoToken(quanToken);
         }
      }
      tbLink.setGoods(goods);
      // 存储分享商品的信息,用于加快分享网页接口请求速度
      if (Constant.IS_OUTNET)
         redisManager.saveTaoBaoGoodsBriefTemp(goods);
      return tbLink;
   }
   @Override
   public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String specialId, Long auctionId, String pid)
         throws ShareGoodsException {
      if (uid == null || uid <= 0)
         throw new ShareGoodsException(1, "用户ID不能为空");
      if (auctionId == null || auctionId <= 0)
         throw new ShareGoodsException(1, "商品ID不能为空");
      TaoBaoGoodsBrief goods = null;
      try {
         goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
      } catch (TaobaoGoodsDownException e) {
         throw new ShareGoodsException(1, "该商品已下架");
      }
      if (goods == null)
         throw new ShareGoodsException(1, "该商品已下架");
      String taoLiJinLink = null;
      try {
         goods.setAuctionId(auctionId);
         taoLiJinLink = userTaoLiJinNewbiesService.createTaoLiJinForBuy(goods, uid);
      } catch (UserTaoLiJinNewbiesException e1) {
         throw new ShareGoodsException(e1.getCode(), e1.getMsg());
      }
      TaoBaoLink taoBaoLink = new TaoBaoLink();
      taoBaoLink.setAuctionId(auctionId);
      taoBaoLink.setClickUrl(goods.getAuctionUrl());
      taoBaoLink.setCouponLink(taoLiJinLink);
      taoBaoLink.setGoods(goods);
      return taoBaoLink;
   }
   @Override
   public TaoBaoLink getTaoLiJinLinkForShare(Long uid, Long auctionId, String relationId) throws ShareGoodsException {
        if (uid == null || uid <= 0) {
            throw new ShareGoodsException(1, "用户ID不能为空");
        }
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
        if (auctionId == null || auctionId <= 0) {
            throw new ShareGoodsException(2, "商品ID不能为空");
        }
      if (auctionId == null || auctionId <= 0) {
         throw new ShareGoodsException(2, "商品ID不能为空");
      }
        if (StringUtil.isNullOrEmpty(pid)) {
            throw new ShareGoodsException(3, "无推广位");
        }
      TaoKeAppInfo info = new TaoKeAppInfo();
        String appId = pid.split("_")[2];
        String adzoneId = pid.split("_")[3];
        TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
      if (!StringUtil.isNullOrEmpty(relationId)) {
         String pid = TaoBaoConstant.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);
      } catch (TaobaoGoodsDownException e) {
         throw new ShareGoodsException(4, "商品已下架");
      } finally {
      }
      if (goods == null) {
         throw new ShareGoodsException(5, "获取商品详情失败");
      }
        TaoKeAppInfo info = new TaoKeAppInfo();
        info.setAdzoneId(adzoneId);
        info.setAppKey(taoBaoUnionConfig.getAppKey());
        info.setAppSecret(taoBaoUnionConfig.getAppSecret());
        info.setPid(pid);
        TaoBaoGoodsBrief goods = null;
        try {
            goods = TaoKeApiUtil.searchGoodsDetailForConvert(auctionId, info);
        } catch (TaobaoGoodsDownException e) {
            throw new ShareGoodsException(4, "商品已下架");
        } finally {
      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);
         if (taoBaoLink == null) {
            throw new ShareGoodsException(201, "商品转链失败");
         }
         goods.setCouponLink(taoBaoLink.getCouponLink());
         goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
      }
        }
        if (goods == null) {
            throw new ShareGoodsException(5, "获取商品详情失败");
        }
      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);
      }
        if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) {
            TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info);
            if (taoBaoLink == null) {
                throw new ShareGoodsException(201, "商品转链失败");
            }
            goods.setCouponLink(taoBaoLink.getCouponLink());
            goods.setAuctionUrl(taoBaoLink.getAuctionUrl());
        }
      // 创建淘口令
      TaoBaoLink tbLink = new TaoBaoLink();
      tbLink.setAuctionId(goods.getAuctionId());
      tbLink.setClickUrl(goods.getAuctionUrl());
      tbLink.setCouponLink(goods.getCouponLink());
      tbLink.setGoods(goods);
        // 创建淘口令
        TaoBaoLink tbLink = new TaoBaoLink();
        tbLink.setAuctionId(goods.getAuctionId());
        tbLink.setClickUrl(goods.getAuctionUrl());
        tbLink.setCouponLink(goods.getCouponLink());
        return tbLink;
    }
      // 存储分享商品的信息,用于加快分享网页接口请求速度
      if (Constant.IS_OUTNET)
         redisManager.saveTaoBaoGoodsBriefTemp(goods);
    @Override
    public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) {
        return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId);
    }
      return tbLink;
   }
    @Override
    public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app)
            throws ShareGoodsException, TaoLiJinCreateException {
        if (uid == null || uid <= 0) {
            throw new ShareGoodsException(1, "用户ID不能为空");
        }
   @Override
   public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app)
         throws ShareGoodsException, TaoLiJinCreateException {
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
        if (auctionId == null || auctionId <= 0) {
            throw new ShareGoodsException(2, "商品ID不能为空");
        }
      if (auctionId == null || auctionId <= 0) {
         throw new ShareGoodsException(2, "商品ID不能为空");
      }
        boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId);
        if (!canBuy) {
            throw new ShareGoodsException(3, "立减红包已抢光,请稍后再试");
        }
      boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId);
      if (!canBuy) {
         throw new ShareGoodsException(3, "立减红包已抢光,请稍后再试");
      }
        SystemEnum system = userInfoService.getUserSystem(uid);
      long currentTime = System.currentTimeMillis();
      Date sendEndTime = new Date(TimeUtil.convertToTimeTemp(
            TimeUtil.getGernalTime(currentTime + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd"));
      TaoBaoGoodsBrief goods = null;
      try {
         goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
      } catch (TaobaoGoodsDownException e) {
         throw new ShareGoodsException(4, "商品已下架");
      }
        long currentTime = System.currentTimeMillis();
        Date sendEndTime = new Date(TimeUtil.convertToTimeTemp(
                TimeUtil.getGernalTime(currentTime + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd"));
        TaoBaoGoodsBrief goods = null;
        try {
            goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
        } catch (TaobaoGoodsDownException e) {
            throw new ShareGoodsException(4, "商品已下架");
        }
      BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70));
      TaoLiJinDTO taoLiJinDTO = null;
      try {
         taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "自购立减", perface, 1,
               new Date(currentTime - 1000 * 60 * 10L), sendEndTime, new Date(currentTime - 1000 * 60 * 10L),
               sendEndTime, app);
      } catch (TaoLiJinCreateException e1) {
         if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {// 资金不足
            TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppKeyCache(app.getAppKey());
            businessEmergent110Service.tljNoMoney(config.getAccount());
         } else if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 商品不允许创建淘礼金
            tljBuyGoodsService.removeGoods(auctionId);
         }
         LogHelper.errorDetailInfo(e1, e1.getMessage(), null);
      } catch (TaoKeApiException e) {
         LogHelper.errorDetailInfo(e, e.getMessage(), null);
         throw new ShareGoodsException(5, "生成推广链接失败");
      }
        BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70), false);
        TaoLiJinDTO taoLiJinDTO = null;
        try {
            taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "自购立减", perface, 1,
                    new Date(currentTime - 1000 * 60 * 10L), sendEndTime, new Date(currentTime - 1000 * 60 * 10L),
                    sendEndTime, app);
        } catch (TaoLiJinCreateException e1) {
            if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {// 资金不足
                TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppKeyCache(app.getAppKey());
                businessEmergent110Service.tljNoMoney(config.getAccount(), system);
            } else if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 商品不允许创建淘礼金
                tljBuyGoodsService.removeGoods(auctionId);
            }
            LogHelper.errorDetailInfo(e1, e1.getMessage(), null);
        } catch (TaoKeApiException e) {
            LogHelper.errorDetailInfo(e, e.getMessage(), null);
            throw new ShareGoodsException(5, "生成推广链接失败");
        }
      if (taoLiJinDTO == null)
         throw new ShareGoodsException(5, "生成推广链接失败");
        if (taoLiJinDTO == null)
            throw new ShareGoodsException(5, "生成推广链接失败");
      // 减去剩余个数(随机减去8到10个)
      tljBuyGoodsService.subHongBaoLeftCount(auctionId, TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"),
            8 + (int) (3 * Math.random()));
        // 减去剩余个数(随机减去8到10个)
        tljBuyGoodsService.subHongBaoLeftCount(auctionId, TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"),
                8 + (int) (3 * Math.random()));
      // 插入记录
      try {
         userTLJBuyHistoryService.addHistory(new UserTLJBuyHistory(null, uid, auctionId,
               TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), taoLiJinDTO.getRightsId(), new Date()));
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
        // 插入记录
        try {
            userTLJBuyHistoryService.addHistory(new UserTLJBuyHistory(null, uid, auctionId,
                    TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), taoLiJinDTO.getRightsId(), new Date()));
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
      TaoBaoLink taoBaoLink = new TaoBaoLink();
      taoBaoLink.setAuctionId(auctionId);
      taoBaoLink.setClickUrl(goods.getAuctionUrl());
      taoBaoLink.setCouponLink(taoLiJinDTO.getSendUrl());
      taoBaoLink.setGoods(goods);
      return taoBaoLink;
   }
        TaoBaoLink taoBaoLink = new TaoBaoLink();
        taoBaoLink.setAuctionId(auctionId);
        taoBaoLink.setClickUrl(goods.getAuctionUrl());
        taoBaoLink.setCouponLink(taoLiJinDTO.getSendUrl());
        taoBaoLink.setGoods(goods);
        return taoBaoLink;
    }
}