...
|
...
|
@@ -31,25 +31,35 @@ public class PromotionPriceService { |
|
|
@Autowired
|
|
|
private PromotionTagHelper promotionTagHelper;
|
|
|
|
|
|
/**
|
|
|
* 给商品列表塞入促销价字段
|
|
|
*/
|
|
|
public void fillPromotionPrice(List<Map<String, Object>> productList) {
|
|
|
//1、参数判断
|
|
|
if (productList == null || productList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
//2、获取所有促销信息,制作一个以promotionId为key的Map
|
|
|
List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
|
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
|
|
try {
|
|
|
//1、参数判断
|
|
|
if (productList == null || productList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
//2、获取所有促销信息,制作一个以promotionId为key的Map
|
|
|
List<PromotionIndexBO> promotionIndexBOList = promotionCondService.getPromotionList();
|
|
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
|
|
return;
|
|
|
}
|
|
|
Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
|
|
//3、循环匹配promotionPrice
|
|
|
for (Map<String, Object> product : productList) {
|
|
|
Integer promotionPrice = this.getPromotionPrice(product, promotionIndexBOMap);
|
|
|
product.put("promotion_price", promotionPrice);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return;
|
|
|
}
|
|
|
Map<Integer, PromotionIndexBO> promotionIndexBOMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, p -> p));
|
|
|
//3、循环匹配promotionPrice
|
|
|
for (Map<String, Object> product : productList) {
|
|
|
Integer promotionPrice = this.getPromotionPrice(product, promotionIndexBOMap);
|
|
|
product.put("promotion_price", promotionPrice);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 计算促销价格
|
|
|
*/
|
|
|
private Integer getPromotionPrice(Map<String, Object> product, Map<Integer, PromotionIndexBO> promotionIndexBOMap) {
|
|
|
try {
|
|
|
//全球购skn,promotion_price为空
|
...
|
...
|
@@ -63,7 +73,7 @@ public class PromotionPriceService { |
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//获取单个skn的促销列表
|
|
|
//1、获取单个skn的促销列表
|
|
|
List<Map<String, String>> promotionTagList = (List<Map<String, String>>) product.get("promotion_tag");
|
|
|
if (CollectionUtils.isEmpty(promotionTagList)) {
|
|
|
return null;
|
...
|
...
|
@@ -77,7 +87,7 @@ public class PromotionPriceService { |
|
|
promotionIndexBOList.add(promotionIndexBO);
|
|
|
}
|
|
|
|
|
|
//生成按照权重排序后的促销列表
|
|
|
//2、促销列表按照权重从大到小排序
|
|
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
|
|
return null;
|
|
|
}
|
...
|
...
|
@@ -85,77 +95,57 @@ public class PromotionPriceService { |
|
|
|
|
|
//是否有任何促销满足标志位
|
|
|
boolean isPromotionPriceActive = false;
|
|
|
|
|
|
//上一个满足的促销互斥参数
|
|
|
//记录上一个满足的促销互斥参数,用于判断互斥
|
|
|
String lastPromotionRejectParam = "";
|
|
|
//促销价
|
|
|
Double currentSalesPrice = salesPrice;
|
|
|
|
|
|
//循环促销,计算促销价格
|
|
|
//3、循环skn的促销列表,计算促销价格
|
|
|
for (PromotionIndexBO promotionIndexBO : sortedPromotionIndexBos) {
|
|
|
|
|
|
//和上一个满足的促销互斥的话,直接跳过
|
|
|
//不是这三种类型之一的直接跳过
|
|
|
Map<String, String> promotionTag = promotionTagMap.get(promotionIndexBO.getId());
|
|
|
if (!"Discount".equals(promotionTag.get("type")) && !"Cashreduce".equals(promotionTag.get("type")) && !"Degressdiscount".equals(promotionTag.get("type"))) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//和上一个满足的促销互斥的话直接跳过
|
|
|
boolean isPromotionReject = this.isPromotionReject(lastPromotionRejectParam, promotionIndexBO.getId().toString());
|
|
|
if (isPromotionReject) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//用上一个满足的促销优惠过的价格判断下一个促销是否满足
|
|
|
//用上一个满足的促销优惠过的价格判断下一个促销是否满足,不满足跳过
|
|
|
boolean isPromotionAvailable = this.isPromotionAvailable(promotionIndexBO.getConditionParam(), currentSalesPrice);
|
|
|
if (!isPromotionAvailable) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//更新上一个满足的促销互斥
|
|
|
lastPromotionRejectParam = promotionIndexBO.getRejectParam();
|
|
|
|
|
|
//判断促销的类型是否满足,然后促销开始计算价格
|
|
|
String actionParam = promotionIndexBO.getActionParam();
|
|
|
JSONObject actionParamJson = JSONObject.parseObject(actionParam);
|
|
|
if (actionParamJson == null) {
|
|
|
continue;
|
|
|
}
|
|
|
Map<String, String> promotionTag = promotionTagMap.get(promotionIndexBO.getId());
|
|
|
isPromotionPriceActive = true;
|
|
|
lastPromotionRejectParam = promotionIndexBO.getRejectParam();
|
|
|
if ("Discount".equals(promotionTag.get("type"))) {
|
|
|
Double discount = Double.valueOf(actionParamJson.get("discount").toString());
|
|
|
if (discount == null || currentSalesPrice == null) {
|
|
|
continue;
|
|
|
}
|
|
|
currentSalesPrice = currentSalesPrice * discount;
|
|
|
if (currentSalesPrice != null) {
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
}
|
|
|
if ("Cashreduce".equals(promotionTag.get("type"))) {
|
|
|
Double reduce = Double.valueOf(actionParamJson.get("reduce").toString());
|
|
|
if (reduce == null || currentSalesPrice == null) {
|
|
|
continue;
|
|
|
}
|
|
|
currentSalesPrice = currentSalesPrice - reduce;
|
|
|
if (currentSalesPrice != null) {
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
}
|
|
|
if ("Degressdiscount".equals(promotionTag.get("type"))) {
|
|
|
if (actionParamJson.get("degress_discount_list") == null || currentSalesPrice == null) {
|
|
|
continue;
|
|
|
}
|
|
|
String degressDiscountList = actionParamJson.get("degress_discount_list").toString();
|
|
|
String[] degress = degressDiscountList.split(";");
|
|
|
if (degress[0] == null) {
|
|
|
Double discount = this.countDegreeDiscount(actionParamJson);
|
|
|
if (discount == null) {
|
|
|
continue;
|
|
|
}
|
|
|
String[] degressKeyValue = degress[0].split(":");
|
|
|
if (degressKeyValue[1] == null || Double.valueOf(degressKeyValue[1]) == 1) {
|
|
|
continue;
|
|
|
}
|
|
|
Double discount = Double.valueOf(degressKeyValue[1]);
|
|
|
currentSalesPrice = currentSalesPrice * discount;
|
|
|
if (currentSalesPrice != null) {
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//4、有任何满足的促销,才赋值手价
|
|
|
if (isPromotionPriceActive) {
|
|
|
return getIntCeilPrice(currentSalesPrice);
|
|
|
}
|
...
|
...
|
@@ -166,6 +156,26 @@ public class PromotionPriceService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 计算分件折扣促销的折扣
|
|
|
*/
|
|
|
private Double countDegreeDiscount(JSONObject actionParamJson) {
|
|
|
if (actionParamJson.get("degress_discount_list") == null) {
|
|
|
return null;
|
|
|
}
|
|
|
String degreeDiscountList = actionParamJson.get("degress_discount_list").toString();
|
|
|
String[] degree = degreeDiscountList.split(";");
|
|
|
if (degree[0] == null) {
|
|
|
return null;
|
|
|
}
|
|
|
String[] degreeKeyValue = degree[0].split(":");
|
|
|
if (degreeKeyValue[1] == null || Double.valueOf(degreeKeyValue[1]) == 1) {
|
|
|
return null;
|
|
|
}
|
|
|
return Double.valueOf(degreeKeyValue[1]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断本促销是否和上一个促销互斥
|
|
|
*/
|
...
|
...
|
@@ -204,7 +214,7 @@ public class PromotionPriceService { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品最新变价计划中的价格,默认是商品salesprice
|
|
|
* 获取商品最新变价计划中的价格,默认是商品salesPrice
|
|
|
*/
|
|
|
private Double getProductPricePlanSalesPrice(Map<String, Object> productMap) {
|
|
|
//取当前销售价
|
...
|
...
|
@@ -213,7 +223,7 @@ public class PromotionPriceService { |
|
|
if (pricePlanList == null || pricePlanList.isEmpty()) {
|
|
|
return salesPrice;
|
|
|
}
|
|
|
//截取当前销售价格-取满足时间的第一个变价计算,获取current_saleprice
|
|
|
//截取当前销售价格-取满足时间的第一个变价计算(取effect_time最大的一个),获取current_saleprice
|
|
|
List<Map<String, String>> pricePlanListSorted = pricePlanList.stream().sorted(Comparator.comparingInt(map -> MapUtils.getInteger((Map) map, "effect_time")).reversed()).collect(Collectors.toList());
|
|
|
long currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
for (Map<String, String> pricePlanMap : pricePlanListSorted) {
|
...
|
...
|
|