admin
2020-06-10 271ae63c20fcbe28d29c47f1881138ff6551a2a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.yeshi.fanli.util.suning;
 
import java.math.BigDecimal;
 
import org.yeshi.utils.BigDecimalUtil;
import org.yeshi.utils.NumberUtil;
 
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
 
public class SuningUtil {
    public static BigDecimal getGoodsFanLiMoney(SuningGoodsInfo goods, BigDecimal rate) {
 
        BigDecimal hundred = new BigDecimal(100);
        rate = MoneyBigDecimalUtil.div(rate, hundred);
 
        String commodityPrice = goods.getCommodityInfo().getCommodityPrice();
        if (StringUtil.isNullOrEmpty(commodityPrice)) {
            commodityPrice = goods.getCommodityInfo().getSnPrice();
        }
 
        BigDecimal afterUseCouponPrice = new BigDecimal(commodityPrice);
        if (goods.getCouponInfo() != null && !StringUtil.isNullOrEmpty(goods.getCouponInfo().getCouponUrl())) {
            // 有券
            BigDecimal startPrice = null;
            if (StringUtil.isNullOrEmpty(goods.getCouponInfo().getBounsLimit())) {
                startPrice = new BigDecimal(goods.getCouponInfo().getCouponValue());
            } else
                startPrice = new BigDecimal(goods.getCouponInfo().getBounsLimit());
            if (afterUseCouponPrice.compareTo(startPrice) >= 0) {
                afterUseCouponPrice = afterUseCouponPrice.subtract(new BigDecimal(goods.getCouponInfo().getCouponValue()));
            }
        }
        
        BigDecimal commission=MoneyBigDecimalUtil.mul(afterUseCouponPrice,MoneyBigDecimalUtil.div(new BigDecimal(goods.getCommodityInfo().getRate()), new BigDecimal(100),5));
 
        BigDecimal money = MoneyBigDecimalUtil.mul(commission,
                rate);
        return BigDecimalUtil.getWithNoZera(money).setScale(2);
    }
 
    /**
     * 获取拼接的商品ID
     * @Title: getConcatGoodsIId
     * @Description: 
     * @param supplierCode
     * @param goodsId
     * @return 
     * String 返回类型
     * @throws
     */
    public static String getConcatGoodsIId(String supplierCode, String goodsId) {
 
        return supplierCode + "-" + goodsId;
    }
 
    public static String getFullSupplierCode(String supplierCode) {
        for (int i = 0; i < 10; i++) {
            if (supplierCode.length() < 10)
                supplierCode = "0" + supplierCode;
        }
 
        return supplierCode;
    }
 
    /**
     * 通过拼接的商品ID解析出来正确的商品ID
     * @Title: getGoodsIdDetail
     * @Description: 
     * @param concatGoodsId
     * @return 
     * String[] 返回类型
     * @throws
     */
    public static String[] getGoodsIdDetail(String concatGoodsId) {
        String[] sts = concatGoodsId.split("-");
        String supplierCode = sts[0];
        for (int i = 0; i < 10; i++) {
            if (supplierCode.length() < 10)
                supplierCode = "0" + supplierCode;
        }
        return new String[] { supplierCode, sts[1] };
    }
 
    public static String getProductUrl(String supplierCode, String goodsId) {
 
        return String.format("https://product.suning.com/%s/%s.html", supplierCode, goodsId);
    }
 
    public static String parseGoodsIdByUrl(String url) {
        try {
            if (url.contains(".suning.com/")
                    && (url.contains(".suning.com/product/") || url.contains("product.suning.com/"))) {
                String preUrl = url.split("\\?")[0];
                String[] sts = preUrl.split("/");
                if (sts.length > 2) {
                    String goodsId = sts[sts.length - 1].replace(".html", "").replace(".htm", "");
                    String supplierCode = sts[sts.length - 2];
                    if (NumberUtil.isNumeric(goodsId) && NumberUtil.isNumeric(supplierCode)) {
                        return supplierCode + "-" + goodsId;
                    }
                }
            }
        } catch (Exception e) {
        }
        return null;
    }
 
}