yujian
2019-07-17 20d1a38a0f8049873f1fbbaef96c22e971ea9d77
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;
@@ -69,7 +70,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;
@@ -159,13 +160,13 @@
    */
   @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和商品平台不能为空"));
      if (id == null) {
         out.print(JsonUtil.loadFalseResult(1, "商品id不能为空"));
         return;
      }
      // 淘宝商品
      if (Constant.SOURCE_TYPE_TAOBAO == goodsType) {
      if (goodsType == null || Constant.SOURCE_TYPE_TAOBAO == goodsType) {
         getTaoBaoGoodsDetial(acceptData, id, uid, from, out);
         return;
      }
@@ -346,10 +347,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 +451,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 +512,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 +537,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));
@@ -664,10 +665,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));
@@ -776,10 +777,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 +798,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));
   }
}