mall:新增价格计算的接口

This commit is contained in:
YunaiV 2022-08-16 08:57:18 +08:00
parent 515c0de78d
commit 5948be86a8
11 changed files with 375 additions and 58 deletions

View File

@ -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>

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.market.controller.admin.activity.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum;
import cn.iocoder.yudao.module.market.enums.activity.MarketActivityTypeEnum;
import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
@ -24,7 +24,7 @@ public class ActivityBaseVO {
@ApiModelProperty(value = "活动类型", required = true)
@NotNull(message = "活动类型不能为空")
@InEnum(MarketActivityTypeEnum.class)
@InEnum(PromotionTypeEnum.class)
private Integer activityType;
@ApiModelProperty(value = "活动状态", required = true)

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.market.controller.admin.activity.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum;
import cn.iocoder.yudao.module.market.enums.activity.MarketActivityTypeEnum;
import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
@ -21,7 +21,7 @@ public class ActivityPageReqVO extends PageParam {
private String title;
@ApiModelProperty(value = "活动类型")
@InEnum(MarketActivityTypeEnum.class)
@InEnum(PromotionTypeEnum.class)
private Integer activityType;
@ApiModelProperty(value = "活动状态")

View File

@ -110,6 +110,8 @@ public class TradeOrderDO extends BaseDO {
// ========== 价格 + 支付基本信息 ==========
// 价格文档 - 淘宝https://open.taobao.com/docV3.htm?docId=108471&docType=1
// 价格文档 - 京东到家https://openo2o.jddj.com/api/getApiDetail/182/4d1494c5e7ac4679bfdaaed950c5bc7f.htm
// 价格文档 - 有赞https://doc.youzanyun.com/detail/API/0/906
// TODO promotion_details(订单优惠信息明细商品和订单级优惠一般都在里面)
@ -118,7 +120,8 @@ public class TradeOrderDO extends BaseDO {
*
* 基于 {@link TradeOrderItemDO#getTotalOriginalPrice()} 求和
*/
private Integer skuOriginalPrice; // niu - goods_money
// niu - goods_money
private Integer skuOriginalPrice;
/**
* 商品优惠单位
*
@ -130,11 +133,13 @@ public class TradeOrderDO extends BaseDO {
*
* 例如说满减折扣不包括优惠劵商品优惠
*/
private Integer orderPromotionPrice; // niu - promotion_moneytaobao - discount_fee主订单优惠
// niu - promotion_moneytaobao - discount_fee主订单优惠
private Integer orderPromotionPrice;
/**
* 运费金额单位
*/
private Integer deliveryPrice; // niu - delivery_moneytaobao - post_fee订单邮费
// niu - delivery_moneytaobao - post_fee订单邮费
private Integer deliveryPrice;
// TODO 芋艿taobao trade.adjust_fee/order.adjust_fee调整金额卖家手动修改订单价格官方数据修复等等
/**
* 应付金额单位
@ -145,7 +150,8 @@ public class TradeOrderDO extends BaseDO {
* - {@link #orderPromotionPrice}
* - {@link #couponPrice}
*/
private Integer payPrice; // niu - pay_moneytaobao - payment主订单实付金额 | trade.total_fee主订单应付金额参考使用
// niu - pay_moneytaobao - payment主订单实付金额 | trade.total_fee主订单应付金额参考使用
private Integer payPrice;
/**
* 支付订单编号
*
@ -244,7 +250,8 @@ public class TradeOrderDO extends BaseDO {
/**
* 优惠劵减免金额单位
*/
private Integer couponPrice; // niu - coupon_money
// niu - coupon_money
private Integer couponPrice;
// /**
// * 积分抵扣的金额单位
// */

View File

@ -84,19 +84,22 @@ public class TradeOrderItemDO extends BaseDO {
*
* 对应 ProductSkuDO price 字段
*/
private Integer originalPrice; // like - original_priceniu - costPrice
// like - original_priceniu - costPrice
private Integer originalPrice;
/**
* 商品原价单位
*
* = {@link #originalPrice} * {@link #count}
*/
private Integer totalOriginalPrice; // like - total_priceniu - 暂无
// like - total_priceniu - 暂无
private Integer totalOriginalPrice;
/**
* 商品级优惠单位
*
* 例如说限时折扣商品原价的 8 商品原价的减 50
*/
private Integer totalPromotionPrice; // taobao - order.discount_fee子订单商品优惠
// taobao - order.discount_fee子订单商品优惠
private Integer totalPromotionPrice;
/**
* 最终购买金额单位
*
@ -109,12 +112,14 @@ public class TradeOrderItemDO extends BaseDO {
* = {@link #totalOriginalPrice}
* - {@link #totalPromotionPrice}
*/
private Integer totalPresentPrice; // like - total_pay_priceniu - goods_money; taobao - order.payment子订单实付金额不算主订单分摊金额 | order.total_fee子订单应付金额参考使用
// like - total_pay_priceniu - goods_money; taobao - order.payment子订单实付金额不算主订单分摊金额 | order.total_fee子订单应付金额参考使用
private Integer totalPresentPrice;
// TODO 芋艿part_mjz_discount(子订单分摊金额)本质上totalOriginalPrice - totalPayPrice
/**
* 应付金额单位
*/
private Integer totalPayPrice; // taobao - divide_order_fee 分摊后子订单实付金额
// taobao - divide_order_fee 分摊后子订单实付金额
private Integer totalPayPrice;
// ========== 营销基本信息 ==========
// /**