CouponController
/**
* 删除优惠券--管理端
*/
@ApiOperation("删除优惠券--管理端")
@DeleteMapping("/{id}")
public void removeCouponById(@PathVariable("id") Long id) {
couponService.removeCouponById(id);
}
ICouponService
/**
* 删除优惠券--管理端
* @param id
*/
void removeCouponById(Long id);
CouponServiceImpl
/**
* 删除优惠券--管理端
* @param id
*/
@Override
public void removeCouponById(Long id) {
//1、校验
if (id == null){
throw new BadRequestException("非法参数!");
}
//2、查询优惠券表
Coupon coupon = this.getById(id);
if (coupon == null) {
throw new BadRequestException("优惠券不存在!");
}
//3、判断优惠券配置状态
if (coupon.getStatus() != CouponStatus.DRAFT) {
throw new BadRequestException("该优惠券不处于待发放状态,不能删除!");
}
//4、删除优惠券
this.removeById(id);
}