trade:增加优惠劵使用、商品库存的扣减

This commit is contained in:
YunaiV
2022-11-09 23:56:00 +08:00
parent 734236df97
commit 16f5d0f5a4
21 changed files with 454 additions and 159 deletions

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.promotion.api.coupon;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 优惠劵 API 实现类
*
* @author 芋道源码
*/
@Service
public class CouponApiImpl implements CouponApi {
@Resource
private CouponService couponService;
@Override
public void useCoupon(CouponUseReqDTO useReqDTO) {
couponService.useCoupon(useReqDTO.getId(), useReqDTO.getUserId(),
useReqDTO.getOrderId());
}
}

View File

@@ -45,10 +45,11 @@ public interface CouponService {
/**
* 使用优惠劵
*
* @param id 优惠劵编号
* @param userId 用户编号
* @param id 优惠劵编号
* @param userId 用户编号
* @param orderId 订单编号
*/
void useCoupon(Long id, Long userId);
void useCoupon(Long id, Long userId, Long orderId);
/**
* 回收优惠劵

View File

@@ -81,12 +81,13 @@ public class CouponServiceImpl implements CouponService {
}
@Override
public void useCoupon(Long id, Long userId) {
public void useCoupon(Long id, Long userId, Long orderId) {
// 校验优惠劵
validCoupon(id, userId);
// 更新状态
int updateCount = couponMapper.updateByIdAndStatus(id, CouponStatusEnum.UNUSED.getStatus(),
new CouponDO().setStatus(CouponStatusEnum.USED.getStatus()).setUseTime(new Date()));
new CouponDO().setStatus(CouponStatusEnum.USED.getStatus())
.setUseOrderId(orderId).setUseTime(new Date()));
if (updateCount == 0) {
throw exception(COUPON_STATUS_NOT_UNUSED);
}