Commit 2cdc02ce by 周晓航

额外配送费逻辑开发

Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent 8d4ad97d
...@@ -13,7 +13,7 @@ public class ExtraDeliveryDto { ...@@ -13,7 +13,7 @@ public class ExtraDeliveryDto {
/** /**
* 原有配送费类型 * 原有配送费类型
*/ */
public static int TYPE_DEFAULT = 0; public static int TYPE_DEFAULT = -1;
/** /**
* 晚间时段 附加配送费类型 * 晚间时段 附加配送费类型
*/ */
...@@ -21,7 +21,7 @@ public class ExtraDeliveryDto { ...@@ -21,7 +21,7 @@ public class ExtraDeliveryDto {
/** /**
* 早间时段 附加配送费类型 * 早间时段 附加配送费类型
*/ */
public static int TYPE_EXTRA_MORNING = 2; public static int TYPE_EXTRA_MORNING = 0;
/** /**
* 费用类型 * 费用类型
......
...@@ -76,4 +76,12 @@ public class DeliveryInfoDTO { ...@@ -76,4 +76,12 @@ public class DeliveryInfoDTO {
*/ */
private Integer finalDeliveryAmount; private Integer finalDeliveryAmount;
/**
* 额外拓展属性 json
* @see cn.freemud.entities.dto.console.DeliveryInfoExpandFieldDTO
*/
private String expandFields;
} }
package cn.freemud.entities.dto.console;
import lombok.Data;
import java.util.List;
/**
* @author : xh.Z
* @email : fisherman0510@163.com
* @Date : 2021/12/10 上午11:04
* @description :
*/
@Data
public class DeliveryInfoExpandFieldDTO {
/**
* 夜间 早间 额外配送费配置
*/
private List<NightDeliveryuInfo> nightDeliveryInfo;
}
package cn.freemud.entities.dto.console;
import lombok.Data;
import java.util.Date;
/**
* @author : xh.Z
* @email : fisherman0510@163.com
* @Date : 2021/12/10 上午11:05
* @description :
*/
@Data
public class NightDeliveryuInfo {
public static int COMMON_STATUS_CLOSE = 0;
public static int COMMON_STATUS_OPEN = 1;
/**
* 类型 0早间 1晚间
*/
private int type;
/**
* 开始时间
*/
private Date startTime;
/**
* 结束时间
*/
private Date endTime;
/**
* 是否开启 1开启 0关闭
*/
private int status;
/**
* 加的价格
*/
private Long price;
}
...@@ -13,12 +13,24 @@ ...@@ -13,12 +13,24 @@
package cn.freemud.service.delivery; package cn.freemud.service.delivery;
import cn.freemud.entities.ExtraDeliveryDto;
import cn.freemud.entities.dto.console.DeliveryInfoExpandFieldDTO;
import cn.freemud.entities.dto.console.NightDeliveryuInfo;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo; import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
import com.alibaba.fastjson.JSON;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
public interface DeliveryService { public interface DeliveryService {
/** /**
* 计算运费 * 计算运费
*
* @param receiveId * @param receiveId
* @param partnerId * @param partnerId
* @param storeId * @param storeId
...@@ -28,4 +40,37 @@ public interface DeliveryService { ...@@ -28,4 +40,37 @@ public interface DeliveryService {
Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo); Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo);
Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId); Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId);
/**
* 处理 额外配送费逻辑
*
* @param amount 原始配送费价格
* @param expandFields 门店反馈的额外配送费配置
*/
default List<ExtraDeliveryDto> nightDeliveryAmountHandle(long amount, String expandFields) {
List<ExtraDeliveryDto> list = new ArrayList<>();
if (amount > 0) {
ExtraDeliveryDto defaultAmount = new ExtraDeliveryDto(ExtraDeliveryDto.TYPE_DEFAULT, amount);
list.add(defaultAmount);
}
if (StringUtils.isNotBlank(expandFields)) {
DeliveryInfoExpandFieldDTO expandField = JSON.parseObject(expandFields, DeliveryInfoExpandFieldDTO.class);
if (Objects.nonNull(expandField) && CollectionUtils.isNotEmpty(expandField.getNightDeliveryInfo())) {
Date currentDate = new Date();
for (NightDeliveryuInfo info : expandField.getNightDeliveryInfo()) {
if (info.getStatus() == NightDeliveryuInfo.COMMON_STATUS_OPEN) {
// 当前时间在区间内
if (currentDate.after(info.getStartTime()) && currentDate.before(info.getEndTime())) {
ExtraDeliveryDto extraDeliveryDto = new ExtraDeliveryDto(info.getType(), amount);
list.add(extraDeliveryDto);
// 金额 增加
amount += info.getPrice();
}
}
}
}
}
return list;
}
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
package cn.freemud.service.delivery.impl; package cn.freemud.service.delivery.impl;
import cn.freemud.entities.ExtraDeliveryDto;
import cn.freemud.entities.dto.console.*; import cn.freemud.entities.dto.console.*;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo; import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
import cn.freemud.enums.ResponseResult; import cn.freemud.enums.ResponseResult;
...@@ -26,6 +27,7 @@ import com.freemud.application.sdk.api.storecenter.service.StoreCenterService; ...@@ -26,6 +27,7 @@ import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Service("fixDeliveryService") @Service("fixDeliveryService")
...@@ -48,12 +50,14 @@ public class FixDeliveryServiceImpl extends AbstractDeliveryServiceImpl implemen ...@@ -48,12 +50,14 @@ public class FixDeliveryServiceImpl extends AbstractDeliveryServiceImpl implemen
.build(); .build();
ConsoleResponseDTO<BizDTO> responseDto = consoleApiClient.getStoreMix(query); ConsoleResponseDTO<BizDTO> responseDto = consoleApiClient.getStoreMix(query);
DeliveryInfoDTO deliveryInfo = responseDto.getBizVO().getDeliveryInfo(); DeliveryInfoDTO deliveryInfo = responseDto.getBizVO().getDeliveryInfo();
// fisherman 处理 额外配送费
long amount = Objects.isNull(deliveryInfo.getFinalDeliveryAmount()) ? 0L : deliveryInfo.getFinalDeliveryAmount();
List<ExtraDeliveryDto> deliveryAmountList = super.nightDeliveryAmountHandle(amount, deliveryInfo.getExpandFields());
if (Objects.nonNull(shoppingCartGoodsResponseVo)) { if (Objects.nonNull(shoppingCartGoodsResponseVo)) {
shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(0); shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(0);
shoppingCartGoodsResponseVo.setDeliveryAmountList(deliveryAmountList);
} }
// fisherman 处理 额外配送费 return amount;
return Objects.isNull(deliveryInfo.getFinalDeliveryAmount()) ? 0L : deliveryInfo.getFinalDeliveryAmount();
} }
@Override @Override
......
...@@ -119,10 +119,8 @@ public class GradDeliveryServiceImpl extends AbstractDeliveryServiceImpl impleme ...@@ -119,10 +119,8 @@ public class GradDeliveryServiceImpl extends AbstractDeliveryServiceImpl impleme
return new DeliveryDto(0L, 1, new ArrayList<>()); return new DeliveryDto(0L, 1, new ArrayList<>());
} else { } else {
// 标准配送费 // 标准配送费
List<ExtraDeliveryDto> list = new ArrayList<>();
ExtraDeliveryDto defaultAmount = new ExtraDeliveryDto(ExtraDeliveryDto.TYPE_DEFAULT, amount);
list.add(defaultAmount);
// fisherman 处理 额外配送费 // fisherman 处理 额外配送费
List<ExtraDeliveryDto> list = super.nightDeliveryAmountHandle(amount, deliveryInfo.getExpandFields());
return new DeliveryDto(amount, 0, list); return new DeliveryDto(amount, 0, list);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment