mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-29 18:51:53 +08:00
【代码评审】商城:满减送订单
This commit is contained in:
parent
7a7ca4293c
commit
d60374d646
@ -36,6 +36,7 @@ public interface CouponApi {
|
|||||||
*/
|
*/
|
||||||
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
||||||
|
|
||||||
|
// TODO @puhui999:Map<Long, Integer> 优惠劵 会不会好点。
|
||||||
/**
|
/**
|
||||||
* 【管理员】给指定用户批量发送优惠券
|
* 【管理员】给指定用户批量发送优惠券
|
||||||
*
|
*
|
||||||
|
@ -181,6 +181,7 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) {
|
public void takeCouponsByAdmin(List<Long> templateIds, List<Integer> counts, Long userId) {
|
||||||
|
// TODO @puhui999:要不要循环调用上面的 takeCoupon 方法?按道理说,赠送也不会很多张。如果某次发卷失败,可以打个 error log;
|
||||||
// 1. 获得优惠券模版
|
// 1. 获得优惠券模版
|
||||||
List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds);
|
List<CouponTemplateDO> templateList = couponTemplateService.getCouponTemplateList(templateIds);
|
||||||
if (CollUtil.isEmpty(templateList)) {
|
if (CollUtil.isEmpty(templateList)) {
|
||||||
|
@ -291,6 +291,8 @@ public class TradeOrderDO extends BaseDO {
|
|||||||
* VIP 减免金额,单位:分
|
* VIP 减免金额,单位:分
|
||||||
*/
|
*/
|
||||||
private Integer vipPrice;
|
private Integer vipPrice;
|
||||||
|
|
||||||
|
// TODO @puhui999::1)建议命名要 giveXXX;不然不好理解哈;2)是不是搞成 Map 好点哈。
|
||||||
/**
|
/**
|
||||||
* 赠送的优惠劵编号的数组
|
* 赠送的优惠劵编号的数组
|
||||||
*
|
*
|
||||||
|
@ -201,7 +201,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
||||||
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
||||||
order.setUserIp(getClientIP()).setTerminal(getTerminal());
|
order.setUserIp(getClientIP()).setTerminal(getTerminal());
|
||||||
// 优惠券
|
// 使用 + 赠送优惠券
|
||||||
order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts());
|
order.setCouponIds(calculateRespBO.getCouponIds()).setCouponCounts(calculateRespBO.getCouponCounts());
|
||||||
// 支付 + 退款信息
|
// 支付 + 退款信息
|
||||||
order.setAdjustPrice(0).setPayStatus(false);
|
order.setAdjustPrice(0).setPayStatus(false);
|
||||||
@ -861,17 +861,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) {
|
public void cancelPaidOrder(Long userId, Long orderId, Integer cancelType) {
|
||||||
// 1. 这里校验下 cancelType 只允许拼团关闭;
|
// 1.1 这里校验下 cancelType 只允许拼团关闭;
|
||||||
if (!TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType().equals(cancelType)) {
|
if (ObjUtil.notEqual(TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getType(), cancelType)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 1.1 检验订单存在
|
// 1.2 检验订单存在
|
||||||
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
|
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
throw exception(ORDER_NOT_FOUND);
|
throw exception(ORDER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.2 校验订单是否支付
|
// 1.3 校验订单是否支付
|
||||||
if (!order.getPayStatus()) {
|
if (!order.getPayStatus()) {
|
||||||
throw exception(ORDER_CANCEL_PAID_FAIL, "已支付");
|
throw exception(ORDER_CANCEL_PAID_FAIL, "已支付");
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class TradeCouponOrderHandler implements TradeOrderHandler {
|
|||||||
if (CollUtil.isEmpty(order.getCouponIds())) {
|
if (CollUtil.isEmpty(order.getCouponIds())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO @puhui999: 收回优惠券再考虑一下,是直接删除券还是改个状态
|
// TODO @puhui999: 收回优惠券再考虑一下,是直接删除券还是改个状态;建议是【已作废】
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ public class TradePriceCalculateRespBO {
|
|||||||
*/
|
*/
|
||||||
private Boolean freeDelivery;
|
private Boolean freeDelivery;
|
||||||
|
|
||||||
|
// TODO @puhui999:感觉要不要试着改成 Map<Long, Integer> giveCoupons?貌似整体会更好理解一点。
|
||||||
/**
|
/**
|
||||||
* 赠送的优惠劵编号的数组
|
* 赠送的优惠劵编号的数组
|
||||||
*/
|
*/
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
|
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
|
||||||
import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
|
import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
||||||
@ -56,7 +57,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈
|
// 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈
|
||||||
if (anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) {
|
if (CollectionUtils.anyMatch(result.getItems(), item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) {
|
||||||
throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL);
|
throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
|||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||||
import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice;
|
import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice;
|
||||||
|
|
||||||
|
// TODO @puhui999:相关的单测,建议改一改
|
||||||
/**
|
/**
|
||||||
* 满减送活动的 {@link TradePriceCalculator} 实现类
|
* 满减送活动的 {@link TradePriceCalculator} 实现类
|
||||||
*
|
*
|
||||||
@ -94,8 +95,8 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
if (rule.getGivePoint()) {
|
if (rule.getGivePoint()) {
|
||||||
List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint());
|
List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, rule.getPoint());
|
||||||
for (int i = 0; i < orderItems.size(); i++) {
|
for (int i = 0; i < orderItems.size(); i++) {
|
||||||
TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
|
|
||||||
// 商品可能赠送了积分,所以这里要加上
|
// 商品可能赠送了积分,所以这里要加上
|
||||||
|
TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
|
||||||
orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i));
|
orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,7 +190,7 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
|
|||||||
Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
|
Integer price = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
|
||||||
assert count != null && price != null;
|
assert count != null && price != null;
|
||||||
|
|
||||||
// 2. 构建不满足时的提示信息-按最低档规则算
|
// 2. 构建不满足时的提示信息:按最低档规则算
|
||||||
String meetTip = "满减送:购满 {} {},可以减 {} 元";
|
String meetTip = "满减送:购满 {} {},可以减 {} 元";
|
||||||
List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules());
|
List<RewardActivityMatchRespDTO.Rule> rules = new ArrayList<>(rewardActivity.getRules());
|
||||||
rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序
|
rules.sort(Comparator.comparing(RewardActivityMatchRespDTO.Rule::getLimit)); // 按优惠门槛降序
|
||||||
|
Loading…
Reference in New Issue
Block a user