yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/GoodsControllerV2.java
@@ -3,10 +3,12 @@
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.json.simple.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -17,6 +19,7 @@
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.PDDPromotionUrl;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.ShamUser;
@@ -410,7 +413,7 @@
      // 推广红包
      if (from != null && from.equals("taolijin")) {
         // 计算推广红包
         String warningRate = configTaoLiJinService.getValueByKey("warning_value");
         String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date());
         BigDecimal spreadMoney = TaoLiJinUtil.getSpreadMoney(warningRate, goods);
         // 推广红包 不能小于1
@@ -419,8 +422,8 @@
            return;
         }
         // 是否为新用户
         boolean isNewUser = userInfoExtraService.isNewUser(uid);
         // 取消新用户自购
         boolean isNewUser = false;// userInfoExtraService.isNewUser(uid);
         if (isNewUser) {
            // 判定为老用户: 新人只要使用了新人红包,也就是那1块钱,那么,他看到的分享爆款中的商品-就只能分享。
            long countRecord = userTaoLiJinRecordService.countRecordByUid(uid);
@@ -464,6 +467,11 @@
         otherInfo.setSpreadHongBao(spreadHongBao);
         goodsDetail.setOtherInfo(otherInfo);
         goodsDetail.getMoneyInfo().setFanliMoney(TaoBaoUtil.getGoodsHongBaoInfo(goods,
               hongBaoManageService.getTLJShareRate(System.currentTimeMillis())));
         goodsDetail.getMoneyInfo().setShareMoney(TaoBaoUtil.getGoodsHongBaoInfo(goods,
               hongBaoManageService.getTLJShareRate(System.currentTimeMillis())));
         // 用户淘礼金
         UserMoneyExtra userMoneyExtra = userMoneyExtraService.selectByPrimaryKey(uid);
         if (userMoneyExtra == null || userMoneyExtra.getTlj() == null) {
@@ -471,7 +479,7 @@
         } else {
            extraVO.setUserTLJ(userMoneyExtra.getTlj().setScale(2).toString());
         }
         helpLink = configTaoLiJinService.getValueByKey("share_goods_help_link");
         helpLink = configTaoLiJinService.getValueByKey("share_goods_help_link", new Date());
      } else if (from != null && from.equals("taolijin_buy")) {
         // 查询分享库
@@ -583,8 +591,7 @@
      if (couponInfo != null) {
         // 券链接处理
         String materialId = "https://item.jd.com/" + id + ".html";
         String url = JDApiUtil.convertShortLink(materialId, couponInfo.getLink(), JDApiUtil.POSITION_COUPON + "",
               null);
         String url = JDApiUtil.convertLink(materialId, couponInfo.getLink(), JDApiUtil.POSITION_COUPON + "", null);
         couponInfo.setLink(url);
      }
@@ -715,9 +722,11 @@
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      GoodsDetailVO goodsDetail = GoodsDetailVOFactory.convertPDDGoods(pddGoods, fanLiRate, shareRate);
      CouponInfoVO couponInfo = goodsDetail.getCouponInfo();
      PDDPromotionUrl convertUrl = null;
      if (couponInfo != null) {
         String url = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_COUPON + "", null);
         couponInfo.setLink(url);
         convertUrl = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_COUPON + "", null);
         if (convertUrl != null)
            couponInfo.setLink(convertUrl.getUrl());
      }
      ShopInfoVO shopInfo = goodsDetail.getShopInfo();
@@ -741,6 +750,11 @@
      String salesTip = pddGoods.getSalesTip();
      if (!StringUtil.isNullOrEmpty(salesTip)) {
         int indexOf = salesTip.indexOf("+");
         if (indexOf > 0) {
            salesTip = salesTip.substring(0, indexOf);
         }
         int totalSales = 0;
         if (salesTip.contains("万")) {
            salesTip = salesTip.substring(0, salesTip.indexOf("万"));
@@ -776,12 +790,7 @@
         extraVO.setStorage(userGoodsStorageService.isExistStorage(uid, id, Constant.SOURCE_TYPE_PDD));
      }
      // 测试
      SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
            "goods_detail_jump_taobao");
      if ("1".equalsIgnoreCase((params.getValue() + "").trim())) {
         extraVO.setIsNative(true);
      }
      extraVO.setIsNative(true);
      // 分享路径
      String h5Url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(),
@@ -803,6 +812,11 @@
      ShareVO shareInfoVO = new ShareVO();
      shareInfoVO.setHelpLink(helpLink);
      extraVO.setShare(shareInfoVO);
      if (convertUrl != null) {
         extraVO.setCouponJumpLink(convertUrl.getUrl());
         extraVO.setNativeCouponJumpLink(PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl()));
      }
      JSONObject object = new JSONObject();
      object.put("extra", JsonUtil.getApiCommonGson().toJson(extraVO));
@@ -834,148 +848,156 @@
         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, 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, 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) {
         // 京东
         if (goodsType == Constant.SOURCE_TYPE_JD) {
            JSONObject data = new JSONObject();
            data.put("listGuess", JsonUtil.getApiCommonGson().toJson(new ArrayList<GoodsDetailVO>()));
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
            List<JDGoods> list = JDUtil.getRecommendGoodsById(id);
            if (list == null) {
               list = new ArrayList<JDGoods>();
            } else if (list.size() > 10) {
               list = list.subList(0, 10);
            }
         goodsList.parallelStream().forEach(goods -> {
            if (goods != null) {
               // 获取详情
               TaoBaoGoodsBrief taoBaoGoodsBrief = null;
               try {
                  taoBaoGoodsBrief = taoBaoGoodsCacheUtil.getCommonTaoBaoGoodsInfo(goods.getAuctionId());
               } catch (Exception e) {
                  e.printStackTrace();
               }
            BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
            BigDecimal shareRate = hongBaoManageService.getShareRate();
            List<GoodsDetailVO> listDetailVO = new ArrayList<GoodsDetailVO>();
               if (taoBaoGoodsBrief == null) {
                  TaoBaoGoodsBrief newGoods = TaoKeApiUtil.specialConvertCoupon(goods.getAuctionId(), app);
                  goods.setCouponInfo(newGoods.getCouponInfo());
                  goods.setCouponLink(newGoods.getCouponLink());
                  goods.setTkRate(newGoods.getTkRate());
                  taoBaoGoodsBrief = goods;
               }
            for (JDGoods goods : list) {
               listDetailVO.add(GoodsDetailVOFactory.convertJDGoods(goods, fanLiRate, shareRate));
            }
               if (taoBaoGoodsBrief != null) {
                  listExtra.add(GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, 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, fanLiRate, shareRate));
                     }
                  }
               }
            }
         });
      }
      List<GoodsDetailVO> listQuality = new ArrayList<GoodsDetailVO>();
      // 取偶数个数据
      if (listExtra.size() % 2 != 0) {
         listExtra.remove(listExtra.size() - 1);
      }
            // 取偶数个数据
            if (listDetailVO.size() % 2 != 0) {
               listDetailVO.remove(listDetailVO.size() - 1);
            }
      if (listQuality.size() % 2 != 0) {
         listQuality.remove(listQuality.size() - 1);
      }
            data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listDetailVO));
            out.print(JsonUtil.loadTrueResult(data));
            return;
         }
      JSONObject data = new JSONObject();
      data.put("listQuality", JsonUtil.getApiCommonGson().toJson(listExtra));
      data.put("listGuess", JsonUtil.getApiCommonGson().toJson(listQuality));
      out.print(JsonUtil.loadTrueResult(data));
         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) {
         } catch (TaobaoGoodsDownException e1) {
         }
         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));
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
         JSONObject data = new JSONObject();
         data.put("listQuality", new JSONArray());
         data.put("listGuess", new JSONArray());
         out.print(JsonUtil.loadTrueResult(data));
      }
   }
   /**
@@ -1018,7 +1040,7 @@
      if (couponInfo != null) {
         couponUrl = couponInfo.getLink();
      }
      String jumpLink = JDApiUtil.convertShortLink(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", uid + "");
      String jumpLink = JDApiUtil.convertLink(materialId, couponUrl, JDApiUtil.POSITION_FANLI + "", uid + "");
      JSONObject data = new JSONObject();
      data.put("native", true);
@@ -1060,10 +1082,11 @@
         return;
      }
      String jumpLink = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_FANLI + "", uid + "");
      PDDPromotionUrl convertUrl = PinDuoDuoApiUtil.convert(id, PinDuoDuoApiUtil.PID_FANLI + "", uid + "");
      JSONObject data = new JSONObject();
      data.put("native", true);
      data.put("jumpLink", jumpLink);
      data.put("jumpLink", convertUrl.getUrl());
      data.put("nativeJumpLink", PinDuoDuoUtil.getAndroidNativeURI(convertUrl.getUrl()));
      out.print(JsonUtil.loadTrueResult(data));
   }