...
|
...
|
@@ -392,6 +392,7 @@ public class ProductIndexBaseService { |
|
|
|
|
|
/**
|
|
|
* 获取skn促销标签-用于在待返回的列表返回之前加上促销标签这个节点
|
|
|
* add by wangnan in 2018/1/29
|
|
|
*/
|
|
|
public List<Map<String, Object>> getProductListWithPromotion(List<Map<String, Object>> productList) {
|
|
|
try {
|
...
|
...
|
@@ -435,9 +436,6 @@ public class ProductIndexBaseService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 给列表添加到手价字段
|
|
|
*/
|
|
|
public List<Map<String, Object>> getProductListWithPriceInHand(List<Map<String, Object>> productList) {
|
|
|
try {
|
|
|
List<Map<String, Object>> results = new ArrayList<>();
|
...
|
...
|
@@ -449,17 +447,20 @@ public class ProductIndexBaseService { |
|
|
if (CollectionUtils.isEmpty(promotionIndexBOList)) {
|
|
|
return productList;
|
|
|
}
|
|
|
Map<Integer, String> promotionActionParamMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId, PromotionIndexBO::getActionParam));
|
|
|
Map<Integer, PromotionIndexBO> promotionActionParamMap = promotionIndexBOList.stream().collect(Collectors.toMap(PromotionIndexBO::getId,p->p));
|
|
|
//遍历每个skn,计算promotion_price字段
|
|
|
for (Map<String, Object> productMap : productList) {
|
|
|
|
|
|
//全球购跳过
|
|
|
if ("Y".equals(MapUtils.getString(productMap, "is_global"))) {
|
|
|
productMap.put("promotion_price", null);
|
|
|
results.add(productMap);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//默认salesPrice为skn的sales_price
|
|
|
Double salesPrice = Double.valueOf(productMap.get("sales_price").toString());
|
|
|
|
|
|
//获取当前变价计划里的current_saleprice为salesPrice
|
|
|
List<Map<String, String>> pricePlanList = (List<Map<String, String>>) productMap.get("product_price_plan_list");
|
|
|
if (CollectionUtils.isNotEmpty(pricePlanList)) {
|
...
|
...
|
@@ -472,80 +473,81 @@ public class ProductIndexBaseService { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取促销列表,得到每个促销的actionParam
|
|
|
Double minSalesPrice = salesPrice;
|
|
|
List<Map<String, String>> promotionTagList = (List<Map<String, String>>) productMap.get("promotion_tag");
|
|
|
productMap.put("promotion_price", null);
|
|
|
//计算到手价
|
|
|
this.countPromotionPrice(promotionTagList, salesPrice, promotionActionParamMap, productMap);
|
|
|
//插入字段
|
|
|
results.add(productMap);
|
|
|
}
|
|
|
return results;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算到手价
|
|
|
*/
|
|
|
private void countPromotionPrice(List<Map<String, String>> promotionTagList, Double salesPrice, Map<Integer, String> promotionActionParamMap, Map<String, Object> productMap) {
|
|
|
try {
|
|
|
if (CollectionUtils.isNotEmpty(promotionTagList)) {
|
|
|
Double minSalesPrice = salesPrice;
|
|
|
boolean isPromotionPriceActive = false;
|
|
|
for (Map<String, String> promotionTag : promotionTagList) {
|
|
|
Double currentSalesPrice = salesPrice;
|
|
|
Integer promotionId = MapUtils.getInteger(promotionTag, "id");
|
|
|
String actionParam = promotionActionParamMap.get(promotionId);
|
|
|
JSONObject actionParamJson = JSONObject.parseObject(actionParam);
|
|
|
if (actionParamJson == null) {
|
|
|
continue;
|
|
|
}
|
|
|
if ("Discount".equals(promotionTag.get("type"))) {
|
|
|
|
|
|
}
|
|
|
if ("Cashreduce".equals(promotionTag.get("type"))) {
|
|
|
Double reduce = Double.valueOf(actionParamJson.get("reduce").toString());
|
|
|
if (reduce == null) {
|
|
|
if (CollectionUtils.isNotEmpty(promotionTagList)) {
|
|
|
boolean isPromotionPriceActive = false;
|
|
|
for (Map<String, String> promotionTag : promotionTagList) {
|
|
|
Double currentSalesPrice = salesPrice;
|
|
|
Integer promotionId = MapUtils.getInteger(promotionTag, "id");
|
|
|
//判断是否满足金额和件数条件
|
|
|
String conditionParam = promotionActionParamMap.get(promotionId).getConditionParam();
|
|
|
PromotionCond promotionCond = promotionCondService.buildPromotionCondWithJsonString(conditionParam);
|
|
|
boolean result = promotionMatchService.matchProductForPromotionPrice(promotionCond,productMap);
|
|
|
if(!result){
|
|
|
continue;
|
|
|
}
|
|
|
currentSalesPrice = salesPrice - reduce;
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
if ("Degressdiscount".equals(promotionTag.get("type"))) {
|
|
|
if (actionParamJson.get("degress_discount_list") == null) {
|
|
|
|
|
|
String actionParam = promotionActionParamMap.get(promotionId).getActionParam();
|
|
|
JSONObject actionParamJson = JSONObject.parseObject(actionParam);
|
|
|
if (actionParamJson == null) {
|
|
|
continue;
|
|
|
}
|
|
|
String degressDiscountList = actionParamJson.get("degress_discount_list").toString();
|
|
|
String[] degress = degressDiscountList.split(";");
|
|
|
if (degress[0] == null) {
|
|
|
continue;
|
|
|
if ("Discount".equals(promotionTag.get("type"))) {
|
|
|
Double discount = Double.valueOf(actionParamJson.get("discount").toString());
|
|
|
if(discount==null){
|
|
|
continue;
|
|
|
}
|
|
|
currentSalesPrice = salesPrice * discount;
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
String[] one = degress[0].split(":");
|
|
|
if (one[1] == null) {
|
|
|
continue;
|
|
|
if ("Cashreduce".equals(promotionTag.get("type"))) {
|
|
|
Double reduce = Double.valueOf(actionParamJson.get("reduce").toString());
|
|
|
if(reduce==null){
|
|
|
continue;
|
|
|
}
|
|
|
currentSalesPrice = salesPrice - reduce;
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
if ("Degressdiscount".equals(promotionTag.get("type"))) {
|
|
|
if(actionParamJson.get("degress_discount_list")==null){
|
|
|
continue;
|
|
|
}
|
|
|
String degressDiscountList = actionParamJson.get("degress_discount_list").toString();
|
|
|
String[] degress = degressDiscountList.split(";");
|
|
|
if(degress[0]==null){
|
|
|
continue;
|
|
|
}
|
|
|
String[] one = degress[0].split(":");
|
|
|
if(one[1]==null){
|
|
|
continue;
|
|
|
}
|
|
|
Double discount = Double.valueOf(one[1]);
|
|
|
currentSalesPrice = salesPrice * discount;
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
if (currentSalesPrice < minSalesPrice) {
|
|
|
minSalesPrice = currentSalesPrice;
|
|
|
}
|
|
|
Double discount = Double.valueOf(one[1]);
|
|
|
currentSalesPrice = salesPrice * discount;
|
|
|
isPromotionPriceActive = true;
|
|
|
}
|
|
|
if (currentSalesPrice < minSalesPrice) {
|
|
|
minSalesPrice = currentSalesPrice;
|
|
|
if (isPromotionPriceActive) {
|
|
|
Integer finalPrice = getIntCeilPrice(minSalesPrice);
|
|
|
productMap.put("promotion_price", finalPrice.toString());
|
|
|
}
|
|
|
}
|
|
|
if (isPromotionPriceActive) {
|
|
|
Integer finalPrice = getIntCeilPrice(minSalesPrice);
|
|
|
productMap.put("promotion_price", finalPrice.toString());
|
|
|
}
|
|
|
//插入字段
|
|
|
results.add(productMap);
|
|
|
}
|
|
|
return results;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private static Integer getIntCeilPrice(Double price) {
|
|
|
return Double.valueOf(Math.ceil(price)).intValue();
|
|
|
}
|
...
|
...
|
|