promotion:增加优惠劵的回收操作

pull/2/head
YunaiV 2022-11-04 21:17:37 +08:00
parent 47c2dfa623
commit 873b530652
13 changed files with 96 additions and 9 deletions

View File

@ -25,5 +25,6 @@ public interface ErrorCodeConstants {
// ========== 优惠劵模板 1003005000 ========== // ========== 优惠劵模板 1003005000 ==========
ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在"); ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在");
ErrorCode COUPON_DELETE_FAIL_USED = new ErrorCode(1003005001, "回收优惠劵失败,优惠劵已被使用");
} }

View File

@ -20,12 +20,12 @@ public enum CouponStatusEnum implements IntArrayValuable {
EXPIRE(3, "已过期"), EXPIRE(3, "已过期"),
; ;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponStatusEnum::getValue).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponStatusEnum::getStatus).toArray();
/** /**
* *
*/ */
private final Integer value; private final Integer status;
/** /**
* *
*/ */

View File

@ -12,12 +12,11 @@ import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert;
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.service.coupon.CouponService; import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
@ -47,6 +46,15 @@ public class CouponController {
// return success(CouponConvert.INSTANCE.convert(coupon)); // return success(CouponConvert.INSTANCE.convert(coupon));
// } // }
@DeleteMapping("/delete")
@ApiOperation("回收优惠劵")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('promotion:coupon:delete')")
public CommonResult<Boolean> deleteCoupon(@RequestParam("id") Long id) {
couponService.deleteCoupon(id);
return success(true);
}
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得优惠劵分页") @ApiOperation("获得优惠劵分页")
@PreAuthorize("@ss.hasPermission('promotion:coupon:query')") @PreAuthorize("@ss.hasPermission('promotion:coupon:query')")

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 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 com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Collection; import java.util.Collection;
@ -26,4 +27,10 @@ public interface CouponMapper extends BaseMapperX<CouponDO> {
.orderByDesc(CouponDO::getId)); .orderByDesc(CouponDO::getId));
} }
default int delete(Long id, Collection<Integer> whereStatuses) {
return update(null, new LambdaUpdateWrapper<CouponDO>()
.eq(CouponDO::getId, id).in(CouponDO::getStatus, whereStatuses)
.set(CouponDO::getDeleted, 1));
}
} }

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* Mapper * Mapper
@ -24,4 +25,6 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> {
.orderByDesc(CouponTemplateDO::getId)); .orderByDesc(CouponTemplateDO::getId));
} }
void updateTakeCount(@Param("id") Long id, @Param("incrCount") Integer incrCount);
} }

View File

@ -31,4 +31,11 @@ public interface CouponService {
*/ */
PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO); PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO);
/**
*
*
* @param id
*/
void deleteCoupon(Long id);
} }

View File

@ -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.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.dal.mysql.coupon.CouponMapper; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Set; 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 * Service
* *
@ -25,10 +32,14 @@ import java.util.Set;
public class CouponServiceImpl implements CouponService { public class CouponServiceImpl implements CouponService {
@Resource @Resource
private MemberUserApi memberUserApi; private CouponTemplateService couponTemplateService;
@Resource @Resource
private CouponMapper couponMapper; private CouponMapper couponMapper;
@Resource
private MemberUserApi memberUserApi;
// TODO 芋艿:待实现 // TODO 芋艿:待实现
@Override @Override
public CouponDO validCoupon(Long id, Long userId) { public CouponDO validCoupon(Long id, Long userId) {
@ -50,4 +61,26 @@ public class CouponServiceImpl implements CouponService {
return couponMapper.selectPage(pageReqVO, userIds); 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);
}
}
} }

View File

@ -61,4 +61,12 @@ public interface CouponTemplateService {
*/ */
PageResult<CouponTemplateDO> getCouponTemplatePage(CouponTemplatePageReqVO pageReqVO); PageResult<CouponTemplateDO> getCouponTemplatePage(CouponTemplatePageReqVO pageReqVO);
/**
*
*
* @param id
* @param incrCount
*/
void updateCouponTemplateTakeCount(Long id, int incrCount);
} }

View File

@ -86,4 +86,9 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
return couponTemplateMapper.selectPage(pageReqVO); return couponTemplateMapper.selectPage(pageReqVO);
} }
@Override
public void updateCouponTemplateTakeCount(Long id, int incrCount) {
couponTemplateMapper.updateTakeCount(id, incrCount);
}
} }

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper">
<update id="updateTakeCount">
UPDATE promotion_coupon_template
SET take_count = take_count + #{incrCount}
WHERE id = #{id}
</update>
</mapper>

View File

@ -174,6 +174,7 @@ logging:
cn.iocoder.yudao.module.tool.dal.mysql: debug cn.iocoder.yudao.module.tool.dal.mysql: debug
cn.iocoder.yudao.module.member.dal.mysql: debug cn.iocoder.yudao.module.member.dal.mysql: debug
cn.iocoder.yudao.module.trade.dal.mysql: debug cn.iocoder.yudao.module.trade.dal.mysql: debug
cn.iocoder.yudao.module.promotion.dal.mysql: debug
--- #################### 微信公众号、小程序相关配置 #################### --- #################### 微信公众号、小程序相关配置 ####################
wx: wx:

View File

@ -57,7 +57,7 @@
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
v-hasPermi="['promotion:coupon:delete']">删除</el-button> v-hasPermi="['promotion:coupon:delete']">回收</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -145,11 +145,11 @@ export default {
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const id = row.id; const id = row.id;
this.$modal.confirm('是否确认删除优惠劵编号为"' + id + '"的数据项?').then(function() { this.$modal.confirm('回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?').then(function() {
return deleteCoupon(id); return deleteCoupon(id);
}).then(() => { }).then(() => {
this.getList(); this.getList();
this.$modal.msgSuccess("删除成功"); this.$modal.msgSuccess("回收成功");
}).catch(() => {}); }).catch(() => {});
}, },
/** tab 切换 */ /** tab 切换 */

View File

@ -33,6 +33,9 @@
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['promotion:coupon-template:create']">新增</el-button> v-hasPermi="['promotion:coupon-template:create']">新增</el-button>
<el-button type="info" plain icon="el-icon-s-operation" size="mini"
@click="() => this.$router.push('/promotion/coupon')"
v-hasPermi="['promotion:coupon:query']">会员优惠劵</el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>