mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-13 00:54:59 +08:00
【代码评审】商城:满减送订单
This commit is contained in:
parent
ebf5693255
commit
eaeeb34e74
@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|||||||
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
|
||||||
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.github.yulichang.toolkit.MPJWrappers;
|
import com.github.yulichang.toolkit.MPJWrappers;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
@ -108,11 +107,4 @@ public interface CouponMapper extends BaseMapperX<CouponDO> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CouponDO> selectListByIdAndUserIdAndTakeType(Long couponId, Long userId, Integer takeType) {
|
|
||||||
return selectList(new LambdaQueryWrapper<CouponDO>()
|
|
||||||
.eq(CouponDO::getId, couponId)
|
|
||||||
.eq(CouponDO::getUserId, userId)
|
|
||||||
.eq(CouponDO::getTakeType, takeType));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public interface CouponService {
|
|||||||
*/
|
*/
|
||||||
int expireCoupon();
|
int expireCoupon();
|
||||||
|
|
||||||
//======================= 查询相关 =======================
|
// ======================= 查询相关 =======================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得未使用的优惠劵数量
|
* 获得未使用的优惠劵数量
|
||||||
|
@ -179,7 +179,7 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
// 循环收回
|
// 循环收回
|
||||||
for (Long couponId : giveCouponIds) {
|
for (Long couponId : giveCouponIds) {
|
||||||
try {
|
try {
|
||||||
getSelf().takeBackCoupon(couponId, userId, CouponTakeTypeEnum.ADMIN);
|
getSelf().invalidateCoupon(couponId, userId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[invalidateCouponsByAdmin][couponId({}) 收回优惠券失败]", couponId, e);
|
log.error("[invalidateCouponsByAdmin][couponId({}) 收回优惠券失败]", couponId, e);
|
||||||
}
|
}
|
||||||
@ -191,10 +191,9 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
*
|
*
|
||||||
* @param couponId 模版编号
|
* @param couponId 模版编号
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param takeType 领取方式
|
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void takeBackCoupon(Long couponId, Long userId, CouponTakeTypeEnum takeType) {
|
public void invalidateCoupon(Long couponId, Long userId) {
|
||||||
// 1.1 校验优惠券
|
// 1.1 校验优惠券
|
||||||
CouponDO coupon = couponMapper.selectByIdAndUserId(couponId, userId);
|
CouponDO coupon = couponMapper.selectByIdAndUserId(couponId, userId);
|
||||||
if (coupon == null) {
|
if (coupon == null) {
|
||||||
@ -205,19 +204,15 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
if (couponTemplate == null) {
|
if (couponTemplate == null) {
|
||||||
throw exception(COUPON_TEMPLATE_NOT_EXISTS);
|
throw exception(COUPON_TEMPLATE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
// 1.3 校验领取方式
|
// 1.3 校验优惠券是否已经使用,如若使用则先不管
|
||||||
if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getValue())) {
|
|
||||||
throw exception(COUPON_TEMPLATE_CANNOT_TAKE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2.1 校验优惠券是否已经使用,如若使用则先不管
|
|
||||||
if (ObjUtil.equal(coupon.getStatus(), CouponStatusEnum.USED.getStatus())) {
|
if (ObjUtil.equal(coupon.getStatus(), CouponStatusEnum.USED.getStatus())) {
|
||||||
|
log.info("[invalidateCoupon][coupon({}) 已经使用,无法作废]", couponId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 2.2 减少优惠劵模板的领取数量
|
|
||||||
|
// 2.1 减少优惠劵模板的领取数量
|
||||||
couponTemplateService.updateCouponTemplateTakeCount(couponTemplate.getId(), -1);
|
couponTemplateService.updateCouponTemplateTakeCount(couponTemplate.getId(), -1);
|
||||||
// 2.3 批量作废优惠劵
|
// 2.2 作废优惠劵
|
||||||
// TODO @puhui999:捉摸了下,貌似搞成逻辑删除好了?不然好多地方的 status 都要做一些变动。可能未来加个 invalidateType 来标识,是管理后台删除,还是取消回收。或者优惠劵的 change log 可能更好。
|
|
||||||
couponMapper.deleteById(couponId);
|
couponMapper.deleteById(couponId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,10 +296,11 @@ public class TradeOrderDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer vipPrice;
|
private Integer vipPrice;
|
||||||
|
|
||||||
|
// TODO @puhui999:我们要不要把相关的字段,定义的更明确一点?例如说,giveCouponTemplateCounts 赠送的优惠劵模版数量,或者 giveCouponCounts 赠送的优惠劵数量。感受上,Coupons 和 Map 有点点重叠哈。
|
||||||
/**
|
/**
|
||||||
* 赠送的优惠劵
|
* 赠送的优惠劵
|
||||||
*
|
*
|
||||||
* key: 优惠劵编号
|
* key: 优惠劵模版编号
|
||||||
* value:对应的优惠券数量
|
* value:对应的优惠券数量
|
||||||
*
|
*
|
||||||
* 目的:用于订单支付后赠送优惠券
|
* 目的:用于订单支付后赠送优惠券
|
||||||
|
@ -892,15 +892,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOrderGiveCouponIds(Long userId, Long orderId, List<Long> giveCouponIds) {
|
public void updateOrderGiveCouponIds(Long userId, Long orderId, List<Long> giveCouponIds) {
|
||||||
// 1.1 检验订单存在
|
// 1. 检验订单存在
|
||||||
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 校验订单是否支付
|
|
||||||
if (!order.getPayStatus()) {
|
|
||||||
throw exception(ORDER_CANCEL_PAID_FAIL, "已支付");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 更新订单赠送的优惠券编号列表
|
// 2. 更新订单赠送的优惠券编号列表
|
||||||
tradeOrderMapper.updateById(new TradeOrderDO().setId(orderId).setGiveCouponIds(giveCouponIds));
|
tradeOrderMapper.updateById(new TradeOrderDO().setId(orderId).setGiveCouponIds(giveCouponIds));
|
||||||
|
Loading…
Reference in New Issue
Block a user