暂存调整 Price 接口
parent
e1d5cfe8fe
commit
5c4b61f5ff
|
@ -35,34 +35,43 @@ public class PriceCalculateRespDTO {
|
||||||
/**
|
/**
|
||||||
* 商品原价(总),单位:分
|
* 商品原价(总),单位:分
|
||||||
*
|
*
|
||||||
* 基于 {@link OrderItem#getTotalOriginalPrice()} 求和
|
* 基于 {@link OrderItem#getOriginalPrice()} 求和
|
||||||
*/
|
*/
|
||||||
private Integer skuOriginalPrice;
|
private Integer originalPrice;
|
||||||
/**
|
/**
|
||||||
* 商品优惠(总),单位:分
|
* 活动减免优惠(总),单位:分
|
||||||
*
|
*
|
||||||
* 基于 {@link OrderItem#getTotalPromotionPrice()} 求和
|
* 基于 {@link OrderItem#getActivityPrice()} 求和
|
||||||
*/
|
*/
|
||||||
private Integer skuPromotionPrice;
|
private Integer activityPrice;
|
||||||
/**
|
/**
|
||||||
* 订单优惠(总),单位:分
|
* 优惠劵减免金额(总),单位:分
|
||||||
*
|
*
|
||||||
* 例如说:满减折扣;不包括优惠劵、商品优惠
|
* 基于 {@link OrderItem#getCouponPrice()} 求和
|
||||||
*/
|
*/
|
||||||
private Integer orderPromotionPrice;
|
private Integer couponPrice;
|
||||||
|
/**
|
||||||
|
* 积分减免金额(总),单位:分
|
||||||
|
*
|
||||||
|
* 基于 {@link OrderItem#getPointPrice()} 求和
|
||||||
|
*/
|
||||||
|
private Integer pointPrice;
|
||||||
|
/**
|
||||||
|
* 会员减免金额(总),单位:分
|
||||||
|
*
|
||||||
|
* 基于 {@link OrderItem#getMemberPrice()} 求和
|
||||||
|
*/
|
||||||
|
private Integer memberPrice;
|
||||||
/**
|
/**
|
||||||
* 运费金额,单位:分
|
* 运费金额,单位:分
|
||||||
*/
|
*/
|
||||||
private Integer deliveryPrice;
|
private Integer deliveryPrice;
|
||||||
/**
|
/**
|
||||||
* 应付金额(总),单位:分
|
* 最终购买金额(总),单位:分
|
||||||
*
|
*
|
||||||
* = {@link #skuOriginalPrice}
|
* = {@link OrderItem#getPayPrice()} 求和
|
||||||
* + {@link #deliveryPrice}
|
* + {@link #deliveryPrice}
|
||||||
* - {@link #skuPromotionPrice}
|
|
||||||
* - {@link #orderPromotionPrice}
|
|
||||||
*/
|
*/
|
||||||
// * - {@link #couponPrice} // TODO 芋艿:靠营销表记录
|
|
||||||
private Integer payPrice;
|
private Integer payPrice;
|
||||||
/**
|
/**
|
||||||
* 商品 SKU 数组
|
* 商品 SKU 数组
|
||||||
|
@ -74,12 +83,6 @@ public class PriceCalculateRespDTO {
|
||||||
* 优惠劵编号
|
* 优惠劵编号
|
||||||
*/
|
*/
|
||||||
private Long couponId;
|
private Long couponId;
|
||||||
// /**
|
|
||||||
// * 优惠劵减免金额,单位:分
|
|
||||||
// *
|
|
||||||
// * // TODO 芋艿:靠营销表记录
|
|
||||||
// */
|
|
||||||
// private Integer couponPrice;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,41 +97,54 @@ public class PriceCalculateRespDTO {
|
||||||
*/
|
*/
|
||||||
private Integer count;
|
private Integer count;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品原价(总),单位:分
|
||||||
|
*
|
||||||
|
* = {@link #originalUnitPrice} * {@link #getCount()}
|
||||||
|
*/
|
||||||
|
private Integer originalPrice;
|
||||||
/**
|
/**
|
||||||
* 商品原价(单),单位:分
|
* 商品原价(单),单位:分
|
||||||
*
|
*
|
||||||
* 对应 ProductSkuDO 的 price 字段
|
* 对应 ProductSkuDO 的 price 字段
|
||||||
*/
|
*/
|
||||||
private Integer originalPrice;
|
private Integer originalUnitPrice;
|
||||||
/**
|
/**
|
||||||
* 商品原价(总),单位:分
|
* 活动减免优惠(总),单位:分
|
||||||
*
|
*
|
||||||
* = {@link #originalPrice} * {@link #getCount()}
|
* 例如说,限时折扣、满减送等营销活动
|
||||||
*/
|
*/
|
||||||
private Integer totalOriginalPrice;
|
private Integer activityPrice;
|
||||||
/**
|
/**
|
||||||
* 商品级优惠(总),单位:分
|
* 优惠劵减免金额(总),单位:分
|
||||||
*
|
*
|
||||||
* 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
|
* 一个优惠劵会作用到的多个 SKU 商品,按照计算时的 {@link #payPrice} 的比例分摊
|
||||||
*/
|
*/
|
||||||
private Integer totalPromotionPrice;
|
private Integer couponPrice;
|
||||||
|
/**
|
||||||
|
* 积分减免金额(总),单位:分
|
||||||
|
*/
|
||||||
|
private Integer pointPrice;
|
||||||
|
/**
|
||||||
|
* 会员减免金额(总),单位:分
|
||||||
|
*/
|
||||||
|
private Integer memberPrice;
|
||||||
/**
|
/**
|
||||||
* 最终购买金额(总),单位:分。
|
* 最终购买金额(总),单位:分。
|
||||||
*
|
*
|
||||||
* = {@link #totalOriginalPrice}
|
* = {@link #originalPrice}
|
||||||
* - {@link #totalPromotionPrice}
|
* - {@link #activityPrice}
|
||||||
|
* - {@link #couponPrice}
|
||||||
|
* - {@link #pointPrice}
|
||||||
|
* - {@link #memberPrice}
|
||||||
*/
|
*/
|
||||||
private Integer totalPresentPrice;
|
private Integer payPrice;
|
||||||
/**
|
/**
|
||||||
* 最终购买金额(单),单位:分。
|
* 最终购买金额(单),单位:分。
|
||||||
*
|
*
|
||||||
* = {@link #totalPresentPrice} / {@link #getCount()}
|
* = {@link #payPrice} / {@link #getCount()}
|
||||||
*/
|
*/
|
||||||
private Integer presentPrice;
|
private Integer payUnitPrice;
|
||||||
/**
|
|
||||||
* 应付金额(总),单位:分
|
|
||||||
*/
|
|
||||||
private Integer totalPayPrice;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ import java.util.Arrays;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum PromotionLevelEnum implements IntArrayValuable {
|
public enum PromotionLevelEnum implements IntArrayValuable {
|
||||||
|
|
||||||
ORDER(1, "订单级"),
|
ORDER(1, "订单级"), // 多个商品,进行组合后优惠
|
||||||
SKU(2, "商品级"),
|
SKU(2, "商品级"), // 单个商品,直接优惠
|
||||||
;
|
;
|
||||||
|
|
||||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionLevelEnum::getLevel).toArray();
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionLevelEnum::getLevel).toArray();
|
||||||
|
|
|
@ -15,8 +15,8 @@ import java.util.Arrays;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum PromotionTypeEnum implements IntArrayValuable {
|
public enum PromotionTypeEnum implements IntArrayValuable {
|
||||||
|
|
||||||
DISCOUNT(1, "限时折扣"),
|
DISCOUNT_ACTIVITY(1, "限时折扣"),
|
||||||
REWARD(2, "满减送"),
|
REWARD_ACTIVITY(2, "满减送"),
|
||||||
;
|
;
|
||||||
|
|
||||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();
|
||||||
|
|
|
@ -19,8 +19,8 @@ public interface PriceConvert {
|
||||||
default PriceCalculateRespDTO convert(PriceCalculateReqDTO calculateReqDTO, List<ProductSkuRespDTO> skuList) {
|
default PriceCalculateRespDTO convert(PriceCalculateReqDTO calculateReqDTO, List<ProductSkuRespDTO> skuList) {
|
||||||
// 创建 PriceCalculateRespDTO 对象
|
// 创建 PriceCalculateRespDTO 对象
|
||||||
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO();
|
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO();
|
||||||
priceCalculate.setOrder(new PriceCalculateRespDTO.Order().setSkuOriginalPrice(0).setSkuPromotionPrice(0)
|
priceCalculate.setOrder(new PriceCalculateRespDTO.Order().setOriginalPrice(0).setActivityPrice(0)
|
||||||
.setOrderPromotionPrice(0).setDeliveryPrice(0).setPayPrice(0).setItems(new ArrayList<>())
|
.setDeliveryPrice(0).setPayPrice(0).setItems(new ArrayList<>())
|
||||||
.setCouponId(calculateReqDTO.getCouponId()));
|
.setCouponId(calculateReqDTO.getCouponId()));
|
||||||
priceCalculate.setPromotions(new ArrayList<>());
|
priceCalculate.setPromotions(new ArrayList<>());
|
||||||
// 创建它的 OrderItem 属性
|
// 创建它的 OrderItem 属性
|
||||||
|
@ -29,9 +29,9 @@ public interface PriceConvert {
|
||||||
skuList.forEach(sku -> {
|
skuList.forEach(sku -> {
|
||||||
Integer count = skuIdCountMap.get(sku.getId());
|
Integer count = skuIdCountMap.get(sku.getId());
|
||||||
PriceCalculateRespDTO.OrderItem orderItem = new PriceCalculateRespDTO.OrderItem().setCount(count)
|
PriceCalculateRespDTO.OrderItem orderItem = new PriceCalculateRespDTO.OrderItem().setCount(count)
|
||||||
.setOriginalPrice(sku.getPrice()).setTotalOriginalPrice(sku.getPrice() * count).setTotalPromotionPrice(0);
|
.setOriginalUnitPrice(sku.getPrice()).setOriginalPrice(sku.getPrice() * count).setActivityPrice(0);
|
||||||
orderItem.setTotalPresentPrice(orderItem.getTotalPresentPrice()).setPresentPrice(orderItem.getOriginalPrice())
|
orderItem.setPayPrice(orderItem.getPayPrice()).setPayUnitPrice(orderItem.getOriginalUnitPrice())
|
||||||
.setTotalPayPrice(orderItem.getTotalPayPrice());
|
.setPayPrice(orderItem.getPayPrice());
|
||||||
priceCalculate.getOrder().getItems().add(orderItem);
|
priceCalculate.getOrder().getItems().add(orderItem);
|
||||||
});
|
});
|
||||||
return priceCalculate;
|
return priceCalculate;
|
||||||
|
|
|
@ -15,7 +15,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
|
||||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_STOCK_NOT_ENOUGH;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 价格计算 Service 实现类
|
* 价格计算 Service 实现类
|
||||||
|
@ -54,9 +53,7 @@ public class PriceServiceImpl implements PriceService {
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
throw exception(SKU_NOT_EXISTS);
|
throw exception(SKU_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
if (count > sku.getStock()) {
|
// 不校验库存不足,避免购物车场景,商品无货的情况
|
||||||
throw exception(SKU_STOCK_NOT_ENOUGH);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return skus;
|
return skus;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue