yujian
2019-09-10 65460a2dc7c69d8c0e031ec4c89e25d47e5173f2
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java
@@ -35,15 +35,17 @@
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.exception.ShareGoodsException;
import com.yeshi.fanli.exception.share.ShareGoodsException;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException;
import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException;
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.monitor.BusinessEmergent110Service;
import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.taobao.UserTLJBuyHistoryService;
@@ -113,6 +115,9 @@
   @Resource
   private TLJBuyGoodsService tljBuyGoodsService;
   @Resource
   private BusinessEmergent110Service businessEmergent110Service;
   @Override
   public void addShareGoodsHistory(UserShareGoodsHistory history) {
@@ -667,7 +672,8 @@
   }
   @Override
   public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String specialId, Long auctionId) throws ShareGoodsException {
   public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String specialId, Long auctionId, String pid)
         throws ShareGoodsException {
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
@@ -685,7 +691,10 @@
      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(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
      else
         app.setPid(pid);
      TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, app);
      if (goods == null) {
         throw new ShareGoodsException(1, "");
@@ -788,7 +797,8 @@
   }
   @Override
   public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId) throws ShareGoodsException {
   public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app)
         throws ShareGoodsException, TaoLiJinCreateException {
      if (uid == null || uid <= 0) {
         throw new ShareGoodsException(1, "用户ID不能为空");
      }
@@ -799,7 +809,7 @@
      boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId);
      if (!canBuy) {
         throw new ShareGoodsException(3, "同一商品每日只能领取三次");
         throw new ShareGoodsException(3, "立减红包已抢光,请稍后再试");
      }
      long currentTime = System.currentTimeMillis();
@@ -813,14 +823,24 @@
      }
      BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70));
      TaoKeAppInfo app = TaoBaoConstant.ownBuyApp;
      TaoLiJinDTO taoLiJinDTO = null;
      try {
         taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "自购立减", perface, 1, new Date(currentTime), sendEndTime,
               new Date(currentTime), sendEndTime, app);
         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, "生成推广链接失败");
      }
      if (taoLiJinDTO == null)
         throw new ShareGoodsException(5, "生成推广链接失败");