yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -158,8 +158,9 @@
    * 获取淘宝的分享链接
    * 
    * @param acceptData
    * @param uid        -用户ID
    * @param            auctionId-商品ID
    * @param uid
    *            -用户ID
    * @param auctionId-商品ID
    * @param out
    */
   @RequestMapping(value = "createShareInfo")
@@ -303,7 +304,7 @@
         // 分享id
         try {
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
                  Constant.SOURCE_TYPE_TAOBAO);
                  Constant.SOURCE_TYPE_TAOBAO, false);
            shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
            try {
@@ -367,12 +368,21 @@
   public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, HttpServletRequest request,
         PrintWriter out) {
      try {
         TaoBaoLink taoBaoLink = shareGoodsService.getTaoLiJinLinkForShare(uid, auctionId, relationId);
         TaoBaoGoodsBrief goods = null;
         try {
            goods = TaoKeApiUtil.searchGoodsDetail(auctionId, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                  TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
         } catch (TaobaoGoodsDownException e2) {
            e2.printStackTrace();
         }
         TaoBaoGoodsBrief goods = taoBaoLink.getGoods();
         if (goods == null) {
            out.print(JsonUtil.loadFalseResult("商品已下架"));
            return;
         }
         // 计算推广红包
         String warningRate = configTaoLiJinService.getValueByKey("warning_value");
         String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date());
         BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
         // 推广红包 不能小于1
@@ -406,53 +416,50 @@
         }
         shareInfo.setClickUrl(url);
         TaoBaoLink taoBaoLink = new TaoBaoLink();
         taoBaoLink.setCouponLink(taoLiJinLink);
         taoBaoLink.setClickUrl(taoLiJinLink);
         // 创建淘口令
         if (!StringUtil.isNullOrEmpty(taoLiJinLink)) {// 通过立即推广方式获取淘口令成功
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoLiJinLink);
            if (!StringUtil.isNullOrEmpty(quanToken)) {
               taoBaoLink.setTaoToken(quanToken);
            }
         } else if (!StringUtil.isNullOrEmpty(taoBaoLink.getClickUrl())) {
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                  taoBaoLink.getClickUrl());
            if (!StringUtil.isNullOrEmpty(quanToken)) {
               taoBaoLink.setTaoToken(quanToken);
            }
         }
         shareInfo.setToken(taoBaoLink.getTaoToken());
         shareInfo.setRule(configService.get("share_single_goods_rule"));
         shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
         shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(goods.getPictUrl(), 500));
         // 无券
         String shopType = taoBaoLink.getGoods().getUserType() == 0 ? "淘宝价" : "天猫价";
         String shopType = goods.getUserType() == 0 ? "淘宝价" : "天猫价";
         String shareText = "";
         if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
         if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
            String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
               text = configService.get("goods_share_text_nocoupon");
            shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle()).replace("{商品原价}",
                  MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "");
            shareText = text.replace("{标题}", goods.getTitle()).replace("{商品原价}",
                  MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()) + "");
         } else// 有券
         {
            String text = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
               text = configTaoLiJinService.getValueByKey("goods_share_text");
               text = configTaoLiJinService.getValueByKey("goods_share_text", new Date());
            shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                  .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                  .replace("{优惠券面额}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
            shareText = text.replace("{标题}", goods.getTitle())
                  .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()) + "")
                  .replace("{优惠券面额}", MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString())
                  .replace("{淘礼金面额}", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString())
                  .replace("{优惠券价}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + "");
                  .replace("{优惠券价}", TaoBaoUtil.getAfterUseCouplePrice(goods) + "");
         }
         shareText = shareText.replace("{店铺类型}", shopType)
               .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
               .replace("{领券短链}", shortLink).replace("{淘口令}", taoBaoLink.getTaoToken());
               .replace("{月销量}", TaoBaoUtil.getSaleCount(goods.getBiz30day())).replace("{领券短链}", shortLink)
               .replace("{淘口令}", taoBaoLink.getTaoToken());
         shareInfo.setShareText(shareText);
         String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
         String descText = shareText.replace(goods.getTitle(), "").trim();
         if (descText.startsWith("\\r\\n"))
            descText = descText.substring(0);
@@ -468,11 +475,11 @@
         // 添加分享记录
         BigDecimal rate = hongBaoManageService.getShareRate();
         BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
         BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate);
         shareInfo.setShareMoney("¥" + shareMoney.toString());
         try {
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId,
                  Constant.SOURCE_TYPE_TAOBAO);
                  Constant.SOURCE_TYPE_TAOBAO, true);
            shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
            try {
@@ -484,6 +491,7 @@
         out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(shareInfo)));
         final TaoBaoLink taobaoLink = taoBaoLink;
         final TaoBaoGoodsBrief finalGoods=goods;
         // 异步操作
         com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
            @Override
@@ -497,10 +505,10 @@
               history.setTkCode(taobaoLink.getTaoToken());
               history.setLink(taobaoLink.getClickUrl());
               history.setQuanLink(taobaoLink.getCouponLink());
               history.setGoodsId(taobaoLink.getGoods().getAuctionId());
               history.setPostPicture(taobaoLink.getGoods().getPictUrl());
               history.setGoodsId(finalGoods.getAuctionId());
               history.setPostPicture(finalGoods.getPictUrl());
               List<String> imgList = taobaoLink.getGoods().getImgList();
               List<String> imgList = finalGoods.getImgList();
               if (imgList == null) {
                  imgList = new ArrayList<>();
               }
@@ -509,14 +517,9 @@
            }
         });
         return;
      } catch (ShareGoodsException e) {
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + "auctionId:" + auctionId, "");
         // 分享出错报警
         try {
            monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
         } catch (Exception e1) {
         }
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
         out.print(JsonUtil.loadFalseResult("创建分享出错"));
         businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""));
      }
   }
@@ -539,9 +542,11 @@
         return;
      }
//      String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(),
//            Constant.systemCommonConfig.getShareGoodsPagePathJD(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
//            goodsId + "");
      // String url = String.format("http://%s%s?uid=%s&id=%s",
      // configService.getH5Host(),
      // Constant.systemCommonConfig.getShareGoodsPagePathJD(),
      // AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
      // goodsId + "");
      String couponUrl = null;
      JDCouponInfo couponInfo = jdGoods.getCouponInfo();
@@ -549,34 +554,34 @@
         couponUrl = couponInfo.getLink();
      }
      String materialId = "https://item.jd.com/" + goodsId + ".html";
      String jumpLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", uid+ "");
      String jumpLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", uid + "");
      ShareInfoVO shareInfo = new ShareInfoVO();
      shareInfo.setClickUrl(jumpLink);
      shareInfo.setRule(configService.get("share_rule_link_jd"));
      shareInfo.setPictUrl(jdGoods.getPicUrl());
      String shareText = "";
      boolean hasCoupon = false;
      // 分享模板
      ShareGoodsTextTemplate textTemplate = shareGoodsTextTemplateService.getShareGoodsTextTemplate(uid);
      if (couponInfo == null) { // 无券模板
         if (textTemplate != null)
         if (textTemplate != null)
            shareText = textTemplate.getShareJDTextTemplate();
         if (StringUtil.isNullOrEmpty(shareText))
            shareText = configService.get("goods_share_text_nocoupon_jd");
      } else { // 有券模板
         hasCoupon = true;
         if (textTemplate != null)
            shareText = textTemplate.getShareJDTextTemplateCoupon();
         if (StringUtil.isNullOrEmpty(shareText))
            shareText = configService.get("goods_share_text_coupon_jd");
      }
      shareText = shareGoodsTextTemplateService.createContentByTemplateJD(shareText, uid, jdGoods, jumpLink, hasCoupon);
      shareText = shareGoodsTextTemplateService.createContentByTemplateJD(shareText, uid, jdGoods, jumpLink,
            hasCoupon);
      shareInfo.setShareText(shareText);
      String descText = shareText.replace(jdGoods.getSkuName(), "").trim();
@@ -599,7 +604,7 @@
      shareInfo.setShareMoney("¥" + shareMoney.toString());
      try {
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
               Constant.SOURCE_TYPE_JD);
               Constant.SOURCE_TYPE_JD, false);
         shareInfo.setShareId(shareRecord.getRedisKey());
      } catch (Exception e) {
         try {
@@ -653,12 +658,14 @@
         return;
      }
//      String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(),
//            Constant.systemCommonConfig.getShareGoodsPagePathPDD(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
//            goodsId + "");
      // String url = String.format("http://%s%s?uid=%s&id=%s",
      // configService.getH5Host(),
      // Constant.systemCommonConfig.getShareGoodsPagePathPDD(),
      // AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
      // goodsId + "");
      String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", uid + "");
      ShareInfoVO shareInfo = new ShareInfoVO();
      shareInfo.setClickUrl(jumpLink);
      shareInfo.setRule(configService.get("share_rule_link_pdd"));
@@ -677,17 +684,17 @@
         hasCoupon = true;
         if (textTemplate != null)
            template = textTemplate.getSharePDDTextTemplateCoupon();
         if (StringUtil.isNullOrEmpty(template))
            template = configService.get("goods_share_text_coupon_pdd");
      }
      // 创建口令
      String token = PinDuoDuoApiUtil.createGenerate(goodsId);
      // 生成分享内容
      String shareText = shareGoodsTextTemplateService.createContentByTemplatePDD(template, uid, goods, jumpLink,
                  hasCoupon, token);
            hasCoupon, token);
      shareInfo.setShareText(shareText);
      String descText = shareText.replace(goods.getGoodsName(), "").trim();
@@ -712,7 +719,7 @@
      try {
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
               Constant.SOURCE_TYPE_PDD);
               Constant.SOURCE_TYPE_PDD, false);
         shareInfo.setShareId(shareRecord.getRedisKey());
      } catch (Exception e) {
         try {
@@ -946,7 +953,7 @@
         couponUrl = couponInfo.getLink();
      }
      String materialId = "https://item.jd.com/" + goodsId + ".html";
      String shortLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", uid+ "");
      String shortLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", uid + "");
      String content = shareGoodsTextTemplateService.createContentByTemplateJD(template, uid, goods, shortLink,
            hasCoupon);
@@ -998,12 +1005,14 @@
         }
      }
//      // 创建h5连接
//      String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
//            Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
//            goodsId + "");
//      String shortLink = HttpUtil.getShortLink(url);
      // // 创建h5连接
      // String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq",
      // configService.getH5Host(),
      // Constant.systemCommonConfig.getShareGoodsPagePath(),
      // AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
      // goodsId + "");
      // String shortLink = HttpUtil.getShortLink(url);
      String shortLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", uid + "");
      // 创建口令
@@ -1033,7 +1042,7 @@
            if (tljId != null) {
               template = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
               if (StringUtil.isNullOrEmpty(template))
                  template = configTaoLiJinService.getValueByKey("goods_share_text");
                  template = configTaoLiJinService.getValueByKey("goods_share_text", new Date());
            } else {
               template = shareGoodsTextTemplateService.geteCouponTemplate(uid);
               if (StringUtil.isNullOrEmpty(template))
@@ -1126,7 +1135,8 @@
      if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
         if (tljId != null) {
            out.print(JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules")));
            out.print(
                  JsonUtil.loadTrueResult(configTaoLiJinService.getValueByKey("share_goods_rules", new Date())));
         } else {
            out.print(JsonUtil.loadTrueResult(configService.get("share_goods_template_rules")));
         }
@@ -1207,7 +1217,8 @@
    * 
    * @param acceptData
    * @param uid
    * @param hasCoupon  -是否有券
    * @param hasCoupon
    *            -是否有券
    * @param out
    */
   @RequestMapping(value = "resetShareTextTemplate", method = RequestMethod.POST)
@@ -1223,7 +1234,7 @@
         return;
      }
       if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
      if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
         if (hasCoupon) {
            if (tljId != null) {
               shareGoodsTextTemplateService.resetTaoLijinTemplate(uid);
@@ -1233,21 +1244,20 @@
         } else {
            shareGoodsTextTemplateService.resetCommonTemplate(uid);
         }
       } else  if (goodsType == Constant.SOURCE_TYPE_JD) {
          if (hasCoupon) {
      } else if (goodsType == Constant.SOURCE_TYPE_JD) {
         if (hasCoupon) {
            shareGoodsTextTemplateService.resetCouponTemplateJD(uid);
         } else {
            shareGoodsTextTemplateService.resetCommonTemplateJD(uid);
         }
       } else  if (goodsType == Constant.SOURCE_TYPE_PDD) {
          if (hasCoupon) {
      } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
         if (hasCoupon) {
            shareGoodsTextTemplateService.resetCouponTemplatePDD(uid);
         } else {
            shareGoodsTextTemplateService.resetCommonTemplatePDD(uid);
         }
       }
      }
      if (goodsId != null) {
         viewShareTextTemplate(acceptData, uid, null, goodsType, goodsId, tljId, hasCoupon, out);
         return;