|
@@ -9,12 +9,19 @@ import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
|
|
|
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.mysql.coupon.CouponMapper;
|
|
|
+import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Set;
|
|
|
|
|
|
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_DELETE_FAIL_USED;
|
|
|
+import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NOT_EXISTS;
|
|
|
+import static java.util.Arrays.asList;
|
|
|
+
|
|
|
/**
|
|
|
* 优惠劵 Service 实现类
|
|
|
*
|
|
@@ -25,10 +32,14 @@ import java.util.Set;
|
|
|
public class CouponServiceImpl implements CouponService {
|
|
|
|
|
|
@Resource
|
|
|
- private MemberUserApi memberUserApi;
|
|
|
+ private CouponTemplateService couponTemplateService;
|
|
|
+
|
|
|
@Resource
|
|
|
private CouponMapper couponMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MemberUserApi memberUserApi;
|
|
|
+
|
|
|
// TODO 芋艿:待实现
|
|
|
@Override
|
|
|
public CouponDO validCoupon(Long id, Long userId) {
|
|
@@ -50,4 +61,26 @@ public class CouponServiceImpl implements CouponService {
|
|
|
return couponMapper.selectPage(pageReqVO, userIds);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void deleteCoupon(Long id) {
|
|
|
+ // 校验存在
|
|
|
+ validateCouponExists(id);
|
|
|
+
|
|
|
+ // 更新优惠劵
|
|
|
+ int deleteCount = couponMapper.delete(id,
|
|
|
+ asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus()));
|
|
|
+ if (deleteCount == 0) {
|
|
|
+ throw exception(COUPON_DELETE_FAIL_USED);
|
|
|
+ }
|
|
|
+ // 减少优惠劵模板的领取数量 -1
|
|
|
+ couponTemplateService.updateCouponTemplateTakeCount(id, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateCouponExists(Long id) {
|
|
|
+ if (couponMapper.selectById(id) == null) {
|
|
|
+ throw exception(COUPON_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|