Commit eaeeb34e74c14d1b89c95c727bae8a2f64ca6aaa
1 parent
ebf56932
【代码评审】商城:满减送订单
Showing
5 changed files
with
11 additions
and
27 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java
| ... | ... | @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; |
| 11 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 12 | 11 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 13 | 12 | import com.github.yulichang.toolkit.MPJWrappers; |
| 14 | 13 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -108,11 +107,4 @@ public interface CouponMapper extends BaseMapperX<CouponDO> { |
| 108 | 107 | ); |
| 109 | 108 | } |
| 110 | 109 | |
| 111 | - default List<CouponDO> selectListByIdAndUserIdAndTakeType(Long couponId, Long userId, Integer takeType) { | |
| 112 | - return selectList(new LambdaQueryWrapper<CouponDO>() | |
| 113 | - .eq(CouponDO::getId, couponId) | |
| 114 | - .eq(CouponDO::getUserId, userId) | |
| 115 | - .eq(CouponDO::getTakeType, takeType)); | |
| 116 | - } | |
| 117 | - | |
| 118 | 110 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| ... | ... | @@ -179,7 +179,7 @@ public class CouponServiceImpl implements CouponService { |
| 179 | 179 | // 循环收回 |
| 180 | 180 | for (Long couponId : giveCouponIds) { |
| 181 | 181 | try { |
| 182 | - getSelf().takeBackCoupon(couponId, userId, CouponTakeTypeEnum.ADMIN); | |
| 182 | + getSelf().invalidateCoupon(couponId, userId); | |
| 183 | 183 | } catch (Exception e) { |
| 184 | 184 | log.error("[invalidateCouponsByAdmin][couponId({}) 收回优惠券失败]", couponId, e); |
| 185 | 185 | } |
| ... | ... | @@ -191,10 +191,9 @@ public class CouponServiceImpl implements CouponService { |
| 191 | 191 | * |
| 192 | 192 | * @param couponId 模版编号 |
| 193 | 193 | * @param userId 用户编号 |
| 194 | - * @param takeType 领取方式 | |
| 195 | 194 | */ |
| 196 | 195 | @Transactional(rollbackFor = Exception.class) |
| 197 | - public void takeBackCoupon(Long couponId, Long userId, CouponTakeTypeEnum takeType) { | |
| 196 | + public void invalidateCoupon(Long couponId, Long userId) { | |
| 198 | 197 | // 1.1 校验优惠券 |
| 199 | 198 | CouponDO coupon = couponMapper.selectByIdAndUserId(couponId, userId); |
| 200 | 199 | if (coupon == null) { |
| ... | ... | @@ -205,19 +204,15 @@ public class CouponServiceImpl implements CouponService { |
| 205 | 204 | if (couponTemplate == null) { |
| 206 | 205 | throw exception(COUPON_TEMPLATE_NOT_EXISTS); |
| 207 | 206 | } |
| 208 | - // 1.3 校验领取方式 | |
| 209 | - if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getValue())) { | |
| 210 | - throw exception(COUPON_TEMPLATE_CANNOT_TAKE); | |
| 211 | - } | |
| 212 | - | |
| 213 | - // 2.1 校验优惠券是否已经使用,如若使用则先不管 | |
| 207 | + // 1.3 校验优惠券是否已经使用,如若使用则先不管 | |
| 214 | 208 | if (ObjUtil.equal(coupon.getStatus(), CouponStatusEnum.USED.getStatus())) { |
| 209 | + log.info("[invalidateCoupon][coupon({}) 已经使用,无法作废]", couponId); | |
| 215 | 210 | return; |
| 216 | 211 | } |
| 217 | - // 2.2 减少优惠劵模板的领取数量 | |
| 212 | + | |
| 213 | + // 2.1 减少优惠劵模板的领取数量 | |
| 218 | 214 | couponTemplateService.updateCouponTemplateTakeCount(couponTemplate.getId(), -1); |
| 219 | - // 2.3 批量作废优惠劵 | |
| 220 | - // TODO @puhui999:捉摸了下,貌似搞成逻辑删除好了?不然好多地方的 status 都要做一些变动。可能未来加个 invalidateType 来标识,是管理后台删除,还是取消回收。或者优惠劵的 change log 可能更好。 | |
| 215 | + // 2.2 作废优惠劵 | |
| 221 | 216 | couponMapper.deleteById(couponId); |
| 222 | 217 | } |
| 223 | 218 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java
| ... | ... | @@ -296,10 +296,11 @@ public class TradeOrderDO extends BaseDO { |
| 296 | 296 | */ |
| 297 | 297 | private Integer vipPrice; |
| 298 | 298 | |
| 299 | + // TODO @puhui999:我们要不要把相关的字段,定义的更明确一点?例如说,giveCouponTemplateCounts 赠送的优惠劵模版数量,或者 giveCouponCounts 赠送的优惠劵数量。感受上,Coupons 和 Map 有点点重叠哈。 | |
| 299 | 300 | /** |
| 300 | 301 | * 赠送的优惠劵 |
| 301 | 302 | * |
| 302 | - * key: 优惠劵编号 | |
| 303 | + * key: 优惠劵模版编号 | |
| 303 | 304 | * value:对应的优惠券数量 |
| 304 | 305 | * |
| 305 | 306 | * 目的:用于订单支付后赠送优惠券 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| ... | ... | @@ -892,15 +892,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 892 | 892 | |
| 893 | 893 | @Override |
| 894 | 894 | public void updateOrderGiveCouponIds(Long userId, Long orderId, List<Long> giveCouponIds) { |
| 895 | - // 1.1 检验订单存在 | |
| 895 | + // 1. 检验订单存在 | |
| 896 | 896 | TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); |
| 897 | 897 | if (order == null) { |
| 898 | 898 | throw exception(ORDER_NOT_FOUND); |
| 899 | 899 | } |
| 900 | - // 1.2 校验订单是否支付 | |
| 901 | - if (!order.getPayStatus()) { | |
| 902 | - throw exception(ORDER_CANCEL_PAID_FAIL, "已支付"); | |
| 903 | - } | |
| 904 | 900 | |
| 905 | 901 | // 2. 更新订单赠送的优惠券编号列表 |
| 906 | 902 | tradeOrderMapper.updateById(new TradeOrderDO().setId(orderId).setGiveCouponIds(giveCouponIds)); | ... | ... |