From 00f90e75d90520e56ac25277e97bad53d1faca36 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 5 Nov 2022 10:52:09 +0800 Subject: [PATCH] =?UTF-8?q?promotion=EF=BC=9A=E5=A2=9E=E5=8A=A0=E6=BB=A1?= =?UTF-8?q?=E5=87=8F=E9=80=81=E6=B4=BB=E5=8A=A8=E7=9A=84=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 4 + .../reward/RewardActivityController.java | 9 + .../service/reward/RewardActivityService.java | 7 + .../reward/RewardActivityServiceImpl.java | 37 ++- .../reward/RewardActivityServiceImplTest.java | 19 +- .../src/api/mall/promotion/rewardActivity.js | 52 +++ yudao-ui-admin/src/utils/constants.js | 22 ++ .../mall/promotion/rewardActivity/index.vue | 305 ++++++++++++++++++ 8 files changed, 447 insertions(+), 8 deletions(-) create mode 100755 yudao-ui-admin/src/api/mall/promotion/rewardActivity.js create mode 100755 yudao-ui-admin/src/views/mall/promotion/rewardActivity/index.vue diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 425cfdcf8..89b583a5c 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -30,5 +30,9 @@ public interface ErrorCodeConstants { // ========== 满减送活动 1003006000 ========== ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1003006000, "满减送活动不存在"); ErrorCode REWARD_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1003006001, "商品({}) 已经参加满减送活动({})"); + ErrorCode REWARD_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1003006002, "满减送活动已关闭,不能修改"); + ErrorCode REWARD_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED = new ErrorCode(1003006003, "满减送活动未关闭,不能删除"); + ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1003006004, "满减送活动已关闭,不能重复关闭"); + ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_END = new ErrorCode(1003006004, "满减送活动已结束,不能关闭"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/RewardActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/RewardActivityController.java index ed868a353..043571e5e 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/RewardActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/RewardActivityController.java @@ -45,6 +45,15 @@ public class RewardActivityController { return success(true); } + @PutMapping("/close") + @ApiOperation("关闭满减送活动") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:close')") + public CommonResult closeRewardActivity(@RequestParam("id") Long id) { + rewardActivityService.closeRewardActivity(id); + return success(true); + } + @DeleteMapping("/delete") @ApiOperation("删除满减送活动") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java index e0ea4a282..40bcc2836 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java @@ -32,6 +32,13 @@ public interface RewardActivityService { */ void updateRewardActivity(@Valid RewardActivityUpdateReqVO updateReqVO); + /** + * 关闭满减送活动 + * + * @param id 活动编号 + */ + void closeRewardActivity(Long id); + /** * 删除满减送活动 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java index 1264a1a57..327770413 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivi import cn.iocoder.yudao.module.promotion.convert.reward.RewardActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; import cn.iocoder.yudao.module.promotion.util.PromotionUtils; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -19,8 +20,7 @@ import java.util.Map; import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.REWARD_ACTIVITY_NOT_EXISTS; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.REWARD_ACTIVITY_SPU_CONFLICTS; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; /** * 满减送活动 Service 实现类 @@ -50,7 +50,10 @@ public class RewardActivityServiceImpl implements RewardActivityService { @Override public void updateRewardActivity(RewardActivityUpdateReqVO updateReqVO) { // 校验存在 - validateRewardActivityExists(updateReqVO.getId()); + RewardActivityDO dbRewardActivity = validateRewardActivityExists(updateReqVO.getId()); + if (dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.CLOSE.getStatus())) { // 已关闭的活动,不能修改噢 + throw exception(REWARD_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); + } validateRewardActivitySpuConflicts(updateReqVO.getId(), updateReqVO.getProductSpuIds()); // 更新 @@ -59,18 +62,40 @@ public class RewardActivityServiceImpl implements RewardActivityService { rewardActivityMapper.updateById(updateObj); } + @Override + public void closeRewardActivity(Long id) { + // 校验存在 + RewardActivityDO dbRewardActivity = validateRewardActivityExists(id); + if (dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.CLOSE.getStatus())) { // 已关闭的活动,不能关闭噢 + throw exception(REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED); + } + if (dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.END.getStatus())) { // 已关闭的活动,不能关闭噢 + throw exception(REWARD_ACTIVITY_CLOSE_FAIL_STATUS_END); + } + + // 更新 + RewardActivityDO updateObj = new RewardActivityDO().setId(id).setStatus(PromotionActivityStatusEnum.CLOSE.getStatus()); + rewardActivityMapper.updateById(updateObj); + } + @Override public void deleteRewardActivity(Long id) { // 校验存在 - validateRewardActivityExists(id); + RewardActivityDO dbRewardActivity = validateRewardActivityExists(id); + if (!dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.CLOSE.getStatus())) { // 未关闭的活动,不能删除噢 + throw exception(REWARD_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED); + } + // 删除 rewardActivityMapper.deleteById(id); } - private void validateRewardActivityExists(Long id) { - if (rewardActivityMapper.selectById(id) == null) { + private RewardActivityDO validateRewardActivityExists(Long id) { + RewardActivityDO activity = rewardActivityMapper.selectById(id); + if (activity == null) { throw exception(REWARD_ACTIVITY_NOT_EXISTS); } + return activity; } /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImplTest.java index fd7a12e5d..ceda4faba 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImplTest.java @@ -66,7 +66,7 @@ public class RewardActivityServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateRewardActivity_success() { // mock 数据 - RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class); + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> o.setStatus(PromotionActivityStatusEnum.WAIT.getStatus())); rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 // 准备参数 RewardActivityUpdateReqVO reqVO = randomPojo(RewardActivityUpdateReqVO.class, o -> { @@ -88,6 +88,21 @@ public class RewardActivityServiceImplTest extends BaseDbUnitTest { } } + @Test + public void testCloseRewardActivity() { + // mock 数据 + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> o.setStatus(PromotionActivityStatusEnum.WAIT.getStatus())); + rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbRewardActivity.getId(); + + // 调用 + rewardActivityService.closeRewardActivity(id); + // 校验状态 + RewardActivityDO rewardActivity = rewardActivityMapper.selectById(id); + assertEquals(rewardActivity.getStatus(), PromotionActivityStatusEnum.CLOSE.getStatus()); + } + @Test public void testUpdateRewardActivity_notExists() { // 准备参数 @@ -100,7 +115,7 @@ public class RewardActivityServiceImplTest extends BaseDbUnitTest { @Test public void testDeleteRewardActivity_success() { // mock 数据 - RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class); + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> o.setStatus(PromotionActivityStatusEnum.CLOSE.getStatus())); rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 // 准备参数 Long id = dbRewardActivity.getId(); diff --git a/yudao-ui-admin/src/api/mall/promotion/rewardActivity.js b/yudao-ui-admin/src/api/mall/promotion/rewardActivity.js new file mode 100755 index 000000000..b792f903b --- /dev/null +++ b/yudao-ui-admin/src/api/mall/promotion/rewardActivity.js @@ -0,0 +1,52 @@ +import request from '@/utils/request' + +// 创建满减送活动 +export function createRewardActivity(data) { + return request({ + url: '/promotion/reward-activity/create', + method: 'post', + data: data + }) +} + +// 更新满减送活动 +export function updateRewardActivity(data) { + return request({ + url: '/promotion/reward-activity/update', + method: 'put', + data: data + }) +} + +// 关闭满减送活动 +export function closeRewardActivity(id) { + return request({ + url: '/promotion/reward-activity/close?id=' + id, + method: 'put' + }) +} + +// 删除满减送活动 +export function deleteRewardActivity(id) { + return request({ + url: '/promotion/reward-activity/delete?id=' + id, + method: 'delete' + }) +} + +// 获得满减送活动 +export function getRewardActivity(id) { + return request({ + url: '/promotion/reward-activity/get?id=' + id, + method: 'get' + }) +} + +// 获得满减送活动分页 +export function getRewardActivityPage(query) { + return request({ + url: '/promotion/reward-activity/page', + method: 'get', + params: query + }) +} diff --git a/yudao-ui-admin/src/utils/constants.js b/yudao-ui-admin/src/utils/constants.js index c465466e2..3efb0e3c0 100644 --- a/yudao-ui-admin/src/utils/constants.js +++ b/yudao-ui-admin/src/utils/constants.js @@ -292,3 +292,25 @@ export const PromotionConditionTypeEnum = { name: '满 N 件' } } + +/** + * 促销活动的状态枚举 + */ +export const PromotionActivityStatusEnum = { + WAIT: { + type: 10, + name: '未开始' + }, + RUN: { + type: 20, + name: '进行中' + }, + END: { + type: 30, + name: '已结束' + }, + CLOSE: { + type: 40, + name: '已关闭' + } +} diff --git a/yudao-ui-admin/src/views/mall/promotion/rewardActivity/index.vue b/yudao-ui-admin/src/views/mall/promotion/rewardActivity/index.vue new file mode 100755 index 000000000..cf270c021 --- /dev/null +++ b/yudao-ui-admin/src/views/mall/promotion/rewardActivity/index.vue @@ -0,0 +1,305 @@ + + +