admin
2021-05-15 6d29a32259f3f5e896b26db27d29f616203127ca
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
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.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;
    }
 
 
 
}