|
@@ -31,25 +31,35 @@ public class PromotionPriceService { |
|
@@ -31,25 +31,35 @@ public class PromotionPriceService { |
31
|
@Autowired
|
31
|
@Autowired
|
32
|
private PromotionTagHelper promotionTagHelper;
|
32
|
private PromotionTagHelper promotionTagHelper;
|
33
|
|
33
|
|
|
|
34
|
+ /**
|
|
|
35
|
+ * 给商品列表塞入促销价字段
|
|
|
36
|
+ */
|
34
|
public void fillPromotionPrice(List<Map<String, Object>> productList) {
|
37
|
public void fillPromotionPrice(List<Map<String, Object>> productList) {
|
35
|
- //1、参数判断
|
|
|
36
|
- if (productList == null || productList.isEmpty()) {
|
|
|
37
|
- return;
|
|
|
38
|
- }
|
|
|
39
|
- //2、获取所有促销信息,制作一个以promotionId为key的Map
|
|
|
40
|
- List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
|
|
41
|
- if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
38
|
+ try {
|
|
|
39
|
+ //1、参数判断
|
|
|
40
|
+ if (productList == null || productList.isEmpty()) {
|
|
|
41
|
+ return;
|
|
|
42
|
+ }
|
|
|
43
|
+ //2、获取所有促销信息,制作一个以promotionId为key的Map
|
|
|
44
|
+ List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
|
|
45
|
+ if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
|
|
46
|
+ return;
|
|
|
47
|
+ }
|
|
|
48
|
+ Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
|
|
49
|
+ //3、循环匹配promotionPrice
|
|
|
50
|
+ for (Map<String, Object> product : productList) {
|
|
|
51
|
+ Integer promotionPrice = this.getPromotionPrice(product, promotionIndexBOMap);
|
|
|
52
|
+ product.put("promotion_price", promotionPrice);
|
|
|
53
|
+ }
|
|
|
54
|
+ } catch (Exception e) {
|
|
|
55
|
+ logger.error(e.getMessage(), e);
|
42
|
return;
|
56
|
return;
|
43
|
}
|
57
|
}
|
44
|
- Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
|
|
45
|
- //3、循环匹配promotionPrice
|
|
|
46
|
- for (Map<String, Object> product : productList) {
|
|
|
47
|
- Integer promotionPrice = this.getPromotionPrice(product, promotionIndexBOMap);
|
|
|
48
|
- product.put("promotion_price", promotionPrice);
|
|
|
49
|
- }
|
|
|
50
|
}
|
58
|
}
|
51
|
|
59
|
|
52
|
-
|
60
|
+ /**
|
|
|
61
|
+ * 计算促销价格
|
|
|
62
|
+ */
|
53
|
private Integer getPromotionPrice(Map<String, Object> product, Map<Integer, PromotionIndexBO> promotionIndexBOMap) {
|
63
|
private Integer getPromotionPrice(Map<String, Object> product, Map<Integer, PromotionIndexBO> promotionIndexBOMap) {
|
54
|
try {
|
64
|
try {
|
55
|
//全球购skn,promotion_price为空
|
65
|
//全球购skn,promotion_price为空
|
|
@@ -63,7 +73,7 @@ public class PromotionPriceService { |
|
@@ -63,7 +73,7 @@ public class PromotionPriceService { |
63
|
return null;
|
73
|
return null;
|
64
|
}
|
74
|
}
|
65
|
|
75
|
|
66
|
- //获取单个skn的促销列表
|
76
|
+ //1、获取单个skn的促销列表
|
67
|
List<Map<String, String>> promotionTagList = (List<Map<String, String>>) product.get("promotion_tag");
|
77
|
List<Map<String, String>> promotionTagList = (List<Map<String, String>>) product.get("promotion_tag");
|
68
|
if (CollectionUtils.isEmpty(promotionTagList)) {
|
78
|
if (CollectionUtils.isEmpty(promotionTagList)) {
|
69
|
return null;
|
79
|
return null;
|
|
@@ -77,7 +87,7 @@ public class PromotionPriceService { |
|
@@ -77,7 +87,7 @@ public class PromotionPriceService { |
77
|
promotionIndexBOList.add(promotionIndexBO);
|
87
|
promotionIndexBOList.add(promotionIndexBO);
|
78
|
}
|
88
|
}
|
79
|
|
89
|
|
80
|
- //生成按照权重排序后的促销列表
|
90
|
+ //2、促销列表按照权重从大到小排序
|
81
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
91
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
82
|
return null;
|
92
|
return null;
|
83
|
}
|
93
|
}
|
|
@@ -85,77 +95,57 @@ public class PromotionPriceService { |
|
@@ -85,77 +95,57 @@ public class PromotionPriceService { |
85
|
|
95
|
|
86
|
//是否有任何促销满足标志位
|
96
|
//是否有任何促销满足标志位
|
87
|
boolean isPromotionPriceActive = false;
|
97
|
boolean isPromotionPriceActive = false;
|
88
|
-
|
|
|
89
|
- //上一个满足的促销互斥参数
|
98
|
+ //记录上一个满足的促销互斥参数,用于判断互斥
|
90
|
String lastPromotionRejectParam = "";
|
99
|
String lastPromotionRejectParam = "";
|
91
|
//促销价
|
100
|
//促销价
|
92
|
Double currentSalesPrice = salesPrice;
|
101
|
Double currentSalesPrice = salesPrice;
|
93
|
|
102
|
|
94
|
- //循环促销,计算促销价格
|
103
|
+ //3、循环skn的促销列表,计算促销价格
|
95
|
for (PromotionIndexBO promotionIndexBO : sortedPromotionIndexBos) {
|
104
|
for (PromotionIndexBO promotionIndexBO : sortedPromotionIndexBos) {
|
96
|
|
105
|
|
97
|
- //和上一个满足的促销互斥的话,直接跳过
|
106
|
+ //不是这三种类型之一的直接跳过
|
|
|
107
|
+ Map<String, String> promotionTag = promotionTagMap.get(promotionIndexBO.getId());
|
|
|
108
|
+ if (!"Discount".equals(promotionTag.get("type")) && !"Cashreduce".equals(promotionTag.get("type")) && !"Degressdiscount".equals(promotionTag.get("type"))) {
|
|
|
109
|
+ continue;
|
|
|
110
|
+ }
|
|
|
111
|
+
|
|
|
112
|
+ //和上一个满足的促销互斥的话直接跳过
|
98
|
boolean isPromotionReject = this.isPromotionReject(lastPromotionRejectParam, promotionIndexBO.getId().toString());
|
113
|
boolean isPromotionReject = this.isPromotionReject(lastPromotionRejectParam, promotionIndexBO.getId().toString());
|
99
|
if (isPromotionReject) {
|
114
|
if (isPromotionReject) {
|
100
|
continue;
|
115
|
continue;
|
101
|
}
|
116
|
}
|
102
|
|
117
|
|
103
|
- //用上一个满足的促销优惠过的价格判断下一个促销是否满足
|
118
|
+ //用上一个满足的促销优惠过的价格判断下一个促销是否满足,不满足跳过
|
104
|
boolean isPromotionAvailable = this.isPromotionAvailable(promotionIndexBO.getConditionParam(), currentSalesPrice);
|
119
|
boolean isPromotionAvailable = this.isPromotionAvailable(promotionIndexBO.getConditionParam(), currentSalesPrice);
|
105
|
if (!isPromotionAvailable) {
|
120
|
if (!isPromotionAvailable) {
|
106
|
continue;
|
121
|
continue;
|
107
|
}
|
122
|
}
|
108
|
|
123
|
|
109
|
- //更新上一个满足的促销互斥
|
|
|
110
|
- lastPromotionRejectParam = promotionIndexBO.getRejectParam();
|
|
|
111
|
-
|
|
|
112
|
//判断促销的类型是否满足,然后促销开始计算价格
|
124
|
//判断促销的类型是否满足,然后促销开始计算价格
|
113
|
String actionParam = promotionIndexBO.getActionParam();
|
125
|
String actionParam = promotionIndexBO.getActionParam();
|
114
|
JSONObject actionParamJson = JSONObject.parseObject(actionParam);
|
126
|
JSONObject actionParamJson = JSONObject.parseObject(actionParam);
|
115
|
if (actionParamJson == null) {
|
127
|
if (actionParamJson == null) {
|
116
|
continue;
|
128
|
continue;
|
117
|
}
|
129
|
}
|
118
|
- Map<String, String> promotionTag = promotionTagMap.get(promotionIndexBO.getId());
|
130
|
+ isPromotionPriceActive = true;
|
|
|
131
|
+ lastPromotionRejectParam = promotionIndexBO.getRejectParam();
|
119
|
if ("Discount".equals(promotionTag.get("type"))) {
|
132
|
if ("Discount".equals(promotionTag.get("type"))) {
|
120
|
Double discount = Double.valueOf(actionParamJson.get("discount").toString());
|
133
|
Double discount = Double.valueOf(actionParamJson.get("discount").toString());
|
121
|
- if (discount == null || currentSalesPrice == null) {
|
|
|
122
|
- continue;
|
|
|
123
|
- }
|
|
|
124
|
currentSalesPrice = currentSalesPrice * discount;
|
134
|
currentSalesPrice = currentSalesPrice * discount;
|
125
|
- if (currentSalesPrice != null) {
|
|
|
126
|
- isPromotionPriceActive = true;
|
|
|
127
|
- }
|
|
|
128
|
}
|
135
|
}
|
129
|
if ("Cashreduce".equals(promotionTag.get("type"))) {
|
136
|
if ("Cashreduce".equals(promotionTag.get("type"))) {
|
130
|
Double reduce = Double.valueOf(actionParamJson.get("reduce").toString());
|
137
|
Double reduce = Double.valueOf(actionParamJson.get("reduce").toString());
|
131
|
- if (reduce == null || currentSalesPrice == null) {
|
|
|
132
|
- continue;
|
|
|
133
|
- }
|
|
|
134
|
currentSalesPrice = currentSalesPrice - reduce;
|
138
|
currentSalesPrice = currentSalesPrice - reduce;
|
135
|
- if (currentSalesPrice != null) {
|
|
|
136
|
- isPromotionPriceActive = true;
|
|
|
137
|
- }
|
|
|
138
|
}
|
139
|
}
|
139
|
if ("Degressdiscount".equals(promotionTag.get("type"))) {
|
140
|
if ("Degressdiscount".equals(promotionTag.get("type"))) {
|
140
|
- if (actionParamJson.get("degress_discount_list") == null || currentSalesPrice == null) {
|
|
|
141
|
- continue;
|
|
|
142
|
- }
|
|
|
143
|
- String degressDiscountList = actionParamJson.get("degress_discount_list").toString();
|
|
|
144
|
- String[] degress = degressDiscountList.split(";");
|
|
|
145
|
- if (degress[0] == null) {
|
141
|
+ Double discount = this.countDegreeDiscount(actionParamJson);
|
|
|
142
|
+ if (discount == null) {
|
146
|
continue;
|
143
|
continue;
|
147
|
}
|
144
|
}
|
148
|
- String[] degressKeyValue = degress[0].split(":");
|
|
|
149
|
- if (degressKeyValue[1] == null || Double.valueOf(degressKeyValue[1]) == 1) {
|
|
|
150
|
- continue;
|
|
|
151
|
- }
|
|
|
152
|
- Double discount = Double.valueOf(degressKeyValue[1]);
|
|
|
153
|
currentSalesPrice = currentSalesPrice * discount;
|
145
|
currentSalesPrice = currentSalesPrice * discount;
|
154
|
- if (currentSalesPrice != null) {
|
|
|
155
|
- isPromotionPriceActive = true;
|
|
|
156
|
- }
|
|
|
157
|
}
|
146
|
}
|
158
|
}
|
147
|
}
|
|
|
148
|
+ //4、有任何满足的促销,才赋值手价
|
159
|
if (isPromotionPriceActive) {
|
149
|
if (isPromotionPriceActive) {
|
160
|
return getIntCeilPrice(currentSalesPrice);
|
150
|
return getIntCeilPrice(currentSalesPrice);
|
161
|
}
|
151
|
}
|
|
@@ -166,6 +156,26 @@ public class PromotionPriceService { |
|
@@ -166,6 +156,26 @@ public class PromotionPriceService { |
166
|
}
|
156
|
}
|
167
|
}
|
157
|
}
|
168
|
|
158
|
|
|
|
159
|
+
|
|
|
160
|
+ /**
|
|
|
161
|
+ * 计算分件折扣促销的折扣
|
|
|
162
|
+ */
|
|
|
163
|
+ private Double countDegreeDiscount(JSONObject actionParamJson) {
|
|
|
164
|
+ if (actionParamJson.get("degress_discount_list") == null) {
|
|
|
165
|
+ return null;
|
|
|
166
|
+ }
|
|
|
167
|
+ String degreeDiscountList = actionParamJson.get("degress_discount_list").toString();
|
|
|
168
|
+ String[] degree = degreeDiscountList.split(";");
|
|
|
169
|
+ if (degree[0] == null) {
|
|
|
170
|
+ return null;
|
|
|
171
|
+ }
|
|
|
172
|
+ String[] degreeKeyValue = degree[0].split(":");
|
|
|
173
|
+ if (degreeKeyValue[1] == null || Double.valueOf(degreeKeyValue[1]) == 1) {
|
|
|
174
|
+ return null;
|
|
|
175
|
+ }
|
|
|
176
|
+ return Double.valueOf(degreeKeyValue[1]);
|
|
|
177
|
+ }
|
|
|
178
|
+
|
169
|
/**
|
179
|
/**
|
170
|
* 判断本促销是否和上一个促销互斥
|
180
|
* 判断本促销是否和上一个促销互斥
|
171
|
*/
|
181
|
*/
|
|
@@ -204,7 +214,7 @@ public class PromotionPriceService { |
|
@@ -204,7 +214,7 @@ public class PromotionPriceService { |
204
|
}
|
214
|
}
|
205
|
|
215
|
|
206
|
/**
|
216
|
/**
|
207
|
- * 获取商品最新变价计划中的价格,默认是商品salesprice
|
217
|
+ * 获取商品最新变价计划中的价格,默认是商品salesPrice
|
208
|
*/
|
218
|
*/
|
209
|
private Double getProductPricePlanSalesPrice(Map<String, Object> productMap) {
|
219
|
private Double getProductPricePlanSalesPrice(Map<String, Object> productMap) {
|
210
|
//取当前销售价
|
220
|
//取当前销售价
|
|
@@ -213,7 +223,7 @@ public class PromotionPriceService { |
|
@@ -213,7 +223,7 @@ public class PromotionPriceService { |
213
|
if (pricePlanList == null || pricePlanList.isEmpty()) {
|
223
|
if (pricePlanList == null || pricePlanList.isEmpty()) {
|
214
|
return salesPrice;
|
224
|
return salesPrice;
|
215
|
}
|
225
|
}
|
216
|
- //截取当前销售价格-取满足时间的第一个变价计算,获取current_saleprice
|
226
|
+ //截取当前销售价格-取满足时间的第一个变价计算(取effect_time最大的一个),获取current_saleprice
|
217
|
List<Map<String, String>> pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
227
|
List<Map<String, String>> pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
218
|
long currentTime = DateUtil.getCurrentTimeSecond();
|
228
|
long currentTime = DateUtil.getCurrentTimeSecond();
|
219
|
for (Map<String, String> pricePlanMap : pricePlanListSorted) {
|
229
|
for (Map<String, String> pricePlanMap : pricePlanListSorted) {
|