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

pull/2/head
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()}
*
* taobao trade.total_fee
*/
private Integer originalPrice;
/**
*
*
* {@link OrderItem#getPayPrice()}
* {@link #originalPrice}
*/
private Integer orderPrice;
/**
*
*
@ -82,6 +90,7 @@ public class PriceCalculateRespDTO {
* - {@link #couponPrice}
* - {@link #pointPrice}
* + {@link #deliveryPrice}
* - {@link #discountPrice}
*/
private Integer payPrice;
/**

View File

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

View File

@ -420,13 +420,16 @@ public class PriceServiceImpl implements PriceService {
*/
private void modifyOrderItemPayPrice(PriceCalculateRespDTO.OrderItem orderItem, Integer newPayPrice,
PriceCalculateRespDTO priceCalculate) {
// diffPayPrice 等于额外增加的商品级的优惠
int diffPayPrice = orderItem.getPayPrice() - newPayPrice;
// 设置 OrderItem 价格相关字段
orderItem.setDiscountPrice(orderItem.getDiscountPrice() + diffPayPrice);
orderItem.setPayPrice(newPayPrice);
orderItem.setOrderDividePrice(orderItem.getPayPrice() - orderItem.getOrderPartPrice());
// 设置 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 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 200);
assertEquals(order.getOrderPrice(), 180);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -126,6 +127,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 350);
assertEquals(order.getOrderPrice(), 210);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -217,6 +219,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 470);
assertEquals(order.getOrderPrice(), 470);
assertEquals(order.getDiscountPrice(), 130);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -314,6 +317,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 350);
assertEquals(order.getOrderPrice(), 350);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);
@ -386,6 +390,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
// 断言 Order 部分
PriceCalculateRespDTO.Order order = priceCalculate.getOrder();
assertEquals(order.getOriginalPrice(), 470);
assertEquals(order.getOrderPrice(), 470);
assertEquals(order.getDiscountPrice(), 0);
assertEquals(order.getPointPrice(), 0);
assertEquals(order.getDeliveryPrice(), 0);

View File

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

View File

@ -19,7 +19,7 @@ public class AppTradeOrderCreateReqVO {
@ApiModelProperty(name = "优惠劵编号", example = "1024")
private Long couponId;
@ApiModelProperty(name = "备注", example = "1024")
@ApiModelProperty(name = "备注", example = "这个是我的订单哟")
private String remark;
@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.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.TradeOrderRefundStatusEnum;
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()}
*
* taobao trade.total_fee
*/
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 #deliveryPrice}
* + {@link #adjustPrice}
* - {@link #promotionPrice}
* = {@link OrderItem#getPayPrice()}
* - {@link #couponPrice}
* - {@link #pointPrice}
* + {@link #deliveryPrice}
* - {@link #discountPrice}
* + {@link #adjustPrice}
*/
private Integer payPrice;
/**
@ -164,11 +176,11 @@ public class TradeOrderDO extends BaseDO {
*
* 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;
/**
*
*
* taobao trade.coupon_fee
*/
private Integer couponPrice;
/**
*
*
* taobao trade.point_fee
*/
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;
/**
* TODO @LeeYan9:
* Service
*
* @author LeeYan9
* @since 2022-08-26
*/
public interface TradeOrderService {
/**
* TODO @LeeYan9: ,
*
*
* @param loginUserId
* @param clientIp ip // TODO @LeeYan9: 中英文之间, 空一行哈
* @param clientIp IP
* @param createReqVO
* @return
* @return
*/
Long createTradeOrder(Long loginUserId, String clientIp, AppTradeOrderCreateReqVO createReqVO);
}

View File

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