admin
2020-05-31 2a48f2bd979d56ce4114ba9d56efaf49bab705d7
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -27,6 +27,10 @@
import com.yeshi.fanli.dto.jd.JDPingouInfo;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.share.ShareGoodsRecordDTO;
import com.yeshi.fanli.dto.suning.SuningGoodsImg;
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.dto.vip.VIPConvertResultDTO;
import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
@@ -35,6 +39,7 @@
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
@@ -55,6 +60,7 @@
import com.yeshi.fanli.service.inter.goods.ShareGoodsTextTemplateService;
import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service;
import com.yeshi.fanli.service.inter.monitor.MonitorService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService;
@@ -79,9 +85,13 @@
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
import com.yeshi.fanli.util.suning.SuningApiUtil;
import com.yeshi.fanli.util.suning.SuningUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.util.taobao.TaoLiJinUtil;
import com.yeshi.fanli.util.vipshop.VipShopApiUtil;
import com.yeshi.fanli.util.vipshop.VipShopUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.goods.ShareGoodsCommentChoiceInfo;
import com.yeshi.fanli.vo.goods.ShareInfoVO;
@@ -104,6 +114,9 @@
   @Resource
   private HongBaoManageService hongBaoManageService;
   @Resource
   private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
   @Resource
   private MonitorService monitorService;
@@ -197,7 +210,7 @@
    * @param out
    */
   @RequestMapping(value = "createShareInfo")
   public void createShareInfo(AcceptData acceptData, Long uid, Long goodsId, String source, Integer totalNum,
   public void createShareInfo(AcceptData acceptData, Long uid, String goodsId, String source, Integer totalNum,
         Integer goodsType, Boolean needGoods, HttpServletRequest request, PrintWriter out) {
      if (uid == null || uid <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
@@ -220,28 +233,41 @@
         return;
      }
      if (goodsId == null || goodsId <= 0) {
      if (goodsId == null ) {
         out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空"));
         return;
      }
      // 淘宝
      if (goodsType == null || goodsType == Constant.SOURCE_TYPE_TAOBAO) {
         createTaoBaoShare(acceptData, uid, goodsId, totalNum, source, needGoods, request, out);
         createTaoBaoShare(acceptData, uid,Long.parseLong(goodsId), totalNum, source, needGoods, request, out);
         return;
      }
      // 京东
      if (goodsType == Constant.SOURCE_TYPE_JD) {
         createJDShare(acceptData, uid, goodsId, source, needGoods, out);
         createJDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out);
         return;
      }
      // 拼多多
      if (goodsType == Constant.SOURCE_TYPE_PDD) {
         createPDDShare(acceptData, uid, goodsId, source, needGoods, out);
         createPDDShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out);
         return;
      }
      // 唯品会
      if (goodsType == Constant.SOURCE_TYPE_VIP) {
         createVIPShare(acceptData, uid, Long.parseLong(goodsId), source, needGoods, out);
         return;
      }
      // 苏宁
      if (goodsType == Constant.SOURCE_TYPE_SUNING) {
         createSuningShare(acceptData, uid, goodsId, source, needGoods, out);
         return;
      }
   }
   public static String getERCodeContentNew(String template, TaoBaoGoodsBrief goods, String token) {
@@ -254,6 +280,13 @@
         commentText = commentText.replace("[券后价]", TaoBaoUtil.getAfterUseCouplePrice(goods) + "");
      }
      commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n");
      return commentText;
   }
   // 淘宝分享活动
   public static String getTaoBaoActiivtyERCodeContentNew(String template, String token) {
      String commentText = template.replace("[淘口令]", token);
      commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n");
      return commentText;
   }
@@ -492,7 +525,7 @@
         TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, goodsId, relationId);
         if (taoBaoLink != null && taoBaoLink.getGoods() != null && needGoods) {
            ConfigParamsDTO dto = hongBaoManageService.getShowComputeRate(platform, version);
            ConfigParamsDTO dto = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version);
            GoodsDetailVO goodsInfo = GoodsDetailVOFactory.convertTaoBao(taoBaoLink.getGoods(), dto);
            shareInfo.setGoodsInfo(goodsInfo);
         }
@@ -649,8 +682,9 @@
         shareInfo.setRecommendText(deleteBlankLine(recommendText));
         // 设置评论文本选项
         shareInfo.setCommentTextChoiceList(getCommentChoiceList(shareInfo.getCommentText(), null, inviteCode,
               TaoBaoUtil.getGoodsHongBaoMoney(taoBaoLink.getGoods(), hongBaoManageService.getVIPFanLiRate())));
         shareInfo.setCommentTextChoiceList(
               getCommentChoiceList(shareInfo.getCommentText(), null, inviteCode, TaoBaoUtil.getGoodsHongBaoMoney(
                     taoBaoLink.getGoods(), hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP),false)));
         out.print(JsonUtil.loadTrueResult(
               JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo)));
@@ -729,8 +763,8 @@
      shareInfo.setCommentTexts(new ArrayList<>());
      if (needGoods)
         shareInfo.setGoodsInfo(GoodsDetailVOFactory.convertJDGoods(jdGoods,
               hongBaoManageService.getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion())));
         shareInfo.setGoodsInfo(GoodsDetailVOFactory.convertJDGoods(jdGoods, orderHongBaoMoneyComputeService
               .getShowComputeRate(acceptData.getPlatform(), acceptData.getVersion())));
      boolean hasCoupon = false;
      if (couponInfo != null) {
@@ -819,7 +853,7 @@
      // 设置评论文本选项
      shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode,
            JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getVIPFanLiRate())));
            JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      out.print(JsonUtil.loadTrueResult(
            JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo)));
@@ -892,7 +926,7 @@
               .setGoodsInfo(GoodsDetailVOFactory.convertPDDGoods(goods,
                     new ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
                           hongBaoManageService.getShareRate(), Constant.MAX_REWARD_RATE,
                           hongBaoManageService.getVIPFanLiRate())));
                           hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      }
      // 创建口令
@@ -989,7 +1023,7 @@
      // 设置评论文本选项
      shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode,
            PinDuoDuoUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getVIPFanLiRate())));
            PinDuoDuoUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      out.print(JsonUtil.loadTrueResult(
            JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo)));
@@ -1017,6 +1051,277 @@
            }
            if (imgList == null) {
               imgList = new ArrayList<>();
            }
            history.setPictures(JsonUtil.getGson().toJson(imgList));
            shareGoodsService.addShareGoodsHistory(history);
         }
      });
   }
   /**
    * 唯品会分享
    * @Title: createVIPShare
    * @Description:
    * @param acceptData
    * @param uid
    * @param goodsId
    * @param source
    * @param needGoods
    * @param out
    * void 返回类型
    * @throws
    */
   public void createVIPShare(AcceptData acceptData, Long uid, Long goodsId, String source, boolean needGoods,
         PrintWriter out) {
      VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId + "");
      if (goods == null) {
         out.print(JsonUtil.loadFalseResult(1, "该商品已下架"));
         return;
      }
      VIPConvertResultDTO jumpLink = VipShopApiUtil.convertLink(goodsId + "", VipShopUtil.getShareChanTag(uid));
      ShareInfoVO shareInfo = new ShareInfoVO();
      shareInfo.setClickUrl(jumpLink.getUrl());
      shareInfo.setWxErCode(jumpLink.getUrl());
      shareInfo.setCommentTexts(new ArrayList<>());
      shareInfo.setRule(configService.get(ConfigKeyEnum.shareRuleLinkVIP.getKey()));
      shareInfo.setPictUrl(goods.getGoodsThumbUrl());
      if (needGoods) {
         shareInfo
               .setGoodsInfo(GoodsDetailVOFactory.convertVIPGoods(goods,
                     new ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
                           hongBaoManageService.getShareRate(), Constant.MAX_REWARD_RATE,
                           hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      }
      String template = shareGoodsTextTemplateService.getTextTemplateByVIP(uid);
      String shareText = shareGoodsTextTemplateService.createContentVIP(template, goods, jumpLink.getUrl());
      shareInfo.setShareText(shareText);
      String descText = shareText.replace(goods.getGoodsName(), "").trim();
      if (descText.startsWith("\\r\\n")) {
         descText = descText.substring(0);
      }
      shareInfo.setDescText(descText);
      //
      String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getPlatform(),
            Integer.parseInt(acceptData.getVersion()));
      JSONArray array = JSONArray.fromObject(imgs);
      shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0));
      // 2.0.7版本后的提示图片
      imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs207.getKey());
      array = JSONArray.fromObject(imgs);
      shareInfo.setNotifyPictureNew(array.size() > 1 ? array.optString(1) : array.optString(0));
      shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotifyPDD.getKey()));
      // 添加分享记录
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      BigDecimal shareMoney = VipShopUtil.getGoodsFanLiMoney(goods, shareRate);
      shareInfo.setShareMoney("¥" + shareMoney.toString());
      try {
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid, goodsId,
               Constant.SOURCE_TYPE_VIP, false);
         shareInfo.setShareId(shareRecord.getRedisKey());
      } catch (Exception e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
      String commentText = "";
      String recommendText = "";
      String qtemplate = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey());
      recommendText = qtemplate.replace("[商品标题]", goods.getGoodsName());
      recommendText = recommendText.replace("推荐理由:[推荐语]", "");
      String quickCommentText = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
      commentText = quickCommentText.replace("[原价]", goods.getMarketPrice());
      commentText = commentText.replace("[链接]", jumpLink.getUrl());
      commentText = commentText.replace("领券抢购", "抢购");
      commentText = commentText.replace("【券后价】[券后价]元", "");
      recommendText = recommendText.replace("优惠券:[券面额]元", "");
      shareInfo.setRecommendText(deleteBlankLine(recommendText));
      shareInfo.setCommentText(deleteBlankLine(commentText));
      // 设置评论文本选项
      shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode,
            VipShopUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      out.print(JsonUtil.loadTrueResult(
            JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo)));
      // 异步操作
      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_VIP);
            history.setTkCode(null);
            history.setLink(null);
            history.setQuanLink(null);
            history.setGoodsId(goodsId);
            history.setPostPicture(goods.getGoodsThumbUrl());
            history.setShareImg(jumpLink.getUrl());
            List<String> imgList = goods.getGoodsDetailPictures();
            if (imgList == null) {
               imgList = new ArrayList<>();
            }
            history.setPictures(JsonUtil.getGson().toJson(imgList));
            shareGoodsService.addShareGoodsHistory(history);
         }
      });
   }
   /**
    * 苏宁易购分享
    * @Title: createSuningShare
    * @Description:
    * @param acceptData
    * @param uid
    * @param goodsId
    * @param source
    * @param needGoods
    * @param out
    * void 返回类型
    * @throws
    */
   public void createSuningShare(AcceptData acceptData, Long uid, String goodsId, String source, boolean needGoods,
         PrintWriter out) {
      String[] sts = SuningUtil.getGoodsIdDetail(goodsId);
      SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(sts[1], sts[0]);
      if (goods == null) {
         out.print(JsonUtil.loadFalseResult(1, "该商品已下架"));
         return;
      }
      String couponLink = goods.getCouponInfo().getCouponUrl();
      String jumpLink = SuningApiUtil.convertLink(SuningUtil.getProductUrl(sts[0], sts[1]),
            StringUtil.isNullOrEmpty(couponLink) ? null : couponLink, SuningApiUtil.PID_SHARE, uid + "");
      ShareInfoVO shareInfo = new ShareInfoVO();
      shareInfo.setClickUrl(jumpLink);
      shareInfo.setWxErCode(jumpLink);
      shareInfo.setCommentTexts(new ArrayList<>());
      shareInfo.setRule(configService.get(ConfigKeyEnum.shareRuleLinkSuning.getKey()));
      if (goods.getCommodityInfo().getPictureUrl() != null && goods.getCommodityInfo().getPictureUrl().size() > 0)
         shareInfo.setPictUrl(goods.getCommodityInfo().getPictureUrl().get(0).getPicUrl());
      if (needGoods) {
         shareInfo
               .setGoodsInfo(GoodsDetailVOFactory.convertSuningGoods(goods,
                     new ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
                           hongBaoManageService.getShareRate(), Constant.MAX_REWARD_RATE,
                           hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      }
      String template = shareGoodsTextTemplateService.getTextTemplateByVIP(uid);
      String shareText = shareGoodsTextTemplateService.createContentSuning(template, goods, jumpLink);
      shareInfo.setShareText(shareText);
      String descText = shareText.replace(goods.getCommodityInfo().getCommodityName(), "").trim();
      if (descText.startsWith("\\r\\n")) {
         descText = descText.substring(0);
      }
      shareInfo.setDescText(descText);
      //
      String imgs = configService.getByVersion(ConfigKeyEnum.goodsShareNotifyImgs.getKey(), acceptData.getPlatform(),
            Integer.parseInt(acceptData.getVersion()));
      JSONArray array = JSONArray.fromObject(imgs);
      shareInfo.setNotifyPicture(array.size() > 1 ? array.optString(1) : array.optString(0));
      // 2.0.7版本后的提示图片
      imgs = configService.get(ConfigKeyEnum.goodsShareNotifyImgs207.getKey());
      array = JSONArray.fromObject(imgs);
      shareInfo.setNotifyPictureNew(array.size() > 1 ? array.optString(1) : array.optString(0));
      shareInfo.setNotifyDesc(configService.get(ConfigKeyEnum.goodsShareNotifySuning.getKey()));
      // 添加分享记录
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      BigDecimal shareMoney = SuningUtil.getGoodsFanLiMoney(goods, shareRate);
      shareInfo.setShareMoney("¥" + shareMoney.toString());
      try {
         ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsDetail(uid,
               Long.parseLong(sts[1]), Constant.SOURCE_TYPE_SUNING, false);
         shareInfo.setShareId(shareRecord.getRedisKey());
      } catch (Exception e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
      String commentText = "";
      String recommendText = "";
      String qtemplate = configService.get(ConfigKeyEnum.quickShareGoodsText.getKey());
      recommendText = qtemplate.replace("[商品标题]", goods.getCommodityInfo().getCommodityName());
      recommendText = recommendText.replace("推荐理由:[推荐语]", "");
      String quickCommentText = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
      commentText = quickCommentText.replace("[原价]", goods.getCommodityInfo().getCommodityPrice());
      commentText = commentText.replace("[链接]", jumpLink);
      commentText = commentText.replace("领券抢购", "抢购");
      commentText = commentText.replace("【券后价】[券后价]元", "");
      recommendText = recommendText.replace("优惠券:[券面额]元", "");
      shareInfo.setRecommendText(deleteBlankLine(recommendText));
      shareInfo.setCommentText(deleteBlankLine(commentText));
      // 设置评论文本选项
      shareInfo.setCommentTextChoiceList(getCommentChoiceList(null, shareInfo.getCommentText(), inviteCode,
            SuningUtil.getGoodsFanLiMoney(goods, hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
      out.print(JsonUtil.loadTrueResult(
            JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create().toJson(shareInfo)));
      // 异步操作
      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_VIP);
            history.setTkCode(null);
            history.setLink(null);
            history.setQuanLink(null);
            history.setGoodsId(Long.parseLong(sts[1]));
            if (goods.getCommodityInfo().getPictureUrl() != null
                  && goods.getCommodityInfo().getPictureUrl().size() > 0)
               history.setPostPicture(goods.getCommodityInfo().getPictureUrl().get(0).getPicUrl());
            history.setShareImg(jumpLink);
            List<SuningGoodsImg> pictureList = goods.getCommodityInfo().getPictureUrl();
            List<String> imgList = new ArrayList<>();
            if (pictureList != null) {
               for (SuningGoodsImg gi : pictureList)
                  imgList.add(gi.getPicUrl());
            }
            history.setPictures(JsonUtil.getGson().toJson(imgList));
            shareGoodsService.addShareGoodsHistory(history);
@@ -1394,7 +1699,11 @@
      JSONArray array = new JSONArray();
      JSONObject data = new JSONObject();
      List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
      boolean notBackSuVip = false;
      if (!VersionUtil.greaterThan_2_1_2(acceptData.getPlatform(), acceptData.getVersion()))
         notBackSuVip = true;
      List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId, notBackSuVip);
      if (list == null || list.size() == 0) {
         data.put("title", "分享商品");
         data.put("count", 0);
@@ -1427,7 +1736,7 @@
         }
      }
      ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
      ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
            acceptData.getVersion());
      Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
@@ -1499,7 +1808,7 @@
      }
      GoodsDetailVO goodsDetail = null;
      ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
      ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
            acceptData.getVersion());
      paramsDTO.setBaseFanliRate(hongBaoManageService.getBaseFanliRate());