admin
2020-05-29 d99f45a1c358282ab0d4333232da25f03560778f
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
package com.yeshi.fanli.util.suning;
 
import java.math.BigDecimal;
 
import org.yeshi.utils.BigDecimalUtil;
 
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);
 
        BigDecimal afterUseCouponPrice = new BigDecimal(goods.getCommodityInfo().getCommodityPrice());
        if (goods.getCouponInfo() != null && !StringUtil.isNullOrEmpty(goods.getCouponInfo().getCouponUrl())) {
            // 有券
            BigDecimal startPrice = new BigDecimal(goods.getCouponInfo().getBounsLimit());
            if (afterUseCouponPrice.compareTo(startPrice) >= 0) {
                afterUseCouponPrice = afterUseCouponPrice.subtract(startPrice);
            }
        }
 
        BigDecimal money = MoneyBigDecimalUtil.mul(afterUseCouponPrice, 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);
    }
 
}