yujian
2019-12-10 c8041ec0544bf122e6819e6bf698997ccbf30aaf
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java
@@ -3,7 +3,9 @@
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@@ -15,6 +17,7 @@
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.jd.JDCategoryInfo;
import com.yeshi.fanli.dto.jd.JDCouponInfo;
@@ -26,6 +29,7 @@
import com.yeshi.fanli.entity.bus.user.ShamUser;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.jd.JDGoodsClass;
import com.yeshi.fanli.entity.system.BusinessSystem;
@@ -494,6 +498,12 @@
         otherInfo.setReduceHongBao(newUserHongBao);
         goodsDetail.setOtherInfo(otherInfo);
         
         // 专属标签
         List<ClientTextStyleVO> labels = new ArrayList<ClientTextStyleVO>();
         labels.add(new ClientTextStyleVO("新人专属", "#FE0014"));
         labels.add(new ClientTextStyleVO("实付0元", "#FF9600"));
         goodsDetail.setLabels(labels);
      } else {// 普通购买
         OtherInfo otherInfo = new OtherInfo();
         RewardCouponVO rewardCoupon = new RewardCouponVO();
@@ -610,14 +620,14 @@
               jdGoods.setCommissionPlus(threeClass.getSelfComm());
               // plus返利
               BigDecimal fanliMoneyPlus = JDUtil.getGoodsFanLiMoneyPlus(jdGoods, fanLiRate);
               otherInfo.setFanliMoneyPlus("京东plus会员返¥" + fanliMoneyPlus);
               otherInfo.setFanliMoneyPlus("京东plus返¥" + fanliMoneyPlus);
               // 使用奖励券最高返
               if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
                  maxMoneyPlus = "(京东plus返¥"
                        + fanliMoneyPlus.add(MoneyBigDecimalUtil.mul(fanliMoneyPlus, Constant.MAX_REWARD_RATE))
                        + ")";
               } else
                  maxMoneyPlus = "(京东plus会员最高返¥"
                  maxMoneyPlus = "(京东plus最高返¥"
                        + fanliMoneyPlus.add(MoneyBigDecimalUtil.mul(fanliMoneyPlus, Constant.MAX_REWARD_RATE))
                        + ")";
            }
@@ -648,7 +658,8 @@
      if (couponInfo != null) {
         // 券链接处理
         String materialId = "https://item.jd.com/" + id + ".html";
         String url = JDApiUtil.convertLink(materialId, couponInfo.getLink(), JDApiUtil.POSITION_COUPON + "", null);
         String url = JDApiUtil.convertLinkWithSubUnionId(materialId, couponInfo.getLink(),
               JDApiUtil.POSITION_COUPON + "", null);
         couponInfo.setLink(url);
      }
@@ -1123,9 +1134,11 @@
         if (couponInfo != null) {
            couponUrl = couponInfo.getLink();
         }
         jumpLink = JDApiUtil.convertLink(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", uid + "");
         jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "",
               uid + "");
      } else {
         jumpLink = JDApiUtil.convertLink(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", uid + "");
         jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "",
               uid + "");
      }
      JSONObject data = new JSONObject();
@@ -1151,7 +1164,7 @@
      String jumpLink = null;
      String materialId = "https://item.jd.com/" + id + ".html";
      jumpLink = JDApiUtil.convertLink(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", null + "");
      jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", null);
      JSONObject data = new JSONObject();
      data.put("native", true);
@@ -1260,4 +1273,92 @@
      }
      out.print(JsonUtil.loadTrueResult(data));
   }
   @RequestMapping(value = "listSimpleGoods", method = RequestMethod.POST)
   public void listSimpleGoods(AcceptData acceptData, String goodsInfo, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(goodsInfo)) {
         out.print(JsonUtil.loadFalseResult(1, "商品信息为空"));
         return;
      }
      net.sf.json.JSONArray array = net.sf.json.JSONArray.fromObject(goodsInfo);
      List<CommonGoods> commonGoodsList = new ArrayList<>();
      for (int i = 0; i < array.size(); i++) {
         JSONObject obj = array.optJSONObject(i);
         CommonGoods cg = new CommonGoods();
         cg.setGoodsId(obj.optLong("goodsId"));
         cg.setGoodsType(obj.optInt("goodsType"));
         commonGoodsList.add(cg);
      }
      if (commonGoodsList.size() > 9) {
         out.print(JsonUtil.loadFalseResult(1, "最多同时获取9条数据"));
         return;
      }
      // 分离各个平台的商品信息
      List<Long> tbGoodsList = new ArrayList<>();
      List<Long> jdGoodsList = new ArrayList<>();
      List<Long> pddGoodsList = new ArrayList<>();
      List<String> keyList = new ArrayList<>();
      for (CommonGoods cg : commonGoodsList) {
         keyList.add(cg.getGoodsId() + "-" + cg.getGoodsType());
         if (cg.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
            tbGoodsList.add(cg.getGoodsId());
         } else if (cg.getGoodsType() == Constant.SOURCE_TYPE_JD) {
            jdGoodsList.add(cg.getGoodsId());
         } else if (cg.getGoodsType() == Constant.SOURCE_TYPE_PDD) {
            pddGoodsList.add(cg.getGoodsId());
         }
      }
      Map<String, GoodsDetailVO> tempGoodsList = new HashMap<>();
      ConfigParamsDTO params = new ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
            hongBaoManageService.getShareRate(), new BigDecimal(80));
      if (tbGoodsList.size() > 0) {
         List<TaoBaoGoodsBrief> goodsList = null;
         try {
            goodsList = TaoKeApiUtil.getBatchGoodsInfo(tbGoodsList);
         } catch (TaobaoGoodsDownException e) {
            e.printStackTrace();
         } catch (TaoKeApiException e) {
            e.printStackTrace();
         }
         if (goodsList != null)
            for (TaoBaoGoodsBrief goods : goodsList) {
               goods.setTkRate(new BigDecimal(0));
               tempGoodsList.put(goods.getAuctionId() + "-" + Constant.SOURCE_TYPE_TAOBAO,
                     GoodsDetailVOFactory.convertTaoBao(goods, params));
            }
      }
      if (jdGoodsList.size() > 0) {
         List<JDGoods> goodsList = JDApiUtil.getGoodsDetail(jdGoodsList);
         for (JDGoods goods : goodsList) {
            tempGoodsList.put(goods.getSkuId() + "-" + Constant.SOURCE_TYPE_JD,
                  GoodsDetailVOFactory.convertJDGoods(goods, params));
         }
      }
      if (pddGoodsList.size() > 0) {
         List<PDDGoodsDetail> goodsList = PinDuoDuoApiUtil.listGoodsDetail(pddGoodsList);
         for (PDDGoodsDetail goods : goodsList) {
            tempGoodsList.put(goods.getGoodsId() + "-" + Constant.SOURCE_TYPE_PDD,
                  GoodsDetailVOFactory.convertPDDGoods(goods, params));
         }
      }
      List<GoodsDetailVO> voList = new ArrayList<>();
      Gson gson = JsonUtil.getApiCommonGson();
      for (String key : keyList) {
         GoodsDetailVO vo = tempGoodsList.get(key);
         if (vo != null) {
            voList.add(vo);
         }
      }
      out.print(JsonUtil.loadTrueResult(gson.toJson(voList)));
   }
}