申请售后,分为整单售后,和部分售后,退款的金额根据支付方式进行,例如:只有现金支付,或者混合支付(现金,移动,会员卡等多种支付方式)
计算退款金额的抽象类
/**
* 退款规则类
*
*
* @date 2020-10-20
**/
@Service
@Slf4j
public abstract class AbstractRefundRule {
@Resource
private OrderQueryApi orderQueryApi;
@Autowired
private RefundAmountItemService refundAmountItemService;
/**
* 获取退款金额
*
* @param refundAmountContextBO
* @return refundAmountBO
*/
public abstract RefundAmountBO getRefundAmount(RefundAmountContextBO refundAmountContextBO);
/**
* 计算应退总金额
*
* @param refundAmountContextBO
* @return bigDecimal
*/
public BigDecimal calculateSellPrice(RefundAmountContextBO refundAmountContextBO){
return refundAmountContextBO.getRefundItems().stream().map(RefundItemBO::getRefundItemAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
}
/**
* 获取已退金额
* @param orderId
* @param paymentType
* @return bigDecimal
*/
public BigDecimal calculateRefunded(Long orderId, Integer paymentType){
RefundAmountParams refundAmountParams = new RefundAmountParams();
refundAmountParams.setOrderId(orderId);
refundAmountParams.setPaymentType(paymentType);
List<OrderAfterRefundItem> orderAfterRefundItem = refundAmountItemService.queryByOrderIdAndRefundType(refundAmountParams);
return orderAfterRefundItem.stream().map(OrderAfterRefundItem::getRefundAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
}
public RefundResultDTO calculateAmount(RefundContext refundContext) {
RefundResultDTO refundResultDTO = RefundResultDTO.builder().build();
if (refundContext.getIsRefundFinish() == 1) {
return refundResultDTO;
} else {
//拿到订单和订单行信息
QueryOrderItemParam queryOrderItemParam = new QueryOrderItemParam();
queryOrderItemParam.setOrderId(refundContext.getOrderId());
OrderItemDetailDTO orderItemDetailDTO = orderQueryApi.