promotion:优化价格计算的接口,增加 orderPrice 字段

This commit is contained in:
YunaiV 2022-11-06 22:25:02 +08:00
parent 636cc794dd
commit d10f49b6a7
9 changed files with 61 additions and 28 deletions

View File

@ -48,9 +48,17 @@ public class PriceCalculateRespDTO {
* 商品原价单位 * 商品原价单位
* *
* 基于 {@link OrderItem#getOriginalPrice()} 求和 * 基于 {@link OrderItem#getOriginalPrice()} 求和
*
* 对应 taobao trade.total_fee 字段 * 对应 taobao trade.total_fee 字段
*/ */
private Integer originalPrice; private Integer originalPrice;
/**
* 订单原价单位
*
* 基于 {@link OrderItem#getPayPrice()} 求和
* {@link #originalPrice} 的差异去除商品级优惠
*/
private Integer orderPrice;
/** /**
* 订单优惠单位 * 订单优惠单位
* *
@ -82,6 +90,7 @@ public class PriceCalculateRespDTO {
* - {@link #couponPrice} * - {@link #couponPrice}
* - {@link #pointPrice} * - {@link #pointPrice}
* + {@link #deliveryPrice} * + {@link #deliveryPrice}
* - {@link #discountPrice}
*/ */
private Integer payPrice; private Integer payPrice;
/** /**

View File

@ -36,7 +36,8 @@ public interface PriceConvert {
orderItem.setPayPrice(orderItem.getOriginalPrice()).setOrderDividePrice(orderItem.getOriginalPrice()); orderItem.setPayPrice(orderItem.getOriginalPrice()).setOrderDividePrice(orderItem.getOriginalPrice());
priceCalculate.getOrder().getItems().add(orderItem); priceCalculate.getOrder().getItems().add(orderItem);
// 补充价格信息到 Order // 补充价格信息到 Order
order.setOriginalPrice(order.getOriginalPrice() + orderItem.getOriginalPrice()).setPayPrice(order.getOriginalPrice()); order.setOriginalPrice(order.getOriginalPrice() + orderItem.getOriginalPrice())
.setOrderPrice(order.getOriginalPrice()).setPayPrice(order.getOriginalPrice());
}); });
return priceCalculate; return priceCalculate;
} }

View File

@ -420,13 +420,16 @@ public class PriceServiceImpl implements PriceService {
*/ */
private void modifyOrderItemPayPrice(PriceCalculateRespDTO.OrderItem orderItem, Integer newPayPrice, private void modifyOrderItemPayPrice(PriceCalculateRespDTO.OrderItem orderItem, Integer newPayPrice,
PriceCalculateRespDTO priceCalculate) { PriceCalculateRespDTO priceCalculate) {
// diffPayPrice 等于额外增加的商品级的优惠
int diffPayPrice = orderItem.getPayPrice() - newPayPrice; int diffPayPrice = orderItem.getPayPrice() - newPayPrice;
// 设置 OrderItem 价格相关字段 // 设置 OrderItem 价格相关字段
orderItem.setDiscountPrice(orderItem.getDiscountPrice() + diffPayPrice); orderItem.setDiscountPrice(orderItem.getDiscountPrice() + diffPayPrice);
orderItem.setPayPrice(newPayPrice); orderItem.setPayPrice(newPayPrice);
orderItem.setOrderDividePrice(orderItem.getPayPrice() - orderItem.getOrderPartPrice()); orderItem.setOrderDividePrice(orderItem.getPayPrice() - orderItem.getOrderPartPrice());
// 设置 Order 相关相关字段 // 设置 Order 相关相关字段
priceCalculate.getOrder().setPayPrice(priceCalculate.getOrder().getPayPrice() - diffPayPrice); PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
order.setPayPrice(order.getPayPrice() - diffPayPrice);
order.setOrderPrice(order.getOrderPrice() - diffPayPrice);
} }
/** /**

View File

@ -64,6 +64,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分 // 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder(); PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 200); assertEquals(order.getOriginalPrice(), 200);
assertEquals(order.getOrderPrice(), 180);
assertEquals(order.getDiscountPrice(), 0); assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0); assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0); assertEquals(order.getDeliveryPrice(), 0);
@ -126,6 +127,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分 // 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder(); PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 350); assertEquals(order.getOriginalPrice(), 350);
assertEquals(order.getOrderPrice(), 210);
assertEquals(order.getDiscountPrice(), 0); assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0); assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0); assertEquals(order.getDeliveryPrice(), 0);
@ -217,6 +219,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分 // 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder(); PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 470); assertEquals(order.getOriginalPrice(), 470);
assertEquals(order.getOrderPrice(), 470);
assertEquals(order.getDiscountPrice(), 130); assertEquals(order.getDiscountPrice(), 130);
assertEquals(order.getPointPrice(), 0); assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0); assertEquals(order.getDeliveryPrice(), 0);
@ -314,6 +317,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分 // 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder(); PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 350); assertEquals(order.getOriginalPrice(), 350);
assertEquals(order.getOrderPrice(), 350);
assertEquals(order.getDiscountPrice(), 0); assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0); assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0); assertEquals(order.getDeliveryPrice(), 0);
@ -386,6 +390,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分 // 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder(); PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 470); assertEquals(order.getOriginalPrice(), 470);
assertEquals(order.getOrderPrice(), 470);
assertEquals(order.getDiscountPrice(), 0); assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0); assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0); assertEquals(order.getDeliveryPrice(), 0);

View File

@ -43,13 +43,12 @@ public class AppTradeOrderController {
@PreAuthenticated @PreAuthenticated
public CommonResult<Long> createTradeOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO, public CommonResult<Long> createTradeOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO,
HttpServletRequest servletRequest) { HttpServletRequest servletRequest) {
// 获取登录用户 // 获取登录用户用户 IP 地址
Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
// 获取用户ip地址
String clientIp = ServletUtil.getClientIP(servletRequest); String clientIp = ServletUtil.getClientIP(servletRequest);
// 创建交易订单预支付记录 // 创建交易订单预支付记录
Long result = tradeOrderService.createTradeOrder(loginUserId, clientIp, createReqVO); Long orderId = tradeOrderService.createTradeOrder(loginUserId, clientIp, createReqVO);
return CommonResult.success(result); return CommonResult.success(orderId);
} }
@GetMapping("/get") @GetMapping("/get")

View File

@ -19,7 +19,7 @@ public class AppTradeOrderCreateReqVO {
@ApiModelProperty(name = "优惠劵编号", example = "1024") @ApiModelProperty(name = "优惠劵编号", example = "1024")
private Long couponId; private Long couponId;
@ApiModelProperty(name = "备注", example = "1024") @ApiModelProperty(name = "备注", example = "这个是我的订单哟")
private String remark; private String remark;
@ApiModelProperty(name = "是否来自购物车", required = true, example = "true", notes = "true - 来自购物车false - 立即购买") @ApiModelProperty(name = "是否来自购物车", required = true, example = "true", notes = "true - 来自购物车false - 立即购买")

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.order;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO.OrderItem;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
@ -74,7 +75,7 @@ public class TradeOrderDO extends BaseDO {
/** /**
* 购买的商品数量 * 购买的商品数量
*/ */
private Integer productCount; // total_num private Integer productCount;
/** /**
* 订单完成时间 * 订单完成时间
*/ */
@ -116,14 +117,25 @@ public class TradeOrderDO extends BaseDO {
* 商品原价单位 * 商品原价单位
* *
* 基于 {@link TradeOrderItemDO#getTotalOriginalPrice()} 求和 * 基于 {@link TradeOrderItemDO#getTotalOriginalPrice()} 求和
*
* 对应 taobao trade.total_fee 字段
*/ */
private Integer originalPrice; private Integer originalPrice;
/**
* 订单原价单位
*
* 基于 {@link OrderItem#getPayPrice()} 求和
* {@link #originalPrice} 的差异去除商品级优惠
*/
private Integer orderPrice;
/** /**
* 订单优惠单位 * 订单优惠单位
* *
* 例如说满减折扣不包括优惠劵商品优惠TODO * 订单级优惠对主订单的优惠常见如订单满 200 元减 10 订单满 80 包邮
*
* 对应 taobao order.discount_fee 字段
*/ */
private Integer promotionPrice; private Integer discountPrice;
/** /**
* 运费金额单位 * 运费金额单位
*/ */
@ -137,12 +149,12 @@ public class TradeOrderDO extends BaseDO {
/** /**
* 应付金额单位 * 应付金额单位
* *
* = {@link #originalPrice} * = {@link OrderItem#getPayPrice()} 求和
* + {@link #deliveryPrice}
* + {@link #adjustPrice}
* - {@link #promotionPrice}
* - {@link #couponPrice} * - {@link #couponPrice}
* - {@link #pointPrice} * - {@link #pointPrice}
* + {@link #deliveryPrice}
* - {@link #discountPrice}
* + {@link #adjustPrice}
*/ */
private Integer payPrice; private Integer payPrice;
/** /**
@ -164,11 +176,11 @@ public class TradeOrderDO extends BaseDO {
* *
* 关联 DeliveryTemplateDO id 编号 * 关联 DeliveryTemplateDO id 编号
*/ */
private Long deliveryTemplateId; // dvy_id private Long deliveryTemplateId;
/** /**
* 物流公司单号 * 物流公司单号
*/ */
private String expressNo; // dvy_flow_id private String expressNo;
/** /**
* 发货状态 * 发货状态
* *
@ -227,10 +239,14 @@ public class TradeOrderDO extends BaseDO {
private Long couponId; private Long couponId;
/** /**
* 优惠劵减免金额单位 * 优惠劵减免金额单位
*
* 对应 taobao trade.coupon_fee 字段
*/ */
private Integer couponPrice; private Integer couponPrice;
/** /**
* 积分抵扣的金额单位 * 积分抵扣的金额单位
*
* 对应 taobao trade.point_fee 字段
*/ */
private Integer pointPrice; private Integer pointPrice;

View File

@ -3,18 +3,20 @@ package cn.iocoder.yudao.module.trade.service.order;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
/** /**
* TODO @LeeYan9: 类注释 * 交易订单 Service 接口
*
* @author LeeYan9 * @author LeeYan9
* @since 2022-08-26 * @since 2022-08-26
*/ */
public interface TradeOrderService { public interface TradeOrderService {
/** /**
* 创建交易订单 TODO @LeeYan9: 方法注释, 和参数要空一行 * 创建交易订单
*
* @param loginUserId 登录用户 * @param loginUserId 登录用户
* @param clientIp 用户ip地址 // TODO @LeeYan9: 中英文之间, 空一行哈 * @param clientIp 用户 IP 地址
* @param createReqVO 创建交易订单请求模型 * @param createReqVO 创建交易订单请求模型
* @return 交易订单创建结果 * @return 交易订单的编号
*/ */
Long createTradeOrder(Long loginUserId, String clientIp, AppTradeOrderCreateReqVO createReqVO); Long createTradeOrder(Long loginUserId, String clientIp, AppTradeOrderCreateReqVO createReqVO);
} }

View File

@ -45,14 +45,17 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
* TODO @LeeYan9: 注释 * 交易订单 Service 实现类
*
* @author LeeYan9 * @author LeeYan9
* @since 2022-08-26 * @since 2022-08-26
*/ */
@Service @Service
public class TradeOrderServiceImpl implements TradeOrderService { public class TradeOrderServiceImpl implements TradeOrderService {
// TODO @LeeYan9: 相同类型的, 可以放在一起,不用空行; 例如说 Mapper API Properties // TODO LeeYan9: 静态变量, 需要在最前面哈; 另外, 静态变量的注释最好写下;
private static final String BLANK_PLACEHOLDER = " ";
private static final String MULTIPLIER_PLACEHOLDER = "x";
@Resource @Resource
private TradeOrderMapper tradeOrderMapper; private TradeOrderMapper tradeOrderMapper;
@ -71,15 +74,10 @@ public class TradeOrderServiceImpl implements TradeOrderService {
@Resource @Resource
private TradeOrderProperties tradeOrderProperties; private TradeOrderProperties tradeOrderProperties;
// TODO LeeYan9: 静态变量, 需要在最前面哈; 另外, 静态变量的注释最好写下;
private static final String BLANK_PLACEHOLDER = " ";
private static final String MULTIPLIER_PLACEHOLDER = "x";
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long createTradeOrder(Long loginUserId, String clientIp, AppTradeOrderCreateReqVO createReqVO) { public Long createTradeOrder(Long loginUserId, String clientIp, AppTradeOrderCreateReqVO createReqVO) {
List<Item> items = createReqVO.getItems();
List<Item> items = createReqVO.getItems(); // TODO @LeeYan9: 方法第一行, 不用空哈;
// 商品SKU检查 sku可售状态,库存 // 商品SKU检查 sku可售状态,库存
List<ProductSkuRespDTO> skuInfos = productSkuApi.getSkuList(CollectionUtils.convertSet(items, Item::getSkuId)); List<ProductSkuRespDTO> skuInfos = productSkuApi.getSkuList(CollectionUtils.convertSet(items, Item::getSkuId));
Map<Long, ProductSkuRespDTO> skuInfoMap = CollectionUtils.convertMap(skuInfos, ProductSkuRespDTO::getId); Map<Long, ProductSkuRespDTO> skuInfoMap = CollectionUtils.convertMap(skuInfos, ProductSkuRespDTO::getId);