yujian
2019-07-17 20d1a38a0f8049873f1fbbaef96c22e971ea9d77
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -13,7 +13,6 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
@@ -73,10 +72,10 @@
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.util.taobao.TaoLiJinUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.goods.ShareInfoVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v2/share")
@@ -142,144 +141,20 @@
   @Resource
   private UserTaoLiJinRecordService userTaoLiJinRecordService;
   /**
    * 获取分享记录中的商品 分享信息
    * 获取淘宝的分享链接
    * 
    * @param acceptData
    * @param recordId
    * @param out
    */
   @RequestMapping(value = "getShareGoods")
   public void getShareGoods(AcceptData acceptData, Long recordId, PrintWriter out) {
      if (recordId == null) {
         out.print(JsonUtil.loadFalseResult("参数不正确"));
         return;
      }
      try {
         JSONArray array = new JSONArray();
         JSONObject data = new JSONObject();
         List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
         if (list == null || list.size() == 0) {
            data.put("title", "分享商品");
            data.put("count", 0);
            data.put("result_list", array);
            out.print(JsonUtil.loadTrueResult(data));
            return;
         }
         // API网络接口验证是否在售
         List<TaoBaoGoodsBrief> listTaoKeGoods = null;
         List<Long> listGid = new ArrayList<Long>();
         for (UserShareGoodsGroup goodsGroup : list) {
            CommonGoods commonGoods = goodsGroup.getCommonGoods();
            if (commonGoods == null || commonGoods.getGoodsType() != Constant.SOURCE_TYPE_TAOBAO) {
               continue;
            }
            listGid.add(commonGoods.getGoodsId());
         }
         if (listGid.size() > 0) {
            try {
               listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
            } catch (TaoKeApiException e) {
               e.printStackTrace();
            } catch (TaobaoGoodsDownException e) {
               e.printStackTrace();
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
         Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
               .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         for (UserShareGoodsGroup goodsGroup : list) {
            CommonGoods commonGoods = goodsGroup.getCommonGoods();
            if (commonGoods == null) {
               continue;
            }
            if (listTaoKeGoods != null && listTaoKeGoods.size() > 0
                  && commonGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
               int state = 1; // 默认停售
               Long goodsId = commonGoods.getGoodsId();
               for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
                  Long auctionId = taoKeGoods.getAuctionId();
                  if (goodsId == auctionId || goodsId.equals(auctionId)) {
                     state = 0; // 在售
                     break;
                  }
               }
               commonGoods.setState(state);
            }
            // 今日浏览记录处理
            Date date = new Date();
            Date browseTime = goodsGroup.getBrowseTime();
            if (!DateUtil.isSameDay(browseTime, date)) {
               goodsGroup.setTodayBrowse(0); // 不是同一天浏览记录设置0
            }
            JSONObject dataObject = new JSONObject();
            dataObject.put("todayBrowse", goodsGroup.getTodayBrowse());
            dataObject.put("totalBrowse", goodsGroup.getTotalBrowse());
            dataObject.put("totalOrder", goodsGroup.getTotalOrder());
            dataObject.put("totalMoney", "¥" + goodsGroup.getTotalMoney());
            GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate,
                  shareRate);
            detailVO.setId(commonGoods.getId());
            dataObject.put("goods", gson.toJson(detailVO));
            array.add(dataObject);
         }
         String title = "";
         UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordService.selectByPrimaryKey(recordId);
         if (userShareGoodsRecord != null) {
            title = userShareGoodsRecord.getTitle();
         }
         data.put("title", title);
         data.put("count", list.size());
         data.put("result_list", array);
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("加载失败"));
         e.printStackTrace();
      }
   }
   /**
    * 创建分享
    * @param acceptData
    * @param uid
    * @param auctionId
    * @param source
    * @param totalNum
    * @param goodsType
    * @param request
    * @param uid        -用户ID
    * @param            auctionId-商品ID
    * @param out
    */
   @RequestMapping(value = "createShareInfo")
   public void createShareInfo(AcceptData acceptData, Long uid, Long goodsId, String source, Integer totalNum,
         Integer goodsType, HttpServletRequest request, PrintWriter out) {
      if (uid == null || uid <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
         return;
      }
      if (goodsId == null || goodsId <= 0) {
         out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空"));
         return;
      }
@@ -289,55 +164,84 @@
         return;
      }
      if (goodsType == null) {
         goodsType = Constant.SOURCE_TYPE_TAOBAO;
      if (goodsId == null || goodsId <= 0) {
         out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空"));
         return;
      }
      // 淘宝
      if (goodsType == null || goodsType == Constant.SOURCE_TYPE_TAOBAO) {
         createTaoBaoShare(acceptData, uid, goodsId, totalNum, source, request, out);
         return;
      }
      // 京东
      if (goodsType == Constant.SOURCE_TYPE_JD) {
         // 京东
         createJDShare(acceptData, uid, goodsId, source, out);
         return;
      } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
         // 拼多多
      }
      // 拼多多
      if (goodsType == Constant.SOURCE_TYPE_PDD) {
         createPDDShare(acceptData, uid, goodsId, source, out);
         return;
      }
   }
   /**
    * 创建淘宝分享信息
    * @param acceptData
    * @param uid
    * @param goodsId
    * @param totalNum
    * @param source
    * @param request
    * @param out
    */
   public void createTaoBaoShare(AcceptData acceptData, Long uid, Long goodsId, Integer totalNum, String source,
         HttpServletRequest request, PrintWriter out) {
      UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
      String relationId = null;
      if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
            && extraInfo.getRelationValid() == true)
         relationId = extraInfo.getRelationId();
      if (StringUtil.isNullOrEmpty(relationId)) {
         out.print(JsonUtil.loadFalseResult(3, "淘宝未授权,请前往\"我的\"绑定淘宝账号"));
         return;
      }
      
      // 淘礼金创建分享
      if (source != null && "taolijin".equals(source)) {
         createTaoLijin(uid, goodsId, totalNum, relationId, request, out);
         return;
      }
      try {
         TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, goodsId, relationId);
         ShareInfoVO shareInfo = new ShareInfoVO();
         
         JSONObject data = new JSONObject();
         TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, goodsId, relationId);
         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);
         if (!StringUtil.isNullOrEmpty(shortLink)) {
            url = shortLink;
         }
         data.put("clickUrl", url);
         data.put("token", taoBaoLink.getTaoToken());
         data.put("rule", configService.get("share_rule_link_tb"));
         data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
         shareInfo.setClickUrl(url);
         shareInfo.setToken(taoBaoLink.getTaoToken());
         shareInfo.setRule(configService.get("share_single_goods_rule"));
         shareInfo.setPictUrl(TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
         String shareText = "";
         // 无券
         String shopType = taoBaoLink.getGoods().getUserType() == 0 ? "淘宝价" : "天猫价";
         if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
            String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
@@ -349,38 +253,45 @@
            String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
               text = configService.get("goods_share_text_coupon");
            shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                  .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                  .replace("{优惠券面额}",
                        MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getCouponAmount()).toString())
                  .replace("{优惠券价}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + "");
         }
         shareText = shareText.replace("{店铺类型}", shopType)
               .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
               .replace("{领券短链}", shortLink).replace("{淘口令}", taoBaoLink.getTaoToken());
         data.put("shareText", shareText);
         String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
         if (descText.startsWith("\\r\\n"))
            descText = descText.substring(0);
         data.put("descText", descText);
         //
         shareInfo.setShareText(shareText);
//         String descText = shareText.replace(taoBaoLink.getGoods().getTitle(), "").trim();
//         if (descText.startsWith("\\r\\n"))
//            descText = descText.substring(0);
//         data.put("descText", descText);
         // 提示图文内容
         String imgs = configService.get("goods_share_notify_imgs");
         JSONArray array = JSONArray.fromObject(imgs);
         int p = (int) (array.size() * Math.random());
         if (p < array.size())
            data.put("notifyPicture", array.optString(p));
         data.put("notifyDesc", configService.get("goods_share_notify"));
         if (p < array.size()) {
            shareInfo.setNotifyPicture(array.optString(p));
         }
         shareInfo.setNotifyDesc(configService.get("goods_share_notify"));
         // 添加分享记录
         // 分享金额
         BigDecimal rate = hongBaoManageService.getShareRate();
         BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
         data.put("shareMoney", "¥" + shareMoney.toString());
         shareInfo.setShareMoney("¥" + shareMoney.toString());
         // 分享id
         try {
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, Constant.SOURCE_TYPE_TAOBAO);
            data.put("shareId", shareRecord.getRedisKey());
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
                  Constant.SOURCE_TYPE_TAOBAO);
            shareInfo.setShareId(shareRecord.getRedisKey());
         } catch (Exception e) {
            try {
               LogHelper.errorDetailInfo(e);
@@ -388,7 +299,8 @@
               e1.printStackTrace();
            }
         }
         out.print(JsonUtil.loadTrueResult(data));
         out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(shareInfo)));
         final TaoBaoLink taobaoLink = taoBaoLink;
         // 异步操作
@@ -417,7 +329,7 @@
         });
         return;
      } catch (ShareGoodsException e) {
         LogHelper.errorDetailInfo(e, "分享出错:uid:"+uid+"auctionId:"+goodsId, "");
         LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + " goodsId:" + goodsId, "");
         // 分享出错报警
         try {
            monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
@@ -426,11 +338,12 @@
         out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
         businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(goodsId + ""));
      }
   }
   /**
    * 淘礼金创建分享
    *
    * @param uid
    * @param auctionId
    * @param totalNum
@@ -438,25 +351,26 @@
    * @param request
    * @param out
    */
   public void createTaoLijin(Long uid, Long auctionId, int totalNum, String relationId, HttpServletRequest request, PrintWriter out) {
   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 = taoBaoLink.getGoods();
         // 计算推广红包
         String warningRate = configTaoLiJinService.getValueByKey("warning_value");
         BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
         // 推广红包 不能小于1
         if (spreadMoney.compareTo(new BigDecimal(1.1)) < 0) {
            out.print(JsonUtil.loadFalseResult(1, "该商品淘礼金不足"));
            return;
         }
         JSONObject data = new JSONObject();
         data.put("spreadMoney", " ¥" + spreadMoney.toString());
         String taoLiJinLink = null;
         Long tljId = null;
         try {
@@ -469,17 +383,16 @@
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
            return;
         }
         String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&tid=%s", configService.getH5Host(),
               Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
               auctionId + "",AESUtil.encrypt(tljId + "", Constant.UIDAESKEY));
               auctionId + "", AESUtil.encrypt(tljId + "", Constant.UIDAESKEY));
         String shortLink = HttpUtil.getShortLink(url);
         if (!StringUtil.isNullOrEmpty(shortLink)) {
            url = shortLink;
         }
         data.put("clickUrl", url);
         // 创建淘口令
         if (!StringUtil.isNullOrEmpty(taoLiJinLink)) {// 通过立即推广方式获取淘口令成功
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoLiJinLink);
@@ -487,19 +400,22 @@
               taoBaoLink.setTaoToken(quanToken);
            }
         } else if (!StringUtil.isNullOrEmpty(taoBaoLink.getClickUrl())) {
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), taoBaoLink.getClickUrl());
            String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(),
                  taoBaoLink.getClickUrl());
            if (!StringUtil.isNullOrEmpty(quanToken)) {
               taoBaoLink.setTaoToken(quanToken);
            }
         }
         data.put("token", taoBaoLink.getTaoToken());
         data.put("rule", configService.get("share_rule_link_tb"));
         data.put("rule",
               "http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
         data.put("pictUrl", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
         // 无券
         String shopType = taoBaoLink.getGoods().getUserType() == 0 ? "淘宝价" : "天猫价";
         String shareText = "";
         if (StringUtil.isNullOrEmpty(taoBaoLink.getGoods().getCouponInfo())) {
            String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
@@ -511,7 +427,7 @@
            String text = shareGoodsTextTemplateService.getTaoLiJinTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
               text = configTaoLiJinService.getValueByKey("goods_share_text");
            shareText = text.replace("{标题}", taoBaoLink.getGoods().getTitle())
                  .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(taoBaoLink.getGoods().getZkPrice()) + "")
                  .replace("{优惠券面额}",
@@ -519,7 +435,7 @@
                  .replace("{淘礼金面额}", MoneyBigDecimalUtil.getWithNoZera(spreadMoney).toString())
                  .replace("{优惠券价}", TaoBaoUtil.getAfterUseCouplePrice(taoBaoLink.getGoods()) + "");
         }
         shareText = shareText.replace("{店铺类型}", shopType)
               .replace("{月销量}", TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()))
               .replace("{领券短链}", shortLink).replace("{淘口令}", taoBaoLink.getTaoToken());
@@ -528,7 +444,7 @@
         if (descText.startsWith("\\r\\n"))
            descText = descText.substring(0);
         data.put("descText", descText);
         String imgs = configService.get("goods_share_notify_imgs");
         JSONArray array = JSONArray.fromObject(imgs);
         int p = (int) (array.size() * Math.random());
@@ -542,7 +458,8 @@
         data.put("shareMoney", "¥" + shareMoney.toString());
         try {
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId, Constant.SOURCE_TYPE_TAOBAO);
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, auctionId,
                  Constant.SOURCE_TYPE_TAOBAO);
            data.put("shareId", shareRecord.getRedisKey());
         } catch (Exception e) {
            try {
@@ -580,7 +497,7 @@
         });
         return;
      } catch (ShareGoodsException e) {
         LogHelper.errorDetailInfo(e, "分享出错:uid:"+uid+"auctionId:"+auctionId, "");
         LogHelper.errorDetailInfo(e, "分享出错:uid:" + uid + "auctionId:" + auctionId, "");
         // 分享出错报警
         try {
            monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "分享出错"));
@@ -590,11 +507,10 @@
         businessEmergent110Service.shareTaoBaoGoodsError(StringUtil.Md5(auctionId + ""));
      }
   }
   /**
    * 京东创建分享
    *
    * @param acceptData
    * @param uid
    * @param goodsId
@@ -604,123 +520,122 @@
    * @param out
    */
   public void createJDShare(AcceptData acceptData, Long uid, Long goodsId, String source, PrintWriter out) {
         JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
         if (jdGoods == null) {
            jdGoods = JDApiUtil.getGoodsDetail(goodsId);
      JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
      if (jdGoods == null) {
         jdGoods = JDApiUtil.getGoodsDetail(goodsId);
      }
      if (jdGoods == null) {
         out.print(JsonUtil.loadFalseResult(1, "该商品淘已下架"));
         return;
      }
      JSONObject data = new JSONObject();
      String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&goodsType=%s", configService.getH5Host(),
            Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
            goodsId + "", Constant.SOURCE_TYPE_JD);
      // 券短连接
      String shortLink = HttpUtil.getShortLink(url);
      if (!StringUtil.isNullOrEmpty(shortLink)) {
         url = shortLink;
      }
      data.put("clickUrl", url);
      data.put("rule", configService.get("share_rule_link_jd"));
      data.put("pictUrl", jdGoods.getPicUrl());
      String shareText = "";
      String shopType = "京东价";
      // 分享模板
      JDCouponInfo couponInfo = jdGoods.getCouponInfo();
      if (couponInfo == null) {
         String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
         if (StringUtil.isNullOrEmpty(text)) {
            text = configService.get("goods_share_text_nocoupon");
         }
         if (jdGoods == null) {
            out.print(JsonUtil.loadFalseResult(1, "该商品淘已下架"));
            return;
         }
         shareText = text.replace("{标题}", jdGoods.getSkuName()).replace("{商品原价}",
               MoneyBigDecimalUtil.getWithNoZera(jdGoods.getPrice()) + "");
      } else// 有券
      {
         String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
         if (StringUtil.isNullOrEmpty(text))
            text = configService.get("goods_share_text_coupon");
         JSONObject data = new JSONObject();
         String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&goodsType=%s", configService.getH5Host(),
               Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
               goodsId + "", Constant.SOURCE_TYPE_JD);
         // 券短连接
         String shortLink = HttpUtil.getShortLink(url);
         if (!StringUtil.isNullOrEmpty(shortLink)) {
            url = shortLink;
         }
         shareText = text.replace("{标题}", jdGoods.getSkuName())
               .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(jdGoods.getPrice()) + "")
               .replace("{优惠券面额}", MoneyBigDecimalUtil.getWithNoZera(couponInfo.getDiscount()) + "")
               .replace("{优惠券价}", JDUtil.getQuanPrice(jdGoods) + "");
      }
         data.put("clickUrl", url);
         data.put("rule", configService.get("share_rule_link_jd"));
         data.put("pictUrl", jdGoods.getPicUrl());
      shareText = shareText.replace("{店铺类型}", shopType)
            .replace("{月销量}", JDUtil.getSaleCount(jdGoods.getInOrderCount30Days())).replace("{领券短链}", shortLink)
            .replace("{淘口令}", null);
      data.put("shareText", shareText);
         String shareText = "";
         String shopType = "京东价";
      String descText = shareText.replace(jdGoods.getSkuName(), "").trim();
      if (descText.startsWith("\\r\\n"))
         descText = descText.substring(0);
      data.put("descText", descText);
      //
      String imgs = configService.get("goods_share_notify_imgs");
      JSONArray array = JSONArray.fromObject(imgs);
      int p = (int) (array.size() * Math.random());
      if (p < array.size())
         data.put("notifyPicture", array.optString(p));
      data.put("notifyDesc", configService.get("goods_share_notify_jd"));
         // 分享模板
         JDCouponInfo couponInfo = jdGoods.getCouponInfo();
         if (couponInfo == null) {
            String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
            if (StringUtil.isNullOrEmpty(text)) {
               text = configService.get("goods_share_text_nocoupon");
            }
            shareText = text.replace("{标题}", jdGoods.getSkuName()).replace("{商品原价}",
                  MoneyBigDecimalUtil.getWithNoZera(jdGoods.getPrice()) + "");
         } else// 有券
         {
            String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
            if (StringUtil.isNullOrEmpty(text))
               text = configService.get("goods_share_text_coupon");
            shareText = text.replace("{标题}", jdGoods.getSkuName())
                  .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(jdGoods.getPrice()) + "")
                  .replace("{优惠券面额}", MoneyBigDecimalUtil.getWithNoZera(couponInfo.getDiscount()) + "")
                  .replace("{优惠券价}", JDUtil.getQuanPrice(jdGoods) + "" );
         }
         shareText = shareText.replace("{店铺类型}", shopType)
               .replace("{月销量}", JDUtil.getSaleCount(jdGoods.getInOrderCount30Days()))
               .replace("{领券短链}", shortLink).replace("{淘口令}", null);
         data.put("shareText", shareText);
         String descText = shareText.replace(jdGoods.getSkuName(), "").trim();
         if (descText.startsWith("\\r\\n"))
            descText = descText.substring(0);
         data.put("descText", descText);
         //
         String imgs = configService.get("goods_share_notify_imgs");
         JSONArray array = JSONArray.fromObject(imgs);
         int p = (int) (array.size() * Math.random());
         if (p < array.size())
            data.put("notifyPicture", array.optString(p));
         data.put("notifyDesc", configService.get("goods_share_notify_jd"));
      // 添加分享记录
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      BigDecimal shareMoney = JDUtil.getGoodsFanLiMoney(jdGoods, shareRate);
         // 添加分享记录
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         BigDecimal shareMoney =JDUtil.getGoodsFanLiMoney(jdGoods, shareRate);
         data.put("shareMoney", "¥" + shareMoney.toString());
      data.put("shareMoney", "¥" + shareMoney.toString());
      try {
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
               Constant.SOURCE_TYPE_JD);
         data.put("shareId", shareRecord.getRedisKey());
      } catch (Exception e) {
         try {
            ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, Constant.SOURCE_TYPE_JD);
            data.put("shareId", shareRecord.getRedisKey());
         } catch (Exception e) {
            try {
               LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
               e1.printStackTrace();
            }
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
         out.print(JsonUtil.loadTrueResult(data));
      }
      out.print(JsonUtil.loadTrueResult(data));
         // 异步操作
         final JDGoods goods = jdGoods;
         com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
               // 异步操作 添加分享记录
               UserShareGoodsHistory history = new UserShareGoodsHistory();
               history.setUser(new UserInfo(uid));
               history.setHongbao(shareMoney);
               history.setCreateTime(new Date());
               history.setGoodsType(Constant.SOURCE_TYPE_JD);
               history.setTkCode(null);
               history.setLink(null);
               history.setQuanLink(null);
               history.setGoodsId(goodsId);
               history.setPostPicture(goods.getPicUrl());
      // 异步操作
      final JDGoods goods = jdGoods;
      com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
         @Override
         public void run() {
            // 异步操作 添加分享记录
            UserShareGoodsHistory history = new UserShareGoodsHistory();
            history.setUser(new UserInfo(uid));
            history.setHongbao(shareMoney);
            history.setCreateTime(new Date());
            history.setGoodsType(Constant.SOURCE_TYPE_JD);
            history.setTkCode(null);
            history.setLink(null);
            history.setQuanLink(null);
            history.setGoodsId(goodsId);
            history.setPostPicture(goods.getPicUrl());
               List<String> imgList = goods.getImageList();
               if (imgList == null) {
                  imgList = new ArrayList<>();
               }
               history.setPictures(JsonUtil.getGson().toJson(imgList));
               shareGoodsService.addShareGoodsHistory(history);
            List<String> imgList = goods.getImageList();
            if (imgList == null) {
               imgList = new ArrayList<>();
            }
         });
            history.setPictures(JsonUtil.getGson().toJson(imgList));
            shareGoodsService.addShareGoodsHistory(history);
         }
      });
   }
   /**
    * 拼多多分享
    *
    * @param acceptData
    * @param uid
    * @param goodsId
@@ -728,7 +643,6 @@
    * @param out
    */
   public void createPDDShare(AcceptData acceptData, Long uid, Long goodsId, String source, PrintWriter out) {
      PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(goodsId);
      if (goods == null) {
         out.print(JsonUtil.loadFalseResult(1, "该商品已下架"));
@@ -738,8 +652,8 @@
      JSONObject data = new JSONObject();
      String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq&goodsType=%s", configService.getH5Host(),
            Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
            goodsId + "",Constant.SOURCE_TYPE_PDD);
            goodsId + "", Constant.SOURCE_TYPE_PDD);
      String shortLink = HttpUtil.getShortLink(url);
      if (!StringUtil.isNullOrEmpty(shortLink)) {
         url = shortLink;
@@ -751,11 +665,11 @@
      data.put("pictUrl", goods.getGoodsImageUrl());
      String shareText = "";
      String shopType = "拼多多价";
      // 无券
      if (goods.getHasCoupon()== null || !goods.getHasCoupon()) {
      if (goods.getHasCoupon() == null || !goods.getHasCoupon()) {
         String text = shareGoodsTextTemplateService.getCommonTemplate(uid);
         if (StringUtil.isNullOrEmpty(text))
            text = configService.get("goods_share_text_nocoupon");
@@ -766,16 +680,18 @@
         String text = shareGoodsTextTemplateService.geteCouponTemplate(uid);
         if (StringUtil.isNullOrEmpty(text))
            text = configService.get("goods_share_text_coupon");
         shareText = text.replace("{标题}", goods.getGoodsName())
               .replace("{商品原价}", MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(goods.getMinNormalPrice())) + "")
               .replace("{优惠券面额}", MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(goods.getCouponDiscount())) + "")
               .replace("{优惠券价}", PinDuoDuoUtil.getQuanPrice(goods) + "" );
               .replace("{商品原价}",
                     MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(goods.getMinNormalPrice())) + "")
               .replace("{优惠券面额}",
                     MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(goods.getCouponDiscount())) + "")
               .replace("{优惠券价}", PinDuoDuoUtil.getQuanPrice(goods) + "");
      }
      shareText = shareText.replace("{店铺类型}", shopType)
            .replace("{月销量}", PinDuoDuoUtil.getSaleCount(goods.getSoldQuantity()))
            .replace("{领券短链}", shortLink).replace("{淘口令}", null);
            .replace("{月销量}", PinDuoDuoUtil.getSaleCount(goods.getSoldQuantity())).replace("{领券短链}", shortLink)
            .replace("{淘口令}", null);
      data.put("shareText", shareText);
      String descText = shareText.replace(goods.getGoodsName(), "").trim();
      if (descText.startsWith("\\r\\n"))
@@ -787,16 +703,17 @@
      int p = (int) (array.size() * Math.random());
      if (p < array.size())
         data.put("notifyPicture", array.optString(p));
      data.put("notifyDesc", configService.get("goods_share_notify_pdd"));
      // 添加分享记录
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      BigDecimal shareMoney =PinDuoDuoUtil.getGoodsFanLiMoney(goods, shareRate);
      BigDecimal shareMoney = PinDuoDuoUtil.getGoodsFanLiMoney(goods, shareRate);
      data.put("shareMoney", "¥" + shareMoney.toString());
      try {
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId, Constant.SOURCE_TYPE_JD);
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
               Constant.SOURCE_TYPE_JD);
         data.put("shareId", shareRecord.getRedisKey());
      } catch (Exception e) {
         try {
@@ -822,7 +739,7 @@
            history.setQuanLink(null);
            history.setGoodsId(goodsId);
            history.setPostPicture(goods.getGoodsImageUrl());
            List<String> imgList = null;
            String[] goodsGalleryUrls = goods.getGoodsGalleryUrls();
            if (goodsGalleryUrls != null) {
@@ -835,7 +752,115 @@
            shareGoodsService.addShareGoodsHistory(history);
         }
      });
}
   }
   /**
    * 获取分享记录中的商品 分享信息
    *
    * @param acceptData
    * @param recordId
    * @param out
    */
   @RequestMapping(value = "getShareGoods")
   public void getShareGoods(AcceptData acceptData, Long recordId, PrintWriter out) {
      if (recordId == null) {
         out.print(JsonUtil.loadFalseResult("参数不正确"));
         return;
      }
      JSONArray array = new JSONArray();
      JSONObject data = new JSONObject();
      List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
      if (list == null || list.size() == 0) {
         data.put("title", "分享商品");
         data.put("count", 0);
         data.put("result_list", array);
         out.print(JsonUtil.loadTrueResult(data));
         return;
      }
      // API网络接口验证是否在售
      List<TaoBaoGoodsBrief> listTaoKeGoods = null;
      List<Long> listGid = new ArrayList<Long>();
      for (UserShareGoodsGroup goodsGroup : list) {
         CommonGoods commonGoods = goodsGroup.getCommonGoods();
         Integer goodsType = commonGoods.getGoodsType();
         if (commonGoods == null || goodsType == null || goodsType != Constant.SOURCE_TYPE_TAOBAO) {
            continue;
         }
         listGid.add(commonGoods.getGoodsId());
      }
      if (listGid.size() > 0) {
         try {
            listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
         } catch (TaoKeApiException e) {
            e.printStackTrace();
         } catch (TaobaoGoodsDownException e) {
            e.printStackTrace();
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
            .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
      for (UserShareGoodsGroup goodsGroup : list) {
         CommonGoods commonGoods = goodsGroup.getCommonGoods();
         if (commonGoods == null) {
            continue;
         }
         // 验证淘宝商品是否在售
         Integer goodsType = commonGoods.getGoodsType();
         if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 && goodsType != null
               && goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            int state = 1; // 默认停售
            Long goodsId = commonGoods.getGoodsId();
            for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
               Long auctionId = taoKeGoods.getAuctionId();
               if (goodsId == auctionId || goodsId.equals(auctionId)) {
                  state = 0; // 在售
                  break;
               }
            }
            commonGoods.setState(state);
         }
         // 今日浏览记录处理
         Date date = new Date();
         Date browseTime = goodsGroup.getBrowseTime();
         if (!DateUtil.isSameDay(browseTime, date)) {
            goodsGroup.setTodayBrowse(0); // 不是同一天浏览记录设置0
         }
         JSONObject dataObject = new JSONObject();
         dataObject.put("todayBrowse", goodsGroup.getTodayBrowse());
         dataObject.put("totalBrowse", goodsGroup.getTotalBrowse());
         dataObject.put("totalOrder", goodsGroup.getTotalOrder());
         dataObject.put("totalMoney", "¥" + goodsGroup.getTotalMoney());
         GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate, shareRate);
         detailVO.setId(commonGoods.getId());
         dataObject.put("goods", gson.toJson(detailVO));
         array.add(dataObject);
      }
      String title = "";
      UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordService.selectByPrimaryKey(recordId);
      if (userShareGoodsRecord != null) {
         title = userShareGoodsRecord.getTitle();
      }
      data.put("title", title);
      data.put("count", list.size());
      data.put("result_list", array);
      out.print(JsonUtil.loadTrueResult(data));
   }
}