mall + trade:调整价格字段,更易懂

This commit is contained in:
YunaiV 2023-05-26 23:58:26 +08:00
parent 0083d12404
commit 02fa6fc5c6
10 changed files with 58 additions and 93 deletions

View File

@ -38,6 +38,7 @@ public class PriceCalculateRespDTO {
*/
private List<Promotion> promotions;
// TODO @芋艿需要改造下主要是价格字段
/**
* 订单
*/
@ -51,14 +52,7 @@ public class PriceCalculateRespDTO {
*
* 对应 taobao trade.total_fee 字段
*/
private Integer originalPrice;
/**
* 订单原价单位
*
* 基于 {@link OrderItem#getPayPrice()} 求和
* {@link #originalPrice} 的差异去除商品级优惠
*/
private Integer orderPrice;
private Integer totalPrice;
/**
* 订单优惠单位
*
@ -207,7 +201,7 @@ public class PriceCalculateRespDTO {
/**
* 计算时的原价单位
*/
private Integer originalPrice;
private Integer totalPrice;
/**
* 计算时的优惠单位
*/

View File

@ -22,7 +22,7 @@ public interface PriceConvert {
// 创建 PriceCalculateRespDTO 对象
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO();
// 创建它的 Order 属性
PriceCalculateRespDTO.Order order = new PriceCalculateRespDTO.Order().setOriginalPrice(0).setDiscountPrice(0)
PriceCalculateRespDTO.Order order = new PriceCalculateRespDTO.Order().setTotalPrice(0).setDiscountPrice(0)
.setCouponPrice(0).setPointPrice(0).setDeliveryPrice(0).setPayPrice(0)
.setItems(new ArrayList<>()).setCouponId(calculateReqDTO.getCouponId());
priceCalculate.setOrder(order).setPromotions(new ArrayList<>());
@ -38,8 +38,8 @@ public interface PriceConvert {
orderItem.setPayPrice(orderItem.getOriginalPrice()).setOrderDividePrice(orderItem.getOriginalPrice());
priceCalculate.getOrder().getItems().add(orderItem);
// 补充价格信息到 Order
order.setOriginalPrice(order.getOriginalPrice() + orderItem.getOriginalPrice())
.setOrderPrice(order.getOriginalPrice()).setPayPrice(order.getOriginalPrice());
order.setTotalPrice(order.getTotalPrice() + orderItem.getOriginalPrice())
.setPayPrice(order.getTotalPrice());
});
return priceCalculate;
}

View File

@ -406,7 +406,7 @@ public class PriceServiceImpl implements PriceService {
// 创建营销明细
PriceCalculateRespDTO.Promotion promotion = new PriceCalculateRespDTO.Promotion()
.setId(id).setName(name).setType(type).setLevel(level)
.setOriginalPrice(promotionItem.getOriginalPrice()).setDiscountPrice(promotionItem.getDiscountPrice())
.setTotalPrice(promotionItem.getOriginalPrice()).setDiscountPrice(promotionItem.getDiscountPrice())
.setItems(singletonList(promotionItem)).setMeet(meet).setMeetTip(meetTip);
priceCalculate.getPromotions().add(promotion);
}
@ -437,7 +437,7 @@ public class PriceServiceImpl implements PriceService {
// 创建营销明细
PriceCalculateRespDTO.Promotion promotion = new PriceCalculateRespDTO.Promotion()
.setId(id).setName(name).setType(type).setLevel(level)
.setOriginalPrice(getSumValue(orderItems, PriceCalculateRespDTO.OrderItem::getOrderDividePrice, Integer::sum))
.setTotalPrice(getSumValue(orderItems, PriceCalculateRespDTO.OrderItem::getOrderDividePrice, Integer::sum))
.setDiscountPrice(getSumValue(discountPrices, value -> value, Integer::sum))
.setItems(promotionItems).setMeet(meet).setMeetTip(meetTip);
priceCalculate.getPromotions().add(promotion);
@ -453,7 +453,7 @@ public class PriceServiceImpl implements PriceService {
Integer originalPrice = getSumValue(orderItems, PriceCalculateRespDTO.OrderItem::getOrderDividePrice, Integer::sum);
PriceCalculateRespDTO.Promotion promotion = new PriceCalculateRespDTO.Promotion()
.setId(id).setName(name).setType(type).setLevel(level)
.setOriginalPrice(originalPrice).setDiscountPrice(0)
.setTotalPrice(originalPrice).setDiscountPrice(0)
.setItems(promotionItems).setMeet(false).setMeetTip(meetTip);
priceCalculate.getPromotions().add(promotion);
}
@ -476,7 +476,6 @@ public class PriceServiceImpl implements PriceService {
// 设置 Order 相关相关字段
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
order.setPayPrice(order.getPayPrice() - diffPayPrice);
order.setOrderPrice(order.getOrderPrice() - diffPayPrice);
}
/**

View File

@ -70,8 +70,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO);
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 200);
assertEquals(order.getOrderPrice(), 180);
assertEquals(order.getTotalPrice(), 200);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -95,7 +94,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion.getName(), "会员折扣");
assertEquals(promotion.getType(), PromotionTypeEnum.MEMBER.getType());
assertEquals(promotion.getLevel(), PromotionLevelEnum.SKU.getLevel());
assertEquals(promotion.getOriginalPrice(), 200);
assertEquals(promotion.getTotalPrice(), 200);
assertEquals(promotion.getDiscountPrice(), 20);
assertTrue(promotion.getMeet());
assertEquals(promotion.getMeetTip(), "会员折扣:省 0.20 元");
@ -133,8 +132,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO);
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 350);
assertEquals(order.getOrderPrice(), 210);
assertEquals(order.getTotalPrice(), 350);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -167,7 +165,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion01.getName(), "活动 1000 号");
assertEquals(promotion01.getType(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType());
assertEquals(promotion01.getLevel(), PromotionLevelEnum.SKU.getLevel());
assertEquals(promotion01.getOriginalPrice(), 200);
assertEquals(promotion01.getTotalPrice(), 200);
assertEquals(promotion01.getDiscountPrice(), 80);
assertTrue(promotion01.getMeet());
assertEquals(promotion01.getMeetTip(), "限时折扣:省 0.80 元");
@ -181,7 +179,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion02.getName(), "活动 2000 号");
assertEquals(promotion02.getType(), PromotionTypeEnum.DISCOUNT_ACTIVITY.getType());
assertEquals(promotion02.getLevel(), PromotionLevelEnum.SKU.getLevel());
assertEquals(promotion02.getOriginalPrice(), 150);
assertEquals(promotion02.getTotalPrice(), 150);
assertEquals(promotion02.getDiscountPrice(), 60);
assertTrue(promotion02.getMeet());
assertEquals(promotion02.getMeetTip(), "限时折扣:省 0.60 元");
@ -225,8 +223,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO);
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 470);
assertEquals(order.getOrderPrice(), 470);
assertEquals(order.getTotalPrice(), 470);
assertEquals(order.getDiscountPrice(), 130);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -268,7 +265,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion01.getName(), "活动 1000 号");
assertEquals(promotion01.getType(), PromotionTypeEnum.REWARD_ACTIVITY.getType());
assertEquals(promotion01.getLevel(), PromotionLevelEnum.ORDER.getLevel());
assertEquals(promotion01.getOriginalPrice(), 350);
assertEquals(promotion01.getTotalPrice(), 350);
assertEquals(promotion01.getDiscountPrice(), 70);
assertTrue(promotion01.getMeet());
assertEquals(promotion01.getMeetTip(), "满减送:省 0.70 元");
@ -287,7 +284,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion02.getName(), "活动 2000 号");
assertEquals(promotion02.getType(), PromotionTypeEnum.REWARD_ACTIVITY.getType());
assertEquals(promotion02.getLevel(), PromotionLevelEnum.ORDER.getLevel());
assertEquals(promotion02.getOriginalPrice(), 120);
assertEquals(promotion02.getTotalPrice(), 120);
assertEquals(promotion02.getDiscountPrice(), 60);
assertTrue(promotion02.getMeet());
assertEquals(promotion02.getMeetTip(), "满减送:省 0.60 元");
@ -323,8 +320,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO);
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 350);
assertEquals(order.getOrderPrice(), 350);
assertEquals(order.getTotalPrice(), 350);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -357,7 +353,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion01.getName(), "活动 1000 号");
assertEquals(promotion01.getType(), PromotionTypeEnum.REWARD_ACTIVITY.getType());
assertEquals(promotion01.getLevel(), PromotionLevelEnum.ORDER.getLevel());
assertEquals(promotion01.getOriginalPrice(), 350);
assertEquals(promotion01.getTotalPrice(), 350);
assertEquals(promotion01.getDiscountPrice(), 0);
assertFalse(promotion01.getMeet());
assertEquals(promotion01.getMeetTip(), "TODO"); // TODO 芋艿后面再想想
@ -396,8 +392,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
PriceCalculateRespDTO priceCalculate = priceService.calculatePrice(calculateReqDTO);
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 470);
assertEquals(order.getOrderPrice(), 470);
assertEquals(order.getTotalPrice(), 470);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -440,7 +435,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals(promotion01.getName(), "程序员节");
assertEquals(promotion01.getType(), PromotionTypeEnum.COUPON.getType());
assertEquals(promotion01.getLevel(), PromotionLevelEnum.COUPON.getLevel());
assertEquals(promotion01.getOriginalPrice(), 350);
assertEquals(promotion01.getTotalPrice(), 350);
assertEquals(promotion01.getDiscountPrice(), 70);
assertTrue(promotion01.getMeet());
assertEquals(promotion01.getMeetTip(), "优惠劵:省 0.70 元");

View File

@ -73,9 +73,6 @@ public class TradeOrderBaseVO {
@Schema(description = "商品原价(总)", required = true, example = "1000")
private Integer originalPrice;
@Schema(description = "订单原价(总)", required = true, example = "1000")
private Integer orderPrice;
@Schema(description = "订单优惠(总)", required = true, example = "100")
private Integer discountPrice;

View File

@ -59,10 +59,7 @@ public class AppTradeOrderDetailRespVO {
private String payChannelCode;
@Schema(description = "商品原价(总)", required = true, example = "1000")
private Integer originalPrice;
@Schema(description = "订单原价(总)", required = true, example = "1000")
private Integer orderPrice;
private Integer totalPrice;
@Schema(description = "订单优惠(总)", required = true, example = "100")
private Integer discountPrice;

View File

@ -2,13 +2,8 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.order;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
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.delivery.DeliveryTypeEnum;
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.TradeOrderDeliveryStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.enums.order.*;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
@ -134,25 +129,15 @@ public class TradeOrderDO extends BaseDO {
private String payChannelCode;
/**
* 商品原价单位
* 商品原价单位
*
* totalPrice = {@link TradeOrderItemDO#getPrice()} * {@link TradeOrderItemDO#getCount()} 求和
*
* 对应 taobao trade.total_fee 字段
*/
private Integer totalPrice;
// TODO 芋艿是不是要删除这个字段
/**
* 订单原价单位
*
* 1. orderPrice = {@link OrderItem#getPayPrice()} 求和
* 2. orderPrice = {@link #totalPrice} - 商品级优惠
*/
private Integer orderPrice;
/**
* 订单优惠单位
*
* 订单级优惠对主订单的优惠常见如订单满 200 元减 10 订单满 80 包邮
* 优惠金额单位
*
* 对应 taobao order.discount_fee 字段
*/
@ -162,7 +147,7 @@ public class TradeOrderDO extends BaseDO {
*/
private Integer deliveryPrice;
/**
* 订单调价单位
* 订单调价单位
*
* 正数加价负数减价
*/
@ -170,11 +155,11 @@ public class TradeOrderDO extends BaseDO {
/**
* 应付金额单位
*
* = {@link OrderItem#getPayPrice()} 求和
* = {@link #totalPrice}
* - {@link #couponPrice}
* - {@link #pointPrice}
* + {@link #deliveryPrice}
* - {@link #discountPrice}
* + {@link #deliveryPrice}
* + {@link #adjustPrice}
*/
private Integer payPrice;

View File

@ -102,44 +102,47 @@ public class TradeOrderItemDO extends BaseDO {
*/
private Integer price;
/**
* 商品优惠单位
*
* 商品级优惠对单个商品的常见如商品原价的 8 商品原价的减 50
* 优惠金额单位
*
* 对应 taobao order.discount_fee 字段
*/
private Integer discountPrice;
/**
* 子订单实付金额不算主订单分摊金额单位
* 运费金额单位
*/
private Integer deliveryPrice;
/**
* 订单调价单位
*
* 正数加价负数减价
*/
private Integer adjustPrice;
/**
* 应付金额单位
*
* = {@link #price} * {@link #count}
* - {@link #couponPrice}
* - {@link #pointPrice}
* - {@link #discountPrice}
*
* 对应 taobao order.payment 字段
* + {@link #deliveryPrice}
* + {@link #adjustPrice}
*/
private Integer payPrice;
/**
* 子订单分摊金额单位
* 需要分摊 {@link TradeOrderDO#getDiscountPrice()}{@link TradeOrderDO#getCouponPrice()}{@link TradeOrderDO#getPointPrice()}
*
* 对应 taobao order.part_mjz_discount 字段
* 淘宝说明子订单分摊优惠基础逻辑一般正常优惠券和满减优惠按照子订单的金额进行分摊特殊情况如果优惠券是指定商品使用的只会分摊到对应商品子订单上不分摊
*/
private Integer orderPartPrice;
/**
* 分摊后子订单实付金额单位
*
* = {@link #payPrice}
* - {@link #orderPartPrice}
*
* 对应 taobao divide_order_fee 字段
*/
private Integer orderDividePrice;
// ========== 营销基本信息 ==========
// TODO 芋艿在捉摸一下
/**
* 优惠劵减免金额单位
*
* 对应 taobao trade.coupon_fee 字段
*/
private Integer couponPrice;
/**
* 积分抵扣的金额单位
*
* 对应 taobao trade.point_fee 字段
*/
private Integer pointPrice;
// ========== 售后基本信息 ==========
/**

View File

@ -97,7 +97,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService {
}
// 申请的退款金额不能超过商品的价格
if (createReqVO.getRefundPrice() > orderItem.getOrderDividePrice()) {
if (createReqVO.getRefundPrice() > orderItem.getPayPrice()) {
throw exception(AFTER_SALE_CREATE_FAIL_REFUND_PRICE_ERROR);
}

View File

@ -124,7 +124,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
.setSpuId(21L).setSkuId(2L).setCount(4).setOriginalPrice(80).setOriginalUnitPrice(20)
.setDiscountPrice(40).setPayPrice(40).setOrderPartPrice(15).setOrderDividePrice(25);
PriceCalculateRespDTO.Order priceOrder = new PriceCalculateRespDTO.Order()
.setOriginalPrice(230).setOrderPrice(100).setDiscountPrice(0).setCouponPrice(30)
.setTotalPrice(230).setDiscountPrice(0).setCouponPrice(30)
.setPointPrice(10).setDeliveryPrice(20).setPayPrice(80).setCouponId(101L).setCouponPrice(30)
.setItems(Arrays.asList(priceOrderItem01, priceOrderItem02));
when(priceApi.calculatePrice(argThat(priceCalculateReqDTO -> {
@ -170,7 +170,6 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
assertFalse(tradeOrderDO.getPayed());
assertNull(tradeOrderDO.getPayTime());
assertEquals(tradeOrderDO.getTotalPrice(), 230);
assertEquals(tradeOrderDO.getOrderPrice(), 100);
assertEquals(tradeOrderDO.getDiscountPrice(), 0);
assertEquals(tradeOrderDO.getAdjustPrice(), 0);
assertEquals(tradeOrderDO.getPayPrice(), 80);
@ -208,8 +207,6 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
assertEquals(tradeOrderItemDO01.getPrice(), 50);
assertEquals(tradeOrderItemDO01.getDiscountPrice(), 20);
assertEquals(tradeOrderItemDO01.getPayPrice(), 130);
assertEquals(tradeOrderItemDO01.getOrderPartPrice(), 7);
assertEquals(tradeOrderItemDO01.getOrderDividePrice(), 35);
assertEquals(tradeOrderItemDO01.getAfterSaleStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus());
// 断言 TradeOrderItemDO 订单 2
TradeOrderItemDO tradeOrderItemDO02 = tradeOrderItemDOs.get(1);
@ -228,8 +225,6 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
assertEquals(tradeOrderItemDO02.getPrice(), 20);
assertEquals(tradeOrderItemDO02.getDiscountPrice(), 40);
assertEquals(tradeOrderItemDO02.getPayPrice(), 40);
assertEquals(tradeOrderItemDO02.getOrderPartPrice(), 15);
assertEquals(tradeOrderItemDO02.getOrderDividePrice(), 25);
assertEquals(tradeOrderItemDO02.getAfterSaleStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus());
// 校验调用
verify(productSkuApi).updateSkuStock(argThat(updateStockReqDTO -> {