From 1d2a6ad065a5459a4321a51c13dc316b6ebd8d5f Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 20 Sep 2023 10:09:15 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8:=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84=20app=20=E7=AB=AF=E8=8E=B7=E5=8F=96=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E5=88=86=E9=A1=B5=E3=80=81=E5=88=97=E8=A1=A8=E3=80=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 3 +- .../AppCombinationActivityController.java | 127 +++++++----------- .../AppCombinationActivityRespVO.java | 1 - .../seckill/AppSeckillActivityController.java | 17 +-- .../CombinationActivityConvert.java | 43 ++++++ .../CombinationActivityMapper.java | 6 + .../bargain/BargainActivityService.java | 3 +- .../CombinationActivityService.java | 17 +++ .../CombinationActivityServiceImpl.java | 17 +++ 9 files changed, 139 insertions(+), 95 deletions(-) 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 c39fbb316..798e59851 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 @@ -56,7 +56,7 @@ public interface ErrorCodeConstants { ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除"); ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭"); ErrorCode SECKILL_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1013008006, "秒杀失败,原因秒杀库存不足"); - ErrorCode SECKILL_ACTIVITY_FAIL_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭"); + ErrorCode SECKILL_ACTIVITY_APP_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭"); // ========== 秒杀时段 1013009000 ========== ErrorCode SECKILL_CONFIG_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在"); @@ -69,6 +69,7 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE_NOT_UPDATE = new ErrorCode(1013010002, "拼团活动已关闭不能修改"); ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除"); ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010004, "拼团失败,原因:拼团活动已关闭"); + ErrorCode COMBINATION_ACTIVITY_APP_STATUS_DISABLE = new ErrorCode(1013010005, "拼团活动已关闭"); // ========== 拼团记录 1013011000 ========== ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013011000, "拼团不存在"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 75693f90b..e2c8c67bd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -1,10 +1,19 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -14,11 +23,14 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.time.LocalDateTime; -import java.util.ArrayList; +import javax.annotation.Resource; +import java.util.Arrays; import java.util.List; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_APP_STATUS_DISABLE; @Tag(name = "用户 APP - 拼团活动") @RestController @@ -26,104 +38,55 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppCombinationActivityController { + @Resource + private CombinationActivityService activityService; + @Resource + private ProductSpuApi spuApi; + + @GetMapping("/list") @Operation(summary = "获得拼团活动列表", description = "用于小程序首页") - // TODO 芋艿:增加 Spring Cache - // TODO 芋艿:缺少 swagger 注解 + @Parameter(name = "count", description = "需要展示的数量", example = "6") public CommonResult> getCombinationActivityList( @RequestParam(name = "count", defaultValue = "6") Integer count) { - List activityList = new ArrayList<>(); - AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO(); - activity1.setId(1L); - activity1.setName("618 大拼团"); - activity1.setUserSize(3); - activity1.setSpuId(2048L); - activity1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); - activity1.setMarketPrice(50); - activity1.setCombinationPrice(100); - activityList.add(activity1); + List list = activityService.getCombinationActivityAppList(count); + if (CollUtil.isEmpty(list)) { + return success(CombinationActivityConvert.INSTANCE.convertAppList(list)); + } - AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO(); - activity2.setId(2L); - activity2.setName("双十一拼团"); - activity2.setUserSize(5); - activity2.setSpuId(4096L); - activity2.setPicUrl("https://static.iocoder.cn/mall/132.jpeg"); - activity2.setMarketPrice(100); - activity2.setCombinationPrice(200); - activityList.add(activity2); - - return success(activityList); + List spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId)); + // TODO 芋艿:增加 Spring Cache + return success(CombinationActivityConvert.INSTANCE.convertAppList(list, spuList)); } @GetMapping("/page") @Operation(summary = "获得拼团活动分页") public CommonResult> getCombinationActivityPage(PageParam pageParam) { - List activityList = new ArrayList<>(); - AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO(); - activity1.setId(1L); - activity1.setName("618 大拼团"); - activity1.setUserSize(3); - activity1.setSpuId(2048L); - activity1.setPicUrl("商品图片地址"); - activity1.setMarketPrice(50); - activity1.setCombinationPrice(100); - activityList.add(activity1); + PageResult result = activityService.getCombinationActivityAppPage(pageParam); + if (CollUtil.isEmpty(result.getList())) { + return success(PageResult.empty(result.getTotal())); + } - AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO(); - activity2.setId(2L); - activity2.setName("双十一拼团"); - activity2.setUserSize(5); - activity2.setSpuId(4096L); - activity2.setPicUrl("商品图片地址"); - activity2.setMarketPrice(100); - activity2.setCombinationPrice(200); - activityList.add(activity2); - - return success(new PageResult<>(activityList, 2L)); + List spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId)); + return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList)); } @GetMapping("/get-detail") @Operation(summary = "获得拼团活动明细") @Parameter(name = "id", description = "活动编号", required = true, example = "1024") public CommonResult getCombinationActivityDetail(@RequestParam("id") Long id) { - // TODO 芋艿:如果禁用的时候,需要抛出异常; - AppCombinationActivityDetailRespVO obj = new AppCombinationActivityDetailRespVO(); - // 设置其属性的值 - obj.setId(id); - obj.setName("晚九点限时秒杀"); - obj.setStatus(1); - obj.setStartTime(LocalDateTime.of(2023, 6, 15, 0, 0, 0)); - obj.setEndTime(LocalDateTime.of(2023, 6, 20, 23, 59, 0)); - obj.setUserSize(2); - obj.setSuccessCount(100); - obj.setSpuId(633L); - obj.setSingleLimitCount(2); - obj.setTotalLimitCount(3); + // 1、获取活动 + CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id); + if (combinationActivity == null) { + return success(null); + } + if (ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { + throw exception(COMBINATION_ACTIVITY_APP_STATUS_DISABLE); + } - // 创建一个Product对象的列表 - List productList = new ArrayList<>(); - // 创建三个新的Product对象并设置其属性的值 - AppCombinationActivityDetailRespVO.Product product1 = new AppCombinationActivityDetailRespVO.Product(); - product1.setSkuId(1L); - product1.setCombinationPrice(100); - // 将第一个Product对象添加到列表中 - productList.add(product1); - // 创建第二个Product对象并设置其属性的值 - AppCombinationActivityDetailRespVO.Product product2 = new AppCombinationActivityDetailRespVO.Product(); - product2.setSkuId(2L); - product2.setCombinationPrice(200); - // 将第二个Product对象添加到列表中 - productList.add(product2); - // 创建第三个Product对象并设置其属性的值 - AppCombinationActivityDetailRespVO.Product product3 = new AppCombinationActivityDetailRespVO.Product(); - product3.setSkuId(3L); - product3.setCombinationPrice(300); - // 将第三个Product对象添加到列表中 - productList.add(product3); - // 将Product列表设置为对象的属性值 - obj.setProducts(productList); - return success(obj); + // 2、获取活动商品 + List products = activityService.getCombinationProductsByActivityIds(Arrays.asList(combinationActivity.getId())); + return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java index b536e8abe..64462a377 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java @@ -28,7 +28,6 @@ public class AppCombinationActivityRespVO { private Integer marketPrice; @Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - // 从拼团商品里取最低价 private Integer combinationPrice; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index 8037c36cb..0e047f1a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityDetailRespVO; @@ -33,10 +32,9 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_FAIL_STATUS_CLOSED; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_APP_STATUS_CLOSED; @Tag(name = "用户 App - 秒杀活动") @RestController @@ -53,8 +51,7 @@ public class AppSeckillActivityController { private ProductSpuApi spuApi; @GetMapping("/get-now") - @Operation(summary = "获得当前秒杀活动") // 提供给首页使用 - // TODO 芋艿:需要增加 spring cache + @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用") public CommonResult getNowSeckillActivity() { // 1、获取当前时间处在哪个秒杀阶段 List configList = configService.getSeckillConfigList(); @@ -69,7 +66,8 @@ public class AppSeckillActivityController { List activityList = activityService.getSeckillActivityListByConfigIds(Arrays.asList(filteredConfig.getId())); List filteredList = filterList(activityList, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.ENABLE.getStatus())); // 2、1 获取 spu 信息 - List spuList = spuApi.getSpuList(CollectionUtils.convertList(filteredList, SeckillActivityDO::getSpuId)); + List spuList = spuApi.getSpuList(convertList(filteredList, SeckillActivityDO::getSpuId)); + // TODO 芋艿:需要增加 spring cache return success(SeckillActivityConvert.INSTANCE.convert(filteredConfig, filteredList, spuList)); } @@ -79,7 +77,7 @@ public class AppSeckillActivityController { // 1、查询满足当前阶段的活动 PageResult pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO); // 1、1 获取 spu 信息 - List spuList = spuApi.getSpuList(CollectionUtils.convertList(pageResult.getList(), SeckillActivityDO::getSpuId)); + List spuList = spuApi.getSpuList(convertList(pageResult.getList(), SeckillActivityDO::getSpuId)); return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, spuList)); } @@ -101,9 +99,8 @@ public class AppSeckillActivityController { if (seckillActivity == null) { return success(null); } - // TODO 芋艿:如果禁用的时候,需要抛出异常; if (ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { - throw exception(SECKILL_ACTIVITY_FAIL_STATUS_CLOSED); + throw exception(SECKILL_ACTIVITY_APP_STATUS_CLOSED); } // 3、获取活动商品 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index a6e086cc2..67b300c44 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -13,6 +13,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; @@ -25,6 +27,7 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; /** * 拼团活动 Convert @@ -109,4 +112,44 @@ public interface CombinationActivityConvert { List convert(List bean); + List convertAppList(List list); + + default List convertAppList(List list, List spuList) { + List activityList = convertAppList(list); + Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + return CollectionUtils.convertList(activityList, item -> { + findAndThen(spuMap, item.getSpuId(), spu -> { + item.setPicUrl(spu.getPicUrl()); + item.setMarketPrice(spu.getMarketPrice()); + }); + return item; + }); + } + + PageResult convertAppPage(PageResult result); + + default PageResult convertAppPage(PageResult result, List spuList) { + PageResult appPage = convertAppPage(result); + Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + List list = CollectionUtils.convertList(appPage.getList(), item -> { + findAndThen(spuMap, item.getSpuId(), spu -> { + item.setPicUrl(spu.getPicUrl()); + item.setMarketPrice(spu.getMarketPrice()); + }); + return item; + }); + appPage.setList(list); + return appPage; + } + + AppCombinationActivityDetailRespVO convert2(CombinationActivityDO combinationActivity); + + List convertList1(List products); + + default AppCombinationActivityDetailRespVO convert3(CombinationActivityDO combinationActivity, List products) { + AppCombinationActivityDetailRespVO detailRespVO = convert2(combinationActivity); + detailRespVO.setProducts(convertList1(products)); + return detailRespVO; + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index c2868d191..76e914f3a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -28,4 +29,9 @@ public interface CombinationActivityMapper extends BaseMapperX selectAppPage(PageParam pageParam, Integer status) { + return selectPage(pageParam, new LambdaQueryWrapperX() + .eq(CombinationActivityDO::getStatus, status)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java index e59e1ce3e..d560f6549 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java @@ -75,7 +75,8 @@ public interface BargainActivityService { * 获取 APP 端活动展示数据 * * @param count 需要的数量 - * @return + * @return 活动列表 */ List getBargainActivityAppList(Integer count); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index c3e0f5313..235bf142c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; @@ -82,4 +83,20 @@ public interface CombinationActivityService { */ void validateCombination(Long activityId, Long userId, Long skuId, Integer count); + /** + * 获取 APP 端活动展示数据 + * + * @param count 需要的数量 + * @return 活动列表 + */ + List getCombinationActivityAppList(Integer count); + + /** + * 获取 APP 端活动分页数据 + * + * @param pageParam 分页参数 + * @return 活动分页数据 + */ + PageResult getCombinationActivityAppPage(PageParam pageParam); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index a9f95fa62..e29bc69a8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; @@ -245,4 +246,20 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } + @Override + public List getCombinationActivityAppList(Integer count) { + if (count == null) { + count = 6; + } + + PageResult result = combinationActivityMapper.selectAppPage(new PageParam().setPageSize(count), + CommonStatusEnum.ENABLE.getStatus()); + return result.getList(); + } + + @Override + public PageResult getCombinationActivityAppPage(PageParam pageParam) { + return combinationActivityMapper.selectAppPage(pageParam, CommonStatusEnum.ENABLE.getStatus()); + } + } From 6ef94ade6a5d0ea850e67975d43b0c233797b881 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 20 Sep 2023 16:06:29 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=92=8C=E6=B4=BB=E5=8A=A8=20review=20=E6=8F=90=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/date/LocalDateTimeUtils.java | 11 ---- .../api/seckill/SeckillActivityApi.java | 5 +- .../api/seckill/SeckillActivityApiImpl.java | 4 +- .../bargain/AppBargainActivityController.java | 5 +- .../AppCombinationActivityController.java | 5 +- .../seckill/AppSeckillActivityController.java | 30 +++------ .../seckill/AppSeckillConfigController.java | 11 +--- .../bargain/BargainActivityConvert.java | 12 +--- .../CombinationActivityConvert.java | 32 ++++------ .../SeckillActivityConvert.java | 28 ++++---- .../mysql/bargain/BargainActivityMapper.java | 25 +++++++- .../CombinationActivityMapper.java | 22 ++++++- .../bargain/BargainActivityService.java | 10 ++- .../bargain/BargainActivityServiceImpl.java | 15 ++--- .../CombinationActivityService.java | 14 ++-- .../CombinationActivityServiceImpl.java | 17 ++--- .../seckill/SeckillActivityService.java | 13 +++- .../seckill/SeckillActivityServiceImpl.java | 19 ++++-- .../service/seckill/SeckillConfigService.java | 9 +++ .../seckill/SeckillConfigServiceImpl.java | 8 +++ .../aftersale/TradeAfterSaleController.java | 6 +- .../aftersale/TradeAfterSaleConvert.java | 10 +-- ...pDTO.java => TradeAfterSaleLogRespVO.java} | 3 +- .../core/service/AfterSaleLogService.java | 4 +- .../aftersale/TradeAfterSaleServiceImpl.java | 4 +- .../order/TradeOrderUpdateServiceImpl.java | 64 +++++++++++-------- .../order/bo/TradeBeforeOrderCreateReqBO.java | 48 ++++++++++++-- 27 files changed, 248 insertions(+), 186 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/{TradeAfterSaleLogRespDTO.java => TradeAfterSaleLogRespVO.java} (95%) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java index 275e9f5a1..414c0af7d 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java @@ -43,17 +43,6 @@ public class LocalDateTimeUtils { return LocalDateTime.of(year, mouth, day, 0, 0, 0); } - /** - * 创建指定时间 - * - * @param timeStr 时间字符串 - * @return 指定时间 - */ - public static LocalDateTime buildTime(String timeStr) { - // TODO @puhui999:这个方法的实现,和 LocalDateTimeUtil.parse() 的差异点是啥呀 - return LocalDateTime.of(LocalDate.now(), LocalTime.parse(timeStr)); - } - public static LocalDateTime[] buildBetweenTime(int year1, int mouth1, int day1, int year2, int mouth2, int day2) { return new LocalDateTime[]{buildTime(year1, mouth1, day1), buildTime(year2, mouth2, day2)}; diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java index ebe4bb0e5..11cc22864 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java @@ -7,14 +7,13 @@ package cn.iocoder.yudao.module.promotion.api.seckill; */ public interface SeckillActivityApi { - // TODO @puhui999:activityId 改成 id 好点哈; /** * 更新秒杀库存 * - * @param activityId 活动编号 + * @param id 活动编号 * @param skuId sku 编号 * @param count 数量 */ - void updateSeckillStock(Long activityId, Long skuId, Integer count); + void updateSeckillStock(Long id, Long skuId, Integer count); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java index 624af86c6..9a15a0ca9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java @@ -17,8 +17,8 @@ public class SeckillActivityApiImpl implements SeckillActivityApi { private SeckillActivityService activityService; @Override - public void updateSeckillStock(Long activityId, Long skuId, Integer count) { - activityService.updateSeckillStock(activityId, skuId, count); + public void updateSeckillStock(Long id, Long skuId, Integer count) { + activityService.updateSeckillStock(id, skuId, count); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java index 72facf935..a996b4521 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java @@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; +import static cn.hutool.core.util.ObjectUtil.defaultIfNull; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -39,7 +40,7 @@ public class AppBargainActivityController { @GetMapping("/page") @Operation(summary = "获得砍价活动分页") public CommonResult> getBargainActivityPage(PageParam pageReqVO) { - PageResult result = bargainActivityService.getBargainActivityPageForApp(pageReqVO); + PageResult result = bargainActivityService.getBargainActivityPage(pageReqVO); if (CollUtil.isEmpty(result.getList())) { return success(PageResult.empty(result.getTotal())); } @@ -54,7 +55,7 @@ public class AppBargainActivityController { @Parameter(name = "count", description = "需要展示的数量", example = "6") public CommonResult> getBargainActivityList( @RequestParam(name = "count", defaultValue = "6") Integer count) { - List list = bargainActivityService.getBargainActivityListForApp(count); + List list = bargainActivityService.getBargainActivityListByCount(defaultIfNull(count, 6)); if (CollUtil.isEmpty(list)) { return success(BargainActivityConvert.INSTANCE.convertAppList(list)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index e2c8c67bd..d09292de9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -27,6 +27,7 @@ import javax.annotation.Resource; import java.util.Arrays; import java.util.List; +import static cn.hutool.core.util.ObjectUtil.defaultIfNull; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -49,7 +50,7 @@ public class AppCombinationActivityController { @Parameter(name = "count", description = "需要展示的数量", example = "6") public CommonResult> getCombinationActivityList( @RequestParam(name = "count", defaultValue = "6") Integer count) { - List list = activityService.getCombinationActivityAppList(count); + List list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6)); if (CollUtil.isEmpty(list)) { return success(CombinationActivityConvert.INSTANCE.convertAppList(list)); } @@ -62,7 +63,7 @@ public class AppCombinationActivityController { @GetMapping("/page") @Operation(summary = "获得拼团活动分页") public CommonResult> getCombinationActivityPage(PageParam pageParam) { - PageResult result = activityService.getCombinationActivityAppPage(pageParam); + PageResult result = activityService.getCombinationActivityPage(pageParam); if (CollUtil.isEmpty(result.getList())) { return success(PageResult.empty(result.getTotal())); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index 0bb283db7..7ee0027ed 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -27,13 +27,11 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Arrays; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_APP_STATUS_CLOSED; @Tag(name = "用户 App - 秒杀活动") @@ -54,22 +52,17 @@ public class AppSeckillActivityController { @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用") public CommonResult getNowSeckillActivity() { // 1. 获取当前时间处在哪个秒杀阶段 - // TODO @puhui999:可以考虑在 service 写个方法;这样 controller 不用关注过多逻辑 - List configList = configService.getSeckillConfigList(); - SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(), - CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime())); - if (filteredConfig == null) { // 时段不存在直接返回 null + SeckillConfigDO configList = configService.getSeckillConfigListByStatusOnCurrentTime(CommonStatusEnum.ENABLE.getStatus()); + if (configList == null) { // 时段不存在直接返回 null return success(null); } // 2. 查询满足当前阶段的活动 - // TODO @puhui999:最好直接返回开启的;不多查询数据 - List activityList = activityService.getSeckillActivityListByConfigIds(Arrays.asList(filteredConfig.getId())); - List filteredList = filterList(activityList, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.ENABLE.getStatus())); + List activityList = activityService.getSeckillActivityListByConfigIdAndStatus(configList.getId(), CommonStatusEnum.ENABLE.getStatus()); // 3 获取 spu 信息 - List spuList = spuApi.getSpuList(convertList(filteredList, SeckillActivityDO::getSpuId)); + List spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); // TODO 芋艿:需要增加 spring cache - return success(SeckillActivityConvert.INSTANCE.convert(filteredConfig, filteredList, spuList)); + return success(SeckillActivityConvert.INSTANCE.convert(configList, activityList, spuList)); } @GetMapping("/page") @@ -87,12 +80,9 @@ public class AppSeckillActivityController { @Operation(summary = "获得秒杀活动明细") @Parameter(name = "id", description = "活动编号", required = true, example = "1024") public CommonResult getSeckillActivity(@RequestParam("id") Long id) { - // 1、获取当前时间处在哪个秒杀阶段 - // TODO puhui999:这里,和 58 行是雷同的 - List configList = configService.getSeckillConfigList(); - SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(), - CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime())); - if (filteredConfig == null) { // 时段不存在直接返回 null + // 1. 获取当前时间处在哪个秒杀阶段 + SeckillConfigDO configList = configService.getSeckillConfigListByStatusOnCurrentTime(CommonStatusEnum.ENABLE.getStatus()); + if (configList == null) { // 时段不存在直接返回 null return success(null); } @@ -107,7 +97,7 @@ public class AppSeckillActivityController { // 3. 拼接数据 List products = activityService.getSeckillProductListByActivityId(seckillActivity.getId()); - return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, filteredConfig)); + return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, configList)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java index fc30a2f24..2795ca9a4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java @@ -1,11 +1,9 @@ package cn.iocoder.yudao.module.promotion.controller.app.seckill; -import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.config.AppSeckillConfigRespVO; import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillConfigConvert; -import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; import cn.iocoder.yudao.module.promotion.service.seckill.SeckillConfigService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -15,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -31,13 +28,7 @@ public class AppSeckillConfigController { @GetMapping("/list") @Operation(summary = "获得秒杀时间段列表") public CommonResult> getSeckillConfigList() { - List list = configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()); - // TODO @puhui999:如果这种,不用判空也问题不大; - if (CollectionUtil.isEmpty(list)) { - return success(Collections.emptyList()); - } - - return success(SeckillConfigConvert.INSTANCE.convertList2(list)); + return success(SeckillConfigConvert.INSTANCE.convertList2(configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java index 24297990f..954558b01 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java @@ -46,9 +46,7 @@ public interface BargainActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - // TODO @puhui999:这里可以使用链式哈 - item.setPicUrl(spu.getPicUrl()); - item.setSpuName(spu.getName()); + item.setPicUrl(spu.getPicUrl()).setSpuName(spu.getName()); }); return item; }); @@ -76,9 +74,7 @@ public interface BargainActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - // TODO @puhui999:这里可以使用链式哈 - item.setPicUrl(spu.getPicUrl()); - item.setMarketPrice(spu.getMarketPrice()); + item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); }); return item; }); @@ -93,9 +89,7 @@ public interface BargainActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); return CollectionUtils.convertList(activityList, item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - // TODO @puhui999:这里可以使用链式哈 - item.setPicUrl(spu.getPicUrl()); - item.setMarketPrice(spu.getMarketPrice()); + item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); }); return item; }); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 69766358b..07a9c4df3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -62,8 +62,7 @@ public interface CombinationActivityConvert { PageResult pageResult = convertPage(page); pageResult.getList().forEach(item -> { MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { - item.setSpuName(spu.getName()); - item.setPicUrl(spu.getPicUrl()); + item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()); }); item.setProducts(convertList2(productList)); }); @@ -100,16 +99,15 @@ public interface CombinationActivityConvert { default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO, CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { - // TODO @puhui999:搞成链式的 set;这样会更规整一点; - CombinationRecordDO record = convert(reqDTO); - record.setVirtualGroup(false); - record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration())); - record.setUserSize(activity.getUserSize()); - record.setNickname(user.getNickname()); - record.setAvatar(user.getAvatar()); - record.setSpuName(spu.getName()); - record.setPicUrl(sku.getPicUrl()); - return record; + // TODO @puhui999:订单付款后需要设置开始时间和结束时间; + return convert(reqDTO) + .setVirtualGroup(false) + .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) + .setUserSize(activity.getUserSize()) + .setNickname(user.getNickname()) + .setAvatar(user.getAvatar()) + .setSpuName(spu.getName()) + .setPicUrl(sku.getPicUrl()); } List convert(List bean); @@ -121,8 +119,7 @@ public interface CombinationActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); return CollectionUtils.convertList(activityList, item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()); - item.setMarketPrice(spu.getMarketPrice()); + item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); }); return item; }); @@ -135,8 +132,7 @@ public interface CombinationActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(appPage.getList(), item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()); - item.setMarketPrice(spu.getMarketPrice()); + item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); }); return item; }); @@ -149,9 +145,7 @@ public interface CombinationActivityConvert { List convertList1(List products); default AppCombinationActivityDetailRespVO convert3(CombinationActivityDO combinationActivity, List products) { - AppCombinationActivityDetailRespVO detailRespVO = convert2(combinationActivity); - detailRespVO.setProducts(convertList1(products)); - return detailRespVO; + return convert2(combinationActivity).setProducts(convertList1(products)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index e4c4d5e36..f0da88cbc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity; +import cn.hutool.core.date.LocalDateTimeUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; @@ -29,7 +30,6 @@ import java.util.Map; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; /** * 秒杀活动 Convert @@ -98,10 +98,9 @@ public interface SeckillActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); respVO.setActivities(CollectionUtils.convertList(convertList3(activityList), item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - // TODO @puhui999:可以尝试链式 set 哈; - item.setPicUrl(spu.getPicUrl()); - item.setMarketPrice(spu.getMarketPrice()); - item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); + item.setPicUrl(spu.getPicUrl()) + .setMarketPrice(spu.getMarketPrice()) + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); }); return item; })); @@ -115,10 +114,9 @@ public interface SeckillActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { findAndThen(spuMap, item.getSpuId(), spu -> { - // TODO @puhui999:可以尝试链式 set 哈; - item.setPicUrl(spu.getPicUrl()); - item.setMarketPrice(spu.getMarketPrice()); - item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); + item.setPicUrl(spu.getPicUrl()) + .setMarketPrice(spu.getMarketPrice()) + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); }); return item; }); @@ -131,12 +129,12 @@ public interface SeckillActivityConvert { List convertList1(List products); default AppSeckillActivityDetailRespVO convert3(SeckillActivityDO seckillActivity, List products, SeckillConfigDO filteredConfig) { - AppSeckillActivityDetailRespVO respVO = convert2(seckillActivity); - respVO.setProducts(convertList1(products)); - // TODO @puhui999:可以尝试链式 set 哈; - respVO.setStartTime(buildTime(filteredConfig.getStartTime())); - respVO.setEndTime(buildTime(filteredConfig.getEndTime())); - return respVO; + return convert2(seckillActivity) + .setProducts(convertList1(products)) + .setStartTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getStartTime(), "yyyy-MM-dd") + " " + filteredConfig.getStartTime(), + "yyyy-MM-dd HH:mm:ss")) // 活动开始日期和时段结合 + .setEndTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getEndTime(), "yyyy-MM-dd") + " " + filteredConfig.getEndTime(), + "yyyy-MM-dd HH:mm:ss")); // 活动结束日期和时段结合 } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index f098895d2..131b8cff9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -45,11 +45,34 @@ public interface BargainActivityMapper extends BaseMapperX { .setSql("stock = stock - " + count)); } - default PageResult selectAppPage(PageParam pageReqVO, Integer status, LocalDateTime now) { + /** + * 查询处在 now 日期时间且是 status 状态的活动分页 + * + * @param pageReqVO 分页参数 + * @param status 状态 + * @param now 当前日期时间 + * @return 活动分页 + */ + default PageResult selectPage(PageParam pageReqVO, Integer status, LocalDateTime now) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eq(BargainActivityDO::getStatus, status) .le(BargainActivityDO::getStartTime, now) .ge(BargainActivityDO::getEndTime, now)); } + /** + * 查询处在 now 日期时间且是 status 状态的活动分页 + * + * @param status 状态 + * @param now 当前日期时间 + * @return 活动分页 + */ + default List selectList(Integer count, Integer status, LocalDateTime now) { + return selectList(new LambdaQueryWrapperX() + .eq(BargainActivityDO::getStatus, status) + .le(BargainActivityDO::getStartTime, now) + .ge(BargainActivityDO::getEndTime, now) + .apply("LIMIT " + count)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 76e914f3a..8efc96abd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -29,9 +29,29 @@ public interface CombinationActivityMapper extends BaseMapperX selectAppPage(PageParam pageParam, Integer status) { + /** + * 查询 status 状态的活动分页 + * + * @param pageParam 分页参数 + * @param status 状态 + * @return 活动分页 + */ + default PageResult selectPage(PageParam pageParam, Integer status) { return selectPage(pageParam, new LambdaQueryWrapperX() .eq(CombinationActivityDO::getStatus, status)); } + /** + * 查询 status 状态的活动分页 + * + * @param status 状态 + * @param count 限制条数 + * @return 活动分页 + */ + default List selectList(Integer status, Integer count) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationActivityDO::getStatus, status) + .apply("LIMIT " + count)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java index 1b3bd35dd..9a0c17af9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java @@ -63,22 +63,20 @@ public interface BargainActivityService { */ PageResult getBargainActivityPage(BargainActivityPageReqVO pageReqVO); - // TODO @puhui999:这里可以改成进行中的活动;尽量避免专门为 app 定制,或者类似的名字哈;mapper 那也是 - /** - * 获取 APP 端活动分页数据 + * 获取正在进行的活动分页数据 * * @param pageReqVO 分页请求 * @return 砍价活动分页 */ - PageResult getBargainActivityPageForApp(PageParam pageReqVO); + PageResult getBargainActivityPage(PageParam pageReqVO); /** - * 获取 APP 端活动展示数据 + * 获取正在进行的活动分页数据 * * @param count 需要的数量 * @return 砍价活动分页 */ - List getBargainActivityListForApp(Integer count); + List getBargainActivityListByCount(Integer count); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 5aa075250..36697c7d4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -142,21 +142,14 @@ public class BargainActivityServiceImpl implements BargainActivityService { } @Override - public PageResult getBargainActivityPageForApp(PageParam pageReqVO) { + public PageResult getBargainActivityPage(PageParam pageReqVO) { // 只查询进行中,且在时间范围内的 - return bargainActivityMapper.selectAppPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); + return bargainActivityMapper.selectPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); } @Override - public List getBargainActivityListForApp(Integer count) { - // TODO @puhui999:这种 default count 的逻辑,可以放到 controller 哈;然后可以使用 ObjectUtils.default 方法 - if (count == null) { - count = 6; - } - // TODO @puhui999:这种不要用 page;会浪费一次 count; - PageResult result = bargainActivityMapper.selectAppPage(new PageParam().setPageSize(count), - CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); - return result.getList(); + public List getBargainActivityListByCount(Integer count) { + return bargainActivityMapper.selectList(count, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index e01d27ec2..c2a090b72 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -85,19 +85,19 @@ public interface CombinationActivityService { void validateCombination(Long activityId, Long userId, Long skuId, Integer count); /** - * 获取 APP 端活动展示数据 + * 获取正在进行的活动分页数据 * * @param count 需要的数量 - * @return 活动列表 + * @return 拼团活动分页 */ - List getCombinationActivityAppList(Integer count); + List getCombinationActivityListByCount(Integer count); /** - * 获取 APP 端活动分页数据 + * 获取正在进行的活动分页数据 * - * @param pageParam 分页参数 - * @return 活动分页数据 + * @param pageParam 分页请求 + * @return 拼团活动分页 */ - PageResult getCombinationActivityAppPage(PageParam pageParam); + PageResult getCombinationActivityPage(PageParam pageParam); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index a70a084f7..87a633064 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -224,8 +224,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); } // 1.3 校验是否超出单次限购数量 - // TODO puhui999:count > activity.getSingleLimitCount() 会更好理解点; - if (activity.getSingleLimitCount() < count) { + if (count > activity.getSingleLimitCount()) { throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); } @@ -247,19 +246,13 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public List getCombinationActivityAppList(Integer count) { - if (count == null) { - count = 6; - } - - PageResult result = combinationActivityMapper.selectAppPage(new PageParam().setPageSize(count), - CommonStatusEnum.ENABLE.getStatus()); - return result.getList(); + public List getCombinationActivityListByCount(Integer count) { + return combinationActivityMapper.selectList(CommonStatusEnum.ENABLE.getStatus(), count); } @Override - public PageResult getCombinationActivityAppPage(PageParam pageParam) { - return combinationActivityMapper.selectAppPage(pageParam, CommonStatusEnum.ENABLE.getStatus()); + public PageResult getCombinationActivityPage(PageParam pageParam) { + return combinationActivityMapper.selectPage(pageParam, CommonStatusEnum.ENABLE.getStatus()); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 2be81ccb9..3cbee8126 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -37,11 +37,11 @@ public interface SeckillActivityService { /** * 更新秒杀库存 * - * @param activityId 活动编号 + * @param id 活动编号 * @param skuId sku 编号 * @param count 数量 */ - void updateSeckillStock(Long activityId, Long skuId, Integer count); + void updateSeckillStock(Long id, Long skuId, Integer count); /** * 关闭秒杀活动 @@ -97,6 +97,15 @@ public interface SeckillActivityService { */ List getSeckillActivityListByConfigIds(Collection ids); + /** + * 通过活动时段编号获取指定 status 的秒杀活动 + * + * @param configId 时段配置编号 + * @param status 状态 + * @return 秒杀活动列表 + */ + List getSeckillActivityListByConfigIdAndStatus(Long configId, Integer status); + /** * 通过活动时段获取秒杀活动 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 10891e071..0092cf1b8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -31,6 +30,7 @@ import java.util.Map; import static cn.hutool.core.collection.CollUtil.isNotEmpty; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -148,16 +148,16 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override @Transactional(rollbackFor = Exception.class) - public void updateSeckillStock(Long activityId, Long skuId, Integer count) { + public void updateSeckillStock(Long id, Long skuId, Integer count) { // 1、校验秒杀活动是否存在 - SeckillActivityDO seckillActivity = getSeckillActivity(activityId); + SeckillActivityDO seckillActivity = getSeckillActivity(id); // 1.1、校验库存是否充足 if (seckillActivity.getTotalStock() < count) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } // 2、获取活动商品 - List products = getSeckillProductListByActivityId(activityId); + List products = getSeckillProductListByActivityId(id); // 2.1、过滤出购买的商品 SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId())); // 2.2、检查活动商品库存是否充足 @@ -268,8 +268,15 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public List getSeckillActivityListByConfigIds(Collection ids) { - return CollectionUtils.filterList(seckillActivityMapper.selectList(), - item -> CollectionUtils.anyMatch(item.getConfigIds(), ids::contains)); + return filterList(seckillActivityMapper.selectList(), + item -> anyMatch(item.getConfigIds(), ids::contains)); + } + + @Override + public List getSeckillActivityListByConfigIdAndStatus(Long configId, Integer status) { + return filterList(seckillActivityMapper.selectList(SeckillActivityDO::getStatus, status), + item -> anyMatch(item.getConfigIds(), id -> ObjectUtil.equal(id, configId)) // 校验时段 + && isBetween(item.getStartTime(), item.getEndTime())); // 追加当前日期是否处在活动日期之间的校验条件 } @Override diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigService.java index 5cbf4fd32..c8377e630 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigService.java @@ -54,6 +54,7 @@ public interface SeckillConfigService { */ List getSeckillConfigList(); + /** * 校验秒杀时段是否存在 * @@ -85,4 +86,12 @@ public interface SeckillConfigService { */ void updateSeckillConfigStatus(Long id, Integer status); + /** + * 获取当前日期时间处于的秒杀时段且状态为 status + * + * @param status 状态 + * @return 时段 + */ + SeckillConfigDO getSeckillConfigListByStatusOnCurrentTime(Integer status); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigServiceImpl.java index ce2171079..a5d2309c8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigServiceImpl.java @@ -20,6 +20,8 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; /** @@ -67,6 +69,12 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { seckillConfigMapper.updateById(new SeckillConfigDO().setId(id).setStatus(status)); } + @Override + public SeckillConfigDO getSeckillConfigListByStatusOnCurrentTime(Integer status) { + return findFirst(seckillConfigMapper.selectList(SeckillConfigDO::getStatus, status), + config -> isBetween(config.getStartTime(), config.getEndTime())); + } + @Override public void deleteSeckillConfig(Long id) { // 校验存在 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index 0bf5a9cd9..a3fcfae40 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -12,7 +12,7 @@ import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; @@ -87,13 +87,13 @@ public class TradeAfterSaleController { // 拼接数据 MemberUserRespDTO user = memberUserApi.getUser(afterSale.getUserId()); // 获取售后日志 - List logs = afterSaleLogService.getLog(afterSale.getId()); + List logs = afterSaleLogService.getLog(afterSale.getId()); // TODO 方便测试看效果,review 后移除 if (logs == null) { logs = new ArrayList<>(); } for (int i = 1; i <= 6; i++) { - TradeAfterSaleLogRespDTO respVO = new TradeAfterSaleLogRespDTO(); + TradeAfterSaleLogRespVO respVO = new TradeAfterSaleLogRespVO(); respVO.setId((long) i); respVO.setUserId((long) i); respVO.setUserType(i % 2 == 0 ? 2 : 1); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java index 0c84c6967..dc220ad31 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO; -import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderBaseVO; @@ -16,7 +15,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -68,10 +67,10 @@ public interface TradeAfterSaleConvert { PageResult convertPage02(PageResult page); - List convertList(List list); + List convertList(List list); default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List orderItems, - MemberUserRespDTO user, List logs) { + MemberUserRespDTO user, List logs) { TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems); // 处理用户信息 respVO.setUser(convert(user)); @@ -81,7 +80,8 @@ public interface TradeAfterSaleConvert { respVO.setLogs(convertList1(logs)); return respVO; } - List convertList1(List list); + + List convertList1(List list); @Mapping(target = "id", source = "afterSale.id") TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List orderItems); TradeOrderBaseVO convert(TradeOrderDO order); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java similarity index 95% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java index 69c6bd939..328aab944 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java @@ -8,7 +8,6 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; -// TODO @puhui999:这个是不是应该搞成 vo 啊? /** * 贸易售后日志详情 DTO * @@ -17,7 +16,7 @@ import java.time.LocalDateTime; @Data @NoArgsConstructor @AllArgsConstructor -public class TradeAfterSaleLogRespDTO { +public class TradeAfterSaleLogRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20669") private Long id; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java index b068afd56..2f9245c01 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import java.util.List; @@ -29,6 +29,6 @@ public interface AfterSaleLogService { * @param afterSaleId 售后编号 * @return 售后日志 */ - List getLog(Long afterSaleId); + List getLog(Long afterSaleId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index f54563d42..1b7866da8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -26,7 +26,7 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; @@ -450,7 +450,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa } @Override - public List getLog(Long afterSaleId) { + public List getLog(Long afterSaleId) { // TODO 不熟悉流程先这么滴 List saleLogDOs = tradeAfterSaleLogMapper.selectList(TradeAfterSaleLogDO::getAfterSaleId, afterSaleId); return TradeAfterSaleConvert.INSTANCE.convertList(saleLogDOs); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 102418260..2d879ae2a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -553,41 +553,49 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { tradeOrderMapper.updateById(update); // TODO @芋艿:改价时,赠送的积分,要不要做改动??? - // TODO @puhui999:应该是按照 payPrice 分配;并且要考虑取余问题;payPrice 也要考虑,item 里的 - // TODO:先按 adjustPrice 实现,没明白 payPrice 怎么搞哈哈哈 - // TODO @puhui999:就是对比新老 adjustPrice 的差值,然后计算补充的 adjustPrice 最终值;另外,可以不用区分 items.size 是不是 > 1 哈;应该是一致的逻辑;分摊的逻辑,有点类似 dividePrice 方法噢; // 5、更新 TradeOrderItem - if (items.size() > 1) { - // TradeOrderItemDO 需要做 adjustPrice 的分摊 - int price = reqVO.getAdjustPrice() / items.size(); - int remainderPrice = reqVO.getAdjustPrice() % items.size(); - List orders = new ArrayList<>(); - for (int i = 0; i < items.size(); i++) { - // 把平摊后剩余的金额加到第一个订单项 - if (remainderPrice != 0 && i == 0) { - orders.add(convertOrderItemPrice(items.get(i), price + remainderPrice)); - } - orders.add(convertOrderItemPrice(items.get(i), price)); - } - tradeOrderItemMapper.updateBatch(orders); - } else { - TradeOrderItemDO orderItem = items.get(0); - TradeOrderItemDO updateItem = convertOrderItemPrice(orderItem, reqVO.getAdjustPrice()); - tradeOrderItemMapper.updateById(updateItem); + // TradeOrderItemDO 需要做 adjustPrice 的分摊 + List dividePrices = dividePrice(items, orderPayPrice); + List updateItems = new ArrayList<>(); + for (int i = 0; i < items.size(); i++) { + TradeOrderItemDO item = items.get(i); + Integer adjustPrice = item.getPrice() - dividePrices.get(i); // 计算调整的金额 + updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(adjustPrice) + .setPayPrice(item.getPayPrice() - adjustPrice)); } + tradeOrderItemMapper.updateBatch(updateItems); + // 6、更新支付订单 payOrderApi.updatePayOrderPrice(order.getPayOrderId(), update.getPayPrice()); } - private TradeOrderItemDO convertOrderItemPrice(TradeOrderItemDO orderItem, Integer price) { - TradeOrderItemDO newOrderItem = new TradeOrderItemDO(); - newOrderItem.setId(orderItem.getId()); - newOrderItem.setAdjustPrice(price); - int payPrice = orderItem.getAdjustPrice() != null ? (orderItem.getPayPrice() - orderItem.getAdjustPrice()) - + price : orderItem.getPayPrice() + price; - newOrderItem.setPayPrice(payPrice); - return newOrderItem; + /** + * 计算订单调价价格分摊 + * + * @param items 订单项 + * @param orderPayPrice 订单支付金额 + * @return 分摊金额数组,和传入的 orderItems 一一对应 + */ + private List dividePrice(List items, Integer orderPayPrice) { + Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum); + assert total != null; + // 遍历每一个,进行分摊 + List prices = new ArrayList<>(items.size()); + int remainPrice = orderPayPrice; + for (int i = 0; i < items.size(); i++) { + TradeOrderItemDO orderItem = items.get(i); + int partPrice; + if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减 + partPrice = (int) (orderPayPrice * (1.0D * orderItem.getPayPrice() / total)); + remainPrice -= partPrice; + } else { + partPrice = remainPrice; + } + Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); + prices.add(partPrice); + } + return prices; } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java index 077b5a5ef..261683d3d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.bo; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -14,36 +15,73 @@ import javax.validation.constraints.NotNull; @Data public class TradeBeforeOrderCreateReqBO { - // TODO @puhui999:注释也写下哈;bo 还是写注释噢 - + /** + * 订单类型 + * + * 枚举 {@link TradeOrderTypeEnum} + */ @NotNull(message = "订单类型不能为空") private Integer orderType; + /** + * 用户编号 + * + * 关联 MemberUserDO 的 id 编号 + */ + @NotNull(message = "用户编号不能为空") + private Long userId; + // ========== 秒杀活动相关字段 ========== + /** + * + */ @Schema(description = "秒杀活动编号", example = "1024") private Long seckillActivityId; // ========== 拼团活动相关字段 ========== + /** + * 拼团活动编号 + */ @Schema(description = "拼团活动编号", example = "1024") private Long combinationActivityId; + /** + * 拼团团长编号 + */ @Schema(description = "拼团团长编号", example = "2048") private Long combinationHeadId; + // ========== 砍价活动相关字段 ========== + + /** + * 砍价活动编号 + */ @Schema(description = "砍价活动编号", example = "123") private Long bargainActivityId; + // ========== 活动购买商品相关字段 ========== + + /** + * 商品 SPU 编号 + * + * 关联 ProductSkuDO 的 spuId 编号 + */ @NotNull(message = "SPU 编号不能为空") private Long spuId; + /** + * 商品 SKU 编号 + * + * 关联 ProductSkuDO 的 id 编号 + */ @NotNull(message = "SKU 编号活动商品不能为空") private Long skuId; - @NotNull(message = "用户编号不能为空") - private Long userId; - + /** + * 购买的商品数量 + */ @NotNull(message = "购买数量不能为空") private Integer count; From 583a0a2dd511b776a69623b4a9a95af0a09af2bb Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 20 Sep 2023 16:28:41 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E7=A0=8D=E4=BB=B7+=E6=8B=BC=E5=9B=A2:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20selectList=20limit=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/dal/mysql/bargain/BargainActivityMapper.java | 2 +- .../dal/mysql/combination/CombinationActivityMapper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index 131b8cff9..a7fe3e58d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -72,7 +72,7 @@ public interface BargainActivityMapper extends BaseMapperX { .eq(BargainActivityDO::getStatus, status) .le(BargainActivityDO::getStartTime, now) .ge(BargainActivityDO::getEndTime, now) - .apply("LIMIT " + count)); + .last("LIMIT " + count)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 8efc96abd..0dce45a28 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -51,7 +51,7 @@ public interface CombinationActivityMapper extends BaseMapperX selectList(Integer status, Integer count) { return selectList(new LambdaQueryWrapperX() .eq(CombinationActivityDO::getStatus, status) - .apply("LIMIT " + count)); + .last("LIMIT " + count)); } } From 8060aeb5e7518e15f226fc7a5c1c8764017e8336 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 21 Sep 2023 09:07:37 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E7=A7=92=E6=9D=80:=20app=20=E7=AB=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=A2=9E=E5=8A=A0=E7=A7=92=E6=9D=80=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/seckill/vo/activity/AppSeckillActivityRespVO.java | 3 +++ .../promotion/service/bargain/BargainActivityServiceImpl.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityRespVO.java index 42f5a5ff4..278ee04a1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityRespVO.java @@ -25,6 +25,9 @@ public class AppSeckillActivityRespVO { // 从 SPU 的 marketPrice 读取 private Integer marketPrice; + @Schema(description = "秒杀活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + @Schema(description = "秒杀库存(剩余)", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer stock; @Schema(description = "秒杀库存(总共)", requiredMode = Schema.RequiredMode.REQUIRED, example = "200") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 36697c7d4..95e50eff5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -114,7 +114,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { public void deleteBargainActivity(Long id) { // 校验存在 BargainActivityDO activityDO = validateBargainActivityExists(id); - // 校验状态 + // 校验状态 TODO puhui: 测试完成后需要恢复校验 //if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { // throw exception(BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); //} From 9451342aae40c88c11a24b3238641a66535a1aac Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 22 Sep 2023 23:54:18 +0800 Subject: [PATCH 05/12] =?UTF-8?q?trade=EF=BC=9A=E8=90=A5=E9=94=80=E5=95=86?= =?UTF-8?q?=E5=93=81=EF=BC=88=E6=8B=BC=E5=9B=A2=E3=80=81=E7=A0=8D=E4=BB=B7?= =?UTF-8?q?=EF=BC=89=E4=B8=8D=E8=83=BD=E4=BD=BF=E7=94=A8=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/trade/enums/ErrorCodeConstants.java | 7 +------ .../price/calculator/TradeCouponPriceCalculator.java | 7 +++++++ .../price/calculator/TradeCouponPriceCalculatorTest.java | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 500601442..ecd31499d 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -12,12 +12,6 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; public interface ErrorCodeConstants { // ========== Order 模块 1011000000 ========== - ErrorCode ORDER_CREATE_SKU_NOT_FOUND = new ErrorCode(1011000001, "商品 SKU 不存在"); - ErrorCode ORDER_CREATE_SPU_NOT_SALE = new ErrorCode(1011000002, "商品 SPU 不可售卖"); - ErrorCode ORDER_CREATE_SKU_STOCK_NOT_ENOUGH = new ErrorCode(1011000004, "商品 SKU 库存不足"); - ErrorCode ORDER_CREATE_SPU_NOT_FOUND = new ErrorCode(1011000005, "商品 SPU 不可售卖"); - ErrorCode ORDER_CREATE_ADDRESS_NOT_FOUND = new ErrorCode(1011000006, "收货地址不存在"); - ErrorCode ORDER_ITEM_NOT_FOUND = new ErrorCode(1011000010, "交易订单项不存在"); ErrorCode ORDER_NOT_FOUND = new ErrorCode(1011000011, "交易订单不存在"); ErrorCode ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL = new ErrorCode(1011000012, "交易订单项更新售后状态失败,请重试"); @@ -61,6 +55,7 @@ public interface ErrorCodeConstants { ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY = new ErrorCode(1011003003, "计算快递运费异常,自提点为空"); + ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1011003004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵"); // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java index 68955ce51..b871186bd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -22,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_MIN_PRICE; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_SPU; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER; /** * 优惠劵的 {@link TradePriceCalculator} 实现类 @@ -44,6 +47,10 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator { CouponRespDTO coupon = couponApi.validateCoupon(new CouponValidReqDTO() .setId(param.getCouponId()).setUserId(param.getUserId())); Assert.notNull(coupon, "校验通过的优惠劵({}),不能为空", param.getCouponId()); + // 1.2 只有【普通】订单,才允许使用优惠劵 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + throw exception(PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER); + } // 2.1 获得匹配的商品 SKU 数组 List orderItems = filterMatchCouponOrderItems(result, coupon); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java index 94ac66c9b..06655e0b2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -47,6 +48,7 @@ public class TradeCouponPriceCalculatorTest extends BaseMockitoUnitTest { new TradePriceCalculateReqBO.Item().setSkuId(40L).setCount(5).setSelected(false) // 匹配优惠劵,但是未选中 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( From 71d6311bd4aa4a547ac7f882c59044031325c6a1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 09:27:29 +0800 Subject: [PATCH 06/12] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E3=80=81=E7=A7=92=E6=9D=80=E7=AD=89=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 2 - .../AppCombinationActivityController.java | 22 +++---- .../seckill/AppSeckillActivityController.java | 19 +++--- .../seckill/AppSeckillConfigController.java | 3 +- .../bargain/BargainActivityConvert.java | 8 +-- .../CombinationActivityConvert.java | 8 +-- .../SeckillActivityConvert.java | 8 +-- .../CombinationActivityMapper.java | 16 +---- .../CombinationActivityService.java | 11 ++++ .../CombinationActivityServiceImpl.java | 2 +- .../aftersale/TradeAfterSaleController.java | 2 +- .../aftersale/TradeAfterSaleConvert.java | 6 +- .../core/dto/TradeAfterSaleLogRespVO.java | 58 ------------------- .../core/service/AfterSaleLogService.java | 2 +- .../aftersale/TradeAfterSaleServiceImpl.java | 3 +- 15 files changed, 46 insertions(+), 124 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java 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 798e59851..4fc58004a 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 @@ -56,7 +56,6 @@ public interface ErrorCodeConstants { ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除"); ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭"); ErrorCode SECKILL_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1013008006, "秒杀失败,原因秒杀库存不足"); - ErrorCode SECKILL_ACTIVITY_APP_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭"); // ========== 秒杀时段 1013009000 ========== ErrorCode SECKILL_CONFIG_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在"); @@ -69,7 +68,6 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE_NOT_UPDATE = new ErrorCode(1013010002, "拼团活动已关闭不能修改"); ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除"); ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010004, "拼团失败,原因:拼团活动已关闭"); - ErrorCode COMBINATION_ACTIVITY_APP_STATUS_DISABLE = new ErrorCode(1013010005, "拼团活动已关闭"); // ========== 拼团记录 1013011000 ========== ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013011000, "拼团不存在"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index d09292de9..ee1d5ed17 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -24,14 +24,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import static cn.hutool.core.util.ObjectUtil.defaultIfNull; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_APP_STATUS_DISABLE; @Tag(name = "用户 APP - 拼团活动") @RestController @@ -44,7 +42,7 @@ public class AppCombinationActivityController { @Resource private ProductSpuApi spuApi; - + // TODO 芋艿:增加 Spring Cache @GetMapping("/list") @Operation(summary = "获得拼团活动列表", description = "用于小程序首页") @Parameter(name = "count", description = "需要展示的数量", example = "6") @@ -52,11 +50,10 @@ public class AppCombinationActivityController { @RequestParam(name = "count", defaultValue = "6") Integer count) { List list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6)); if (CollUtil.isEmpty(list)) { - return success(CombinationActivityConvert.INSTANCE.convertAppList(list)); + return success(Collections.emptyList()); } - + // 拼接返回 List spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId)); - // TODO 芋艿:增加 Spring Cache return success(CombinationActivityConvert.INSTANCE.convertAppList(list, spuList)); } @@ -67,7 +64,7 @@ public class AppCombinationActivityController { if (CollUtil.isEmpty(result.getList())) { return success(PageResult.empty(result.getTotal())); } - + // 拼接返回 List spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId)); return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList)); } @@ -78,15 +75,12 @@ public class AppCombinationActivityController { public CommonResult getCombinationActivityDetail(@RequestParam("id") Long id) { // 1、获取活动 CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id); - if (combinationActivity == null) { + if (combinationActivity == null + || ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { return success(null); } - if (ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { - throw exception(COMBINATION_ACTIVITY_APP_STATUS_DISABLE); - } - // 2、获取活动商品 - List products = activityService.getCombinationProductsByActivityIds(Arrays.asList(combinationActivity.getId())); + List products = activityService.getCombinationProductsByActivityId(combinationActivity.getId()); return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index 7ee0027ed..a83b87ae2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.seckill; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -29,10 +30,8 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_APP_STATUS_CLOSED; @Tag(name = "用户 App - 秒杀活动") @RestController @@ -48,6 +47,7 @@ public class AppSeckillActivityController { @Resource private ProductSpuApi spuApi; + // TODO 芋艿:需要增加 spring cache @GetMapping("/get-now") @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用") public CommonResult getNowSeckillActivity() { @@ -61,7 +61,6 @@ public class AppSeckillActivityController { List activityList = activityService.getSeckillActivityListByConfigIdAndStatus(configList.getId(), CommonStatusEnum.ENABLE.getStatus()); // 3 获取 spu 信息 List spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); - // TODO 芋艿:需要增加 spring cache return success(SeckillActivityConvert.INSTANCE.convert(configList, activityList, spuList)); } @@ -70,7 +69,9 @@ public class AppSeckillActivityController { public CommonResult> getSeckillActivityPage(AppSeckillActivityPageReqVO pageReqVO) { // 1. 查询满足当前阶段的活动 PageResult pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO); - + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); + } // 2. 拼接数据 List spuList = spuApi.getSpuList(convertList(pageResult.getList(), SeckillActivityDO::getSpuId)); return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, spuList)); @@ -88,16 +89,14 @@ public class AppSeckillActivityController { // 2. 获取活动 SeckillActivityDO seckillActivity = activityService.getSeckillActivity(id); - if (seckillActivity == null) { + if (seckillActivity == null + || ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { return success(null); } - if (ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { - throw exception(SECKILL_ACTIVITY_APP_STATUS_CLOSED); - } // 3. 拼接数据 - List products = activityService.getSeckillProductListByActivityId(seckillActivity.getId()); - return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, configList)); + List productList = activityService.getSeckillProductListByActivityId(seckillActivity.getId()); + return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, productList, configList)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java index 2795ca9a4..ec60b2141 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java @@ -28,7 +28,8 @@ public class AppSeckillConfigController { @GetMapping("/list") @Operation(summary = "获得秒杀时间段列表") public CommonResult> getSeckillConfigList() { - return success(SeckillConfigConvert.INSTANCE.convertList2(configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()))); + return success(SeckillConfigConvert.INSTANCE.convertList2( + configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java index 954558b01..92791ed76 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java @@ -73,9 +73,7 @@ public interface BargainActivityConvert { // 拼接关联属性 Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); result.setList(list); @@ -88,9 +86,7 @@ public interface BargainActivityConvert { List activityList = convertAppList(list); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); return CollectionUtils.convertList(activityList, item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 07a9c4df3..f92dbef59 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -61,9 +61,7 @@ public interface CombinationActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); PageResult pageResult = convertPage(page); pageResult.getList().forEach(item -> { - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { - item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()); - }); + MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())); item.setProducts(convertList2(productList)); }); return pageResult; @@ -118,9 +116,7 @@ public interface CombinationActivityConvert { List activityList = convertAppList(list); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); return CollectionUtils.convertList(activityList, item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index f0da88cbc..e1fcc35d8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -113,11 +113,8 @@ public interface SeckillActivityConvert { PageResult result = convertPage1(pageResult); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()) - .setMarketPrice(spu.getMarketPrice()) - .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()) + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()))); return item; }); result.setList(list); @@ -131,6 +128,7 @@ public interface SeckillActivityConvert { default AppSeckillActivityDetailRespVO convert3(SeckillActivityDO seckillActivity, List products, SeckillConfigDO filteredConfig) { return convert2(seckillActivity) .setProducts(convertList1(products)) + // TODO @puhui999:要不要在里面 default 一个方法,处理这个事件;简洁一点; .setStartTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getStartTime(), "yyyy-MM-dd") + " " + filteredConfig.getStartTime(), "yyyy-MM-dd HH:mm:ss")) // 活动开始日期和时段结合 .setEndTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getEndTime(), "yyyy-MM-dd") + " " + filteredConfig.getEndTime(), diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 0dce45a28..5672c34dc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -29,26 +29,12 @@ public interface CombinationActivityMapper extends BaseMapperX selectPage(PageParam pageParam, Integer status) { return selectPage(pageParam, new LambdaQueryWrapperX() .eq(CombinationActivityDO::getStatus, status)); } - /** - * 查询 status 状态的活动分页 - * - * @param status 状态 - * @param count 限制条数 - * @return 活动分页 - */ - default List selectList(Integer status, Integer count) { + default List selectListByStatus(Integer status, Integer count) { return selectList(new LambdaQueryWrapperX() .eq(CombinationActivityDO::getStatus, status) .last("LIMIT " + count)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index c2a090b72..c5f72e6a6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP import javax.validation.Valid; import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -65,6 +66,16 @@ public interface CombinationActivityService { */ PageResult getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO); + /** + * 获得拼团活动商品列表 + * + * @param activityId 拼团活动 id + * @return 拼团活动的商品列表 + */ + default List getCombinationProductsByActivityId(Long activityId) { + return getCombinationProductsByActivityIds(Collections.singletonList(activityId)); + } + /** * 获得拼团活动商品列表 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 87a633064..2dc715039 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -247,7 +247,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public List getCombinationActivityListByCount(Integer count) { - return combinationActivityMapper.selectList(CommonStatusEnum.ENABLE.getStatus(), count); + return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index a3fcfae40..3b438568b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -8,11 +8,11 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.*; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java index dc220ad31..9faaefb5d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderBaseVO; @@ -15,7 +16,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -68,7 +68,7 @@ public interface TradeAfterSaleConvert { PageResult convertPage02(PageResult page); List convertList(List list); - + default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List orderItems, MemberUserRespDTO user, List logs) { TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems); @@ -81,7 +81,7 @@ public interface TradeAfterSaleConvert { return respVO; } - List convertList1(List list); + List convertList1(List list); @Mapping(target = "id", source = "afterSale.id") TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List orderItems); TradeOrderBaseVO convert(TradeOrderDO order); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java deleted file mode 100644 index 328aab944..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -/** - * 贸易售后日志详情 DTO - * - * @author HUIHUI - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TradeAfterSaleLogRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20669") - private Long id; - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22634") - @NotNull(message = "用户编号不能为空") - private Long userId; - - @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "用户类型不能为空") - private Integer userType; - - @Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3023") - @NotNull(message = "售后编号不能为空") - private Long afterSaleId; - - @Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25870") - @NotNull(message = "订单编号不能为空") - private Long orderId; - - @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23154") - @NotNull(message = "订单项编号不能为空") - private Long orderItemId; - - @Schema(description = "售后状态(之前)", example = "2") - private Integer beforeStatus; - - @Schema(description = "售后状态(之后)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "售后状态(之后)不能为空") - private Integer afterStatus; - - @Schema(description = "操作明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "维权完成,退款金额:¥37776.00") - @NotNull(message = "操作明细不能为空") - private String content; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java index 2f9245c01..53019a30b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import java.util.List; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index 1b7866da8..80acf9b99 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDisagreeReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; @@ -26,7 +27,6 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; @@ -449,6 +449,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa } } + // TODO @puhui999:应该返回 do 哈。 @Override public List getLog(Long afterSaleId) { // TODO 不熟悉流程先这么滴 From e9c9ac0cabe54a44e3cc37f0039466051cfb3fc0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 17:47:39 +0800 Subject: [PATCH 07/12] =?UTF-8?q?trade=EF=BC=9A=E7=A1=AE=E8=AE=A4=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderOperateTypeEnum.java | 2 +- .../order/TradeOrderUpdateServiceImpl.java | 47 +++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index f16e35601..892d638b0 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -14,7 +14,7 @@ import lombok.RequiredArgsConstructor; public enum TradeOrderOperateTypeEnum { MEMBER_CREATE(1, "用户下单"), - TEST(2, "用户({nickname})做了({thing})"), + MEMBER_RECEIVE(30, "用户已收货") ; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index ad06c801b..0767fc9d6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -48,6 +48,7 @@ import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; +import cn.iocoder.yudao.module.trade.framework.order.core.utils.TradeOrderLogUtils; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.cart.CartService; @@ -299,6 +300,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 5. 生成预支付 createPayOrder(order, orderItems, calculateRespBO); + // 6. 插入订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), null, order.getStatus()); + // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! } @@ -343,7 +347,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:OrderLog // 增加用户积分 - getSelf().addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); + getSelf().addMemberPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户佣金 @@ -492,7 +496,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { if (updateCount == 0) { throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED); } - // TODO 芋艿:OrderLog // TODO 芋艿:lili 发送订单变化的消息 @@ -500,7 +503,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:销售佣金的记录; - // TODO 芋艿:获得积分; + // 插入订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus()); } @Override @@ -664,7 +668,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // 扣减用户积分 - getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); + getSelf().reduceMemberPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 扣减用户经验 getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 更新分佣记录为已失效 @@ -768,29 +772,54 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + /** + * 添加用户积分 + * + * 目前是支付成功后,就会创建积分记录。 + * + * 业内还有两种做法,可以根据自己的业务调整: + * 1. 确认收货后,才创建积分记录 + * 2. 支付 or 下单成功时,创建积分记录(冻结),确认收货解冻或者 n 天后解冻 + * + * @param userId 用户编号 + * @param payPrice 支付金额 + * @param orderId 订单编号 + */ @Async - protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) { + protected void addMemberPointAsync(Long userId, Integer payPrice, Long orderId) { // TODO @疯狂:具体多少积分,需要分成 2 不分:1. 支付金额;2. 商品金额 int bizType = MemberPointBizTypeEnum.ORDER_REWARD.getType(); memberPointApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); } @Async - protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { + protected void reduceMemberPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { // TODO @疯狂:退款时,按照金额比例,退还积分;https://help.youzan.com/displaylist/detail_4_4-1-49185 int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType(); memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + /** + * 创建分销记录 + * + * 目前是支付成功后,就会创建分销记录。 + * + * 业内还有两种做法,可以根据自己的业务调整: + * 1. 确认收货后,才创建分销记录 + * 2. 支付 or 下单成功时,创建分销记录(冻结),确认收货解冻或者 n 天后解冻 + * + * @param userId 用户编号 + * @param orderId 订单编号 + */ @Async protected void addBrokerageAsync(Long userId, Long orderId) { MemberUserRespDTO user = memberUserApi.getUser(userId); Assert.notNull(user); - + // 每一个订单项,都会去生成分销记录 List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); - List list = convertList(orderItems, + List addList = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(user, item, productSkuApi.getSku(item.getSkuId()))); - brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, list); + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList); } @Async From a9485ad6bffd9974fd1be267ef474d90d51b71cd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 18:13:35 +0800 Subject: [PATCH 08/12] =?UTF-8?q?trade=EF=BC=9A=E5=8F=96=E6=B6=88=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E3=80=81=E7=A1=AE=E8=AE=A4=E6=94=B6=E8=B4=A7=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderOperateTypeEnum.java | 4 ++- .../order/core/aop/TradeOrderLogAspect.java | 3 +++ .../order/TradeOrderUpdateServiceImpl.java | 26 ++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index 892d638b0..08353c3b5 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -14,7 +14,9 @@ import lombok.RequiredArgsConstructor; public enum TradeOrderOperateTypeEnum { MEMBER_CREATE(1, "用户下单"), - MEMBER_RECEIVE(30, "用户已收货") + MEMBER_RECEIVE(30, "用户已收货"), + MEMBER_COMMENT(31, "用户评价"), + MEMBER_CANCEL(40, "取消订单"), ; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java index e8349220f..127291b1c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java @@ -63,6 +63,9 @@ public class TradeOrderLogAspect { Long userId = getUserId(); // 1.2 订单信息 Long orderId = ORDER_ID.get(); + if (orderId == null) { // 如果未设置,只有注解,说明不需要记录订单日志 + return; + } Integer beforeStatus = BEFORE_STATUS.get(); Integer afterStatus = AFTER_STATUS.get(); Map exts = ObjectUtil.defaultIfNull(EXTS.get(), emptyMap()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 0767fc9d6..f4d72a37e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -486,6 +486,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_RECEIVE) public void receiveOrder(Long userId, Long id) { // 校验并获得交易订单(可收货) TradeOrderDO order = validateOrderReceivable(userId, id); @@ -677,6 +678,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_COMMENT) public Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO) { // 先通过订单项 ID,查询订单项是否存在 TradeOrderItemDO orderItem = tradeOrderItemMapper.selectByIdAndUserId(createReqVO.getOrderItemId(), userId); @@ -704,12 +706,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) { tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE)); - // TODO 待实现:已完成评价,要不要写一条订单日志?目前 crmeb 会写,有赞可以研究下 + // 增加订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus()); } return comment; } @Override + @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL) public void cancelOrder(Long userId, Long id) { // 校验存在 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); @@ -721,7 +726,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // 1.更新 TradeOrderDO 状态为已取消 + // 1. 更新 TradeOrderDO 状态为已取消 int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) .setCancelTime(LocalDateTime.now()) @@ -730,22 +735,23 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来 + // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 tradeOrderHandlers.forEach(handler -> handler.rollback()); - // 2.回滚库存 + // 2. 回滚库存 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); - // 3.回滚优惠券 - couponApi.returnUsedCoupon(order.getCouponId()); + // 3. 回滚优惠券 + if (order.getCouponId() > 0) { + couponApi.returnUsedCoupon(order.getCouponId()); + } - // 4.回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; + // 4. 回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。 - // TODO 芋艿:OrderLog - - // TODO 芋艿:lili 发送订单变化的消息 + // 5. 增加订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus()); } /** From 1da14a3f53d8429e3d3028974a9462b4301f5151 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 20:23:28 +0800 Subject: [PATCH 09/12] =?UTF-8?q?trade=EF=BC=9A=E5=88=A0=E9=99=A4=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 1 + .../order/TradeOrderOperateTypeEnum.java | 1 + .../app/order/AppTradeOrderController.java | 2 +- .../order/TradeOrderUpdateService.java | 23 ++++++++---- .../order/TradeOrderUpdateServiceImpl.java | 37 +++++++++++++++---- 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ecd31499d..ffdba1fcf 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -31,6 +31,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价"); ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化"); ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在"); + ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1011000029, "交易订单删除失败,订单不是【已取消】状态"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index 08353c3b5..517928551 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -17,6 +17,7 @@ public enum TradeOrderOperateTypeEnum { MEMBER_RECEIVE(30, "用户已收货"), MEMBER_COMMENT(31, "用户评价"), MEMBER_CANCEL(40, "取消订单"), + MEMBER_DELETE(41, "删除订单"), ; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 4bbd98a27..f1d361d91 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -156,7 +156,7 @@ public class AppTradeOrderController { @Operation(summary = "删除交易订单") @Parameter(name = "id", description = "交易订单编号") public CommonResult deleteOrder(@RequestParam("id") Long id) { - // TODO @芋艿:未实现,mock 用 + tradeOrderUpdateService.deleteOrder(getLoginUserId(), id); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index ee9128b6c..3de830df9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -62,6 +62,22 @@ public interface TradeOrderUpdateService { */ void receiveOrder(Long userId, Long id); + /** + * 【会员】取消订单 + * + * @param userId 用户编号 + * @param id 订单编号 + */ + void cancelOrder(Long userId, Long id); + + /** + * 【会员】删除订单 + * + * @param userId 用户编号 + * @param id 订单编号 + */ + void deleteOrder(Long userId, Long id); + /** * 【管理员】交易订单备注 * @@ -117,11 +133,4 @@ public interface TradeOrderUpdateService { */ Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO); - /** - * 【会员】取消订单 - * - * @param userId 用户ID - * @param id 订单编号 - */ - void cancelOrder(Long userId, Long id); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index f4d72a37e..00b350a10 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -716,17 +716,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL) public void cancelOrder(Long userId, Long id) { - // 校验存在 + // 1.1 校验存在 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); if (order == null) { throw exception(ORDER_NOT_FOUND); } - // 校验状态 + // 1.2 校验状态 if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // 1. 更新 TradeOrderDO 状态为已取消 + // 2. 更新 TradeOrderDO 状态为已取消 int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) .setCancelTime(LocalDateTime.now()) @@ -735,25 +735,46 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 + // 3. TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 tradeOrderHandlers.forEach(handler -> handler.rollback()); - // 2. 回滚库存 + // 4. 回滚库存 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); - // 3. 回滚优惠券 + // 5. 回滚优惠券 if (order.getCouponId() > 0) { couponApi.returnUsedCoupon(order.getCouponId()); } - // 4. 回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; + // 6. 回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。 - // 5. 增加订单日志 + // 7. 增加订单日志 TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus()); } + @Override + @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_DELETE) + public void deleteOrder(Long userId, Long id) { + // 1.1 校验存在 + TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); + if (order == null) { + throw exception(ORDER_NOT_FOUND); + } + // 1.2 校验状态 + if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus())) { + throw exception(ORDER_DELETE_FAIL_STATUS_NOT_CANCEL); + } + + // 2. 删除订单 + tradeOrderMapper.deleteById(id); + + // 3. 记录日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus()); + } + /** * 判断指定订单的所有订单项,是不是都售后成功 * From aa5525d1f58aa2e39731cbd6461a1e18c9c57b81 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 22:21:23 +0800 Subject: [PATCH 10/12] =?UTF-8?q?code=20review=EF=BC=9A=E8=90=A5=E9=94=80?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20&=20=E4=BA=A4=E6=98=93=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bargain/BargainActivityApi.java | 2 +- .../mysql/bargain/BargainActivityMapper.java | 2 +- .../SeckillActivityMapper.java | 2 +- .../seckillactivity/SeckillProductMapper.java | 11 ++++++-- .../bargain/BargainActivityServiceImpl.java | 6 ++-- .../CombinationRecordServiceImpl.java | 6 ++++ .../seckill/SeckillActivityServiceImpl.java | 28 ++++++++----------- .../order/TradeOrderQueryServiceImpl.java | 4 +-- .../order/handler/TradeBargainHandler.java | 7 +++-- .../order/handler/TradeOrderHandler.java | 3 ++ .../order/handler/TradeSeckillHandler.java | 6 +++- 11 files changed, 47 insertions(+), 30 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java index eb912e417..0f9812629 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java @@ -11,7 +11,7 @@ public interface BargainActivityApi { * 更新砍价活动库存 * * @param id 砍价活动编号 - * @param count 购买数量 + * @param count 购买数量 */ void updateBargainActivityStock(Long id, Integer count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index a7fe3e58d..de518f60c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -38,7 +38,7 @@ public interface BargainActivityMapper extends BaseMapperX { * @param count 扣减的库存数量 * @return 影响的行数 */ - default int updateActivityStock(Long id, int count) { + default int updateStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(BargainActivityDO::getId, id) .ge(BargainActivityDO::getStock, count) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 8ce12092f..7e2afdc85 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -41,7 +41,7 @@ public interface SeckillActivityMapper extends BaseMapperX { * @param count 扣减的库存数量 * @return 影响的行数 */ - default int updateActivityStock(Long id, int count) { + default int updateStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(SeckillActivityDO::getId, id) .gt(SeckillActivityDO::getTotalStock, 0) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index 5ca2dae24..db34aa744 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -16,8 +16,13 @@ import java.util.List; @Mapper public interface SeckillProductMapper extends BaseMapperX { - default List selectListByActivityId(Long id) { - return selectList(SeckillProductDO::getActivityId, id); + default List selectListByActivityId(Long activityId) { + return selectList(SeckillProductDO::getActivityId, activityId); + } + + default SeckillProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId) { + return selectOne(SeckillProductDO::getActivityId, activityId, + SeckillProductDO::getSkuId, skuId); } default List selectListByActivityId(Collection ids) { @@ -31,7 +36,7 @@ public interface SeckillProductMapper extends BaseMapperX { * @param count 扣减的库存数量 * @return 影响的行数 */ - default int updateActivityStock(Long id, int count) { + default int updateStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(SeckillProductDO::getId, id) .gt(SeckillProductDO::getStock, count) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 95e50eff5..546b95041 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -75,16 +75,18 @@ public class BargainActivityServiceImpl implements BargainActivityService { } @Override - @Transactional(rollbackFor = Exception.class) public void updateBargainActivityStock(Long id, Integer count) { // 查询砍价活动 BargainActivityDO activity = getBargainActivity(id); if (activity == null) { throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); } + if (count > activity.getStock()) { + throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); + } // 更新砍价库存 - int updateCount = bargainActivityMapper.updateActivityStock(id, count); + int updateCount = bargainActivityMapper.updateStock(id, count); if (updateCount == 0) { throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index bb62295b8..047e060a9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -96,12 +96,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordDO; } + // TODO @puhui999:有一个应该在创建那要做下;就是当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; + @Override @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1.1 校验拼团活动 CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(reqDTO.getActivityId()); // 1.2 需要校验下,他当前是不是已经参加了该拼团; + // TODO @puhui999:拼团应该可以重复参加;应该去校验总共的上限哈,就是 activity.totalLimitCount CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(reqDTO.getUserId(), reqDTO.getOrderId()); if (recordDO != null) { throw exception(COMBINATION_RECORD_EXISTS); @@ -111,6 +114,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (CollUtil.isNotEmpty(recordDOList)) { throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); } + // TODO @puhui999:有个开始时间未校验 // 1.4 校验当前活动是否过期 if (LocalDateTime.now().isAfter(activity.getEndTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_END); @@ -128,6 +132,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } } + // TODO @puhui999:单次限购 + // 2. 创建拼团记录 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 0092cf1b8..6e05191bf 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -149,31 +149,25 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override @Transactional(rollbackFor = Exception.class) public void updateSeckillStock(Long id, Long skuId, Integer count) { - // 1、校验秒杀活动是否存在 + // 1.1 校验活动库存是否充足 SeckillActivityDO seckillActivity = getSeckillActivity(id); - // 1.1、校验库存是否充足 - if (seckillActivity.getTotalStock() < count) { + if (count > seckillActivity.getTotalStock()) { + throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); + } + // 1.2 校验商品库存是否充足 + SeckillProductDO product = seckillProductMapper.selectByActivityIdAndSkuId(id, skuId); + if (product == null || count > product.getStock()) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } - // 2、获取活动商品 - List products = getSeckillProductListByActivityId(id); - // 2.1、过滤出购买的商品 - SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId())); - // 2.2、检查活动商品库存是否充足 - boolean isSufficient = product == null || (product.getStock() == 0 || (product.getStock() < count) || (product.getStock() - count) < 0); - if (isSufficient) { - throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); - } - - // 3、更新活动商品库存 - int updateCount = seckillProductMapper.updateActivityStock(product.getId(), count); + // 2.1 更新活动商品库存 + int updateCount = seckillProductMapper.updateStock(product.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } - // 4、更新活动库存 - updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), count); + // 2.2 更新活动库存 + updateCount = seckillActivityMapper.updateStock(seckillActivity.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index 733ec9780..910e8c911 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -106,7 +106,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { if (order == null) { throw exception(ORDER_NOT_FOUND); } - + // 查询物流 return getExpressTrackList(order); } @@ -117,7 +117,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { if (order == null) { throw exception(ORDER_NOT_FOUND); } - + // 查询物流 return getExpressTrackList(order); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java index 72def213d..18a276fde 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java @@ -20,14 +20,17 @@ public class TradeBargainHandler implements TradeOrderHandler { @Resource private BargainActivityApi bargainActivityApi; + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件: + // 1. 商品存在、库存充足、单次限购; + // 2. 活动进行中、时间段符合 + @Override public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { // 如果是砍价订单 if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), reqBO.getOrderType())) { return; } - - // 额外扣减砍价的库存 + // 扣减砍价活动的库存 bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index b747e35d4..47426dd9b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -24,9 +24,12 @@ public interface TradeOrderHandler { */ void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); + // TODO @puhui999:这个搞成订单取消 /** * 回滚 */ void rollback(); + // TODO @puhui999:再搞个订单项取消哈 + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java index ce1dfdb05..652717b77 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java @@ -20,13 +20,17 @@ public class TradeSeckillHandler implements TradeOrderHandler { @Resource private SeckillActivityApi seckillActivityApi; + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件: + // 1. 商品存在、库存充足、单次限购; + // 2. 活动进行中、时间段符合 + @Override public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { // 如果是秒杀订单:额外扣减秒杀的库存; if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), reqBO.getOrderType())) { return; } - + // 扣减秒杀活动的库存 seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); } From 53e789dfdcfe27c7cf43d96f194e2237d6dea22f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 23:58:22 +0800 Subject: [PATCH 11/12] =?UTF-8?q?trade=EF=BC=9A=E8=AE=A2=E5=8D=95=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=20vip=20=E4=BC=98=E6=83=A0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/common/PromotionTypeEnum.java | 2 +- .../convert/order/TradeOrderConvert.java | 1 + .../dal/dataobject/order/TradeOrderDO.java | 5 + .../dataobject/order/TradeOrderItemDO.java | 5 + .../price/bo/TradePriceCalculateRespBO.java | 10 ++ .../TradeMemberLevelPriceCalculator.java | 82 +++++++++++++ .../calculator/TradePriceCalculator.java | 1 + .../TradePriceCalculatorHelper.java | 12 +- .../TradeMemberLevelPriceCalculatorTest.java | 116 ++++++++++++++++++ .../member/api/level/MemberLevelApi.java | 9 ++ .../api/level/dto/MemberLevelRespDTO.java | 41 +++++++ .../api/user/dto/MemberUserRespDTO.java | 7 ++ .../member/api/level/MemberLevelApiImpl.java | 7 ++ .../convert/level/MemberLevelConvert.java | 3 + 14 files changed, 297 insertions(+), 4 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java index 874651ea3..628f6fe9f 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java @@ -22,7 +22,7 @@ public enum PromotionTypeEnum implements IntArrayValuable { DISCOUNT_ACTIVITY(4, "限时折扣"), REWARD_ACTIVITY(5, "满减送"), - MEMBER(6, "会员折扣"), + MEMBER_LEVEL(6, "会员折扣"), COUPON(7, "优惠劵") ; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index aa78cd170..85d9fa39a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -65,6 +65,7 @@ public interface TradeOrderConvert { @Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"), @Mapping(source = "calculateRespBO.price.couponPrice", target = "couponPrice"), @Mapping(source = "calculateRespBO.price.pointPrice", target = "pointPrice"), + @Mapping(source = "calculateRespBO.price.vipPrice", target = "vipPrice"), @Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice") }) TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index bb68fc1ac..52f8c794d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -168,6 +168,7 @@ public class TradeOrderDO extends BaseDO { * - {@link #discountPrice} * + {@link #deliveryPrice} * + {@link #adjustPrice} + * - {@link #vipPrice} */ private Integer payPrice; @@ -269,5 +270,9 @@ public class TradeOrderDO extends BaseDO { // * 奖励的积分 TODO 疯狂:可以使用这个字段哈; // */ // private Integer rewardPoint; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java index 27dd13f67..760471d3a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java @@ -126,6 +126,7 @@ public class TradeOrderItemDO extends BaseDO { * - {@link #discountPrice} * + {@link #deliveryPrice} * + {@link #adjustPrice} + * - {@link #vipPrice} */ private Integer payPrice; @@ -143,6 +144,10 @@ public class TradeOrderItemDO extends BaseDO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice; // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java index 1171cd8f2..6820059a7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java @@ -89,6 +89,10 @@ public class TradePriceCalculateRespBO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; /** * 最终购买金额(总),单位:分 * @@ -97,6 +101,7 @@ public class TradePriceCalculateRespBO { * - {@link #pointPrice} * - {@link #discountPrice} * + {@link #deliveryPrice} + * - {@link #vipPrice} */ private Integer payPrice; @@ -158,6 +163,10 @@ public class TradePriceCalculateRespBO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; /** * 应付金额(总),单位:分 * @@ -166,6 +175,7 @@ public class TradePriceCalculateRespBO { * - {@link #pointPrice} * - {@link #discountPrice} * + {@link #deliveryPrice} + * - {@link #vipPrice} */ private Integer payPrice; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java new file mode 100644 index 000000000..7bf0d1d29 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.trade.service.price.calculator; + +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice; + +/** + * 会员 VIP 折扣的 {@link TradePriceCalculator} 实现类 + * + * @author 芋道源码 + */ +@Component +@Order(TradePriceCalculator.ORDER_MEMBER_LEVEL) +public class TradeMemberLevelPriceCalculator implements TradePriceCalculator { + + @Resource + private MemberLevelApi memberLevelApi; + @Resource + private MemberUserApi memberUserApi; + + @Override + public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 1. 获得用户的会员等级 + MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); + if (user.getLevelId() == null || user.getLevelId() <= 0) { + return; + } + MemberLevelRespDTO level = memberLevelApi.getMemberLevel(user.getLevelId()); + if (level == null || level.getDiscountPercent() == null) { + return; + } + + // 2. 计算每个 SKU 的优惠金额 + result.getItems().forEach(orderItem -> { + // 2.1 计算优惠金额 + Integer vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); + if (vipPrice <= 0) { + return; + } + + // 2.2 记录优惠明细 + if (orderItem.getSelected()) { + // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 + TradePriceCalculatorHelper.addPromotion(result, orderItem, + level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), + String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)), + vipPrice); + } + + // 2.3 更新 SKU 的优惠金额 + orderItem.setVipPrice(vipPrice); + TradePriceCalculatorHelper.recountPayPrice(orderItem); + }); + TradePriceCalculatorHelper.recountAllPrice(result); + } + + /** + * 计算会员 VIP 优惠价格 + * + * @param price 原价 + * @param discountPercent 折扣 + * @return 优惠价格 + */ + public Integer calculateVipPrice(Integer price, Integer discountPercent) { + if (discountPercent == null) { + return 0; + } + Integer newPrice = price * discountPercent / 100; + return price - newPrice; + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java index cddc1ea21..fa647aea9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; */ public interface TradePriceCalculator { + int ORDER_MEMBER_LEVEL = 5; int ORDER_DISCOUNT_ACTIVITY = 10; int ORDER_REWARD_ACTIVITY = 20; int ORDER_COUPON = 30; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index b8b9e0fb9..df047122c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -52,7 +52,7 @@ public class TradePriceCalculatorHelper { .setCount(item.getCount()).setCartId(item.getCartId()).setSelected(item.getSelected()); // sku 价格 orderItem.setPrice(sku.getPrice()).setPayPrice(sku.getPrice() * item.getCount()) - .setDiscountPrice(0).setDeliveryPrice(0).setCouponPrice(0).setPointPrice(0); + .setDiscountPrice(0).setDeliveryPrice(0).setCouponPrice(0).setPointPrice(0).setVipPrice(0); // sku 信息 orderItem.setPicUrl(sku.getPicUrl()).setProperties(sku.getProperties()) .setWeight(sku.getWeight()).setVolume(sku.getVolume()); @@ -96,7 +96,7 @@ public class TradePriceCalculatorHelper { // 先重置 TradePriceCalculateRespBO.Price price = result.getPrice(); price.setTotalPrice(0).setDiscountPrice(0).setDeliveryPrice(0) - .setCouponPrice(0).setPointPrice(0).setPayPrice(0); + .setCouponPrice(0).setPointPrice(0).setVipPrice(0).setPayPrice(0); // 再合计 item result.getItems().forEach(item -> { if (!item.getSelected()) { @@ -107,6 +107,7 @@ public class TradePriceCalculatorHelper { price.setDeliveryPrice(price.getDeliveryPrice() + item.getDeliveryPrice()); price.setCouponPrice(price.getCouponPrice() + item.getCouponPrice()); price.setPointPrice(price.getPointPrice() + item.getPointPrice()); + price.setVipPrice(price.getVipPrice() + item.getVipPrice()); price.setPayPrice(price.getPayPrice() + item.getPayPrice()); }); } @@ -121,7 +122,9 @@ public class TradePriceCalculatorHelper { - orderItem.getDiscountPrice() + orderItem.getDeliveryPrice() - orderItem.getCouponPrice() - - orderItem.getPointPrice()); + - orderItem.getPointPrice() + - orderItem.getVipPrice() + ); } /** @@ -145,6 +148,9 @@ public class TradePriceCalculatorHelper { if (orderItem.getPointPrice() == null) { orderItem.setPointPrice(0); } + if (orderItem.getVipPrice() == null) { + orderItem.setVipPrice(0); + } recountPayPrice(orderItem); }); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java new file mode 100644 index 000000000..568940366 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java @@ -0,0 +1,116 @@ +package cn.iocoder.yudao.module.trade.service.price.calculator; + +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import java.util.ArrayList; + +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +/** + * {@link TradeMemberLevelPriceCalculator} 的单元测试类 + * + * @author 芋道源码 + */ +public class TradeMemberLevelPriceCalculatorTest extends BaseMockitoUnitTest { + + @InjectMocks + private TradeMemberLevelPriceCalculator memberLevelPriceCalculator; + + @Mock + private MemberLevelApi memberLevelApi; + @Mock + private MemberUserApi memberUserApi; + + @Test + public void testCalculate() { + // 准备参数 + TradePriceCalculateReqBO param = new TradePriceCalculateReqBO() + .setUserId(1024L) + .setItems(asList( + new TradePriceCalculateReqBO.Item().setSkuId(10L).setCount(2).setSelected(true), // 匹配活动,且已选中 + new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中 + )); + TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setPrice(new TradePriceCalculateRespBO.Price()) + .setPromotions(new ArrayList<>()) + .setItems(asList( + new TradePriceCalculateRespBO.OrderItem().setSkuId(10L).setCount(2).setSelected(true) + .setPrice(100), + new TradePriceCalculateRespBO.OrderItem().setSkuId(20L).setCount(3).setSelected(false) + .setPrice(50) + )); + // 保证价格被初始化上 + TradePriceCalculatorHelper.recountPayPrice(result.getItems()); + TradePriceCalculatorHelper.recountAllPrice(result); + + // mock 方法(会员等级) + when(memberUserApi.getUser(eq(1024L))).thenReturn(new MemberUserRespDTO().setLevelId(2048L)); + when(memberLevelApi.getMemberLevel(eq(2048L))).thenReturn( + new MemberLevelRespDTO().setId(2048L).setName("VIP 会员").setDiscountPercent(60)); + + // 调用 + memberLevelPriceCalculator.calculate(param, result); + // 断言:Price 部分 + TradePriceCalculateRespBO.Price price = result.getPrice(); + assertEquals(price.getTotalPrice(), 200); + assertEquals(price.getDiscountPrice(), 0); + assertEquals(price.getPointPrice(), 0); + assertEquals(price.getDeliveryPrice(), 0); + assertEquals(price.getCouponPrice(), 0); + assertEquals(price.getVipPrice(), 80); + assertEquals(price.getPayPrice(), 120); + assertNull(result.getCouponId()); + // 断言:SKU 1 + assertEquals(result.getItems().size(), 2); + TradePriceCalculateRespBO.OrderItem orderItem01 = result.getItems().get(0); + assertEquals(orderItem01.getSkuId(), 10L); + assertEquals(orderItem01.getCount(), 2); + assertEquals(orderItem01.getPrice(), 100); + assertEquals(orderItem01.getDiscountPrice(), 0); + assertEquals(orderItem01.getDeliveryPrice(), 0); + assertEquals(orderItem01.getCouponPrice(), 0); + assertEquals(orderItem01.getPointPrice(), 0); + assertEquals(orderItem01.getVipPrice(), 80); + assertEquals(orderItem01.getPayPrice(), 120); + // 断言:SKU 2 + TradePriceCalculateRespBO.OrderItem orderItem02 = result.getItems().get(1); + assertEquals(orderItem02.getSkuId(), 20L); + assertEquals(orderItem02.getCount(), 3); + assertEquals(orderItem02.getPrice(), 50); + assertEquals(orderItem02.getDiscountPrice(), 0); + assertEquals(orderItem02.getDeliveryPrice(), 0); + assertEquals(orderItem02.getCouponPrice(), 0); + assertEquals(orderItem02.getPointPrice(), 0); + assertEquals(orderItem02.getVipPrice(), 60); + assertEquals(orderItem02.getPayPrice(), 90); + // 断言:Promotion 部分 + assertEquals(result.getPromotions().size(), 1); + TradePriceCalculateRespBO.Promotion promotion01 = result.getPromotions().get(0); + assertEquals(promotion01.getId(), 2048L); + assertEquals(promotion01.getName(), "VIP 会员"); + assertEquals(promotion01.getType(), PromotionTypeEnum.MEMBER_LEVEL.getType()); + assertEquals(promotion01.getTotalPrice(), 200); + assertEquals(promotion01.getDiscountPrice(), 80); + assertTrue(promotion01.getMatch()); + assertEquals(promotion01.getDescription(), "会员等级折扣:省 0.80 元"); + TradePriceCalculateRespBO.PromotionItem promotionItem01 = promotion01.getItems().get(0); + assertEquals(promotion01.getItems().size(), 1); + assertEquals(promotionItem01.getSkuId(), 10L); + assertEquals(promotionItem01.getTotalPrice(), 200); + assertEquals(promotionItem01.getDiscountPrice(), 80); + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java index 2091189a2..1ddd899cb 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.api.level; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; /** @@ -9,6 +10,14 @@ import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; */ public interface MemberLevelApi { + /** + * 获得会员等级 + * + * @param id 会员等级编号 + * @return 会员等级 + */ + MemberLevelRespDTO getMemberLevel(Long id); + /** * 增加会员经验 * diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java new file mode 100644 index 000000000..a72d65f23 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.member.api.level.dto; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import lombok.Data; + +/** + * 会员等级 Resp DTO + * + * @author 芋道源码 + */ +@Data +public class MemberLevelRespDTO { + + /** + * 编号 + */ + private Long id; + /** + * 等级名称 + */ + private String name; + /** + * 等级 + */ + private Integer level; + /** + * 升级经验 + */ + private Integer experience; + /** + * 享受折扣 + */ + private Integer discountPercent; + /** + * 状态 + * + * 枚举 {@link CommonStatusEnum} + */ + private Integer status; + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java index 10d96365f..c8cedb06f 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java @@ -34,4 +34,11 @@ public class MemberUserRespDTO { */ private String mobile; + // ========== 其它信息 ========== + + /** + * 会员级别编号 + */ + private Long levelId; + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index 3cd2cad65..519a8e8a1 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.member.api.level; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import org.springframework.stereotype.Service; @@ -22,6 +24,11 @@ public class MemberLevelApiImpl implements MemberLevelApi { @Resource private MemberLevelService memberLevelService; + @Override + public MemberLevelRespDTO getMemberLevel(Long id) { + return MemberLevelConvert.INSTANCE.convert02(memberLevelService.getLevel(id)); + } + @Override public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) { MemberExperienceBizTypeEnum bizTypeEnum = MemberExperienceBizTypeEnum.getByType(bizType); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java index 073f76027..f2282815e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.convert.level; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelRespVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelSimpleRespVO; @@ -33,4 +34,6 @@ public interface MemberLevelConvert { List convertList02(List list); + MemberLevelRespDTO convert02(MemberLevelDO bean); + } From b4587fd79e5f58cfe52544c87f4146d9c2fdb235 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Sep 2023 00:45:32 +0800 Subject: [PATCH 12/12] =?UTF-8?q?product=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E5=A2=9E=E5=8A=A0=20vip=20=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao-module-product-biz/pom.xml | 6 -- .../property/ProductPropertyValueApiImpl.java | 2 +- .../ProductPropertyValueController.java | 7 +- .../app/spu/AppProductSpuController.java | 72 +++++++++++++++++-- .../ProductPropertyValueConvert.java | 2 +- .../convert/spu/ProductSpuConvert.java | 7 -- .../yudao/module/product/package-info.java | 2 +- .../ProductPropertyValueServiceImpl.java | 2 +- .../trade/enums/ErrorCodeConstants.java | 2 - .../vo/AppTradeOrderSettlementRespVO.java | 3 + .../TradeDeliveryPriceCalculator.java | 6 +- .../TradeDiscountActivityPriceCalculator.java | 6 ++ .../TradeMemberLevelPriceCalculator.java | 6 ++ .../TradeRewardActivityPriceCalculator.java | 6 ++ ...deDiscountActivityPriceCalculatorTest.java | 2 + .../TradeMemberLevelPriceCalculatorTest.java | 2 + ...radeRewardActivityPriceCalculatorTest.java | 3 + 17 files changed, 103 insertions(+), 33 deletions(-) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/{propertyvalue => property}/ProductPropertyValueConvert.java (97%) diff --git a/yudao-module-mall/yudao-module-product-biz/pom.xml b/yudao-module-mall/yudao-module-product-biz/pom.xml index 674f49fc4..f6190ceda 100644 --- a/yudao-module-mall/yudao-module-product-biz/pom.xml +++ b/yudao-module-mall/yudao-module-product-biz/pom.xml @@ -23,12 +23,6 @@ yudao-module-product-api ${revision} - - - cn.iocoder.boot - yudao-module-trade-api - ${revision} - cn.iocoder.boot yudao-module-member-api diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java index 9aab9e560..d3eaaf42d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.product.api.property; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java index fbac32712..54ce881d1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java @@ -1,14 +1,12 @@ package cn.iocoder.yudao.module.product.controller.admin.property; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.crypto.symmetric.AES; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -20,9 +18,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Arrays; -import java.util.List; - import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 商品属性值") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java index 5d79ba7d1..3c9d8f8be 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.product.controller.app.spu; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; -import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; @@ -23,10 +28,12 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_ENABLE; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; @@ -41,6 +48,11 @@ public class AppProductSpuController { @Resource private ProductSkuService productSkuService; + @Resource + private MemberLevelApi memberLevelApi; + @Resource + private MemberUserApi memberUserApi; + @GetMapping("/list") @Operation(summary = "获得商品 SPU 列表") @Parameters({ @@ -51,14 +63,32 @@ public class AppProductSpuController { @RequestParam("recommendType") String recommendType, @RequestParam(value = "count", defaultValue = "10") Integer count) { List list = productSpuService.getSpuList(recommendType, count); - return success(ProductSpuConvert.INSTANCE.convertListForGetSpuList(list)); + if (CollUtil.isEmpty(list)) { + return success(Collections.emptyList()); + } + + // 拼接返回 + List voList = ProductSpuConvert.INSTANCE.convertListForGetSpuList(list); + // 处理 vip 价格 + MemberLevelRespDTO memberLevel = getMemberLevel(); + voList.forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel))); + return success(voList); } @GetMapping("/page") @Operation(summary = "获得商品 SPU 分页") public CommonResult> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) { PageResult pageResult = productSpuService.getSpuPage(pageVO); - return success(ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult)); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); + } + + // 拼接返回 + PageResult voPageResult = ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult); + // 处理 vip 价格 + MemberLevelRespDTO memberLevel = getMemberLevel(); + voPageResult.getList().forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel))); + return success(voPageResult); } @GetMapping("/get-detail") @@ -74,10 +104,40 @@ public class AppProductSpuController { throw exception(SPU_NOT_ENABLE); } - // 查询商品 SKU + // 拼接返回 List skus = productSkuService.getSkuListBySpuId(spu.getId()); - // 拼接 - return success(ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus)); + AppProductSpuDetailRespVO detailVO = ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus); + // 处理 vip 价格 + MemberLevelRespDTO memberLevel = getMemberLevel(); + detailVO.setVipPrice(calculateVipPrice(detailVO.getPrice(), memberLevel)); + return success(detailVO); + } + + private MemberLevelRespDTO getMemberLevel() { + Long userId = getLoginUserId(); + if (userId == null) { + return null; + } + MemberUserRespDTO user = memberUserApi.getUser(userId); + if (user.getLevelId() == null || user.getLevelId() <= 0) { + return null; + } + return memberLevelApi.getMemberLevel(user.getLevelId()); + } + + /** + * 计算会员 VIP 优惠价格 + * + * @param price 原价 + * @param memberLevel 会员等级 + * @return 优惠价格 + */ + public Integer calculateVipPrice(Integer price, MemberLevelRespDTO memberLevel) { + if (memberLevel == null || memberLevel.getDiscountPercent() == null) { + return 0; + } + Integer newPrice = price * memberLevel.getDiscountPercent() / 100; + return price - newPrice; } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java similarity index 97% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java index d6167c174..5429f35fe 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.product.convert.propertyvalue; +package cn.iocoder.yudao.module.product.convert.property; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index 6d52e5cad..e8e6a8bc1 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -79,8 +79,6 @@ public interface ProductSpuConvert { ProductSpuDO spu = list.get(i); AppProductSpuPageRespVO spuVO = voList.get(i); spuVO.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); - // 计算 vip 价格 TODO 芋艿:临时的逻辑,等 vip 支持后 - spuVO.setVipPrice((int) (spuVO.getPrice() * 0.9)); } return voList; } @@ -95,11 +93,6 @@ public interface ProductSpuConvert { .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); // 处理 SKU spuVO.setSkus(convertListForGetSpuDetail(skus)); - // 计算 vip 价格 TODO 芋艿:临时的逻辑,等 vip 支持后 - if (true) { - spuVO.setVipPrice((int) (spuVO.getPrice() * 0.9)); - spuVO.getSkus().forEach(sku -> sku.setVipPrice((int) (sku.getPrice() * 0.9))); - } return spuVO; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java index 01967857e..e32942933 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java @@ -1,5 +1,5 @@ /** - * trade 模块,主要实现交易相关功能 + * product 模块,主要实现交易相关功能 * 例如:订单、退款、购物车等功能。 * * 1. Controller URL:以 /product/ 开头,避免和其它 Module 冲突 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java index 6b4d1e9c8..0f74bca1f 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper; diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ffdba1fcf..6ba8ac37a 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -53,9 +53,7 @@ public interface ErrorCodeConstants { // ========== Price 相关 1011003000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011003000, "支付价格计算异常,原因:价格小于等于 0"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY = new ErrorCode(1011003003, "计算快递运费异常,自提点为空"); ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1011003004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵"); // ========== 物流 Express 模块 1011004000 ========== diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java index bd0312753..4b5d98a37 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java @@ -82,6 +82,9 @@ public class AppTradeOrderSettlementRespVO { @Schema(description = "积分抵扣的金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") private Integer pointPrice; + @Schema(description = "VIP 减免金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "30") + private Integer vipPrice; + @Schema(description = "实际支付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "450") private Integer payPrice; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 20c3feee3..01796ad0e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -64,7 +64,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { private void calculateByPickUp(TradePriceCalculateReqBO param) { if (param.getPickUpStoreId() == null) { - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY); + // 价格计算时,如果为空就不算~最终下单,会校验该字段不允许空 + return; } DeliveryPickUpStoreDO pickUpStore = deliveryPickUpStoreService.getDeliveryPickUpStore(param.getPickUpStoreId()); if (pickUpStore == null || CommonStatusEnum.DISABLE.getStatus().equals(pickUpStore.getStatus())) { @@ -77,7 +78,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { private void calculateExpress(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { // 0. 得到收件地址区域 if (param.getAddressId() == null) { - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY); + // 价格计算时,如果为空就不算~最终下单,会校验该字段不允许空 + return; } AddressRespDTO address = addressApi.getAddress(param.getAddressId(), param.getUserId()); Assert.notNull(address, "收件人({})的地址,不能为空", param.getUserId()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java index fe465f37d..a42780625 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.promotion.api.discount.DiscountActivityApi; import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -33,6 +35,10 @@ public class TradeDiscountActivityPriceCalculator implements TradePriceCalculato @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 0. 只有【普通】订单,才计算该优惠 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + return; + } // 获得 SKU 对应的限时折扣活动 List discountProducts = discountActivityApi.getMatchDiscountProductList( convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java index 7bf0d1d29..8aee001d5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -30,6 +32,10 @@ public class TradeMemberLevelPriceCalculator implements TradePriceCalculator { @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 0. 只有【普通】订单,才计算该优惠 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + return; + } // 1. 获得用户的会员等级 MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); if (user.getLevelId() == null || user.getLevelId() <= 0) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java index f2cfe71cd..d9b44c2b6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi; import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -32,6 +34,10 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 0. 只有【普通】订单,才计算该优惠 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + return; + } // 获得 SKU 对应的满减送活动 List rewardActivities = rewardActivityApi.getMatchRewardActivityList( convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSpuId)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java index 9175e1643..21760217c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.api.discount.DiscountActivityApi; import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -42,6 +43,7 @@ public class TradeDiscountActivityPriceCalculatorTest extends BaseMockitoUnitTes new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java index 568940366..44e783103 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -44,6 +45,7 @@ public class TradeMemberLevelPriceCalculatorTest extends BaseMockitoUnitTest { new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java index 30107d5b4..de72ed616 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi; import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -44,6 +45,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(true) // 匹配活动 2 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( @@ -157,6 +159,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(true) )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList(