code review:拼团、砍价活动

This commit is contained in:
YunaiV 2023-10-04 00:47:17 +08:00
parent 20f5834d9a
commit dc1347184f
11 changed files with 15 additions and 64 deletions

View File

@ -102,6 +102,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
return recordDO;
}
// TODO @芋艿在详细预览下
@Override
public void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count) {
// 1.1 校验拼团活动是否存在
@ -132,12 +133,14 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
}
// 5.1查询关联的订单是否已经支付
// 当前 activityId 已经有未支付的订单不允许在发起新的要么支付要么去掉先
// TODO 芋艿看看是不是可以删除掉
Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId());
if (ObjectUtil.equal(orderStatus, TradeOrderStatusEnum.UNPAID.getStatus())) {
throw exception(COMBINATION_RECORD_FAILED_ORDER_STATUS_UNPAID);
}
}
// TODO 芋艿在详细 review
@Override
@Transactional(rollbackFor = Exception.class)
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {

View File

@ -7,6 +7,7 @@ package cn.iocoder.yudao.module.trade.api.order;
*/
public interface TradeOrderApi {
// TODO 芋艿看看是不是可以删除掉
/**
* 获取订单状态
*

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.trade.controller.app.order.vo;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum;
@ -67,7 +68,7 @@ public class AppTradeOrderSettlementReqVO {
@JsonIgnore
public boolean isValidActivityItems() {
// 校验是否是活动订单
if (seckillActivityId == null && combinationActivityId == null && combinationHeadId == null) {
if (ObjUtil.isAllEmpty(seckillActivityId, combinationActivityId, combinationHeadId)) {
return true;
}
// 校验订单项是否超出

View File

@ -14,7 +14,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Component
public class TradeBargainHandler extends TradeOrderDefaultHandler {
public class TradeBargainHandler implements TradeOrderHandler {
@Resource
private BargainActivityApi bargainActivityApi;

View File

@ -17,7 +17,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Component
public class TradeCombinationHandler extends TradeOrderDefaultHandler {
public class TradeCombinationHandler implements TradeOrderHandler {
@Resource
private CombinationRecordApi combinationRecordApi;

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
/**
* 订单活动特殊逻辑处理器 handler 默认抽象实现类
*
* @author HUIHUI
*/
public abstract class TradeOrderDefaultHandler implements TradeOrderHandler {
@Override
public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) {
}
@Override
public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) {
}
@Override
public void afterPayOrder(TradeAfterPayOrderReqBO reqBO) {
}
@Override
public void cancelOrder() {
}
}

View File

@ -17,25 +17,25 @@ public interface TradeOrderHandler {
*
* @param reqBO 请求
*/
void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO);
default void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) {}
/**
* 订单创建后
*
* @param reqBO 请求
*/
void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO);
default void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) {}
/**
* 支付订单后
*
* @param reqBO 请求
*/
void afterPayOrder(TradeAfterPayOrderReqBO reqBO);
default void afterPayOrder(TradeAfterPayOrderReqBO reqBO) {}
/**
* 订单取消
*/
void cancelOrder();
default void cancelOrder() {}
}

View File

@ -14,7 +14,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Component
public class TradeSeckillHandler extends TradeOrderDefaultHandler {
public class TradeSeckillHandler implements TradeOrderHandler {
@Resource
private SeckillActivityApi seckillActivityApi;

View File

@ -98,19 +98,9 @@ public class TradePriceCalculateRespBO {
* VIP 减免金额单位
*/
private Integer vipPrice;
/**
* 秒杀拼团砍价活动商品的总金额单位
*
* 基于 {@link OrderItem#getActivityPrice()} ()} * {@link OrderItem#getCount()} 求和
*/
private Integer activityPrice;
/**
* 最终购买金额单位
*
* ==========活动情况===========
* = {@link #activityPrice}
* + {@link #deliveryPrice}
* ==========正常情况===========
* = {@link #totalPrice}
* - {@link #couponPrice}
* - {@link #pointPrice}
@ -186,16 +176,9 @@ public class TradePriceCalculateRespBO {
* VIP 减免金额单位
*/
private Integer vipPrice;
/**
* 秒杀拼团砍价活动商品的金额单位
*/
private Integer activityPrice;
/**
* 应付金额单位
* ==========活动情况===========
* = {@link #activityPrice} * {@link #count}
* + {@link #deliveryPrice}
* ==========正常情况===========
*
* = {@link #price} * {@link #count}
* - {@link #couponPrice}
* - {@link #pointPrice}

View File

@ -105,9 +105,6 @@ public class TradePriceCalculatorHelper {
if (!item.getSelected()) {
return;
}
// TODO puhui: 需要在这里计算活动的价格
// ========== 活动情况 ==========
// ========== 正常情况 ==========
price.setTotalPrice(price.getTotalPrice() + item.getPrice() * item.getCount());
price.setDiscountPrice(price.getDiscountPrice() + item.getDiscountPrice());
price.setDeliveryPrice(price.getDeliveryPrice() + item.getDeliveryPrice());

View File

@ -46,7 +46,7 @@ public class TradeSeckillActivityPriceCalculator implements TradePriceCalculator
orderItem.getSkuId(), orderItem.getCount());
// 3.1 记录优惠明细
Integer discountPrice = orderItem.getPayPrice() - seckillActivity.getSeckillPrice();
Integer discountPrice = orderItem.getPayPrice() - seckillActivity.getSeckillPrice() * orderItem.getCount();
TradePriceCalculatorHelper.addPromotion(result, orderItem,
param.getSeckillActivityId(), seckillActivity.getName(), PromotionTypeEnum.SECKILL_ACTIVITY.getType(),
StrUtil.format("秒杀活动:省 {} 元", TradePriceCalculatorHelper.formatPrice(discountPrice)),