Commit 873b5306525f821b7e1177a8f8465f6e45ab03c8
1 parent
47c2dfa6
promotion:增加优惠劵的回收操作
Showing
13 changed files
with
96 additions
and
9 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| @@ -25,5 +25,6 @@ public interface ErrorCodeConstants { | @@ -25,5 +25,6 @@ public interface ErrorCodeConstants { | ||
| 25 | 25 | ||
| 26 | // ========== 优惠劵模板 1003005000 ========== | 26 | // ========== 优惠劵模板 1003005000 ========== |
| 27 | ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在"); | 27 | ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1003005000, "优惠劵不存在"); |
| 28 | + ErrorCode COUPON_DELETE_FAIL_USED = new ErrorCode(1003005001, "回收优惠劵失败,优惠劵已被使用"); | ||
| 28 | 29 | ||
| 29 | } | 30 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/coupon/CouponStatusEnum.java
| @@ -20,12 +20,12 @@ public enum CouponStatusEnum implements IntArrayValuable { | @@ -20,12 +20,12 @@ public enum CouponStatusEnum implements IntArrayValuable { | ||
| 20 | EXPIRE(3, "已过期"), | 20 | EXPIRE(3, "已过期"), |
| 21 | ; | 21 | ; |
| 22 | 22 | ||
| 23 | - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponStatusEnum::getValue).toArray(); | 23 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponStatusEnum::getStatus).toArray(); |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | * 值 | 26 | * 值 |
| 27 | */ | 27 | */ |
| 28 | - private final Integer value; | 28 | + private final Integer status; |
| 29 | /** | 29 | /** |
| 30 | * 名字 | 30 | * 名字 |
| 31 | */ | 31 | */ |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/CouponController.java
| @@ -12,12 +12,11 @@ import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; | @@ -12,12 +12,11 @@ import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; | ||
| 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 13 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; | 13 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 14 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 15 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 15 | import io.swagger.annotations.ApiOperation; | 16 | import io.swagger.annotations.ApiOperation; |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 18 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 19 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 20 | -import org.springframework.web.bind.annotation.RestController; | 19 | +import org.springframework.web.bind.annotation.*; |
| 21 | 20 | ||
| 22 | import javax.annotation.Resource; | 21 | import javax.annotation.Resource; |
| 23 | import javax.validation.Valid; | 22 | import javax.validation.Valid; |
| @@ -47,6 +46,15 @@ public class CouponController { | @@ -47,6 +46,15 @@ public class CouponController { | ||
| 47 | // return success(CouponConvert.INSTANCE.convert(coupon)); | 46 | // return success(CouponConvert.INSTANCE.convert(coupon)); |
| 48 | // } | 47 | // } |
| 49 | 48 | ||
| 49 | + @DeleteMapping("/delete") | ||
| 50 | + @ApiOperation("回收优惠劵") | ||
| 51 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | ||
| 52 | + @PreAuthorize("@ss.hasPermission('promotion:coupon:delete')") | ||
| 53 | + public CommonResult<Boolean> deleteCoupon(@RequestParam("id") Long id) { | ||
| 54 | + couponService.deleteCoupon(id); | ||
| 55 | + return success(true); | ||
| 56 | + } | ||
| 57 | + | ||
| 50 | @GetMapping("/page") | 58 | @GetMapping("/page") |
| 51 | @ApiOperation("获得优惠劵分页") | 59 | @ApiOperation("获得优惠劵分页") |
| 52 | @PreAuthorize("@ss.hasPermission('promotion:coupon:query')") | 60 | @PreAuthorize("@ss.hasPermission('promotion:coupon:query')") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java
| @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 8 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 10 | ||
| 10 | import java.util.Collection; | 11 | import java.util.Collection; |
| @@ -26,4 +27,10 @@ public interface CouponMapper extends BaseMapperX<CouponDO> { | @@ -26,4 +27,10 @@ public interface CouponMapper extends BaseMapperX<CouponDO> { | ||
| 26 | .orderByDesc(CouponDO::getId)); | 27 | .orderByDesc(CouponDO::getId)); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 30 | + default int delete(Long id, Collection<Integer> whereStatuses) { | ||
| 31 | + return update(null, new LambdaUpdateWrapper<CouponDO>() | ||
| 32 | + .eq(CouponDO::getId, id).in(CouponDO::getStatus, whereStatuses) | ||
| 33 | + .set(CouponDO::getDeleted, 1)); | ||
| 34 | + } | ||
| 35 | + | ||
| 29 | } | 36 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponTemplateMapper.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | +import org.apache.ibatis.annotations.Param; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * 优惠劵模板 Mapper | 12 | * 优惠劵模板 Mapper |
| @@ -24,4 +25,6 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | @@ -24,4 +25,6 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | ||
| 24 | .orderByDesc(CouponTemplateDO::getId)); | 25 | .orderByDesc(CouponTemplateDO::getId)); |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 28 | + void updateTakeCount(@Param("id") Long id, @Param("incrCount") Integer incrCount); | ||
| 29 | + | ||
| 27 | } | 30 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java
| @@ -31,4 +31,11 @@ public interface CouponService { | @@ -31,4 +31,11 @@ public interface CouponService { | ||
| 31 | */ | 31 | */ |
| 32 | PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO); | 32 | PageResult<CouponDO> getCouponPage(CouponPageReqVO pageReqVO); |
| 33 | 33 | ||
| 34 | + /** | ||
| 35 | + * 回收优惠劵 | ||
| 36 | + * | ||
| 37 | + * @param id 优惠劵编号 | ||
| 38 | + */ | ||
| 39 | + void deleteCoupon(Long id); | ||
| 40 | + | ||
| 34 | } | 41 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| @@ -9,12 +9,19 @@ import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; | @@ -9,12 +9,19 @@ import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; | ||
| 9 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; |
| 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; |
| 11 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; | 11 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; |
| 12 | +import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; | ||
| 12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 14 | +import org.springframework.transaction.annotation.Transactional; | ||
| 13 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| 14 | 16 | ||
| 15 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 16 | import java.util.Set; | 18 | import java.util.Set; |
| 17 | 19 | ||
| 20 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 21 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_DELETE_FAIL_USED; | ||
| 22 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NOT_EXISTS; | ||
| 23 | +import static java.util.Arrays.asList; | ||
| 24 | + | ||
| 18 | /** | 25 | /** |
| 19 | * 优惠劵 Service 实现类 | 26 | * 优惠劵 Service 实现类 |
| 20 | * | 27 | * |
| @@ -25,10 +32,14 @@ import java.util.Set; | @@ -25,10 +32,14 @@ import java.util.Set; | ||
| 25 | public class CouponServiceImpl implements CouponService { | 32 | public class CouponServiceImpl implements CouponService { |
| 26 | 33 | ||
| 27 | @Resource | 34 | @Resource |
| 28 | - private MemberUserApi memberUserApi; | 35 | + private CouponTemplateService couponTemplateService; |
| 36 | + | ||
| 29 | @Resource | 37 | @Resource |
| 30 | private CouponMapper couponMapper; | 38 | private CouponMapper couponMapper; |
| 31 | 39 | ||
| 40 | + @Resource | ||
| 41 | + private MemberUserApi memberUserApi; | ||
| 42 | + | ||
| 32 | // TODO 芋艿:待实现 | 43 | // TODO 芋艿:待实现 |
| 33 | @Override | 44 | @Override |
| 34 | public CouponDO validCoupon(Long id, Long userId) { | 45 | public CouponDO validCoupon(Long id, Long userId) { |
| @@ -50,4 +61,26 @@ public class CouponServiceImpl implements CouponService { | @@ -50,4 +61,26 @@ public class CouponServiceImpl implements CouponService { | ||
| 50 | return couponMapper.selectPage(pageReqVO, userIds); | 61 | return couponMapper.selectPage(pageReqVO, userIds); |
| 51 | } | 62 | } |
| 52 | 63 | ||
| 64 | + @Override | ||
| 65 | + @Transactional | ||
| 66 | + public void deleteCoupon(Long id) { | ||
| 67 | + // 校验存在 | ||
| 68 | + validateCouponExists(id); | ||
| 69 | + | ||
| 70 | + // 更新优惠劵 | ||
| 71 | + int deleteCount = couponMapper.delete(id, | ||
| 72 | + asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus())); | ||
| 73 | + if (deleteCount == 0) { | ||
| 74 | + throw exception(COUPON_DELETE_FAIL_USED); | ||
| 75 | + } | ||
| 76 | + // 减少优惠劵模板的领取数量 -1 | ||
| 77 | + couponTemplateService.updateCouponTemplateTakeCount(id, -1); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + private void validateCouponExists(Long id) { | ||
| 81 | + if (couponMapper.selectById(id) == null) { | ||
| 82 | + throw exception(COUPON_NOT_EXISTS); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 53 | } | 86 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java
| @@ -61,4 +61,12 @@ public interface CouponTemplateService { | @@ -61,4 +61,12 @@ public interface CouponTemplateService { | ||
| 61 | */ | 61 | */ |
| 62 | PageResult<CouponTemplateDO> getCouponTemplatePage(CouponTemplatePageReqVO pageReqVO); | 62 | PageResult<CouponTemplateDO> getCouponTemplatePage(CouponTemplatePageReqVO pageReqVO); |
| 63 | 63 | ||
| 64 | + /** | ||
| 65 | + * 更新优惠劵模板的领取数量 | ||
| 66 | + * | ||
| 67 | + * @param id 优惠劵模板编号 | ||
| 68 | + * @param incrCount 增加数量 | ||
| 69 | + */ | ||
| 70 | + void updateCouponTemplateTakeCount(Long id, int incrCount); | ||
| 71 | + | ||
| 64 | } | 72 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| @@ -86,4 +86,9 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -86,4 +86,9 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 86 | return couponTemplateMapper.selectPage(pageReqVO); | 86 | return couponTemplateMapper.selectPage(pageReqVO); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | + @Override | ||
| 90 | + public void updateCouponTemplateTakeCount(Long id, int incrCount) { | ||
| 91 | + couponTemplateMapper.updateTakeCount(id, incrCount); | ||
| 92 | + } | ||
| 93 | + | ||
| 89 | } | 94 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/coupon/CouponTemplateMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper"> | ||
| 4 | + | ||
| 5 | + <update id="updateTakeCount"> | ||
| 6 | + UPDATE promotion_coupon_template | ||
| 7 | + SET take_count = take_count + #{incrCount} | ||
| 8 | + WHERE id = #{id} | ||
| 9 | + </update> | ||
| 10 | + | ||
| 11 | +</mapper> |
yudao-server/src/main/resources/application-local.yaml
| @@ -174,6 +174,7 @@ logging: | @@ -174,6 +174,7 @@ logging: | ||
| 174 | cn.iocoder.yudao.module.tool.dal.mysql: debug | 174 | cn.iocoder.yudao.module.tool.dal.mysql: debug |
| 175 | cn.iocoder.yudao.module.member.dal.mysql: debug | 175 | cn.iocoder.yudao.module.member.dal.mysql: debug |
| 176 | cn.iocoder.yudao.module.trade.dal.mysql: debug | 176 | cn.iocoder.yudao.module.trade.dal.mysql: debug |
| 177 | + cn.iocoder.yudao.module.promotion.dal.mysql: debug | ||
| 177 | 178 | ||
| 178 | --- #################### 微信公众号、小程序相关配置 #################### | 179 | --- #################### 微信公众号、小程序相关配置 #################### |
| 179 | wx: | 180 | wx: |
yudao-ui-admin/src/views/mall/promotion/coupon/index.vue
| @@ -57,7 +57,7 @@ | @@ -57,7 +57,7 @@ | ||
| 57 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | 57 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 58 | <template slot-scope="scope"> | 58 | <template slot-scope="scope"> |
| 59 | <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | 59 | <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" |
| 60 | - v-hasPermi="['promotion:coupon:delete']">删除</el-button> | 60 | + v-hasPermi="['promotion:coupon:delete']">回收</el-button> |
| 61 | </template> | 61 | </template> |
| 62 | </el-table-column> | 62 | </el-table-column> |
| 63 | </el-table> | 63 | </el-table> |
| @@ -145,11 +145,11 @@ export default { | @@ -145,11 +145,11 @@ export default { | ||
| 145 | /** 删除按钮操作 */ | 145 | /** 删除按钮操作 */ |
| 146 | handleDelete(row) { | 146 | handleDelete(row) { |
| 147 | const id = row.id; | 147 | const id = row.id; |
| 148 | - this.$modal.confirm('是否确认删除优惠劵编号为"' + id + '"的数据项?').then(function() { | 148 | + this.$modal.confirm('回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?').then(function() { |
| 149 | return deleteCoupon(id); | 149 | return deleteCoupon(id); |
| 150 | }).then(() => { | 150 | }).then(() => { |
| 151 | this.getList(); | 151 | this.getList(); |
| 152 | - this.$modal.msgSuccess("删除成功"); | 152 | + this.$modal.msgSuccess("回收成功"); |
| 153 | }).catch(() => {}); | 153 | }).catch(() => {}); |
| 154 | }, | 154 | }, |
| 155 | /** tab 切换 */ | 155 | /** tab 切换 */ |
yudao-ui-admin/src/views/mall/promotion/couponTemplate/index.vue
| @@ -33,6 +33,9 @@ | @@ -33,6 +33,9 @@ | ||
| 33 | <el-col :span="1.5"> | 33 | <el-col :span="1.5"> |
| 34 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | 34 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" |
| 35 | v-hasPermi="['promotion:coupon-template:create']">新增</el-button> | 35 | v-hasPermi="['promotion:coupon-template:create']">新增</el-button> |
| 36 | + <el-button type="info" plain icon="el-icon-s-operation" size="mini" | ||
| 37 | + @click="() => this.$router.push('/promotion/coupon')" | ||
| 38 | + v-hasPermi="['promotion:coupon:query']">会员优惠劵</el-button> | ||
| 36 | </el-col> | 39 | </el-col> |
| 37 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | 40 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 38 | </el-row> | 41 | </el-row> |