mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-19 12:41:55 +08:00
mall:新增价格计算的接口
This commit is contained in:
@@ -21,6 +21,13 @@
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 参数校验 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.market.api.price;
|
||||
|
||||
import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateReqDTO;
|
||||
import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateRespDTO;
|
||||
|
||||
/**
|
||||
* 价格 API 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface PriceApi {
|
||||
|
||||
/**
|
||||
* 计算商品的价格
|
||||
*
|
||||
* @param calculateReqDTO 价格请求
|
||||
* @return 价格相应
|
||||
*/
|
||||
PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO);
|
||||
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.market.api.price.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 价格计算 Request DTO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class PriceCalculateReqDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*
|
||||
* 对应 MemberUserDO 的 id 编号
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 优惠劵编号
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 商品 SKU 数组
|
||||
*/
|
||||
@NotNull(message = "商品数组不能为空")
|
||||
private List<Item> items;
|
||||
|
||||
/**
|
||||
* 商品 SKU
|
||||
*/
|
||||
@Data
|
||||
public static class Item {
|
||||
|
||||
/**
|
||||
* SKU 编号
|
||||
*/
|
||||
@NotNull(message = "商品 SKU 编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
/**
|
||||
* SKU 数量
|
||||
*/
|
||||
@NotNull(message = "商品 SKU 数量不能为空")
|
||||
@Min(value = 0L, message = "商品 SKU 数量必须大于等于 0") // 可传递 0 数量,用于购物车未选中的情况
|
||||
private Integer count;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,191 @@
|
||||
package cn.iocoder.yudao.module.market.api.price.dto;
|
||||
|
||||
import cn.iocoder.yudao.module.market.enums.common.PromotionLevelEnum;
|
||||
import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 价格计算 Response DTO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class PriceCalculateRespDTO {
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*/
|
||||
private Order order;
|
||||
|
||||
/**
|
||||
* 商品 SKU 数组
|
||||
*/
|
||||
private List<Item> items;
|
||||
|
||||
/**
|
||||
* 营销活动数组
|
||||
*
|
||||
* 只对应 {@link #items} 商品匹配的活动
|
||||
*/
|
||||
private List<Promotion> promotions;
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*/
|
||||
@Data
|
||||
public static class Order {
|
||||
|
||||
/**
|
||||
* 商品原价(总),单位:分
|
||||
*
|
||||
* 基于 {@link Item#getTotalOriginalPrice()} 求和
|
||||
*/
|
||||
private Integer skuOriginalPrice;
|
||||
/**
|
||||
* 商品优惠(总),单位:分
|
||||
*
|
||||
* 基于 {@link Item#getTotalPromotionPrice()} 求和
|
||||
*/
|
||||
private Integer skuPromotionPrice;
|
||||
/**
|
||||
* 订单优惠(总),单位:分
|
||||
*
|
||||
* 例如说:满减折扣;不包括优惠劵、商品优惠
|
||||
*/
|
||||
private Integer orderPromotionPrice;
|
||||
/**
|
||||
* 运费金额,单位:分
|
||||
*/
|
||||
private Integer deliveryPrice;
|
||||
/**
|
||||
* 应付金额(总),单位:分
|
||||
*
|
||||
* = {@link #skuOriginalPrice}
|
||||
* + {@link #deliveryPrice}
|
||||
* - {@link #skuPromotionPrice}
|
||||
* - {@link #orderPromotionPrice}
|
||||
* - {@link #couponPrice} // TODO 芋艿:需要再考虑一下它
|
||||
*/
|
||||
private Integer payPrice;
|
||||
|
||||
// ========== 营销基本信息 ==========
|
||||
/**
|
||||
* 优惠劵编号
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 优惠劵减免金额,单位:分
|
||||
*/
|
||||
private Integer couponPrice;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品 SKU
|
||||
*/
|
||||
@Data
|
||||
public static class Item extends PriceCalculateReqDTO.Item {
|
||||
|
||||
/**
|
||||
* 商品原价(单),单位:分
|
||||
*
|
||||
* 对应 ProductSkuDO 的 price 字段
|
||||
*/
|
||||
private Integer originalPrice;
|
||||
/**
|
||||
* 商品原价(总),单位:分
|
||||
*
|
||||
* = {@link #originalPrice} * {@link #getCount()}
|
||||
*/
|
||||
private Integer totalOriginalPrice;
|
||||
/**
|
||||
* 商品级优惠(总),单位:分
|
||||
*
|
||||
* 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
|
||||
*/
|
||||
private Integer totalPromotionPrice;
|
||||
/**
|
||||
* 最终购买金额(总),单位:分。
|
||||
*
|
||||
* = {@link #totalOriginalPrice}
|
||||
* - {@link #totalPromotionPrice}
|
||||
*/
|
||||
private Integer totalPresentPrice;
|
||||
/**
|
||||
* 最终购买金额(单),单位:分。
|
||||
*
|
||||
* = {@link #totalPresentPrice} / {@link #getCount()}
|
||||
*/
|
||||
private Integer presentPrice;
|
||||
/**
|
||||
* 应付金额(总),单位:分
|
||||
*/
|
||||
private Integer totalPayPrice;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 营销活动
|
||||
*/
|
||||
@Data
|
||||
public static class Promotion {
|
||||
|
||||
/**
|
||||
* 营销编号
|
||||
*
|
||||
* 例如说:营销活动的编号、优惠劵的编号
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 营销类型
|
||||
*
|
||||
* 枚举 {@link PromotionTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 营销级别
|
||||
*
|
||||
* 枚举 {@link PromotionLevelEnum}
|
||||
*/
|
||||
private Integer level;
|
||||
/**
|
||||
* 匹配的商品 SKU 数组
|
||||
*/
|
||||
private List<Item> items;
|
||||
/**
|
||||
* 计算时的原价(总),单位:分
|
||||
*/
|
||||
private Integer totalOriginalPrice;
|
||||
/**
|
||||
* 计算时的优惠(总),单位:分
|
||||
*/
|
||||
private Integer totalPromotionPrice;
|
||||
// TODO 芋艿:是否匹配,match ;不匹配的原因
|
||||
// TODO 芋艿:描述
|
||||
|
||||
/**
|
||||
* 匹配的商品 SKU
|
||||
*/
|
||||
@Data
|
||||
public static class Item {
|
||||
|
||||
/**
|
||||
* 商品 SKU 编号
|
||||
*/
|
||||
private Long skuId;
|
||||
/**
|
||||
* 计算时的原价(总),单位:分
|
||||
*/
|
||||
private Integer totalOriginalPrice;
|
||||
/**
|
||||
* 计算时的优惠(总),单位:分
|
||||
*/
|
||||
private Integer totalPromotionPrice;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.module.market.enums.activity;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 促销活动类型枚举
|
||||
*/
|
||||
public enum MarketActivityTypeEnum implements IntArrayValuable {
|
||||
|
||||
TIME_LIMITED_DISCOUNT(1, "限时折扣"),
|
||||
FULL_PRIVILEGE(2, "满减送"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MarketActivityTypeEnum::getValue).toArray();
|
||||
|
||||
/**
|
||||
* 类型值
|
||||
*/
|
||||
private final Integer value;
|
||||
/**
|
||||
* 类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
MarketActivityTypeEnum(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.market.enums.common;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 营销的级别枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PromotionLevelEnum implements IntArrayValuable {
|
||||
|
||||
ORDER(1, "订单级"),
|
||||
SKU(2, "商品级"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionLevelEnum::getLevel).toArray();
|
||||
|
||||
/**
|
||||
* 级别值
|
||||
*/
|
||||
private final Integer level;
|
||||
/**
|
||||
* 类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.market.enums.common;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 营销类型枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PromotionTypeEnum implements IntArrayValuable {
|
||||
|
||||
TIME_LIMITED_DISCOUNT(1, "限时折扣"),
|
||||
FULL_PRIVILEGE(2, "满减送"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();
|
||||
|
||||
/**
|
||||
* 类型值
|
||||
*/
|
||||
private final Integer type;
|
||||
/**
|
||||
* 类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user