package com.yeshi.fanli.util.goods.douyin;
|
|
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
|
import com.yeshi.fanli.util.goods.douyin.vo.DYGoods;
|
import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail;
|
import org.apache.commons.httpclient.Header;
|
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.yeshi.utils.BigDecimalUtil;
|
import org.yeshi.utils.HttpUtil;
|
import org.yeshi.utils.MoneyBigDecimalUtil;
|
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.net.URLDecoder;
|
|
/**
|
* @author hxh
|
* @title: DYUtil
|
* @description: 抖音帮助类
|
* @date 2022/10/8 14:39
|
*/
|
public class DYUtil {
|
|
public static String createFanLiExtraInfo(Long uid) {
|
return "b_" + uid;
|
}
|
|
public static String createShareExtraInfo(Long uid) {
|
return "s_" + uid;
|
}
|
|
public static String getTypeFromExtraInfo(String extra_info) {
|
if (extra_info != null && extra_info.startsWith("s_")) {
|
return "share";
|
} else {
|
return "buy";
|
}
|
}
|
|
public static Long getUid(String extra_info) {
|
if (extra_info == null || extra_info.indexOf("_") < 0) {
|
return null;
|
}
|
return Long.parseLong(extra_info.split("_")[1].trim());
|
}
|
|
|
public static BigDecimal getCosRatio(DYGoods goods) {
|
return new BigDecimal(goods.getCos_ratio()).divide(new BigDecimal(10000), 4, RoundingMode.FLOOR);
|
}
|
|
public static BigDecimal getCosRatio(DYGoodsDetail goods) {
|
return new BigDecimal(goods.getCos_ratio()).divide(new BigDecimal(10000), 4, RoundingMode.FLOOR);
|
}
|
|
|
public static BigDecimal getGoodsFanLiMoney(DYGoodsDetail goods, BigDecimal rate) {
|
|
BigDecimal hundred = new BigDecimal(100);
|
rate = MoneyBigDecimalUtil.div(rate, hundred);
|
|
BigDecimal afterUseCouponPrice = MoneyBigDecimalUtil.div(new BigDecimal(goods.getPrice()), hundred);
|
if (goods.getCoupon_price() > 0) {
|
afterUseCouponPrice = MoneyBigDecimalUtil.div(new BigDecimal(goods.getCoupon_price()), hundred);
|
}
|
|
BigDecimal commission = MoneyBigDecimalUtil.mul(afterUseCouponPrice, getCosRatio(goods));
|
|
BigDecimal money = MoneyBigDecimalUtil.mul(commission,
|
rate);
|
return BigDecimalUtil.getWithNoZera(money).setScale(2);
|
}
|
|
public static BigDecimal getGoodsFanLiMoney(DYGoods goods, BigDecimal rate) {
|
|
BigDecimal hundred = new BigDecimal(100);
|
rate = MoneyBigDecimalUtil.div(rate, hundred);
|
|
BigDecimal afterUseCouponPrice = getCouponPrice(goods);
|
|
BigDecimal commission = MoneyBigDecimalUtil.mul(afterUseCouponPrice, getCosRatio(goods));
|
|
BigDecimal money = MoneyBigDecimalUtil.mul(commission,
|
rate);
|
return BigDecimalUtil.getWithNoZera(money).setScale(2);
|
}
|
|
|
/**
|
* @return java.math.BigDecimal
|
* @author hxh
|
* @description 获取券后价
|
* @date 18:09 2022/10/8
|
* @param: goods
|
**/
|
public static BigDecimal getCouponPrice(DYGoods goods) {
|
BigDecimal price = new BigDecimal(goods.getPrice()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR);
|
if (goods.getCoupon_price() > 0) {
|
price = new BigDecimal(goods.getCoupon_price()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR);
|
}
|
return price;
|
}
|
|
|
/**
|
* @return java.math.BigDecimal
|
* @author hxh
|
* @description 获取券后价
|
* @date 18:09 2022/10/8
|
* @param: goods
|
**/
|
public static BigDecimal getCouponPrice(DYGoodsDetail goods) {
|
BigDecimal price = new BigDecimal(goods.getPrice()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR);
|
if (goods.getCoupon_price() > 0) {
|
price = new BigDecimal(goods.getCoupon_price()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR);
|
}
|
return price;
|
}
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 从抖音短链中解析商品ID
|
* @date 18:29 2022/10/8
|
* @param: url
|
**/
|
public static String parseProdectIdFromLink(String url) {
|
if (url == null || !url.startsWith("https://v.douyin.com/")) {
|
return null;
|
}
|
|
String id = CSJCPSApiUtil.parseProductId(url);
|
return id;
|
//
|
// HttpClient client = new HttpClient();
|
// client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
// PostMethod pm = new PostMethod(url);
|
// try {
|
// client.executeMethod(pm);
|
// Header header = pm.getResponseHeader("location");
|
// if (header == null) {
|
// return null;
|
// }
|
// if (header.getValue() == null) {
|
// return null;
|
// }
|
// if (!header.getValue().contains("detail/index.html")) {
|
// return null;
|
// }
|
// String value = URLDecoder.decode(header.getValue(), "UTF-8");
|
// value = value.split("\\?")[1];
|
// String[] results = value.split("&");
|
// for (String r : results) {
|
// String key = r.split("=")[0].trim();
|
// String val = r.split("=")[1];
|
// if (!key.equalsIgnoreCase("product_id") && !key.equalsIgnoreCase("id")) {
|
// continue;
|
// }
|
// return val.trim();
|
// }
|
// } catch (IOException e) {
|
// e.printStackTrace();
|
// }
|
//
|
// return null;
|
}
|
|
public static BigDecimal getPrice(int money) {
|
return new BigDecimal(money).divide(new BigDecimal(100), 2, RoundingMode.FLOOR);
|
}
|
|
|
public static void main(String[] args) {
|
parseProdectIdFromLink("https://v.douyin.com/M8dkcv4");
|
|
}
|
|
}
|