【代码评审】商城:积分商城的下单流程

This commit is contained in:
YunaiV 2024-10-04 18:40:33 +08:00
parent ce367d99a9
commit e604cba3bf
7 changed files with 11 additions and 11 deletions

View File

@ -73,12 +73,11 @@ public class AppPointActivityController {
// 2. 拼接数据 // 2. 拼接数据
List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(Collections.singletonList(id)); List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(Collections.singletonList(id));
AppPointActivityDetailRespVO respVO = BeanUtils.toBean(activity, AppPointActivityDetailRespVO.class); PointProductDO minProduct = getMinObject(products, PointProductDO::getPoint);
// 设置 product 信息
respVO.setProducts(BeanUtils.toBean(products, AppPointActivityDetailRespVO.Product.class));
PointProductDO minProduct = getMinPropertyObj(products, PointProductDO::getPoint);
assert minProduct != null; assert minProduct != null;
respVO.setPoint(minProduct.getPoint()).setPrice(minProduct.getPrice()); AppPointActivityDetailRespVO respVO = BeanUtils.toBean(activity, AppPointActivityDetailRespVO.class)
.setProducts(BeanUtils.toBean(products, AppPointActivityDetailRespVO.Product.class))
.setPoint(minProduct.getPoint()).setPrice(minProduct.getPrice());
return success(respVO); return success(respVO);
} }

View File

@ -30,7 +30,7 @@ public class AppPointActivityDetailRespVO {
@Schema(description = "商品信息数组", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "商品信息数组", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Product> products; private List<Product> products;
//======================= 显示所需兑换积分最少的 sku 信息 ======================= //======================= 显示所需兑换积分最少的 SKU 信息 =======================
@Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED)
private Integer point; private Integer point;

View File

@ -116,7 +116,7 @@ public interface TradeOrderQueryService {
* @param activityId 活动编号 * @param activityId 活动编号
* @return 秒杀商品数量 * @return 秒杀商品数量
*/ */
int getActivityProductCount(Long userId, Long activityId); int getSeckillProductCount(Long userId, Long activityId);
// =================== Order Item =================== // =================== Order Item ===================

View File

@ -174,7 +174,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
} }
@Override @Override
public int getActivityProductCount(Long userId, Long activityId) { public int getSeckillProductCount(Long userId, Long activityId) {
// 获得订单列表 // 获得订单列表
List<TradeOrderDO> orders = tradeOrderMapper.selectListByUserIdAndSeckillActivityId(userId, activityId); List<TradeOrderDO> orders = tradeOrderMapper.selectListByUserIdAndSeckillActivityId(userId, activityId);
orders.removeIf(order -> TradeOrderStatusEnum.isCanceled(order.getStatus())); // 过滤掉已取消的订单 orders.removeIf(order -> TradeOrderStatusEnum.isCanceled(order.getStatus())); // 过滤掉已取消的订单

View File

@ -69,7 +69,8 @@ public class TradePriceServiceImpl implements TradePriceService {
.buildCalculateResp(calculateReqBO, spuList, skuList); .buildCalculateResp(calculateReqBO, spuList, skuList);
priceCalculators.forEach(calculator -> calculator.calculate(calculateReqBO, calculateRespBO)); priceCalculators.forEach(calculator -> calculator.calculate(calculateReqBO, calculateRespBO));
// 2.2 如果最终支付金额小于等于 0则抛出业务异常 // 2.2 如果最终支付金额小于等于 0则抛出业务异常
if (calculateReqBO.getPointActivityId() == null && calculateRespBO.getPrice().getPayPrice() <= 0) { if (calculateReqBO.getPointActivityId() == null // 积分订单允许支付金额为 0
&& calculateRespBO.getPrice().getPayPrice() <= 0) {
log.error("[calculatePrice][价格计算不正确,请求 calculateReqDTO({}),结果 priceCalculate({})]", log.error("[calculatePrice][价格计算不正确,请求 calculateReqDTO({}),结果 priceCalculate({})]",
calculateReqBO, calculateRespBO); calculateReqBO, calculateRespBO);
throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL); throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL);

View File

@ -84,7 +84,7 @@ public class TradePointActivityPriceCalculator implements TradePriceCalculator {
// 1. 校验是否可以参与积分商城活动 // 1. 校验是否可以参与积分商城活动
PointValidateJoinRespDTO pointValidateJoinRespDTO = pointActivityApi.validateJoinPointActivity(activityId, skuId, count); PointValidateJoinRespDTO pointValidateJoinRespDTO = pointActivityApi.validateJoinPointActivity(activityId, skuId, count);
// 2. 校验总限购数量目前只有 trade 有具体下单的数据需要交给 trade 价格计算使用 // 2. 校验总限购数量目前只有 trade 有具体下单的数据需要交给 trade 价格计算使用
int activityProductCount = tradeOrderQueryService.getActivityProductCount(userId, activityId); int activityProductCount = tradeOrderQueryService.getSeckillProductCount(userId, activityId);
if (activityProductCount + count > pointValidateJoinRespDTO.getCount()) { if (activityProductCount + count > pointValidateJoinRespDTO.getCount()) {
throw exception(PRICE_CALCULATE_POINT_TOTAL_LIMIT_COUNT); throw exception(PRICE_CALCULATE_POINT_TOTAL_LIMIT_COUNT);
} }

View File

@ -60,7 +60,7 @@ public class TradeSeckillActivityPriceCalculator implements TradePriceCalculator
// 1. 校验是否可以参与秒杀 // 1. 校验是否可以参与秒杀
SeckillValidateJoinRespDTO seckillActivity = seckillActivityApi.validateJoinSeckill(activityId, skuId, count); SeckillValidateJoinRespDTO seckillActivity = seckillActivityApi.validateJoinSeckill(activityId, skuId, count);
// 2. 校验总限购数量目前只有 trade 有具体下单的数据需要交给 trade 价格计算使用 // 2. 校验总限购数量目前只有 trade 有具体下单的数据需要交给 trade 价格计算使用
int seckillProductCount = tradeOrderQueryService.getActivityProductCount(userId, activityId); int seckillProductCount = tradeOrderQueryService.getSeckillProductCount(userId, activityId);
if (seckillProductCount + count > seckillActivity.getTotalLimitCount()) { if (seckillProductCount + count > seckillActivity.getTotalLimitCount()) {
throw exception(PRICE_CALCULATE_SECKILL_TOTAL_LIMIT_COUNT); throw exception(PRICE_CALCULATE_SECKILL_TOTAL_LIMIT_COUNT);
} }