admin
2019-07-23 009e25b40c04d0a66d6d6554c19e542f0e6f9d18
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java
@@ -28,6 +28,7 @@
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;
@@ -57,6 +58,7 @@
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.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.factory.goods.ShopInfoVOFactory;
@@ -69,7 +71,7 @@
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.msg.ClientTextStyleVO;
import com.yeshi.fanli.vo.tlj.ReduceHongBao;
import com.yeshi.fanli.vo.tlj.SpreadHongBao;
@@ -146,42 +148,8 @@
   @Resource
   private TLJBuyGoodsService tljBuyGoodsService;
   
   /**
    * 获取商品详情
    *
    * @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;
      }
      // 淘宝商品
      if (Constant.SOURCE_TYPE_TAOBAO == goodsType) {
         getTaoBaoGoodsDetial(acceptData, id, uid, from, out);
         return;
      }
      // 京东商品
      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;
      }
   }
   @Resource
   private JDGoodsCacheUtil jdGoodsCacheUtil;
   
   
   /**
@@ -192,12 +160,13 @@
    * @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"));
         out.print(JsonUtil.loadFalseResult(1, "商品id不能为空"));
         return;
      }
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
@@ -346,10 +315,10 @@
      
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertTaoBao(tb, null, fanLiRate, shareRate);
      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)) {
@@ -450,11 +419,11 @@
         SpreadHongBao spreadHongBao = new SpreadHongBao();
         if (isNewUser) {
            spreadHongBao.setMoney("¥1");
            spreadHongBao.setMoney("1");
         } else {
            moneyType = 2;
            fanliValid = false;
            spreadHongBao.setMoney("¥" + spreadMoney.toString());
            spreadHongBao.setMoney(spreadMoney.toString());
            
            ClientTextStyleVO textStyleVO1 = new ClientTextStyleVO();
            textStyleVO1.setContent("分享");
@@ -511,7 +480,7 @@
         ReduceHongBao reduceHongBao = new ReduceHongBao();
         reduceHongBao.setLeft(buyGoods.getLeftHongBaoCount());
         reduceHongBao.setMoney(tljHongBao);
         reduceHongBao.setName("付款立减 ¥" + tljHongBao);
         reduceHongBao.setName("付款立减 ");
         reduceHongBao.setTip("当日领取,当日内使用,过期失效");
         reduceHongBao.setTotal(buyGoods.getTotalHongBaoCount());
         
@@ -536,10 +505,10 @@
      
      // 分享路径
      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("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
@@ -569,7 +538,8 @@
    * @param from
    * @param out
    */
   public void getJDGoodsDetial(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());
@@ -587,6 +557,10 @@
         out.print(JsonUtil.loadFalseResult(2, "商品不存在"));
         return;
      }
      // 保存缓存
      jdGoodsCacheUtil.saveGoodsInfo(jdGoods);
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
@@ -664,10 +638,10 @@
      // 分享路径
      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("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
@@ -688,7 +662,7 @@
   }
   /**
    * 京东商品详情
    * 拼多多商品详情
    * 
    * @param acceptData
    * @param id
@@ -696,7 +670,8 @@
    * @param from
    * @param out
    */
   public void getPDDGoodsDetial(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());
@@ -722,7 +697,9 @@
         String version = acceptData.getVersion();
         extraVO.setIosOnling(configService.iosOnLining(Integer.parseInt(version)));
      }
      // 图文详情
      extraVO.setDetailUrl("http://apph5.yeshitv.com/apppage/goods_img_pdd.html?id="+ id);
      
      Long inOrderCount30Days = pddGoods.getSoldQuantity();
      List<ShamUser> listShareUser = new ArrayList<ShamUser>();
@@ -776,10 +753,10 @@
      }
      // 分享路径
      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("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
@@ -797,5 +774,112 @@
         }
      });
   }
   /**
    * 商品详情推荐(猜你喜欢  +  推荐)
    *
    * @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("listQuality", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         out.print(JsonUtil.loadTrueResult(data));
         return;
      }
      // 拼多多
      if (goodsType == Constant.SOURCE_TYPE_PDD) {
         JSONObject data = new JSONObject();
         data.put("listQuality", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         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));
   }
}