Commit 6a38da4ad9dc02fce01a65a8473cd84f3879a99d
promotion:合并最新代码
Showing
23 changed files
with
407 additions
and
219 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
| @@ -25,6 +25,14 @@ public class CollectionUtils { | @@ -25,6 +25,14 @@ public class CollectionUtils { | ||
| 25 | return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); | 25 | return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | + public static <T, U extends Comparable<? super U>> List<T> sortedAsc( | ||
| 29 | + Collection<T> from, Function<? super T, ? extends U> keyExtractor) { | ||
| 30 | + // 按照升序排序 | ||
| 31 | + return from.stream() | ||
| 32 | + .sorted(Comparator.comparing(keyExtractor)) | ||
| 33 | + .collect(Collectors.toList()); | ||
| 34 | + } | ||
| 35 | + | ||
| 28 | public static <T> boolean anyMatch(Collection<T> from, Predicate<T> predicate) { | 36 | public static <T> boolean anyMatch(Collection<T> from, Predicate<T> predicate) { |
| 29 | return from.stream().anyMatch(predicate); | 37 | return from.stream().anyMatch(predicate); |
| 30 | } | 38 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
| @@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr | @@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr | ||
| 4 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; | 4 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; |
| 5 | 5 | ||
| 6 | import javax.validation.Valid; | 6 | import javax.validation.Valid; |
| 7 | -import java.time.LocalDateTime; | ||
| 8 | 7 | ||
| 9 | // TODO @芋艿:后面也再撸撸这几个接口 | 8 | // TODO @芋艿:后面也再撸撸这几个接口 |
| 10 | 9 | ||
| @@ -18,12 +17,13 @@ public interface CombinationRecordApi { | @@ -18,12 +17,13 @@ public interface CombinationRecordApi { | ||
| 18 | /** | 17 | /** |
| 19 | * 校验是否满足拼团条件 | 18 | * 校验是否满足拼团条件 |
| 20 | * | 19 | * |
| 21 | - * @param activityId 活动编号 | ||
| 22 | * @param userId 用户编号 | 20 | * @param userId 用户编号 |
| 21 | + * @param activityId 活动编号 | ||
| 22 | + * @param headId 团长编号 | ||
| 23 | * @param skuId sku 编号 | 23 | * @param skuId sku 编号 |
| 24 | * @param count 数量 | 24 | * @param count 数量 |
| 25 | */ | 25 | */ |
| 26 | - void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count); | 26 | + void validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count); |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * 创建开团记录 | 29 | * 创建开团记录 |
| @@ -42,14 +42,6 @@ public interface CombinationRecordApi { | @@ -42,14 +42,6 @@ public interface CombinationRecordApi { | ||
| 42 | boolean isCombinationRecordSuccess(Long userId, Long orderId); | 42 | boolean isCombinationRecordSuccess(Long userId, Long orderId); |
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | - * 更新拼团状态为【成功】 | ||
| 46 | - * | ||
| 47 | - * @param userId 用户编号 | ||
| 48 | - * @param orderId 订单编号 | ||
| 49 | - */ | ||
| 50 | - void updateRecordStatusToSuccess(Long userId, Long orderId); | ||
| 51 | - | ||
| 52 | - /** | ||
| 53 | * 更新拼团状态为【失败】 | 45 | * 更新拼团状态为【失败】 |
| 54 | * | 46 | * |
| 55 | * @param userId 用户编号 | 47 | * @param userId 用户编号 |
| @@ -58,26 +50,17 @@ public interface CombinationRecordApi { | @@ -58,26 +50,17 @@ public interface CombinationRecordApi { | ||
| 58 | void updateRecordStatusToFailed(Long userId, Long orderId); | 50 | void updateRecordStatusToFailed(Long userId, Long orderId); |
| 59 | 51 | ||
| 60 | /** | 52 | /** |
| 61 | - * 更新拼团状态为 进行中 | ||
| 62 | - * | ||
| 63 | - * @param userId 用户编号 | ||
| 64 | - * @param orderId 订单编号 | ||
| 65 | - * @param startTime 开始时间 | ||
| 66 | - */ | ||
| 67 | - void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime); | ||
| 68 | - | ||
| 69 | - /** | ||
| 70 | * 【下单前】校验是否满足拼团活动条件 | 53 | * 【下单前】校验是否满足拼团活动条件 |
| 71 | * | 54 | * |
| 72 | * 如果校验失败,则抛出业务异常 | 55 | * 如果校验失败,则抛出业务异常 |
| 73 | * | 56 | * |
| 74 | - * @param activityId 活动编号 | ||
| 75 | * @param userId 用户编号 | 57 | * @param userId 用户编号 |
| 58 | + * @param activityId 活动编号 | ||
| 59 | + * @param headId 团长编号 | ||
| 76 | * @param skuId sku 编号 | 60 | * @param skuId sku 编号 |
| 77 | * @param count 数量 | 61 | * @param count 数量 |
| 78 | * @return 拼团信息 | 62 | * @return 拼团信息 |
| 79 | */ | 63 | */ |
| 80 | - // TODO @puhui:userId 放最前面;然后应该还有个 headId 参数; | ||
| 81 | - CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count); | 64 | + CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); |
| 82 | 65 | ||
| 83 | } | 66 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| @@ -80,7 +80,7 @@ public interface ErrorCodeConstants { | @@ -80,7 +80,7 @@ public interface ErrorCodeConstants { | ||
| 80 | ErrorCode COMBINATION_RECORD_EXISTS = new ErrorCode(1_013_011_001, "拼团失败,已参与过该拼团"); | 80 | ErrorCode COMBINATION_RECORD_EXISTS = new ErrorCode(1_013_011_001, "拼团失败,已参与过该拼团"); |
| 81 | ErrorCode COMBINATION_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1_013_011_002, "拼团失败,父拼团不存在"); | 81 | ErrorCode COMBINATION_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1_013_011_002, "拼团失败,父拼团不存在"); |
| 82 | ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1_013_011_003, "拼团失败,拼团人数已满"); | 82 | ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1_013_011_003, "拼团失败,拼团人数已满"); |
| 83 | - ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1_013_011_004, "拼团失败,已参与其它拼团"); | 83 | + ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1_013_011_004, "拼团失败,原因:存在该活动正在进行的拼团记录"); |
| 84 | ErrorCode COMBINATION_RECORD_FAILED_TIME_NOT_START = new ErrorCode(1_013_011_005, "拼团失败,活动未开始"); | 84 | ErrorCode COMBINATION_RECORD_FAILED_TIME_NOT_START = new ErrorCode(1_013_011_005, "拼团失败,活动未开始"); |
| 85 | ErrorCode COMBINATION_RECORD_FAILED_TIME_END = new ErrorCode(1_013_011_006, "拼团失败,活动已经结束"); | 85 | ErrorCode COMBINATION_RECORD_FAILED_TIME_END = new ErrorCode(1_013_011_006, "拼团失败,活动已经结束"); |
| 86 | ErrorCode COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED = new ErrorCode(1_013_011_007, "拼团失败,原因:单次限购超出"); | 86 | ErrorCode COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED = new ErrorCode(1_013_011_007, "拼团失败,原因:单次限购超出"); |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/combination/CombinationRecordStatusEnum.java
| @@ -40,4 +40,8 @@ public enum CombinationRecordStatusEnum implements IntArrayValuable { | @@ -40,4 +40,8 @@ public enum CombinationRecordStatusEnum implements IntArrayValuable { | ||
| 40 | return ObjectUtil.equal(status, SUCCESS.getStatus()); | 40 | return ObjectUtil.equal(status, SUCCESS.getStatus()); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | + public static boolean isInProgress(Integer status) { | ||
| 44 | + return ObjectUtil.equal(status, IN_PROGRESS.getStatus()); | ||
| 45 | + } | ||
| 46 | + | ||
| 43 | } | 47 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java
| @@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.promotion.api.combination; | @@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.promotion.api.combination; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; | 3 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; |
| 4 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; | 4 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; |
| 5 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; | ||
| 5 | import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | 6 | import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; |
| 6 | import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; | 7 | import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; |
| 7 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 8 | 9 | ||
| 9 | import javax.annotation.Resource; | 10 | import javax.annotation.Resource; |
| 10 | -import java.time.LocalDateTime; | 11 | + |
| 12 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 13 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_NOT_EXISTS; | ||
| 11 | 14 | ||
| 12 | /** | 15 | /** |
| 13 | * 拼团活动 API 实现类 | 16 | * 拼团活动 API 实现类 |
| @@ -21,8 +24,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | @@ -21,8 +24,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | ||
| 21 | private CombinationRecordService recordService; | 24 | private CombinationRecordService recordService; |
| 22 | 25 | ||
| 23 | @Override | 26 | @Override |
| 24 | - public void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count) { | ||
| 25 | - recordService.validateCombinationRecord(activityId, userId, skuId, count); | 27 | + public void validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count) { |
| 28 | + recordService.validateCombinationRecord(userId, activityId, headId, skuId, count); | ||
| 26 | } | 29 | } |
| 27 | 30 | ||
| 28 | @Override | 31 | @Override |
| @@ -32,12 +35,12 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | @@ -32,12 +35,12 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | ||
| 32 | 35 | ||
| 33 | @Override | 36 | @Override |
| 34 | public boolean isCombinationRecordSuccess(Long userId, Long orderId) { | 37 | public boolean isCombinationRecordSuccess(Long userId, Long orderId) { |
| 35 | - return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus()); | ||
| 36 | - } | 38 | + CombinationRecordDO combinationRecord = recordService.getCombinationRecord(userId, orderId); |
| 39 | + if (combinationRecord == null) { | ||
| 40 | + throw exception(COMBINATION_RECORD_NOT_EXISTS); | ||
| 41 | + } | ||
| 37 | 42 | ||
| 38 | - @Override | ||
| 39 | - public void updateRecordStatusToSuccess(Long userId, Long orderId) { | ||
| 40 | - recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId); | 43 | + return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus()); |
| 41 | } | 44 | } |
| 42 | 45 | ||
| 43 | @Override | 46 | @Override |
| @@ -46,14 +49,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | @@ -46,14 +49,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | ||
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | @Override | 51 | @Override |
| 49 | - public void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime) { | ||
| 50 | - recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), | ||
| 51 | - userId, orderId, startTime); | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - @Override | ||
| 55 | - public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) { | ||
| 56 | - return recordService.validateJoinCombination(activityId, userId, skuId, count); | 52 | + public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { |
| 53 | + return recordService.validateJoinCombination(userId, activityId, headId, skuId, count); | ||
| 57 | } | 54 | } |
| 58 | 55 | ||
| 59 | } | 56 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java
| @@ -48,8 +48,9 @@ public class CombinationActivityBaseVO { | @@ -48,8 +48,9 @@ public class CombinationActivityBaseVO { | ||
| 48 | @NotNull(message = "开团人数不能为空") | 48 | @NotNull(message = "开团人数不能为空") |
| 49 | private Integer userSize; | 49 | private Integer userSize; |
| 50 | 50 | ||
| 51 | - @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | ||
| 52 | - private Boolean virtualGroup = false; // TODO @puhui999:这个字段界面没做呀。 | 51 | + @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") |
| 52 | + @NotNull(message = "虚拟成团不能为空") | ||
| 53 | + private Boolean virtualGroup; | ||
| 53 | 54 | ||
| 54 | @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | 55 | @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 55 | @NotNull(message = "限制时长不能为空") | 56 | @NotNull(message = "限制时长不能为空") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java
| @@ -6,11 +6,14 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap | @@ -6,11 +6,14 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap | ||
| 6 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; |
| 7 | import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; | 7 | import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; |
| 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 9 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | ||
| 9 | import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; | 10 | import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; |
| 11 | +import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; | ||
| 10 | import io.swagger.v3.oas.annotations.Operation; | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | import io.swagger.v3.oas.annotations.Parameter; | 13 | import io.swagger.v3.oas.annotations.Parameter; |
| 12 | import io.swagger.v3.oas.annotations.Parameters; | 14 | import io.swagger.v3.oas.annotations.Parameters; |
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 16 | +import org.springframework.context.annotation.Lazy; | ||
| 14 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | 18 | import org.springframework.web.bind.annotation.GetMapping; |
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | 19 | import org.springframework.web.bind.annotation.RequestMapping; |
| @@ -35,6 +38,9 @@ public class AppCombinationRecordController { | @@ -35,6 +38,9 @@ public class AppCombinationRecordController { | ||
| 35 | 38 | ||
| 36 | @Resource | 39 | @Resource |
| 37 | private CombinationRecordService combinationRecordService; | 40 | private CombinationRecordService combinationRecordService; |
| 41 | + @Resource | ||
| 42 | + @Lazy | ||
| 43 | + private TradeOrderApi tradeOrderApi; | ||
| 38 | 44 | ||
| 39 | @GetMapping("/get-summary") | 45 | @GetMapping("/get-summary") |
| 40 | @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") | 46 | @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") |
| @@ -96,9 +102,26 @@ public class AppCombinationRecordController { | @@ -96,9 +102,26 @@ public class AppCombinationRecordController { | ||
| 96 | return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); | 102 | return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); |
| 97 | } | 103 | } |
| 98 | 104 | ||
| 99 | - // TODO @puhui:新增一个取消拼团的接口,cancel | ||
| 100 | - // 1. 需要先校验拼团记录未完成; | ||
| 101 | - // 2. 在 Order 那增加一个 cancelPaidOrder 接口,用于取消已支付的订单 | ||
| 102 | - // 3. order 完成后,取消拼团记录。另外,如果它是团长,则顺序(下单时间)继承 | 105 | + @GetMapping("/cancel") |
| 106 | + @Operation(summary = "取消拼团") | ||
| 107 | + @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") | ||
| 108 | + public CommonResult<Boolean> cancelCombinationRecord(@RequestParam("id") Long id) { | ||
| 109 | + Long userId = getLoginUserId(); | ||
| 110 | + // 1、查找这条拼团记录 | ||
| 111 | + CombinationRecordDO record = combinationRecordService.getCombinationRecordByIdAndUser(userId, id); | ||
| 112 | + if (record == null) { | ||
| 113 | + return success(Boolean.FALSE); | ||
| 114 | + } | ||
| 115 | + // 1.1、需要先校验拼团记录未完成; | ||
| 116 | + if (!CombinationRecordStatusEnum.isInProgress(record.getStatus())) { | ||
| 117 | + return success(Boolean.FALSE); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + // 2. 取消已支付的订单 | ||
| 121 | + tradeOrderApi.cancelPaidOrder(userId, record.getOrderId()); | ||
| 122 | + // 3. 取消拼团记录 | ||
| 123 | + combinationRecordService.cancelCombinationRecord(userId, record.getId(), record.getHeadId()); | ||
| 124 | + return success(Boolean.TRUE); | ||
| 125 | + } | ||
| 103 | 126 | ||
| 104 | } | 127 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| @@ -22,11 +22,13 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap | @@ -22,11 +22,13 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap | ||
| 22 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; | 22 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; |
| 23 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; | 23 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; |
| 24 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; | 24 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 25 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | ||
| 25 | import org.mapstruct.Mapper; | 26 | import org.mapstruct.Mapper; |
| 26 | import org.mapstruct.Mapping; | 27 | import org.mapstruct.Mapping; |
| 27 | import org.mapstruct.Mappings; | 28 | import org.mapstruct.Mappings; |
| 28 | import org.mapstruct.factory.Mappers; | 29 | import org.mapstruct.factory.Mappers; |
| 29 | 30 | ||
| 31 | +import java.time.LocalDateTime; | ||
| 30 | import java.util.List; | 32 | import java.util.List; |
| 31 | import java.util.Map; | 33 | import java.util.Map; |
| 32 | 34 | ||
| @@ -110,14 +112,19 @@ public interface CombinationActivityConvert { | @@ -110,14 +112,19 @@ public interface CombinationActivityConvert { | ||
| 110 | CombinationActivityDO activity, MemberUserRespDTO user, | 112 | CombinationActivityDO activity, MemberUserRespDTO user, |
| 111 | ProductSpuRespDTO spu, ProductSkuRespDTO sku) { | 113 | ProductSpuRespDTO spu, ProductSkuRespDTO sku) { |
| 112 | return convert(reqDTO) | 114 | return convert(reqDTO) |
| 113 | - .setCount(reqDTO.getCount()).setUserCount(1) | 115 | + .setHeadId(reqDTO.getHeadId()) // 显示性再设置一下 |
| 116 | + .setCount(reqDTO.getCount()) | ||
| 114 | .setVirtualGroup(false) | 117 | .setVirtualGroup(false) |
| 118 | + .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 | ||
| 119 | + .setStartTime(LocalDateTime.now()) | ||
| 115 | .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) | 120 | .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) |
| 116 | .setUserSize(activity.getUserSize()) | 121 | .setUserSize(activity.getUserSize()) |
| 122 | + .setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 | ||
| 117 | .setNickname(user.getNickname()) | 123 | .setNickname(user.getNickname()) |
| 118 | .setAvatar(user.getAvatar()) | 124 | .setAvatar(user.getAvatar()) |
| 119 | .setSpuName(spu.getName()) | 125 | .setSpuName(spu.getName()) |
| 120 | .setPicUrl(sku.getPicUrl()); | 126 | .setPicUrl(sku.getPicUrl()); |
| 127 | + | ||
| 121 | } | 128 | } |
| 122 | 129 | ||
| 123 | List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list); | 130 | List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list); |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| @@ -32,12 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | @@ -32,12 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | ||
| 32 | CombinationRecordDO::getOrderId, orderId); | 32 | CombinationRecordDO::getOrderId, orderId); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | - default List<CombinationRecordDO> selectListByUserIdAndStatus(Long userId, Integer status) { | ||
| 36 | - return selectList(new LambdaQueryWrapperX<CombinationRecordDO>() | ||
| 37 | - .eq(CombinationRecordDO::getUserId, userId) | ||
| 38 | - .eq(CombinationRecordDO::getStatus, status)); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | /** | 35 | /** |
| 42 | * 查询拼团记录 | 36 | * 查询拼团记录 |
| 43 | * | 37 | * |
| @@ -106,7 +100,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | @@ -106,7 +100,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | ||
| 106 | // 转换数据 | 100 | // 转换数据 |
| 107 | return CollectionUtils.convertMap(result, | 101 | return CollectionUtils.convertMap(result, |
| 108 | record -> MapUtil.getLong(record, "activityId"), | 102 | record -> MapUtil.getLong(record, "activityId"), |
| 109 | - record -> MapUtil.getInt(record, "recordCount" )); | 103 | + record -> MapUtil.getInt(record, "recordCount")); |
| 110 | } | 104 | } |
| 111 | 105 | ||
| 112 | static LocalDateTime[] builderQueryTime(Integer dateType) { | 106 | static LocalDateTime[] builderQueryTime(Integer dateType) { |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
| @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP | ||
| 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 11 | 11 | ||
| 12 | import javax.annotation.Nullable; | 12 | import javax.annotation.Nullable; |
| 13 | -import java.time.LocalDateTime; | ||
| 14 | import java.util.Collection; | 13 | import java.util.Collection; |
| 15 | import java.util.List; | 14 | import java.util.List; |
| 16 | import java.util.Map; | 15 | import java.util.Map; |
| @@ -32,16 +31,18 @@ public interface CombinationRecordService { | @@ -32,16 +31,18 @@ public interface CombinationRecordService { | ||
| 32 | void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId); | 31 | void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId); |
| 33 | 32 | ||
| 34 | /** | 33 | /** |
| 35 | - * 校验是否满足拼团条件 | ||
| 36 | - * 如果不满足,会抛出异常 | 34 | + * 【下单前】校验是否满足拼团活动条件 |
| 35 | + * | ||
| 36 | + * 如果校验失败,则抛出业务异常 | ||
| 37 | * | 37 | * |
| 38 | - * @param activityId 活动编号 | ||
| 39 | * @param userId 用户编号 | 38 | * @param userId 用户编号 |
| 39 | + * @param activityId 活动编号 | ||
| 40 | + * @param headId 团长编号 | ||
| 40 | * @param skuId sku 编号 | 41 | * @param skuId sku 编号 |
| 41 | * @param count 数量 | 42 | * @param count 数量 |
| 42 | - * @return 返回拼团活动和拼团活动商品 | 43 | + * @return 拼团信息 |
| 43 | */ | 44 | */ |
| 44 | - KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count); | 45 | + KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count); |
| 45 | 46 | ||
| 46 | /** | 47 | /** |
| 47 | * 创建拼团记录 | 48 | * 创建拼团记录 |
| @@ -51,16 +52,6 @@ public interface CombinationRecordService { | @@ -51,16 +52,6 @@ public interface CombinationRecordService { | ||
| 51 | void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); | 52 | void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); |
| 52 | 53 | ||
| 53 | /** | 54 | /** |
| 54 | - * 更新拼团状态和开始时间 | ||
| 55 | - * | ||
| 56 | - * @param status 状态 | ||
| 57 | - * @param userId 用户编号 | ||
| 58 | - * @param orderId 订单编号 | ||
| 59 | - * @param startTime 开始时间 | ||
| 60 | - */ | ||
| 61 | - void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime); | ||
| 62 | - | ||
| 63 | - /** | ||
| 64 | * 获得拼团记录 | 55 | * 获得拼团记录 |
| 65 | * | 56 | * |
| 66 | * @param userId 用户编号 | 57 | * @param userId 用户编号 |
| @@ -83,13 +74,14 @@ public interface CombinationRecordService { | @@ -83,13 +74,14 @@ public interface CombinationRecordService { | ||
| 83 | * | 74 | * |
| 84 | * 如果校验失败,则抛出业务异常 | 75 | * 如果校验失败,则抛出业务异常 |
| 85 | * | 76 | * |
| 86 | - * @param activityId 活动编号 | ||
| 87 | * @param userId 用户编号 | 77 | * @param userId 用户编号 |
| 78 | + * @param activityId 活动编号 | ||
| 79 | + * @param headId 团长编号 | ||
| 88 | * @param skuId sku 编号 | 80 | * @param skuId sku 编号 |
| 89 | * @param count 数量 | 81 | * @param count 数量 |
| 90 | * @return 拼团信息 | 82 | * @return 拼团信息 |
| 91 | */ | 83 | */ |
| 92 | - CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count); | 84 | + CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); |
| 93 | 85 | ||
| 94 | /** | 86 | /** |
| 95 | * 获取所有拼团记录数 | 87 | * 获取所有拼团记录数 |
| @@ -166,12 +158,32 @@ public interface CombinationRecordService { | @@ -166,12 +158,32 @@ public interface CombinationRecordService { | ||
| 166 | * 【拼团活动】获得拼团记录数量 Map | 158 | * 【拼团活动】获得拼团记录数量 Map |
| 167 | * | 159 | * |
| 168 | * @param activityIds 活动记录编号数组 | 160 | * @param activityIds 活动记录编号数组 |
| 169 | - * @param status 拼团状态,允许空 | ||
| 170 | - * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 | 161 | + * @param status 拼团状态,允许空 |
| 162 | + * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 | ||
| 171 | * @return 拼团记录数量 Map | 163 | * @return 拼团记录数量 Map |
| 172 | */ | 164 | */ |
| 173 | Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, | 165 | Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, |
| 174 | @Nullable Integer status, | 166 | @Nullable Integer status, |
| 175 | @Nullable Long headId); | 167 | @Nullable Long headId); |
| 176 | 168 | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 获取拼团记录 | ||
| 172 | + * | ||
| 173 | + * @param userId 用户编号 | ||
| 174 | + * @param id 拼团记录编号 | ||
| 175 | + * @return 拼团记录 | ||
| 176 | + */ | ||
| 177 | + CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id); | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 取消拼团 | ||
| 181 | + * | ||
| 182 | + * @param userId 用户编号 | ||
| 183 | + * @param id 拼团记录编号 | ||
| 184 | + * @param headId 团长编号 | ||
| 185 | + */ | ||
| 186 | + void cancelCombinationRecord(Long userId, Long id, Long headId); | ||
| 187 | + | ||
| 188 | + | ||
| 177 | } | 189 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| 1 | package cn.iocoder.yudao.module.promotion.service.combination; | 1 | package cn.iocoder.yudao.module.promotion.service.combination; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.util.ObjectUtil; | 4 | +import cn.hutool.core.util.ObjUtil; |
| 5 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 5 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | ||
| 9 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | 8 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 10 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 9 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 11 | import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | 10 | import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; |
| @@ -22,7 +21,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR | @@ -22,7 +21,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR | ||
| 22 | import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; | 21 | import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; |
| 23 | import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | 22 | import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; |
| 24 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; | 23 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; |
| 25 | -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; | ||
| 26 | import org.springframework.context.annotation.Lazy; | 24 | import org.springframework.context.annotation.Lazy; |
| 27 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
| 28 | import org.springframework.transaction.annotation.Transactional; | 26 | import org.springframework.transaction.annotation.Transactional; |
| @@ -30,13 +28,12 @@ import org.springframework.validation.annotation.Validated; | @@ -30,13 +28,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 30 | 28 | ||
| 31 | import javax.annotation.Nullable; | 29 | import javax.annotation.Nullable; |
| 32 | import javax.annotation.Resource; | 30 | import javax.annotation.Resource; |
| 33 | -import java.time.LocalDateTime; | ||
| 34 | -import java.util.Collection; | ||
| 35 | -import java.util.List; | ||
| 36 | -import java.util.Map; | 31 | +import java.util.*; |
| 37 | 32 | ||
| 38 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 39 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 34 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 35 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; | ||
| 36 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; | ||
| 40 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | 37 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 41 | 38 | ||
| 42 | // TODO 芋艿:等拼团记录做完,完整 review 下 | 39 | // TODO 芋艿:等拼团记录做完,完整 review 下 |
| @@ -79,31 +76,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -79,31 +76,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 79 | recordMapper.updateById(record); | 76 | recordMapper.updateById(record); |
| 80 | } | 77 | } |
| 81 | 78 | ||
| 82 | - // TODO @芋艿:在详细预览下; | ||
| 83 | - @Override | ||
| 84 | - @Transactional(rollbackFor = Exception.class) | ||
| 85 | - public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { | ||
| 86 | - CombinationRecordDO record = validateCombinationRecord(userId, orderId); | ||
| 87 | - // 更新状态 | ||
| 88 | - record.setStatus(status); | ||
| 89 | - // 更新开始时间 | ||
| 90 | - record.setStartTime(startTime); | ||
| 91 | - recordMapper.updateById(record); | ||
| 92 | - | ||
| 93 | - // 更新拼团参入人数 | ||
| 94 | - List<CombinationRecordDO> records = recordMapper.selectListByHeadIdAndStatus(record.getHeadId(), status); | ||
| 95 | - if (CollUtil.isNotEmpty(records)) { | ||
| 96 | - records.forEach(item -> { | ||
| 97 | - item.setUserCount(records.size()); | ||
| 98 | - // 校验拼团是否满足要求 | ||
| 99 | - if (ObjectUtil.equal(records.size(), record.getUserSize())) { | ||
| 100 | - item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); | ||
| 101 | - } | ||
| 102 | - }); | ||
| 103 | - recordMapper.updateBatch(records); | ||
| 104 | - } | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { | 79 | private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { |
| 108 | // 校验拼团是否存在 | 80 | // 校验拼团是否存在 |
| 109 | CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId); | 81 | CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId); |
| @@ -116,54 +88,76 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -116,54 +88,76 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 116 | // TODO @芋艿:在详细预览下; | 88 | // TODO @芋艿:在详细预览下; |
| 117 | @Override | 89 | @Override |
| 118 | public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord( | 90 | public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord( |
| 119 | - Long activityId, Long userId, Long skuId, Integer count) { | ||
| 120 | - // 1.1 校验拼团活动是否存在 | 91 | + Long userId, Long activityId, Long headId, Long skuId, Integer count) { |
| 92 | + // 1 校验拼团活动是否存在 | ||
| 121 | CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); | 93 | CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); |
| 122 | - // 1.2 校验活动是否开启 | ||
| 123 | - if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { | 94 | + // 1.1 校验活动是否开启 |
| 95 | + if (ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { | ||
| 124 | throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); | 96 | throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); |
| 125 | } | 97 | } |
| 126 | - // 2 校验是否超出单次限购数量 | 98 | + // 1.2、校验活动开始时间 |
| 99 | + if (afterNow(activity.getStartTime())) { | ||
| 100 | + throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); | ||
| 101 | + } | ||
| 102 | + // 1.3 校验是否超出单次限购数量 | ||
| 127 | if (count > activity.getSingleLimitCount()) { | 103 | if (count > activity.getSingleLimitCount()) { |
| 128 | throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); | 104 | throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); |
| 129 | } | 105 | } |
| 130 | - // 2.1、校验活动商品是否存在 | 106 | + |
| 107 | + // 2、父拼团是否存在,是否已经满了 | ||
| 108 | + if (headId != null) { | ||
| 109 | + // 2.1、查询进行中的父拼团 | ||
| 110 | + CombinationRecordDO record = recordMapper.selectOneByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | ||
| 111 | + if (record == null) { | ||
| 112 | + throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); | ||
| 113 | + } | ||
| 114 | + // 2.2、校验拼团是否满足要求 | ||
| 115 | + if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) { | ||
| 116 | + throw exception(COMBINATION_RECORD_USER_FULL); | ||
| 117 | + } | ||
| 118 | + // 2.3、校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间) | ||
| 119 | + if (beforeNow(record.getExpireTime())) { | ||
| 120 | + throw exception(COMBINATION_RECORD_FAILED_TIME_END); | ||
| 121 | + } | ||
| 122 | + } else { | ||
| 123 | + // 3、校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束) | ||
| 124 | + if (beforeNow(activity.getEndTime())) { | ||
| 125 | + throw exception(COMBINATION_RECORD_FAILED_TIME_END); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + // 4、校验活动商品是否存在 | ||
| 131 | CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId); | 130 | CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId); |
| 132 | if (product == null) { | 131 | if (product == null) { |
| 133 | throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); | 132 | throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); |
| 134 | } | 133 | } |
| 135 | - // 2.2、校验 sku 是否存在 | 134 | + |
| 135 | + // 5、校验 sku 是否存在 | ||
| 136 | ProductSkuRespDTO sku = productSkuApi.getSku(skuId); | 136 | ProductSkuRespDTO sku = productSkuApi.getSku(skuId); |
| 137 | if (sku == null) { | 137 | if (sku == null) { |
| 138 | throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); | 138 | throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); |
| 139 | } | 139 | } |
| 140 | - // 2.3、 校验库存是否充足 | 140 | + // 5.1、校验库存是否充足 |
| 141 | if (count > sku.getStock()) { | 141 | if (count > sku.getStock()) { |
| 142 | throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL); | 142 | throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL); |
| 143 | } | 143 | } |
| 144 | - // 3、校验是否有拼团记录 | 144 | + |
| 145 | + // 6、校验是否有拼团记录 | ||
| 145 | List<CombinationRecordDO> recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId); | 146 | List<CombinationRecordDO> recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId); |
| 146 | if (CollUtil.isEmpty(recordList)) { | 147 | if (CollUtil.isEmpty(recordList)) { |
| 147 | return new KeyValue<>(activity, product); | 148 | return new KeyValue<>(activity, product); |
| 148 | } | 149 | } |
| 149 | - // 4、校验是否超出总限购数量 | 150 | + // 6.1、校验用户是否有该活动正在进行的拼团 |
| 151 | + List<CombinationRecordDO> filtered = filterList(recordList, record -> CombinationRecordStatusEnum.isInProgress(record.getStatus())); | ||
| 152 | + if (CollUtil.isNotEmpty(filtered)) { | ||
| 153 | + throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); | ||
| 154 | + } | ||
| 155 | + // 6.2、校验是否超出总限购数量 | ||
| 150 | Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount, | 156 | Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount, |
| 151 | - item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), i -> i, Integer::sum); | 157 | + item -> CombinationRecordStatusEnum.isSuccess(item.getStatus())), i -> i, Integer::sum); |
| 152 | if ((sumValue + count) > activity.getTotalLimitCount()) { | 158 | if ((sumValue + count) > activity.getTotalLimitCount()) { |
| 153 | throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); | 159 | throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); |
| 154 | } | 160 | } |
| 155 | - // 5、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团) | ||
| 156 | - CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null)); | ||
| 157 | - if (record == null) { | ||
| 158 | - return new KeyValue<>(activity, product); | ||
| 159 | - } | ||
| 160 | - // 5.1、查询关联的订单是否已经支付 | ||
| 161 | - // 当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; | ||
| 162 | - // TODO 芋艿:看看是不是可以删除掉; | ||
| 163 | - Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId()); | ||
| 164 | - if (ObjectUtil.equal(orderStatus, TradeOrderStatusEnum.UNPAID.getStatus())) { | ||
| 165 | - throw exception(COMBINATION_RECORD_FAILED_ORDER_STATUS_UNPAID); | ||
| 166 | - } | ||
| 167 | 161 | ||
| 168 | return new KeyValue<>(activity, product); | 162 | return new KeyValue<>(activity, product); |
| 169 | } | 163 | } |
| @@ -173,47 +167,78 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -173,47 +167,78 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 173 | @Transactional(rollbackFor = Exception.class) | 167 | @Transactional(rollbackFor = Exception.class) |
| 174 | public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { | 168 | public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { |
| 175 | // 1、校验拼团活动 | 169 | // 1、校验拼团活动 |
| 176 | - KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord( | ||
| 177 | - reqDTO.getActivityId(), reqDTO.getUserId(), reqDTO.getSkuId(), reqDTO.getCount()); | ||
| 178 | - CombinationActivityDO activity = keyValue.getKey(); | ||
| 179 | - // 2、校验用户是否参加了其它拼团 | ||
| 180 | - List<CombinationRecordDO> recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | ||
| 181 | - if (CollUtil.isNotEmpty(recordDOList)) { | ||
| 182 | - throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); | ||
| 183 | - } | ||
| 184 | - // 3、校验活动是否开启 | ||
| 185 | - if (!LocalDateTimeUtils.beforeNow(activity.getStartTime())) { | ||
| 186 | - throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); | ||
| 187 | - } | ||
| 188 | - // 4、校验当前活动是否过期 | ||
| 189 | - if (LocalDateTime.now().isAfter(activity.getEndTime())) { | ||
| 190 | - throw exception(COMBINATION_RECORD_FAILED_TIME_END); | ||
| 191 | - } | ||
| 192 | - // 5、父拼团是否存在,是否已经满了 | ||
| 193 | - if (reqDTO.getHeadId() != null) { | ||
| 194 | - // 5.1、查询进行中的父拼团 | ||
| 195 | - CombinationRecordDO record = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | ||
| 196 | - if (record == null) { | ||
| 197 | - throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); | ||
| 198 | - } | ||
| 199 | - // 5.2、校验拼团是否满足要求 | ||
| 200 | - if (ObjectUtil.equal(record.getUserCount(), record.getUserSize())) { | ||
| 201 | - throw exception(COMBINATION_RECORD_USER_FULL); | ||
| 202 | - } | ||
| 203 | - } | 170 | + KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(), |
| 171 | + reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); | ||
| 204 | 172 | ||
| 205 | - // 6. 创建拼团记录 | 173 | + // 2. 组合数据创建拼团记录 |
| 206 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); | 174 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 207 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); | 175 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
| 208 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); | 176 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); |
| 209 | - // TODO @puhui999:status 未设置;headId 未设置 | ||
| 210 | - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); | 177 | + CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); |
| 178 | + recordMapper.insert(recordDO); | ||
| 179 | + | ||
| 180 | + // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP | ||
| 181 | + if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) { | ||
| 182 | + recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); | ||
| 183 | + return; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + // TODO 这里要不要弄成异步的 | ||
| 187 | + // 4、更新拼团相关信息到订单 | ||
| 188 | + updateOrderCombinationInfo(recordDO.getOrderId(), recordDO.getActivityId(), recordDO.getId(), recordDO.getHeadId()); | ||
| 189 | + // 4、更新拼团记录 | ||
| 190 | + updateCombinationRecords(keyValue.getKey(), reqDTO.getHeadId()); | ||
| 191 | + | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * 更新拼团相关信息到订单 | ||
| 196 | + * | ||
| 197 | + * @param orderId 订单编号 | ||
| 198 | + * @param activityId 拼团活动编号 | ||
| 199 | + * @param combinationRecordId 拼团记录编号 | ||
| 200 | + * @param headId 团长编号 | ||
| 201 | + */ | ||
| 202 | + private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { | ||
| 203 | + tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + /** | ||
| 207 | + * 更新拼团记录 | ||
| 208 | + * | ||
| 209 | + * @param activity 活动 | ||
| 210 | + * @param headId 团长编号 | ||
| 211 | + */ | ||
| 212 | + private void updateCombinationRecords(CombinationActivityDO activity, Long headId) { | ||
| 213 | + // 团长 | ||
| 214 | + CombinationRecordDO recordHead = recordMapper.selectById(headId); | ||
| 215 | + // 团员 | ||
| 216 | + List<CombinationRecordDO> records = getCombinationRecordListByHeadId(headId); | ||
| 217 | + // 需要更新的记录 | ||
| 218 | + List<CombinationRecordDO> updateRecords = new ArrayList<>(); | ||
| 219 | + | ||
| 220 | + if (CollUtil.isEmpty(records)) { | ||
| 221 | + return; | ||
| 222 | + } | ||
| 223 | + records.add(recordHead); // 加入团长,团长也需要更新 | ||
| 224 | + boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize()); | ||
| 225 | + records.forEach(item -> { | ||
| 226 | + CombinationRecordDO recordDO = new CombinationRecordDO(); | ||
| 227 | + recordDO.setId(item.getId()); | ||
| 228 | + recordDO.setUserCount(records.size()); | ||
| 229 | + // 校验拼团是否满足要求 | ||
| 230 | + if (isEqual) { | ||
| 231 | + recordDO.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); | ||
| 232 | + } | ||
| 233 | + updateRecords.add(recordDO); | ||
| 234 | + }); | ||
| 235 | + | ||
| 236 | + recordMapper.updateBatch(updateRecords); | ||
| 211 | } | 237 | } |
| 212 | 238 | ||
| 213 | @Override | 239 | @Override |
| 214 | public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { | 240 | public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { |
| 215 | - // TODO puhui999:这里直接获得,不适合调用校验的接口; | ||
| 216 | - return validateCombinationRecord(userId, orderId); | 241 | + return recordMapper.selectByUserIdAndOrderId(userId, orderId); |
| 217 | } | 242 | } |
| 218 | 243 | ||
| 219 | @Override | 244 | @Override |
| @@ -222,8 +247,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -222,8 +247,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 222 | } | 247 | } |
| 223 | 248 | ||
| 224 | @Override | 249 | @Override |
| 225 | - public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) { | ||
| 226 | - KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(activityId, userId, skuId, count); | 250 | + public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { |
| 251 | + KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(userId, activityId, headId, skuId, count); | ||
| 227 | return new CombinationValidateJoinRespDTO() | 252 | return new CombinationValidateJoinRespDTO() |
| 228 | .setActivityId(keyValue.getKey().getId()) | 253 | .setActivityId(keyValue.getKey().getId()) |
| 229 | .setName(keyValue.getKey().getName()) | 254 | .setName(keyValue.getKey().getName()) |
| @@ -282,4 +307,59 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -282,4 +307,59 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 282 | return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); | 307 | return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); |
| 283 | } | 308 | } |
| 284 | 309 | ||
| 310 | + @Override | ||
| 311 | + public CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id) { | ||
| 312 | + return recordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id); | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + @Override | ||
| 316 | + @Transactional(rollbackFor = Exception.class) | ||
| 317 | + public void cancelCombinationRecord(Long userId, Long id, Long headId) { | ||
| 318 | + // 删除记录 | ||
| 319 | + recordMapper.deleteById(id); | ||
| 320 | + | ||
| 321 | + // 需要更新的记录 | ||
| 322 | + List<CombinationRecordDO> updateRecords = new ArrayList<>(); | ||
| 323 | + // 如果它是团长,则顺序(下单时间)继承 | ||
| 324 | + if (Objects.equals(headId, CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长 | ||
| 325 | + // 团员 | ||
| 326 | + List<CombinationRecordDO> list = getCombinationRecordListByHeadId(id); | ||
| 327 | + if (CollUtil.isEmpty(list)) { | ||
| 328 | + return; | ||
| 329 | + } | ||
| 330 | + // 按照创建时间升序排序 | ||
| 331 | + List<CombinationRecordDO> recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime); | ||
| 332 | + CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位 | ||
| 333 | + recordsSort.forEach(item -> { | ||
| 334 | + CombinationRecordDO recordDO = new CombinationRecordDO(); | ||
| 335 | + recordDO.setId(item.getId()); | ||
| 336 | + if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长 | ||
| 337 | + recordDO.setHeadId(CombinationRecordDO.HEAD_ID_GROUP); | ||
| 338 | + } else { | ||
| 339 | + recordDO.setHeadId(newHead.getId()); | ||
| 340 | + } | ||
| 341 | + recordDO.setUserCount(recordsSort.size()); | ||
| 342 | + updateRecords.add(recordDO); | ||
| 343 | + }); | ||
| 344 | + } else { // 情况二:团员 | ||
| 345 | + // 团长 | ||
| 346 | + CombinationRecordDO recordHead = recordMapper.selectById(headId); | ||
| 347 | + // 团员 | ||
| 348 | + List<CombinationRecordDO> records = getCombinationRecordListByHeadId(headId); | ||
| 349 | + if (CollUtil.isEmpty(records)) { | ||
| 350 | + return; | ||
| 351 | + } | ||
| 352 | + records.add(recordHead); // 加入团长,团长数据也需要更新 | ||
| 353 | + records.forEach(item -> { | ||
| 354 | + CombinationRecordDO recordDO = new CombinationRecordDO(); | ||
| 355 | + recordDO.setId(item.getId()); | ||
| 356 | + recordDO.setUserCount(records.size()); | ||
| 357 | + updateRecords.add(recordDO); | ||
| 358 | + }); | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | + // 更新拼团记录 | ||
| 362 | + recordMapper.updateBatch(updateRecords); | ||
| 363 | + } | ||
| 364 | + | ||
| 285 | } | 365 | } |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java
| @@ -30,15 +30,6 @@ public interface TradeOrderApi { | @@ -30,15 +30,6 @@ public interface TradeOrderApi { | ||
| 30 | */ | 30 | */ |
| 31 | TradeOrderRespDTO getOrder(Long id); | 31 | TradeOrderRespDTO getOrder(Long id); |
| 32 | 32 | ||
| 33 | - // TODO 芋艿:看看是不是可以删除掉; | ||
| 34 | - /** | ||
| 35 | - * 获取订单状态 | ||
| 36 | - * | ||
| 37 | - * @param id 订单编号 | ||
| 38 | - * @return 订单状态 | ||
| 39 | - */ | ||
| 40 | - Integer getOrderStatus(Long id); | ||
| 41 | - | ||
| 42 | /** | 33 | /** |
| 43 | * 获取订单统计 | 34 | * 获取订单统计 |
| 44 | * | 35 | * |
| @@ -48,4 +39,22 @@ public interface TradeOrderApi { | @@ -48,4 +39,22 @@ public interface TradeOrderApi { | ||
| 48 | */ | 39 | */ |
| 49 | TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); | 40 | TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); |
| 50 | 41 | ||
| 42 | + /** | ||
| 43 | + * 更新拼团相关信息到订单 | ||
| 44 | + * | ||
| 45 | + * @param orderId 订单编号 | ||
| 46 | + * @param activityId 拼团活动编号 | ||
| 47 | + * @param combinationRecordId 拼团记录编号 | ||
| 48 | + * @param headId 团长编号 | ||
| 49 | + */ | ||
| 50 | + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 取消支付订单 | ||
| 54 | + * | ||
| 55 | + * @param userId 用户编号 | ||
| 56 | + * @param orderId 订单编号 | ||
| 57 | + */ | ||
| 58 | + void cancelPaidOrder(Long userId, Long orderId); | ||
| 59 | + | ||
| 51 | } | 60 | } |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java
| 1 | package cn.iocoder.yudao.module.trade.enums.order; | 1 | package cn.iocoder.yudao.module.trade.enums.order; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ObjectUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | 4 | import cn.iocoder.yudao.framework.common.core.IntArrayValuable; |
| 4 | import lombok.Getter; | 5 | import lombok.Getter; |
| 5 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
| @@ -37,4 +38,20 @@ public enum TradeOrderTypeEnum implements IntArrayValuable { | @@ -37,4 +38,20 @@ public enum TradeOrderTypeEnum implements IntArrayValuable { | ||
| 37 | return ARRAYS; | 38 | return ARRAYS; |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 41 | + public static boolean isNormal(Integer type) { | ||
| 42 | + return ObjectUtil.equal(type, NORMAL.getType()); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public static boolean isSeckill(Integer type) { | ||
| 46 | + return ObjectUtil.equal(type, SECKILL.getType()); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public static boolean isBargain(Integer type) { | ||
| 50 | + return ObjectUtil.equal(type, BARGAIN.getType()); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public static boolean isCombination(Integer type) { | ||
| 54 | + return ObjectUtil.equal(type, COMBINATION.getType()); | ||
| 55 | + } | ||
| 56 | + | ||
| 40 | } | 57 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java
| @@ -3,20 +3,16 @@ package cn.iocoder.yudao.module.trade.api.order; | @@ -3,20 +3,16 @@ package cn.iocoder.yudao.module.trade.api.order; | ||
| 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 4 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; | 4 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; |
| 5 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | 5 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 6 | -import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | ||
| 7 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; | 6 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; |
| 7 | +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; | ||
| 8 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 9 | import org.springframework.validation.annotation.Validated; | 9 | import org.springframework.validation.annotation.Validated; |
| 10 | 10 | ||
| 11 | import javax.annotation.Resource; | 11 | import javax.annotation.Resource; |
| 12 | - | ||
| 13 | import java.time.LocalDateTime; | 12 | import java.time.LocalDateTime; |
| 14 | import java.util.Collection; | 13 | import java.util.Collection; |
| 15 | import java.util.List; | 14 | import java.util.List; |
| 16 | 15 | ||
| 17 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 18 | -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; | ||
| 19 | - | ||
| 20 | /** | 16 | /** |
| 21 | * 订单 API 接口实现类 | 17 | * 订单 API 接口实现类 |
| 22 | * | 18 | * |
| @@ -28,6 +24,8 @@ public class TradeOrderApiImpl implements TradeOrderApi { | @@ -28,6 +24,8 @@ public class TradeOrderApiImpl implements TradeOrderApi { | ||
| 28 | 24 | ||
| 29 | @Resource | 25 | @Resource |
| 30 | private TradeOrderQueryService tradeOrderQueryService; | 26 | private TradeOrderQueryService tradeOrderQueryService; |
| 27 | + @Resource | ||
| 28 | + private TradeOrderUpdateService tradeOrderUpdateService; | ||
| 31 | 29 | ||
| 32 | @Override | 30 | @Override |
| 33 | public List<TradeOrderRespDTO> getOrderList(Collection<Long> ids) { | 31 | public List<TradeOrderRespDTO> getOrderList(Collection<Long> ids) { |
| @@ -40,17 +38,18 @@ public class TradeOrderApiImpl implements TradeOrderApi { | @@ -40,17 +38,18 @@ public class TradeOrderApiImpl implements TradeOrderApi { | ||
| 40 | } | 38 | } |
| 41 | 39 | ||
| 42 | @Override | 40 | @Override |
| 43 | - public Integer getOrderStatus(Long id) { | ||
| 44 | - TradeOrderDO order = tradeOrderQueryService.getOrder(id); | ||
| 45 | - if (order == null) { | ||
| 46 | - throw exception(ORDER_NOT_FOUND); | ||
| 47 | - } | ||
| 48 | - return order.getStatus(); | 41 | + public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { |
| 42 | + return tradeOrderQueryService.getOrderSummary(beginTime, endTime); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { | ||
| 47 | + tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); | ||
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | @Override | 50 | @Override |
| 52 | - public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { | ||
| 53 | - return tradeOrderQueryService.getOrderSummary(beginTime, endTime); | 51 | + public void cancelPaidOrder(Long userId, Long orderId) { |
| 52 | + tradeOrderUpdateService.cancelPaidOrder(userId, orderId); | ||
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | } | 55 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java
| @@ -52,7 +52,6 @@ public class AppTradeOrderSettlementReqVO { | @@ -52,7 +52,6 @@ public class AppTradeOrderSettlementReqVO { | ||
| 52 | private Long seckillActivityId; | 52 | private Long seckillActivityId; |
| 53 | 53 | ||
| 54 | // ========== 拼团活动相关字段 ========== | 54 | // ========== 拼团活动相关字段 ========== |
| 55 | - // TODO @puhui999:是不是拼团记录的编号哈? | ||
| 56 | @Schema(description = "拼团活动编号", example = "1024") | 55 | @Schema(description = "拼团活动编号", example = "1024") |
| 57 | private Long combinationActivityId; | 56 | private Long combinationActivityId; |
| 58 | 57 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
| @@ -170,4 +170,22 @@ public interface TradeOrderUpdateService { | @@ -170,4 +170,22 @@ public interface TradeOrderUpdateService { | ||
| 170 | */ | 170 | */ |
| 171 | int createOrderItemCommentBySystem(); | 171 | int createOrderItemCommentBySystem(); |
| 172 | 172 | ||
| 173 | + /** | ||
| 174 | + * 更新拼团相关信息到订单 | ||
| 175 | + * | ||
| 176 | + * @param orderId 订单编号 | ||
| 177 | + * @param activityId 拼团活动编号 | ||
| 178 | + * @param combinationRecordId 拼团记录编号 | ||
| 179 | + * @param headId 团长编号 | ||
| 180 | + */ | ||
| 181 | + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * 取消支付订单 | ||
| 185 | + * | ||
| 186 | + * @param userId 用户编号 | ||
| 187 | + * @param orderId 订单编号 | ||
| 188 | + */ | ||
| 189 | + void cancelPaidOrder(Long userId, Long orderId); | ||
| 190 | + | ||
| 173 | } | 191 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -250,7 +250,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -250,7 +250,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 250 | /** | 250 | /** |
| 251 | * 订单创建前,执行前置逻辑 | 251 | * 订单创建前,执行前置逻辑 |
| 252 | * | 252 | * |
| 253 | - * @param order 订单 | 253 | + * @param order 订单 |
| 254 | * @param orderItems 订单项 | 254 | * @param orderItems 订单项 |
| 255 | */ | 255 | */ |
| 256 | private void beforeCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | 256 | private void beforeCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| @@ -267,9 +267,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -267,9 +267,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 267 | * <p> | 267 | * <p> |
| 268 | * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 | 268 | * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 |
| 269 | * | 269 | * |
| 270 | - * @param order 订单 | ||
| 271 | - * @param orderItems 订单项 | ||
| 272 | - * @param createReqVO 创建订单请求 | 270 | + * @param order 订单 |
| 271 | + * @param orderItems 订单项 | ||
| 272 | + * @param createReqVO 创建订单请求 | ||
| 273 | */ | 273 | */ |
| 274 | private void afterCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems, | 274 | private void afterCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems, |
| 275 | AppTradeOrderCreateReqVO createReqVO) { | 275 | AppTradeOrderCreateReqVO createReqVO) { |
| @@ -331,7 +331,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -331,7 +331,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | // 3、订单支付成功后 | 333 | // 3、订单支付成功后 |
| 334 | - tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order)); | 334 | + List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id); |
| 335 | + tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order, orderItems)); | ||
| 335 | 336 | ||
| 336 | // 4.1 增加用户积分(赠送) | 337 | // 4.1 增加用户积分(赠送) |
| 337 | addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); | 338 | addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); |
| @@ -624,12 +625,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -624,12 +625,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 624 | throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); | 625 | throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); |
| 625 | } | 626 | } |
| 626 | 627 | ||
| 627 | - // 2. TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 | ||
| 628 | - tradeOrderHandlers.forEach(handler -> handler.cancelOrder()); | ||
| 629 | - | ||
| 630 | - // 3. 回滚库存 | ||
| 631 | List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id); | 628 | List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id); |
| 629 | + // 3. 回滚库存 | ||
| 632 | productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); | 630 | productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); |
| 631 | + // 3.1、 活动相关的回滚 | ||
| 632 | + tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, orderItems)); | ||
| 633 | 633 | ||
| 634 | // 4. 回滚优惠券 | 634 | // 4. 回滚优惠券 |
| 635 | if (order.getCouponId() != null && order.getCouponId() > 0) { | 635 | if (order.getCouponId() != null && order.getCouponId() > 0) { |
| @@ -805,10 +805,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -805,10 +805,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 805 | // 2.2 如果全部退款,则进行取消订单 | 805 | // 2.2 如果全部退款,则进行取消订单 |
| 806 | getSelf().cancelOrderByAfterSale(order, orderRefundPrice); | 806 | getSelf().cancelOrderByAfterSale(order, orderRefundPrice); |
| 807 | 807 | ||
| 808 | - // TODO @puhui999:活动相关的回滚 | ||
| 809 | 808 | ||
| 810 | // 3. 回滚库存 | 809 | // 3. 回滚库存 |
| 811 | productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(Collections.singletonList(orderItem))); | 810 | productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(Collections.singletonList(orderItem))); |
| 811 | + // 3.1、 活动相关的回滚 | ||
| 812 | + tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, Collections.singletonList(orderItem))); | ||
| 812 | 813 | ||
| 813 | // 4.1 回滚积分:扣减用户积分(赠送的) | 814 | // 4.1 回滚积分:扣减用户积分(赠送的) |
| 814 | reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId()); | 815 | reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId()); |
| @@ -908,6 +909,25 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -908,6 +909,25 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 908 | return count; | 909 | return count; |
| 909 | } | 910 | } |
| 910 | 911 | ||
| 912 | + @Override | ||
| 913 | + @Transactional(rollbackFor = Exception.class) | ||
| 914 | + public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { | ||
| 915 | + tradeOrderMapper.updateById( | ||
| 916 | + new TradeOrderDO().setId(orderId).setCombinationActivityId(activityId) | ||
| 917 | + .setCombinationRecordId(combinationRecordId).setCombinationHeadId(headId)); | ||
| 918 | + } | ||
| 919 | + | ||
| 920 | + @Override | ||
| 921 | + @Transactional(rollbackFor = Exception.class) | ||
| 922 | + public void cancelPaidOrder(Long userId, Long orderId) { | ||
| 923 | + TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); | ||
| 924 | + if (order == null) { | ||
| 925 | + throw exception(ORDER_NOT_FOUND); | ||
| 926 | + } | ||
| 927 | + | ||
| 928 | + cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL); | ||
| 929 | + } | ||
| 930 | + | ||
| 911 | /** | 931 | /** |
| 912 | * 创建单个订单的评论 | 932 | * 创建单个订单的评论 |
| 913 | * | 933 | * |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java
| 1 | package cn.iocoder.yudao.module.trade.service.order.handler; | 1 | package cn.iocoder.yudao.module.trade.service.order.handler; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; | 3 | import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; |
| 5 | import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; | 4 | import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; |
| 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| @@ -26,9 +25,10 @@ public class TradeBargainHandler implements TradeOrderHandler { | @@ -26,9 +25,10 @@ public class TradeBargainHandler implements TradeOrderHandler { | ||
| 26 | 25 | ||
| 27 | @Override | 26 | @Override |
| 28 | public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | 27 | public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 29 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { | 28 | + if (TradeOrderTypeEnum.isBargain(order.getType())) { |
| 30 | return; | 29 | return; |
| 31 | } | 30 | } |
| 31 | + | ||
| 32 | // 扣减砍价活动的库存 | 32 | // 扣减砍价活动的库存 |
| 33 | bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), | 33 | bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), |
| 34 | -orderItems.get(0).getCount()); | 34 | -orderItems.get(0).getCount()); |
| @@ -36,13 +36,20 @@ public class TradeBargainHandler implements TradeOrderHandler { | @@ -36,13 +36,20 @@ public class TradeBargainHandler implements TradeOrderHandler { | ||
| 36 | 36 | ||
| 37 | @Override | 37 | @Override |
| 38 | public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | 38 | public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 39 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { | 39 | + if (TradeOrderTypeEnum.isBargain(order.getType())) { |
| 40 | return; | 40 | return; |
| 41 | } | 41 | } |
| 42 | + | ||
| 42 | // 记录砍价记录对应的订单编号 | 43 | // 记录砍价记录对应的订单编号 |
| 43 | bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId()); | 44 | bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId()); |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | - // TODO 芋艿:取消订单时,需要增加库存 | 47 | + @Override |
| 48 | + public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | ||
| 49 | + if (TradeOrderTypeEnum.isBargain(order.getType())) { | ||
| 50 | + return; | ||
| 51 | + } | ||
| 52 | + // TODO 芋艿:取消订单时,需要增加库存 | ||
| 53 | + } | ||
| 47 | 54 | ||
| 48 | } | 55 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java
| 1 | package cn.iocoder.yudao.module.trade.service.order.handler; | 1 | package cn.iocoder.yudao.module.trade.service.order.handler; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.lang.Assert; | 3 | import cn.hutool.core.lang.Assert; |
| 4 | -import cn.hutool.core.util.ObjectUtil; | ||
| 5 | import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; | 4 | import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; |
| 6 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | 5 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| @@ -26,7 +25,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { | @@ -26,7 +25,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { | ||
| 26 | @Override | 25 | @Override |
| 27 | public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | 26 | public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 28 | // 如果不是拼团订单则结束 | 27 | // 如果不是拼团订单则结束 |
| 29 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 28 | + if (TradeOrderTypeEnum.isCombination(order.getType())) { |
| 30 | return; | 29 | return; |
| 31 | } | 30 | } |
| 32 | Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); | 31 | Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); |
| @@ -34,33 +33,30 @@ public class TradeCombinationHandler implements TradeOrderHandler { | @@ -34,33 +33,30 @@ public class TradeCombinationHandler implements TradeOrderHandler { | ||
| 34 | // 获取商品信息 | 33 | // 获取商品信息 |
| 35 | TradeOrderItemDO item = orderItems.get(0); | 34 | TradeOrderItemDO item = orderItems.get(0); |
| 36 | // 校验是否满足拼团活动相关限制 | 35 | // 校验是否满足拼团活动相关限制 |
| 37 | - combinationRecordApi.validateCombinationRecord(order.getCombinationActivityId(), order.getUserId(), item.getSkuId(), item.getCount()); | 36 | + combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(), |
| 37 | + order.getCombinationHeadId(), item.getSkuId(), item.getCount()); | ||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | @Override | 40 | @Override |
| 41 | - public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | 41 | + public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 42 | // 如果不是拼团订单则结束 | 42 | // 如果不是拼团订单则结束 |
| 43 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 43 | + if (TradeOrderTypeEnum.isCombination(order.getType())) { |
| 44 | return; | 44 | return; |
| 45 | } | 45 | } |
| 46 | + | ||
| 46 | Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); | 47 | Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); |
| 47 | 48 | ||
| 48 | // 获取商品信息 | 49 | // 获取商品信息 |
| 49 | TradeOrderItemDO item = orderItems.get(0); | 50 | TradeOrderItemDO item = orderItems.get(0); |
| 50 | // 创建拼团记录 | 51 | // 创建拼团记录 |
| 51 | - // TODO puhui:这里应该先不创建;等支付好,才去创建;另外,创建好后,需要更新编号到订单; | ||
| 52 | combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); | 52 | combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | @Override | 55 | @Override |
| 56 | - public void afterPayOrder(TradeOrderDO order) { | ||
| 57 | - // 如果不是拼团订单则结束 | ||
| 58 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 56 | + public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 57 | + if (TradeOrderTypeEnum.isCombination(order.getType())) { | ||
| 59 | return; | 58 | return; |
| 60 | } | 59 | } |
| 61 | - | ||
| 62 | - // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | ||
| 63 | - combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), order.getPayTime()); | ||
| 64 | } | 60 | } |
| 65 | 61 | ||
| 66 | } | 62 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java
| @@ -33,12 +33,18 @@ public interface TradeOrderHandler { | @@ -33,12 +33,18 @@ public interface TradeOrderHandler { | ||
| 33 | * 支付订单后 | 33 | * 支付订单后 |
| 34 | * | 34 | * |
| 35 | * @param order 订单 | 35 | * @param order 订单 |
| 36 | + * @param orderItems 订单项 | ||
| 36 | */ | 37 | */ |
| 37 | - default void afterPayOrder(TradeOrderDO order) {} | 38 | + default void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 39 | + } | ||
| 38 | 40 | ||
| 39 | /** | 41 | /** |
| 40 | * 订单取消 | 42 | * 订单取消 |
| 43 | + * | ||
| 44 | + * @param order 订单 | ||
| 45 | + * @param orderItems 订单项 | ||
| 41 | */ | 46 | */ |
| 42 | - default void cancelOrder() {} | 47 | + default void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 48 | + } | ||
| 43 | 49 | ||
| 44 | } | 50 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java
| 1 | package cn.iocoder.yudao.module.trade.service.order.handler; | 1 | package cn.iocoder.yudao.module.trade.service.order.handler; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; | 3 | import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; |
| 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 4 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| @@ -23,12 +22,21 @@ public class TradeSeckillHandler implements TradeOrderHandler { | @@ -23,12 +22,21 @@ public class TradeSeckillHandler implements TradeOrderHandler { | ||
| 23 | 22 | ||
| 24 | @Override | 23 | @Override |
| 25 | public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | 24 | public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| 26 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { | 25 | + if (TradeOrderTypeEnum.isSeckill(order.getType())) { |
| 27 | return; | 26 | return; |
| 28 | } | 27 | } |
| 28 | + | ||
| 29 | // 扣减秒杀活动的库存 | 29 | // 扣减秒杀活动的库存 |
| 30 | seckillActivityApi.updateSeckillStock(order.getSeckillActivityId(), | 30 | seckillActivityApi.updateSeckillStock(order.getSeckillActivityId(), |
| 31 | orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); | 31 | orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | + @Override | ||
| 35 | + public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | ||
| 36 | + if (TradeOrderTypeEnum.isSeckill(order.getType())) { | ||
| 37 | + return; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + | ||
| 34 | } | 42 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java
| @@ -68,7 +68,6 @@ public class TradePriceCalculateReqBO { | @@ -68,7 +68,6 @@ public class TradePriceCalculateReqBO { | ||
| 68 | private Long seckillActivityId; | 68 | private Long seckillActivityId; |
| 69 | 69 | ||
| 70 | // ========== 拼团活动相关字段 ========== | 70 | // ========== 拼团活动相关字段 ========== |
| 71 | - // TODO @puhui999:是不是拼团记录的编号哈? | ||
| 72 | /** | 71 | /** |
| 73 | * 拼团活动编号 | 72 | * 拼团活动编号 |
| 74 | */ | 73 | */ |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java
| @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; | @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; | ||
| 13 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 14 | 14 | ||
| 15 | // TODO @puhui999:单测可以后补下 | 15 | // TODO @puhui999:单测可以后补下 |
| 16 | + | ||
| 16 | /** | 17 | /** |
| 17 | * 拼团活动的 {@link TradePriceCalculator} 实现类 | 18 | * 拼团活动的 {@link TradePriceCalculator} 实现类 |
| 18 | * | 19 | * |
| @@ -35,7 +36,7 @@ public class TradeCombinationActivityPriceCalculator implements TradePriceCalcul | @@ -35,7 +36,7 @@ public class TradeCombinationActivityPriceCalculator implements TradePriceCalcul | ||
| 35 | // 2. 校验是否可以参与拼团 | 36 | // 2. 校验是否可以参与拼团 |
| 36 | TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0); | 37 | TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0); |
| 37 | CombinationValidateJoinRespDTO combinationActivity = combinationRecordApi.validateJoinCombination( | 38 | CombinationValidateJoinRespDTO combinationActivity = combinationRecordApi.validateJoinCombination( |
| 38 | - param.getCombinationActivityId(), param.getUserId(), | 39 | + param.getUserId(), param.getCombinationActivityId(), param.getCombinationHeadId(), |
| 39 | orderItem.getSkuId(), orderItem.getCount()); | 40 | orderItem.getSkuId(), orderItem.getCount()); |
| 40 | 41 | ||
| 41 | // 3.1 记录优惠明细 | 42 | // 3.1 记录优惠明细 |