mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-09 07:41:53 +08:00
trade:增加优惠劵使用、商品库存的扣减
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
|
||||
/**
|
||||
* 回收优惠劵
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user