yujian
2019-07-29 cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java
@@ -14,19 +14,25 @@
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.yeshi.fanli.dto.jd.JDCouponInfo;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.ShamUser;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserMoneyExtra;
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
import com.yeshi.fanli.entity.taobao.TLJBuyGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsUpdateException;
import com.yeshi.fanli.log.LogHelper;
@@ -37,6 +43,7 @@
import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
@@ -48,17 +55,23 @@
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserMoneyExtraService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.factory.goods.ShopInfoVOFactory;
import com.yeshi.fanli.util.jd.JDApiUtil;
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.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.util.taobao.TaoLiJinUtil;
@@ -66,8 +79,10 @@
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.goods.MoneyInfoVO;
import com.yeshi.fanli.vo.goods.OtherInfo;
import com.yeshi.fanli.vo.goods.ShareInfoVO;
import com.yeshi.fanli.vo.goods.ShareVO;
import com.yeshi.fanli.vo.goods.ShopInfoVO;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import com.yeshi.fanli.vo.tlj.ReduceHongBao;
import com.yeshi.fanli.vo.tlj.SpreadHongBao;
import net.sf.json.JSONObject;
@@ -139,53 +154,34 @@
   @Resource
   private ScanHistoryV2Service scanHistoryV2Service;
   /**
    * 获取商品详情
    *
    * @param acceptData
    * @param id
    * @param source
    * @param uid
    * @param from
    * @param out
    */
   @RequestMapping(value = "getDetail", method = RequestMethod.POST)
   public void getDetail(AcceptData acceptData, Long id, Integer goodsType, Long uid, String from, PrintWriter out) {
      if (id == null || goodsType == null) {
         out.print(JsonUtil.loadFalseResult(1, "商品id和商品平台不能为空"));
         return;
      }
   @Resource
   private TLJBuyGoodsService tljBuyGoodsService;
   @Resource
   private UserInfoService userInfoService;
   @Resource
   private JDGoodsCacheUtil jdGoodsCacheUtil;
      // 淘宝商品
      if (Constant.SOURCE_TYPE_TAOBAO == goodsType) {
         getTaoBaoGoodsDetial(acceptData, id, uid, from, out);
         return;
      }
   @Resource
   private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
      // 京东商品
      if (Constant.SOURCE_TYPE_JD == goodsType) {
         getJDGoodsDetial(acceptData, id, uid, from, out);
         return;
      }
      // 拼多多商品
      if (Constant.SOURCE_TYPE_PDD == goodsType) {
         getPDDGoodsDetial(acceptData, id, uid, from, out);
         return;
      }
   }
   /**
    * 淘宝商品详情
    *
    * @param acceptData
    * @param id
    * @param uid
    * @param from
    * @param out
    */
   public void getTaoBaoGoodsDetial(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      // 系统验证
   @RequestMapping(value = "getDetailTB", method = RequestMethod.POST)
   public void getDetialTB(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      if (id == null) {
         out.print(JsonUtil.loadFalseResult(1, "商品id不能为空"));
         return;
      }
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
@@ -193,19 +189,35 @@
         return;
      }
      // 获取淘客参数
      GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
      extraVO.setIsNative(false);
      // IOS是否正在上线
      if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      long startTime = java.lang.System.currentTimeMillis();
      // 获取淘客参数
      ClientTBPid clientTBPid = null;
      // 用户未登录
      if (acceptData.getPlatform().equalsIgnoreCase("android")) {
         clientTBPid = tbPidService.getAndroidDefault();
      } else {
         clientTBPid = tbPidService.getIOSDefault();
      }
      LogHelper.test("获取PID耗时:" + (java.lang.System.currentTimeMillis() - startTime));
      TaoBaoGoodsBrief goods = null;
      final List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
      // 是否在服务端进行转链
      boolean convertInServer = configService.isConvertTaoBaoLinkInServer();
      TaoBaoGoodsBrief goods = null;
      if (!convertInServer) {
         try {
            goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(id);
@@ -216,7 +228,6 @@
               app.setPid(TaoBaoConstant.TAOBAO_COMMON_PID);
               app.setAdzoneId(TaoBaoConstant.TAOBAO_COMMON_PID.split("_")[3]);
               goods = TaoKeApiUtil.searchGoodsDetail(id, app);
               final TaoBaoGoodsBrief finalGoods = goods;
               if (goods != null) {
                  ThreadUtil.run(new Runnable() {
@@ -234,10 +245,11 @@
                  taoBaoGoodsUpdateService.offlineTaoBaoGoods(id);
               }
            });
         }
      } else {
         String clientPid = clientTBPid.getPid();
         final String clientPid = clientTBPid.getPid();
         String appId = clientPid.split("_")[2];
         TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
         TaoKeAppInfo app = new TaoKeAppInfo();
@@ -269,266 +281,6 @@
      }
      if (goods == null) {
         out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
         return;
      }
      goods.setState(0);
      final TaoBaoGoodsBrief newGoods = goods;
      ThreadUtil.run(new Runnable() {
         public void run() {
            try {
               LogHelper.test("更新商品详情:" + newGoods.getAuctionId());
               taoBaoGoodsUpdateService.updateTaoBaoGoods(newGoods);
            } catch (TaobaoGoodsUpdateException e) {
            }
         }
      });
      // 替换白底图
      if (!StringUtil.isNullOrEmpty(goods.getPictUrlWhite())) {
         goods.setPictUrl(goods.getPictUrlWhite());
      }
      // 图片;列表处理
      List<String> imgList = goods.getImgList();
      if (imgList == null) {
         goods.setImgList(new ArrayList<>());
      }
      imgList.add(0, goods.getPictUrl());
      // 图片大小限制
      List<String> finalImgList = new ArrayList<>();
      for (String img : imgList) {
         finalImgList.add(TbImgUtil.getTBSizeImg(img, 600));
      }
      // 大淘客商品过滤
      try {
         goods = daTaoKeGoodsDetailService.filterTaoBaoGoods(goods);
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertTaoBao(newGoods, null, fanLiRate, shareRate);
      // 店铺信息
      TaoBaoShop shop = taoBaoShopService.getTaoBaoShop(goods.getAuctionId(), goods.getSellerId());
      if (shop != null) {
         goodsDetail.setShopInfo(ShopInfoVOFactory.convertTaoBaoShop(shop));
      }
      // 券信息
      if (goodsDetail.isHasCoupon()) {
//         CouponInfoVO coupon = goodsDetail.getCouponInfo();
//         String token = "";
//         if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
//            token = redisManager.getCommonTaoToken(id);
//            if (StringUtil.isNullOrEmpty(token)) {
//               token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), goods.getCouponLink());
//               redisManager.saveCommonTaoToken(goods.getAuctionId(), token);
//            }
//         }
//         coupon.setToken(token);
//         goodsInfo.setCouponInfo(coupon);
         if (!StringUtil.isNullOrEmpty(from)) {
            if ("miandan".equals(from)) { // 免单商品
               MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
               moneyInfo.setFanliMoney("¥" + goodsDetail.getCouponPrice());
               goodsDetail.setMoneyInfo(moneyInfo);
            }
         }
      }
      JSONObject object = new JSONObject();
      object.put("code", 0);
      object.put("data", JsonUtil.getApiCommonGson().toJson(goodsDetail));
      out.print(object.toString());
   }
   /**
    * 京东商品详情
    *
    * @param acceptData
    * @param id
    * @param uid
    * @param from
    * @param out
    */
   public void getJDGoodsDetial(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      // 系统验证
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
         return;
      }
      JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id);
      if (jdGoods == null) {
         jdGoods = JDApiUtil.getGoodsDetail(id);
      }
      if (jdGoods == null) {
         out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
         return;
      }
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, null, fanLiRate, shareRate);
      JSONObject object = new JSONObject();
      object.put("code", 0);
      object.put("data", JsonUtil.getApiCommonGson().toJson(goodsDetail));
      out.print(object.toString());
   }
   /**
    * 京东商品详情
    *
    * @param acceptData
    * @param id
    * @param uid
    * @param from
    * @param out
    */
   public void getPDDGoodsDetial(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      // 系统验证
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
         return;
      }
      PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id);
      if (pddGoods == null) {
         out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
         return;
      }
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, null, fanLiRate, shareRate);
      JSONObject object = new JSONObject();
      object.put("code", 0);
      object.put("data", JsonUtil.getApiCommonGson().toJson(goodsDetail));
      out.print(object.toString());
   }
   /**
    * 获取商品详情
    *
    * @param acceptData
    * @param id
    * @param source
    * @param uid
    * @param from
    * @param out
    */
   @RequestMapping(value = "getExtraDetail", method = RequestMethod.POST)
   public void getExtraDetail(AcceptData acceptData, Long id, Integer goodsType, Long uid, String from,
         PrintWriter out) {
      if (id == null || goodsType == null) {
         out.print(JsonUtil.loadFalseResult(1, "商品id和商品平台不能为空"));
         return;
      }
      // 淘宝商品
      if (Constant.SOURCE_TYPE_TAOBAO == goodsType) {
         getTaoBaoExtraDetial(acceptData, id, uid, from, out);
         return;
      }
      // 京东商品
      if (Constant.SOURCE_TYPE_JD == goodsType) {
         getJDExtraDetial(acceptData, id, uid, from, out);
         return;
      }
      // 拼多多商品
      if (Constant.SOURCE_TYPE_PDD == goodsType) {
         getPDDExtraDetial(acceptData, id, uid, from, out);
         return;
      }
   }
   /**
    * 淘宝商品额外配置信息
    *
    * @param acceptData
    * @param id
    * @param uid
    * @param from
    * @param out
    */
   public void getTaoBaoExtraDetial(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
         return;
      }
      GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
      // IOS是否正在上线
      if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      long startTime = java.lang.System.currentTimeMillis();
      // 获取淘客参数
      ClientTBPid clientTBPid = null;
      // 用户未登录
      if (acceptData.getPlatform().equalsIgnoreCase("android")) {
         clientTBPid = tbPidService.getAndroidDefault();
      } else {
         clientTBPid = tbPidService.getIOSDefault();
      }
      extraVO.setTbPidInfo(clientTBPid);
      LogHelper.test("获取PID耗时:" + (java.lang.System.currentTimeMillis() - startTime));
      List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
      TaoBaoGoodsBrief goods = null;
      try {
         goods = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(id);
         if (goods == null) {
            TaoKeAppInfo app = new TaoKeAppInfo();
            app.setAppKey(TaoBaoConstant.TAOBAO_COMMON_APPKEY);
            app.setAppSecret(TaoBaoConstant.TAOBAO_COMMON_APPSECRET);
            app.setPid(TaoBaoConstant.TAOBAO_COMMON_PID);
            app.setAdzoneId(TaoBaoConstant.TAOBAO_COMMON_PID.split("_")[3]);
            goods = TaoKeApiUtil.searchGoodsDetail(id, app);
            final TaoBaoGoodsBrief finalGoods = goods;
            if (goods != null) {
               ThreadUtil.run(new Runnable() {
                  @Override
                  public void run() {
                     taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(finalGoods);
                  }
               });
            }
         }
      } catch (TaobaoGoodsDownException e) {
         // 商品下架
         ThreadUtil.run(new Runnable() {
            public void run() {
               taoBaoGoodsUpdateService.offlineTaoBaoGoods(id);
            }
         });
      }
      if (goods != null) {
         goodsList.add(goods);
         final TaoBaoGoodsBrief newGoods = goods;
@@ -555,43 +307,78 @@
         return;
      }
      if (tb.getImgList() == null) {
         tb.setImgList(new ArrayList<>());
      }
      tb.getImgList().add(0, tb.getPictUrl());
      List<String> finalImgList = new ArrayList<>();
      for (String img : tb.getImgList()) {
         finalImgList.add(TbImgUtil.getTBSizeImg(img, 600));
      }
      if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite()))
         finalImgList.add(0, tb.getPictUrlWhite());
      // 大淘客商品过滤
      try {
         goods = daTaoKeGoodsDetailService.filterTaoBaoGoods(goods);
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
      extraVO.setDetailUrl("http://apph5.yeshitv.com/apppage/goods_img.html?id=" + id);
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertTaoBao(goods, null, fanLiRate, shareRate);
      // 店铺信息
      TaoBaoShop shop = taoBaoShopService.getTaoBaoShop(goods.getAuctionId(), goods.getSellerId());
      TaoBaoShop shop = taoBaoShopService.getTaoBaoShop(id, goods.getSellerId());
      if (shop != null) {
         String shopLink = shop.getShopLink();
         if (StringUtil.isNullOrEmpty(shopLink)) {
            shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
         }
         extraVO.setShopInfo(ShopInfoVOFactory.convertTaoBaoShop(shop));
         goodsDetail.setShopInfo(ShopInfoVOFactory.convertTaoBaoShop(shop));
      }
      BigDecimal shareMoney = taoBaoGoodsBriefService.getShareGoodsUserHongBao(tb);
      // 有券处理
      if (goodsDetail.isHasCoupon()) {
         if (!StringUtil.isNullOrEmpty(from)) {
            if ("miandan".equals(from)) { // 免单商品
               MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
               moneyInfo.setFanliMoney("¥" + goodsDetail.getCouponPrice());
               goodsDetail.setMoneyInfo(moneyInfo);
            }
         }
      }
      extraVO.setTbPidInfo(clientTBPid);
      extraVO.setDetailUrl("http://apph5.yeshitv.com/apppage/goods_img.html?id=" + id);
      // 分享赚人提示
      MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
      List<ShamUser> listShareUser = new ArrayList<ShamUser>();
      if (tb.getBiz30day() >= 1000) {
         listShareUser = shamUserService.listRandShareUser(10, shareMoney, 1, 5);
      if (moneyInfo != null) {
         String shareMoney = moneyInfo.getShareMoney();
         if (goods.getBiz30day() >= 1000) {
            listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney.replaceAll("¥", "")), 1, 5);
         }
      }
      extraVO.setListShareUser(listShareUser);
      // 领券人列表
      List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
      if (!StringUtil.isNullOrEmpty(tb.getCouponInfo()) && tb.getCouponAmount() != null
            && tb.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {
         if (tb.getBiz30day() >= 1000) {
      if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && goods.getCouponAmount() != null
            && goods.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {
         if (goods.getBiz30day() >= 1000) {
            listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
         }
      }
      extraVO.setListCouponUser(listCouponUser);
      if (uid != null) {
         // 是否加入收藏
         CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
@@ -601,16 +388,17 @@
         extraVO.setStorage(userGoodsStorageService.isExistStorage(uid, id, Constant.SOURCE_TYPE_TAOBAO));
      }
      // 测试
      SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
            "goods_detail_jump_taobao");
      if ("1".equalsIgnoreCase((params.getValue() + "").trim())) {
         extraVO.setNative(true);
      }
         extraVO.setIsNative(true);
      }
      // 商品链接
      String h5Url = String.format("http://%s%s?id=%s&appType=flq", configService.getH5Host(),
            Constant.systemCommonConfig.getShareGoodsPagePath(), tb.getAuctionId() + "");
            Constant.systemCommonConfig.getShareGoodsPagePath(), id + "");
      try {
         extraVO.setH5Url(HttpUtil.getShortLink(h5Url));
      } catch (Exception e) {
@@ -618,12 +406,12 @@
      }
      String helpLink = null;
      // 是否有返利
      boolean fanliValid = true;
      /* 推广红包 */
      boolean shareValid = true;
      int moneyType = 1;
      // 推广红包
      if (from != null && from.equals("taolijin")) {
         // 计算推广红包
         String warningRate = configTaoLiJinService.getValueByKey("warning_value");
         BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
@@ -644,8 +432,14 @@
            }
         }
         if (!isNewUser) {
         SpreadHongBao spreadHongBao = new SpreadHongBao();
         if (isNewUser) {
            spreadHongBao.setMoney("1");
         } else {
            moneyType = 2;
            fanliValid = false;
            spreadHongBao.setMoney(spreadMoney.toString());
            ClientTextStyleVO textStyleVO1 = new ClientTextStyleVO();
            textStyleVO1.setContent("分享");
            textStyleVO1.setColor("#666666");
@@ -666,18 +460,12 @@
            listText.add(textStyleVO4);
            extraVO.setTip(listText);
         }
         SpreadHongBao spreadHongBao = new SpreadHongBao();
         if (isNewUser) {
            spreadHongBao.setMoney("¥1");
         } else {
            spreadHongBao.setMoney("¥" + spreadMoney.toString());
         }
         spreadHongBao.setName("推广红包 ");
         spreadHongBao.setTip("当日领取,当日内使用,过期失效");
         OtherInfo otherInfo = new OtherInfo();
         otherInfo.setSpreadHongBao(spreadHongBao);
         extraVO.setOtherInfo(otherInfo);
         goodsDetail.setOtherInfo(otherInfo);
         // 用户淘礼金
         UserMoneyExtra userMoneyExtra = userMoneyExtraService.selectByPrimaryKey(uid);
@@ -687,25 +475,60 @@
            extraVO.setUserTLJ(userMoneyExtra.getTlj().setScale(2).toString());
         }
         helpLink = configTaoLiJinService.getValueByKey("share_goods_help_link");
      } else if (from != null && from.equals("taolijin_buy")) {
         // 查询分享库
         TLJBuyGoods buyGoods = tljBuyGoodsService.selectByAuctionIdAndDay(id,
               TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
         if (buyGoods == null) {
            out.print(JsonUtil.loadFalseResult(2, "自购立减红包过期"));
            return;
         }
         moneyType = 2;
         fanliValid = true;
         shareValid = false;
         helpLink = configService.get("zigoulijian_nofanli_help");
         String tljHongBao = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70)).toString();
         ReduceHongBao reduceHongBao = new ReduceHongBao();
         reduceHongBao.setLeft(buyGoods.getLeftHongBaoCount());
         reduceHongBao.setMoney(tljHongBao);
         reduceHongBao.setName("付款立减 ");
         reduceHongBao.setTip("当日领取,当日内使用,过期失效");
         reduceHongBao.setTotal(buyGoods.getTotalHongBaoCount());
         OtherInfo otherInfo = new OtherInfo();
         otherInfo.setReduceHongBao(reduceHongBao);
         goodsDetail.setOtherInfo(otherInfo);
      }
      extraVO.setFanliValid(fanliValid);
      extraVO.setShareValid(true);
      extraVO.setShareValid(shareValid);
      MoneyInfoVO goodsMoney = goodsDetail.getMoneyInfo();
      if (goodsMoney != null) {
         goodsMoney.setMoneyType(moneyType);
      }
      // 分享路径
      if (StringUtil.isNullOrEmpty(helpLink)) {
         helpLink = configService.get("no_rebate_help_link");
      }
      // 分享路径
      String shareUrl = String.format("%s?id=" + tb.getAuctionId(), Constant.systemCommonConfig.getAppShareInfoUrl());
      ShareInfoVO shareInfoVO = new ShareInfoVO();
      String shareUrl = String.format("%s?id=" + id, Constant.systemCommonConfig.getAppShareInfoUrl());
      ShareVO shareInfoVO = new ShareVO();
      shareInfoVO.setUrl(shareUrl);
      shareInfoVO.setHelpLink(helpLink);
      extraVO.setShareInfo(shareInfoVO);
      extraVO.setShare(shareInfoVO);
      JSONObject object = new JSONObject();
      object.put("code", 0);
      object.put("data", JsonUtil.getApiCommonGson().toJson(extraVO));
      out.print(object.toString());
      object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
      object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
      out.print(JsonUtil.loadTrueResult(object.toString()));
      final TaoBaoGoodsBrief goodsInfo = tb;
      ThreadUtil.run(new Runnable() {
@@ -720,8 +543,9 @@
      });
   }
   /**
    * 京东商品额外配置信息
    * 京东商品详情
    * 
    * @param acceptData
    * @param id
@@ -729,7 +553,9 @@
    * @param from
    * @param out
    */
   public void getJDExtraDetial(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
   @RequestMapping(value = "getDetailJD", method = RequestMethod.POST)
   public void getDetialJD(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      // 系统验证
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
@@ -737,17 +563,10 @@
         return;
      }
      GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
      // IOS是否正在上线
      if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id);
      JDGoods jdGoods = JDApiUtil.queryGoodsDetail(id); // 高级接口
      if (jdGoods == null) {
         jdGoods = JDApiUtil.getGoodsDetail(id);
         jdGoods = JDUtil.getGoodsDetail(id); // 爬取网页
         //jdGoods = JDApiUtil.getGoodsDetail(id); // 普通接口
      }
      
      if (jdGoods == null) {
@@ -755,10 +574,35 @@
         return;
      }
      
      List<String> imageList = jdGoods.getImageList();
      if (imageList == null) {
         imageList = new ArrayList<String>();
         imageList.add(jdGoods.getPicUrl());
      }
      // 保存缓存
      jdGoodsCacheUtil.saveGoodsInfo(jdGoods);
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertJDGoods(jdGoods, null, fanLiRate, shareRate);
      ShopInfoVO shopInfo = goodsDetail.getShopInfo();
      if (shopInfo != null) {
         if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
               || shopInfo.getScoreSeller() == null) {
            goodsDetail.setShopInfo(null);
         }
      }
      GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
      extraVO.setIsNative(false);
      // IOS是否正在上线
      if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      Long inOrderCount30Days = jdGoods.getInOrderCount30Days();
      List<ShamUser> listShareUser = new ArrayList<ShamUser>();
@@ -794,11 +638,14 @@
         extraVO.setStorage(userGoodsStorageService.isExistStorage(uid, id, Constant.SOURCE_TYPE_JD));
      }
      // 图文详情
      extraVO.setDetailUrl("https://in.m.jd.com/product/jieshao/video/"+ id +".html");
      // 测试
      SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
            "goods_detail_jump_taobao");
      if ("1".equalsIgnoreCase((params.getValue() + "").trim())) {
         extraVO.setNative(true);
         extraVO.setIsNative(true);
      }
      // 商品链接
@@ -820,15 +667,15 @@
      // 分享路径
      String shareUrl = String.format("%s?id=" + jdGoods.getSkuId(),
            Constant.systemCommonConfig.getAppShareInfoUrl());
      ShareInfoVO shareInfoVO = new ShareInfoVO();
      ShareVO shareInfoVO = new ShareVO();
      shareInfoVO.setUrl(shareUrl);
      shareInfoVO.setHelpLink(helpLink);
      extraVO.setShareInfo(shareInfoVO);
      extraVO.setShare(shareInfoVO);
      JSONObject object = new JSONObject();
      object.put("code", 0);
      object.put("data", JsonUtil.getApiCommonGson().toJson(extraVO));
      out.print(object.toString());
      object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
      object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
      out.print(JsonUtil.loadTrueResult(object.toString()));
      final JDGoods goods = jdGoods;
      ThreadUtil.run(new Runnable() {
@@ -836,7 +683,6 @@
            // 添加浏览记录
            try {
               scanHistoryV2Service.addJDScanHistory(uid, acceptData.getDevice(), goods);
               ;
            } catch (Exception e) {
               e.printStackTrace();
            }
@@ -845,7 +691,7 @@
   }
   /**
    * 京东商品额外配置信息
    * 拼多多商品详情
    * 
    * @param acceptData
    * @param id
@@ -853,19 +699,14 @@
    * @param from
    * @param out
    */
   public void getPDDExtraDetial(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
   @RequestMapping(value = "getDetailPDD", method = RequestMethod.POST)
   public void getDetialPDD(AcceptData acceptData, Long id, Long uid, String from, PrintWriter out) {
      // 系统验证
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult(1, "系统不存在"));
         return;
      }
      GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
      // IOS是否正在上线
      if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(id);
@@ -878,27 +719,53 @@
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, null, fanLiRate, shareRate);
      //店铺信息
      extraVO.setShopInfo(ShopInfoVOFactory.convertPDDShop(pddGoods));
      Long inOrderCount30Days = pddGoods.getSoldQuantity();
      List<ShamUser> listShareUser = new ArrayList<ShamUser>();
      MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
      if (moneyInfo != null) {
         String shareMoney = moneyInfo.getShareMoney().replaceAll("¥", "");
         if (Integer.parseInt(inOrderCount30Days.toString()) >= 50000) {
            listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5);
      ShopInfoVO shopInfo = goodsDetail.getShopInfo();
      if (shopInfo != null) {
         if (shopInfo.getId() == null || shopInfo.getScoreGoods() == null || shopInfo.getScoreLogistics() == null
               || shopInfo.getScoreSeller() == null) {
            goodsDetail.setShopInfo(null);
         }
      }
      extraVO.setListShareUser(listShareUser);
      // 领券人列表
      List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
      if (goodsDetail.isHasCoupon() && Integer.parseInt(inOrderCount30Days.toString()) >= 50000) {
         listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
      GoodsDetailExtraVO extraVO = new GoodsDetailExtraVO();
      extraVO.setIsNative(false);
      // IOS是否正在上线
      if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      extraVO.setListCouponUser(listCouponUser);
      // 图文详情
      extraVO.setDetailUrl("http://apph5.yeshitv.com/apppage/goods_img_pdd.html?id="+ id);
      String salesTip = pddGoods.getSalesTip();
      if (!StringUtil.isNullOrEmpty(salesTip)) {
         int totalSales = 0;
         if (salesTip.contains("万")) {
            salesTip = salesTip.substring(0, salesTip.indexOf("万"));
            totalSales= (int) (Float.parseFloat(salesTip) * 10000);
         } else {
            totalSales = Integer.parseInt(salesTip);
         }
         List<ShamUser> listShareUser = new ArrayList<ShamUser>();
         MoneyInfoVO moneyInfo = goodsDetail.getMoneyInfo();
         if (moneyInfo != null) {
            String shareMoney = moneyInfo.getShareMoney().replaceAll("¥", "");
            if (totalSales >= 50000) {
               listShareUser = shamUserService.listRandShareUser(10, new BigDecimal(shareMoney), 1, 5);
            }
         }
         extraVO.setListShareUser(listShareUser);
         // 领券人列表
         List<ShamUser> listCouponUser = new ArrayList<ShamUser>();
         if (goodsDetail.isHasCoupon() && totalSales >= 50000) {
            listCouponUser = shamUserService.listRandCouponUser(5, 1, 300);
         }
         extraVO.setListCouponUser(listCouponUser);
      }
      if (uid != null) {
         // 是否加入收藏
         CollectionGoodsV2 collectionGoods = collectionGoodsV2Service.findByUidAndAuctionId(uid, id,
@@ -912,7 +779,7 @@
      SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
            "goods_detail_jump_taobao");
      if ("1".equalsIgnoreCase((params.getValue() + "").trim())) {
         extraVO.setNative(true);
         extraVO.setIsNative(true);
      }
      // 商品链接
@@ -933,26 +800,276 @@
      }
      // 分享路径
      String shareUrl = String.format("%s?id=" + id, Constant.systemCommonConfig.getAppShareInfoUrl());
      ShareInfoVO shareInfoVO = new ShareInfoVO();
      ShareVO shareInfoVO = new ShareVO();
      shareInfoVO.setUrl(shareUrl);
      shareInfoVO.setHelpLink(helpLink);
      extraVO.setShareInfo(shareInfoVO);
      extraVO.setShare(shareInfoVO);
      JSONObject object = new JSONObject();
      object.put("code", 0);
      object.put("data", JsonUtil.getApiCommonGson().toJson(extraVO));
      out.print(object.toString());
      object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
      object.put("goods", JsonUtil.getApiCommonGson().toJson(goodsDetail));
      out.print(JsonUtil.loadTrueResult(object.toString()));
      ThreadUtil.run(new Runnable() {
         public void run() {
            // 添加浏览记录
            try {
               scanHistoryV2Service.addPDDScanHistory(uid, acceptData.getDevice(), pddGoods);
               ;
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
      });
   }
   /**
    * 商品详情推荐(猜你喜欢  +  推荐)
    *
    * @param acceptData
    * @param id
    * @param out
    */
   @RequestMapping(value = "getRecommendGoods", method = RequestMethod.POST)
   public void getRecommendGoods(AcceptData acceptData, long id, Integer goodsType, PrintWriter out) {
      if (goodsType == null) {
         goodsType = Constant.SOURCE_TYPE_TAOBAO;
      }
      // 京东
      if (goodsType == Constant.SOURCE_TYPE_JD) {
         JSONObject data = new JSONObject();
         data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         List<JDGoods> list = JDUtil.getRecommendGoodsById(id);
         if (list == null) {
            list = new ArrayList<JDGoods>();
         } else if (list.size() > 10) {
            list = list.subList(0, 10);
         }
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
         for (JDGoods goods: list) {
            listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, null, fanLiRate, shareRate));
         }
         // 取偶数个数据
         if (listDetailVO.size() % 2 != 0) {
            listDetailVO.remove(listDetailVO.size() - 1);
         }
         data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
         out.print(JsonUtil.loadTrueResult(data));
         return;
      }
      // 拼多多
      if (goodsType == Constant.SOURCE_TYPE_PDD) {
         JSONObject data = new JSONObject();
         data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
         List<Long> goodsIdList = PinDuoDuoUtil.getRecommendGoodsId(id);
         if (goodsIdList != null && goodsIdList.size() > 0) {
            PDDSearchFilter pddfilter = new PDDSearchFilter();
            pddfilter.setPage(1);
            pddfilter.setPageSize(Constant.PAGE_SIZE);
            Long[] strings = new Long[goodsIdList.size()];
            pddfilter.setGoodsIdList(goodsIdList.toArray(strings));
            PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter);
            if (result != null) {
               List<PDDGoodsDetail> goodsList = result.getGoodsList();
               if (goodsList != null && goodsList.size() > 0) {
                  if (goodsList.size() > 10) {
                     goodsList = goodsList.subList(0, 10);
                  }
                  BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
                  BigDecimal shareRate = hongBaoManageService.getShareRate();
                  for (PDDGoodsDetail goods : goodsList) {
                     listDetailVO.add(GoodsDetailVOFactory.convertPDDGoods(goods, null, fanLiRate, shareRate));
                  }
               }
            }
         }
         // 取偶数个数据
         if (listDetailVO.size() % 2 != 0) {
            listDetailVO.remove(listDetailVO.size() - 1);
         }
         data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
         out.print(JsonUtil.loadTrueResult(data));
         return;
      }
      List<TaoBaoGoodsBrief> goodsList = TaoKeApiUtil.getRelationGoodsRecommend(id, 10);
      // 初始化
      if (goodsList == null) {
         goodsList = new ArrayList<TaoBaoGoodsBrief>();
      }
      List<GoodsDetailVO> listExtra = new ArrayList<GoodsDetailVO>();
      TaoKeAppInfo app = new TaoKeAppInfo();
      app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
      app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
      app.setAdzoneId(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
      app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
      List<Long> ids = new ArrayList<>();
      for (TaoBaoGoodsBrief goods : goodsList)
         ids.add(goods.getAuctionId());
      try {
         goodsList = TaoKeApiUtil.getBatchGoodsInfo(ids);
      } catch (TaoKeApiException e1) {
         e1.printStackTrace();
      } catch (TaobaoGoodsDownException e1) {
         e1.printStackTrace();
      }
      if (goodsList != null && goodsList.size() > 0) {
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         goodsList.parallelStream().forEach(goods -> {
            if (goods != null) {
               // 获取详情
               TaoBaoGoodsBrief taoBaoGoodsBrief = null;
               try {
                  taoBaoGoodsBrief = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goods.getAuctionId());
               } catch (Exception e) {
                  e.printStackTrace();
               }
               if (taoBaoGoodsBrief == null) {
                  TaoBaoGoodsBrief newGoods = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app);
                  goods.setCouponInfo(newGoods.getCouponInfo());
                  goods.setCouponLink(newGoods.getCouponLink());
                  goods.setTkRate(newGoods.getTkRate());
                  taoBaoGoodsBrief = goods;
               }
               if (taoBaoGoodsBrief != null) {
                  listExtra.add(GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate));
               }
            }
         });
      }
      List<GoodsDetailVO> listQuality = new ArrayList<GoodsDetailVO>();
      // 取偶数个数据
      if (listExtra.size() % 2 != 0) {
         listExtra.remove(listExtra.size() - 1);
      }
      if (listQuality.size() % 2 != 0) {
         listQuality.remove(listQuality.size() - 1);
      }
      JSONObject data = new JSONObject();
      data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listExtra));
      data.put("listGuess", JsonUtil.getApiCommonGson().toJson(listQuality));
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 京东购买链接
    * @param acceptData
    * @param uid
    * @param id
    * @param source
    * @param request
    * @param out
    */
   @RequestMapping(value = "getJDLink")
   public void getJDLink(AcceptData acceptData, Long uid, Long id, String source, PrintWriter out) {
      if (uid == null || uid <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
         return;
      }
      if (id == null || id <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "商品ID不能为空"));
         return;
      }
      UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
      if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
         out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
         return;
      }
      JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(id);
      if (goods == null) {
         out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
         return;
      }
      String couponUrl = null;
      String materialId = "https://item.jd.com/" + id + ".html";
      JDCouponInfo couponInfo = goods.getCouponInfo();
      if (couponInfo != null) {
         couponUrl = couponInfo.getLink();
      }
      String jumpLink = JDApiUtil.convertLink(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", id + "");
      JSONObject data = new JSONObject();
      data.put("native", true);
      data.put("jumpLink", jumpLink);
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 拼多多购买链接
    * @param acceptData
    * @param uid
    * @param id
    * @param source
    * @param request
    * @param out
    */
   @RequestMapping(value = "getPDDLink")
   public void getPDDLink(AcceptData acceptData, Long uid, Long id, String source, PrintWriter out) {
      if (uid == null || uid <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
         return;
      }
      if (id == null || id <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "商品ID不能为空"));
         return;
      }
      UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
      if (user != null && user.getState() != UserInfo.STATE_NORMAL) {
         out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
         return;
      }
      PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(id);
      if (goods == null) {
         out.print(JsonUtil.loadFalseResult(2, "商品已下架"));
         return;
      }
      String jumpLink = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_FANLI + "", uid + "");
      JSONObject data = new JSONObject();
      data.put("native", true);
      data.put("jumpLink", jumpLink);
      out.print(JsonUtil.loadTrueResult(data));
   }
}