package com.ks.lijin.utils.taobao;
|
|
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.*;
|
|
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
|
|
import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2;
|
|
|
@Component
|
public class TaoBaoUtil {
|
|
|
public final static int SORT_PRICE_HIGH_TO_LOW = 3;// 价格从高到低
|
public final static int SORT_PRICE_LOW_TO_HIGH = 4;// 价格从低到高
|
|
public static final int SORT_TKRATE_LOW_TO_HIGH = 1;// 淘客佣金比率低到高
|
public static final int SORT_TKRATE_HIGH_TO_LOW = 2;// 淘客佣金比率高到低
|
|
public static final int SORT_TOTAL_COMMI_LOW_TO_HIGH = 5;// 总支出佣金低到高
|
public static final int SORT_TOTAL_COMMI_HIGH_TO_LOW = 6;// 总支出佣金高到低
|
|
public static final int SORT_TOTAL_SALES_LOW_TO_HIGH = 10;// 累计推广量低到高
|
public static final int SORT_TOTAL_SALES_HIGH_TO_LOW = 11;// 累计推广量高到低
|
|
public static final int SORT_SALE_COMMISSION = 7;// 月支出佣金从高到低
|
|
public final static int SORT_SALE_LOW_TO_HIGH = 8;// 销量从低到高
|
|
public final static int SORT_SALE_HIGH_TO_LOW = 9;// 销量从高到低
|
public final static int SORT_DEFAULT = 0;// 销量从高到低
|
|
public final static int SORT_FILTER_FROM_ALL = 0;// 淘宝天猫
|
public final static int SORT_FILTER_FROM_TMALL = 1;// 天猫
|
|
private final static int PAGESIZE = 20;
|
|
public final static String SEARCH_URL = "http://pub.alimama.com/items/search.json";
|
private static final String NZJH_URL = "http://pub.alimama.com/items/channel/nzjh.json";
|
private static final String MUYING_URL = "http://pub.alimama.com/items/channel/muying.json";
|
private static final String QQHD_URL = "http://pub.alimama.com/items/channel/qqhd.json";
|
private static final String IFS_URL = "http://pub.alimama.com/items/channel/ifs.json";
|
private static final String QBB_URL = "http://pub.alimama.com/items/channel/qbb.json";
|
private static final String HCH_URL = "http://pub.alimama.com/items/channel/hch.json";
|
private static final String CDJ_URL = "http://pub.alimama.com/items/channel/cdj.json";
|
private static final String JYJ_URL = "http://pub.alimama.com/items/channel/jyj.json";
|
private static final String KDC_URL = "http://pub.alimama.com/items/channel/kdc.json";
|
private static final String DIY_URL = "http://pub.alimama.com/items/channel/diy.json";
|
private static final String K9_URL = "http://pub.alimama.com/items/channel/9k9.json";
|
private static final String K20_URL = "http://pub.alimama.com/items/channel/20k.json";
|
private static final String TEHUI_URL = "http://pub.alimama.com/items/channel/tehui.json";
|
|
private static final String TB_ITEM_URL = "http://gw.api.taobao.com/router/rest";
|
|
public static final String TB_URL = "http://item.taobao.com/item.htm?id=%s";
|
public static final String TM_PHONE_URL = "https://detail.m.tmall.com/item.htm?id=%s";
|
public static final String TB_H5_URL = "http://h5.m.taobao.com/awp/core/detail.htm?id=%s";
|
|
|
/**
|
* 获取商品的用户分成比例
|
*
|
* @param goodsBrief 商品详情
|
* @param rate 用户再次分成比例(0-100)
|
* @return
|
*/
|
public static String getGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate, boolean share) {
|
// if (goodsBrief != null && goodsBrief.getMaterialLibType() != null &&
|
// goodsBrief.getMaterialLibType() == 0)
|
// return "¥0.00";
|
// else
|
return "¥" + getGoodsHongBaoMoney(goodsBrief, rate, share).toString();
|
}
|
|
/**
|
* 获取淘宝商品该获得多少佣金
|
*
|
* @param goodsBrief
|
* @param rate
|
* @return
|
*/
|
public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate, boolean share) {
|
BigDecimal commissionRate = null;
|
if (goodsBrief.getMinTkRate() != null && !share)
|
commissionRate = goodsBrief.getMinTkRate();
|
else
|
commissionRate = goodsBrief.getTkRate();
|
|
BigDecimal money = null;
|
if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|
|| goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
money = MoneyBigDecimalUtil.mul(
|
MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), commissionRate),
|
new BigDecimal("0.01")),
|
MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
} else// 有券
|
{
|
List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
|
BigDecimal startFee = list.get(0);
|
BigDecimal couponAccount = list.get(1);
|
if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
|
&& goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
|
BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
|
money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
.mul(MoneyBigDecimalUtil.mul(finalPrice, commissionRate), new BigDecimal("0.01")),
|
MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
|
} else {// 不能用券
|
money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
|
MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), commissionRate),
|
new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
}
|
}
|
|
if (share)
|
money = TaoBaoUtil.getCanShareMoney(new Date(), money);
|
|
|
return BigDecimalUtil.getWithNoZera(money);
|
}
|
|
|
|
/**
|
* 获取分享赚的金额
|
*
|
* @param goodsBrief
|
* @param rate
|
* @return
|
*/
|
|
public static BigDecimal getShareGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
return getGoodsHongBaoMoney(goodsBrief, rate, true);
|
}
|
|
/**
|
* 计算商品券后价,没有券则返回原价
|
*
|
* @param goodsBrief
|
* @return
|
*/
|
public static BigDecimal getAfterUseCouplePrice(TaoBaoGoodsBrief goodsBrief) {
|
|
if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) || "无".equals(goodsBrief.getCouponInfo())) {
|
return goodsBrief.getZkPrice();
|
} else {
|
List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
|
BigDecimal startFee = list.get(0);
|
BigDecimal couponAccount = list.get(1);
|
if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
|
&& goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
|
BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
|
return finalPrice;
|
} else {// 不能用券
|
return goodsBrief.getZkPrice();
|
}
|
}
|
}
|
|
|
|
public static String getSaleCount(int count) {
|
if (count >= 10000) {
|
double sales = count;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
return salesCountMidea + "万";
|
} else
|
return count + "";
|
}
|
|
|
public static TaoBaoGoodsBrief convert(DaTaoKeDetailV2 detail) {
|
TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
taoBaoGoods.setAuctionId(detail.getGoodsId());
|
taoBaoGoods.setBiz30day(detail.getMonthSales());
|
// 券相关转换
|
taoBaoGoods.setCouponAmount(detail.getCouponPrice());
|
taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", detail.getOriginalPrice(),
|
MoneyBigDecimalUtil.getWithNoZera(detail.getCouponPrice())));
|
if (detail.getCouponTotalNum() != null && detail.getCouponReceiveNum() != null)
|
taoBaoGoods.setCouponLeftCount(detail.getCouponTotalNum() - detail.getCouponReceiveNum());
|
else
|
taoBaoGoods.setCouponLeftCount(0);
|
taoBaoGoods.setCouponStartFee(detail.getOriginalPrice());
|
try {
|
taoBaoGoods.setCouponStartFee(detail.getOriginalPrice());
|
} catch (Exception e) {
|
}
|
|
taoBaoGoods.setCouponTotalCount(detail.getCouponTotalNum());
|
taoBaoGoods.setCouponLink(detail.getCouponLink());
|
taoBaoGoods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(
|
TimeUtil.convertToTimeTemp(detail.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd"));
|
taoBaoGoods.setCouponEffectiveEndTime(TimeUtil.getGernalTime(
|
TimeUtil.convertToTimeTemp(detail.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd"));
|
|
taoBaoGoods.setPictUrl(detail.getMainPic());
|
taoBaoGoods.setPictUrlWhite(detail.getMainPic());
|
if (taoBaoGoods.getPictUrl() != null && !taoBaoGoods.getPictUrl().startsWith("http"))
|
taoBaoGoods.setPictUrl("https:" + taoBaoGoods.getPictUrl());
|
|
if (taoBaoGoods.getPictUrlWhite() != null && !taoBaoGoods.getPictUrlWhite().startsWith("http"))
|
taoBaoGoods.setPictUrlWhite("https:" + taoBaoGoods.getPictUrlWhite());
|
|
|
String imgs = detail.getImgs();
|
if (!StringUtil.isNullOrEmpty(imgs)) {
|
String[] array = imgs.split(",");
|
if (array != null && array.length > 0) {
|
List<String> imgList = new ArrayList<>();
|
for (int i = 0; i < array.length; i++) {
|
imgList.add(array[i]);
|
}
|
taoBaoGoods.setImgList(imgList);
|
}
|
}
|
|
|
taoBaoGoods.setSellerId(detail.getSellerId());
|
taoBaoGoods.setShopTitle(detail.getShopName());
|
taoBaoGoods.setTitle(detail.getDtitle());
|
taoBaoGoods.setUserType(detail.getShopType());
|
taoBaoGoods.setZkPrice(detail.getOriginalPrice());
|
taoBaoGoods.setTkRate(detail.getCommissionRate());
|
taoBaoGoods.setTkCommFee(new BigDecimal("0"));
|
taoBaoGoods.setState(0);
|
return taoBaoGoods;
|
}
|
|
|
/**
|
* 提取自有格式的淘口令
|
*
|
* @param str
|
* @return
|
*/
|
public static String parseSystemTaoToken(String str) {
|
String pattern = "(\\({1}[A-Za-z0-9]+\\){1})";
|
Pattern r = Pattern.compile(pattern);
|
Matcher m = r.matcher(str);
|
while (m.find()) {
|
String group = m.group(0);
|
if (!StringUtil.isNullOrEmpty(group) && group.length() >= 10)
|
return group;
|
}
|
return null;
|
}
|
|
public static boolean isSpecialGoods(Integer materialLibType) {
|
if (materialLibType != null && materialLibType == 1)
|
return true;
|
else
|
return false;
|
}
|
|
private final static String[] taoTokenSymbols = new String[]{"₳-₳", "¥-¥", "¥-¥", "€-€", "\\$-\\$", "₴-₴", "¢-¢",
|
"₤-₤"};
|
|
/**
|
* 从文本中提取淘口令 @Title: getTokenListFromText @Description: @param str @return
|
* List<String> 返回类型 @throws
|
*/
|
public static List<String> getTokenListFromText(String str) {
|
String[] marks = taoTokenSymbols;
|
List<String> list = new ArrayList<>();
|
for (String m : marks) {
|
for (String m1 : marks) {
|
list.add(m.split("-")[0] + "-" + m1.split("-")[1]);
|
}
|
}
|
|
return getTokenListFromText(str, list);
|
}
|
|
/**
|
* 从文本中提取淘口令(括号的口令也算)
|
*
|
* @param str
|
* @return
|
*/
|
public static List<String> getTokenListFromTextWithKuoHao(String str) {
|
String[] marks = taoTokenSymbols;
|
List<String> list = new ArrayList<>();
|
for (String m : marks) {
|
for (String m1 : marks) {
|
list.add(m.split("-")[0] + "-" + m1.split("-")[1]);
|
}
|
}
|
|
list.add("\\(-\\)");
|
list.add("(-)");
|
return getTokenListFromText(str, list);
|
}
|
|
public static List<String> getTokenListFromText(String str, List<String> markList) {
|
List<String> expressList = new ArrayList<>();
|
for (String st : markList) {
|
expressList.add(String.format("(%s{1}[A-Za-z0-9]{11,13}+%s{1})", st.split("-")[0], st.split("-")[1]));
|
}
|
String pattern = StringUtil.concat(expressList, "|");
|
Pattern r = Pattern.compile(pattern);
|
Matcher m = r.matcher(str);
|
List<String> urlList = new ArrayList<>();
|
while (m.find()) {
|
urlList.add(m.group());
|
}
|
return urlList;
|
}
|
|
/**
|
* 获取能够分的钱
|
*
|
* @param estimate
|
* @return BigDecimal 返回类型
|
* @throws
|
* @Title: getCanShareMoney
|
* @Description:
|
*/
|
public static BigDecimal getCanShareMoney(Date createTime, BigDecimal estimate) {
|
if (estimate == null)
|
return null;
|
if (createTime.getTime() < TimeUtil.convertToTimeTemp("2020-06-01 12:30:00", "yyyy-MM-dd HH:mm:ss")) {
|
return estimate;
|
}
|
BigDecimal rate = new BigDecimal("0.9101");
|
return MoneyBigDecimalUtil.mul(estimate, rate);
|
}
|
|
/**
|
* 拼接渠道ID
|
*
|
* @param url
|
* @param relationId
|
* @return
|
*/
|
public static String concatRelationId(String url, String relationId) {
|
if (StringUtil.isNullOrEmpty(relationId))
|
return url;
|
return url + "&relationId=" + relationId;
|
}
|
|
|
//从券链接获取券ID
|
|
/**
|
* 从券链接中获取券ID
|
*
|
* @param couponLink
|
* @return
|
*/
|
public static String getActivityIdFromCouponLink(String couponLink) {
|
Map<String, String> params = HttpUtil.getPramsFromUrl(couponLink);
|
if (params != null && params.containsKey("activityId"))
|
return params.get("activityId");
|
return null;
|
}
|
|
/**
|
* @return boolean
|
* @author hxh
|
* @description 判断淘宝商品ID是否相等
|
* @date 14:55 2022/8/24
|
* @param: auctionId1
|
* @param: auctionId2
|
**/
|
public static boolean isEqual(String auctionId1, String auctionId2) {
|
if (auctionId1 == null || auctionId2 == null) {
|
return false;
|
}
|
|
if (auctionId1.indexOf("-") > 0 && auctionId2.indexOf("-") > 0) {
|
return auctionId1.split("-")[1].equals(auctionId2.split("-")[1]);
|
}
|
return auctionId1.equals(auctionId2);
|
}
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 获取商品ID的后半段
|
* @date 15:20 2022/8/24
|
* @param: auctionId
|
**/
|
public static String getAuctionId(String auctionId) {
|
if (auctionId == null)
|
return auctionId;
|
if (auctionId.indexOf("-") > 0) {
|
return auctionId.split("-")[1];
|
} else {
|
return auctionId;
|
}
|
|
}
|
|
/**
|
* @author hxh
|
* @description 获取mongodb商品ID相同的条件
|
* @date 16:05 2022/8/24
|
* @param: key
|
* @param: auctionId
|
* @return org.springframework.data.mongodb.core.query.Criteria
|
**/
|
public static Criteria getAuctionIdEqualCriteria(String key, String auctionId) {
|
if (!isNewAuctionId(auctionId)) {
|
return Criteria.where(key).is(auctionId);
|
} else {
|
return Criteria.where(key).regex("*-" + getAuctionId(auctionId));
|
}
|
}
|
|
/**
|
* @return boolean
|
* @author hxh
|
* @description 是否为新的商品ID
|
* @date 15:39 2022/8/24
|
* @param: auctionId
|
**/
|
public static boolean isNewAuctionId(String auctionId) {
|
if (auctionId != null && auctionId.indexOf("-") > 0)
|
return true;
|
return false;
|
}
|
|
|
|
}
|