yujian
2019-06-26 020d940ae4e16f55f69cef3dd4c8dc0b9764af07
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java
@@ -28,6 +28,7 @@
import org.springframework.stereotype.Component;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.yeshi.utils.BigDecimalUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.NumberUtil;
import org.yeshi.utils.entity.ProxyIP;
@@ -52,6 +53,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.goods.TaoBaoLinkService;
@@ -705,9 +707,9 @@
      tg.setShopTitle(tb.getShopTitle());
      tg.setState(tb.getState()); // 状态:2018-12-03
      if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) {
         tg.setCoupon(true);// 有券
         TaoBaoQuanInfo quanInfo = new TaoBaoQuanInfo();
         quanInfo.setCouponAmount(tb.getCouponAmount());
         String couponEffectiveEndTime = tb.getCouponEffectiveEndTime();
@@ -718,7 +720,7 @@
         quanInfo.setCouponLeftCount(tb.getCouponLeftCount());
         quanInfo.setCouponLink(
               TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), pid, tb.getAuctionId() + ""));
         quanInfo.setCouponPrice(tb.getZkPrice().subtract(tb.getTkCommFee()));
         quanInfo.setCouponPrice(MoneyBigDecimalUtil.sub(tg.getZkPrice(), tb.getCouponAmount()));
         quanInfo.setCouponStartFee(tb.getCouponStartFee());
         quanInfo.setCouponTotalCount(tb.getCouponTotalCount());
         tg.setTaoBaoQuanInfo(quanInfo);
@@ -761,15 +763,17 @@
      tg.setTaoBaoHongBaoInfo(hongBaoInfo);
      tg.setMoneyType(1);
      tg.setSalesType(1);
      // 测试使用
//      tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
//      tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
//      tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
//      List<ClientTextStyleVO> labels = new ArrayList<>();
//      labels.add(new ClientTextStyleVO("标签测试内容", "#FF0000"));
//      labels.add(new ClientTextStyleVO("标签测试内容", "#00FF00"));
//      tg.setLabels(labels);
      // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
//      if(Constant.IS_TEST)
//      {
//       List<ClientTextStyleVO> labels = new ArrayList<>();
//       labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
//       labels.add(new ClientTextStyleVO("标签内容", "#00FF00"));
//       tg.setLabels(labels);
//      }
      return tg;
   }
@@ -1013,14 +1017,16 @@
      }
      tg.setTaoBaoHongBaoInfo(hongBaoInfo);
      tg.setMoneyType(1);
      tg.setSalesType(1);
      // 测试使用
//      tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
//      tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
//      tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
//      List<ClientTextStyleVO> labels = new ArrayList<>();
//      labels.add(new ClientTextStyleVO("标签测试内容", "#FF0000"));
//      labels.add(new ClientTextStyleVO("标签测试内容", "#00FF00"));
//      tg.setLabels(labels);
      // tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
      // tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
      // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
      // List<ClientTextStyleVO> labels = new ArrayList<>();
      // labels.add(new ClientTextStyleVO("标签内容", "#F14242"));
      // labels.add(new ClientTextStyleVO("标签内容", "#000000"));
      // tg.setLabels(labels);
      return tg;
   }
@@ -1348,9 +1354,11 @@
    * @return
    */
   public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
      BigDecimal money = null;
      if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
            || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
         return MoneyBigDecimalUtil.mul(
         money = MoneyBigDecimalUtil.mul(
               MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
                     new BigDecimal("0.01")),
               MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
@@ -1362,16 +1370,17 @@
         if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
               && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
            BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
            return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
            money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
                  .mul(MoneyBigDecimalUtil.mul(finalPrice, goodsBrief.getTkRate()), new BigDecimal("0.01")),
                  MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
         } else {// 不能用券
            return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
            money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
                  MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
                  new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
         }
      }
      return BigDecimalUtil.getWithNoZera(money);
   }
   // }
@@ -1405,30 +1414,7 @@
    */
   public static BigDecimal getShareGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
      // 计算返利
      // 无券
      if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) || goodsBrief.getCouponInfo().contains("无")) {
         return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
               .setScale(2, BigDecimal.ROUND_DOWN);
      } else// 有券
      {
         List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
         BigDecimal startFee = list.get(0);
         BigDecimal couponAccount = list.get(1);
         if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
               && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
            BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
            return finalPrice.multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
                  .setScale(2, BigDecimal.ROUND_DOWN);
         } else {// 不能用券
            return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000))
                  .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
         }
      }
      return getGoodsHongBaoMoney(goodsBrief, rate);
   }
   /**
@@ -1716,6 +1702,38 @@
      return taoBaoGoods;
   }
   public static TaoBaoGoodsBrief convert(DaTaoKeDetailV2 detail) {
      TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
      taoBaoGoods.setAuctionId(detail.getGoodsId());
      taoBaoGoods.setBiz30day(detail.getMonthSales());
      taoBaoGoods.setCouponAmount(detail.getCouponPrice());
      taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", detail.getCouponConditions(),
            MoneyBigDecimalUtil.getWithNoZera(detail.getCouponPrice())));
      if (detail.getCouponTotalNum() != null && detail.getCouponReceiveNum() != null)
         taoBaoGoods.setCouponLeftCount(detail.getCouponTotalNum() - detail.getCouponReceiveNum());
      else
         taoBaoGoods.setCouponLeftCount(0);
      taoBaoGoods.setCouponStartFee(detail.getOriginalPrice());
      taoBaoGoods.setCouponTotalCount(detail.getCouponTotalNum());
      taoBaoGoods.setPictUrl(detail.getMainPic());
      taoBaoGoods.setPictUrlWhite(detail.getMainPic());
      if (taoBaoGoods.getPictUrl() != null && !taoBaoGoods.getPictUrl().startsWith("http"))
         taoBaoGoods.setPictUrl("https:" + taoBaoGoods.getPictUrl());
      if (taoBaoGoods.getPictUrlWhite() != null && !taoBaoGoods.getPictUrlWhite().startsWith("http"))
         taoBaoGoods.setPictUrlWhite("https:" + taoBaoGoods.getPictUrlWhite());
      taoBaoGoods.setSellerId(detail.getSellerId());
      taoBaoGoods.setShopTitle(detail.getShopName());
      taoBaoGoods.setTitle(detail.getDtitle());
      taoBaoGoods.setUserType(detail.getShopType());
      taoBaoGoods.setZkPrice(detail.getOriginalPrice());
      taoBaoGoods.setTkRate(detail.getCommissionRate());
      taoBaoGoods.setTkCommFee(new BigDecimal("0"));
      taoBaoGoods.setState(0);
      return taoBaoGoods;
   }
   /**
    * 获取淘宝联盟的授权链接
    *