|
|
package com.yohoufo.product.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
...
|
...
|
@@ -19,6 +22,8 @@ import org.springframework.util.CollectionUtils; |
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.core.rest.exception.ServiceNotAvaibleException;
|
|
|
import com.yohoufo.common.cache.Cachable;
|
...
|
...
|
@@ -158,6 +163,10 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
// 处理图片,封面图设置
|
|
|
String default_images = fillProductImgUrl(MapUtils.getString(product, "default_images", ""));
|
|
|
product.replace("default_images", default_images);
|
|
|
//处理有货价格
|
|
|
if(product.getString("is_yoho").equals("Y")) {
|
|
|
handlerPrice(product);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -463,4 +472,83 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
public void handlerPrice(JSONObject product) {
|
|
|
product.put("price", getIntCeilPrice(product.getDouble("price")));
|
|
|
JSONArray planList = product.getJSONArray("product_price_plan_list");
|
|
|
if(CollectionUtils.isEmpty(planList)){
|
|
|
return;
|
|
|
}
|
|
|
JSONObject effectPlan = getEffectProductPricePlan(planList);
|
|
|
//没有符合的价格计划,直接返回
|
|
|
if(null==effectPlan){
|
|
|
return;
|
|
|
}
|
|
|
if(null!=effectPlan.get("current_saleprice")){
|
|
|
product.replace("sales_price", getIntCeilPrice(effectPlan.getDouble("current_saleprice")));
|
|
|
}
|
|
|
if(null!=effectPlan.get("vip1_price")){
|
|
|
product.replace("vip1_price", effectPlan.getDouble("vip1_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip2_price")){
|
|
|
product.replace("vip2_price", effectPlan.getDouble("vip2_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip3_price")){
|
|
|
product.replace("vip3_price", effectPlan.getDouble("vip3_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip_discount_type")){
|
|
|
product.replace("vip_discount_type", effectPlan.getInteger("vip_discount_type"));
|
|
|
}
|
|
|
if(null!=effectPlan.get("student_price") && !"Y".equalsIgnoreCase(product.getString("is_student_price"))){
|
|
|
product.replace("student_price", product.getBigDecimal("sales_price").multiply(new BigDecimal("0.9")));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取一个生效的变价计划
|
|
|
* @param list
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONObject getEffectProductPricePlan(JSONArray planList){
|
|
|
if(CollectionUtils.isEmpty(planList)){
|
|
|
return null;
|
|
|
}
|
|
|
//先计算匹配到的价格计划,然后根据匹配到的价格计划求优先级
|
|
|
int currentTime= DateUtil.getCurrentTimeSecond();
|
|
|
logger.info("currentTime: {}", currentTime);
|
|
|
List<JSONObject> fitProductPricePlanList=Lists.newArrayList();
|
|
|
for (int i=0; i < planList.size(); i++) {
|
|
|
JSONObject item = planList.getJSONObject(i);
|
|
|
//当前时间大于等于生效时间且当前时间小于结束时间或没有结束时间的
|
|
|
if(currentTime>=item.getIntValue("effect_time") && (currentTime<=item.getIntValue("end_time")||item.getIntValue("end_time")==0)){
|
|
|
fitProductPricePlanList.add(item);
|
|
|
}
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(fitProductPricePlanList)){
|
|
|
//在多个价格计划都满足的情况下,生效时间越大越靠前
|
|
|
Collections.sort(fitProductPricePlanList, new Comparator<JSONObject>() {
|
|
|
@Override
|
|
|
public int compare(JSONObject o1, JSONObject o2) {
|
|
|
if(o2.getInteger("effect_time").compareTo(o1.getInteger("effect_time"))==0
|
|
|
&& null!=o2.getInteger("create_time") && null!=o1.getInteger("create_time")){
|
|
|
return o2.getInteger("create_time").compareTo(o1.getInteger("create_time"));
|
|
|
}
|
|
|
return o2.getInteger("effect_time").compareTo(o1.getInteger("effect_time"));
|
|
|
}
|
|
|
});
|
|
|
return fitProductPricePlanList.get(0);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//获取取整的价格
|
|
|
public static Integer getIntCeilPrice(Double price){
|
|
|
if(null == price) {
|
|
|
return 0;
|
|
|
}
|
|
|
return Double.valueOf(Math.ceil(price)).intValue();
|
|
|
}
|
|
|
} |
...
|
...
|
|