| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | |
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.yeshi.fanli.dto.common.CategoryInfoDTO;
|
| | | import com.yeshi.fanli.dto.common.GoodsOtherInfoDTO;
|
| | | import com.yeshi.fanli.dto.jd.JDCategoryInfo;
|
| | | import com.yeshi.fanli.dto.jd.JDCommissionInfo;
|
| | | import com.yeshi.fanli.dto.jd.JDCouponInfo;
|
| | | import com.yeshi.fanli.dto.jd.JDShopInfo;
|
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.jd.JDGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.jd.JDUtil;
|
| | |
|
| | | public class CommonGoodsFactory {
|
| | |
|
| | |
| | | cg.setVideoUrl(null);
|
| | | cg.setState(goods.getState());
|
| | | cg.setMaterialLibType(goods.getMaterialLibType());
|
| | | |
| | | |
| | | // 分类信息
|
| | | CategoryInfoDTO categoryInfo = new CategoryInfoDTO();
|
| | | Integer rootCatId = goods.getRootCatId();
|
| | | if (rootCatId != null) {
|
| | | categoryInfo.setCid1(Long.parseLong(rootCatId.toString()));
|
| | | }
|
| | | categoryInfo.setCid1Name(goods.getRootCategoryName());
|
| | | |
| | | Integer leafCatId = goods.getLeafCatId();
|
| | | if (leafCatId != null) {
|
| | | categoryInfo.setCid2(Long.parseLong(leafCatId.toString()));
|
| | | }
|
| | | categoryInfo.setCid2Name(goods.getLeafName());
|
| | | cg.setCategoryInfo(JSONObject.toJSON(categoryInfo).toString());
|
| | | |
| | | return cg;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 淘宝商品构造
|
| | | * |
| | | * @param goods
|
| | | * @return
|
| | | */
|
| | | public static CommonGoods create(JDGoods goods) {
|
| | | if (goods == null)
|
| | | return null;
|
| | |
|
| | | CommonGoods cg = new CommonGoods();
|
| | | JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(goods);
|
| | | if (couponInfo != null) {
|
| | | cg.setCouponStartPrice(couponInfo.getQuota());
|
| | | BigDecimal discount = couponInfo.getDiscount();
|
| | | if (discount != null && discount.compareTo(new BigDecimal(0)) > 0) {
|
| | | cg.setCouponAmount(discount);
|
| | | if (cg.getCouponStartPrice().compareTo(new BigDecimal(0)) > 0)
|
| | | cg.setCouponInfo(String.format("满%s元减%s元", couponInfo.getQuota() + "", cg.getCouponAmount() + ""));
|
| | | else
|
| | | cg.setCouponInfo(String.format("%s元无条件券", cg.getCouponAmount() + ""));
|
| | | } else {
|
| | | cg.setCouponAmount(new BigDecimal(0));
|
| | | }
|
| | | cg.setCouponLeftCount(1);
|
| | | cg.setCouponTotalCount(1);
|
| | | }
|
| | | |
| | | JDCommissionInfo commissionInfo = goods.getCommissionInfo();
|
| | | if (commissionInfo != null) {
|
| | | cg.setRate(commissionInfo.getCommissionShare());
|
| | | } else {
|
| | | cg.setRate(new BigDecimal(0));
|
| | | }
|
| | | |
| | | JDShopInfo shopInfo = goods.getShopInfo();
|
| | | if (shopInfo != null) {
|
| | | cg.setSellerId(Long.parseLong(shopInfo.getShopId().toString()));
|
| | | cg.setSellerName(shopInfo.getShopName()== null? "" : shopInfo.getShopName());
|
| | | }
|
| | | |
| | | cg.setGoodsId(goods.getSkuId());
|
| | | cg.setTitle(goods.getSkuName());
|
| | | cg.setGoodsType(CommonGoods.GOODS_TYPE_JD);
|
| | | cg.setPicture(goods.getPicUrl());
|
| | | cg.setPrice(goods.getPrice());
|
| | | cg.setSales(Integer.parseInt(goods.getInOrderCount30Days().toString()));
|
| | | |
| | | String owner = goods.getOwner();
|
| | | if (StringUtil.isNullOrEmpty(owner) && "g".equalsIgnoreCase(owner)) {
|
| | | cg.setShopType(CommonGoods.SHOP_TYPE_JD_SELF); // 京东自营
|
| | | } else {
|
| | | cg.setShopType(CommonGoods.SHOP_TYPE_JD); // 京东
|
| | | }
|
| | | |
| | | cg.setState(CommonGoods.STATE_NORMAL);
|
| | | |
| | | // 其他信息
|
| | | GoodsOtherInfoDTO other = new GoodsOtherInfoDTO();
|
| | | other.setOwner(owner); // 是否自营
|
| | | other.setPinGouInfo( goods.getPinGouInfo()); // 拼购信息
|
| | | other.setIsFreeShipping(goods.getIsFreeShipping()); // 是否包邮
|
| | | cg.setOtherInfo(JSONObject.toJSON(other).toString());
|
| | | |
| | | |
| | | // 分类信息
|
| | | JDCategoryInfo categoryJD = goods.getCategoryInfo();
|
| | | if (categoryJD != null) {
|
| | | CategoryInfoDTO categoryInfo = new CategoryInfoDTO();
|
| | | categoryInfo.setCid1(categoryJD.getCid1());
|
| | | categoryInfo.setCid1Name(categoryJD.getCid1Name());
|
| | | categoryInfo.setCid2(categoryJD.getCid2());
|
| | | categoryInfo.setCid2Name(categoryJD.getCid2Name());
|
| | | categoryInfo.setCid3(categoryJD.getCid3());
|
| | | categoryInfo.setCid3Name(categoryJD.getCid3Name());
|
| | | cg.setCategoryInfo(JSONObject.toJSON(categoryInfo).toString());
|
| | | }
|
| | | |
| | | // 保留字段
|
| | | cg.setVideoCover(null);
|
| | | cg.setVideoUrl(null);
|
| | | return cg;
|
| | | }
|
| | |
|
| | | |
| | | public static CommonGoods create(PDDGoodsDetail goods) {
|
| | | if (goods == null)
|
| | | return null;
|
| | |
| | | cg.setGoodsType(CommonGoods.GOODS_TYPE_PDD);
|
| | | cg.setPicture(goods.getGoodsThumbnailUrl());
|
| | | cg.setPictureWhite(null);
|
| | | cg.setPrice(MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinNormalPrice()), new BigDecimal(100)));
|
| | | cg.setSales(Integer.parseInt(goods.getSoldQuantity() + ""));
|
| | | cg.setPrice(MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)));
|
| | | |
| | | String salesTip = goods.getSalesTip();
|
| | | if (StringUtil.isNullOrEmpty(salesTip)) {
|
| | | salesTip = "0";
|
| | | } else {
|
| | | int indexOf = salesTip.indexOf("+");
|
| | | if (indexOf > 0) {
|
| | | salesTip = salesTip.substring(0, indexOf);
|
| | | }
|
| | | }
|
| | | |
| | | int totalSales = 0;
|
| | | if (salesTip.contains("万")) {
|
| | | salesTip = salesTip.substring(0, salesTip.indexOf("万"));
|
| | | totalSales= (int) (Float.parseFloat(salesTip) * 10000);
|
| | | } else {
|
| | | totalSales = Integer.parseInt(salesTip);
|
| | | }
|
| | | cg.setSales(totalSales);
|
| | | cg.setRate(MoneyBigDecimalUtil.div(new BigDecimal(goods.getPromotionRate()), new BigDecimal(10)));
|
| | | cg.setSellerId(goods.getMallId());
|
| | | cg.setSellerName(goods.getMallName());
|
| | | cg.setShopType(goods.getMerchantType());
|
| | | cg.setShopType(CommonGoods.SHOP_TYPE_PDD);
|
| | | cg.setState(CommonGoods.STATE_NORMAL);
|
| | | cg.setTitle(goods.getGoodsName());
|
| | | // 保留字段
|
| | |
| | | cg.setVideoUrl(null);
|
| | | cg.setState(goods.getState());
|
| | | cg.setMaterialLibType(1);
|
| | | |
| | | // 分类信息
|
| | | CategoryInfoDTO categoryInfo = new CategoryInfoDTO();
|
| | | categoryInfo.setCid1(goods.getCategoryId());
|
| | | categoryInfo.setCid1Name(goods.getCategoryName());
|
| | | cg.setCategoryInfo(JSONObject.toJSON(categoryInfo).toString());
|
| | | |
| | | |
| | | return cg;
|
| | | }
|
| | |
|