promotion:合并最新代码

This commit is contained in:
YunaiV 2023-10-07 23:00:13 +08:00
commit 6a38da4ad9
23 changed files with 408 additions and 220 deletions

View File

@ -25,6 +25,14 @@ public class CollectionUtils {
return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty);
}
public static <T, U extends Comparable<? super U>> List<T> sortedAsc(
Collection<T> from, Function<? super T, ? extends U> keyExtractor) {
// 按照升序排序
return from.stream()
.sorted(Comparator.comparing(keyExtractor))
.collect(Collectors.toList());
}
public static <T> boolean anyMatch(Collection<T> from, Predicate<T> predicate) {
return from.stream().anyMatch(predicate);
}

View File

@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
import javax.validation.Valid;
import java.time.LocalDateTime;
// TODO @芋艿后面也再撸撸这几个接口
@ -18,12 +17,13 @@ public interface CombinationRecordApi {
/**
* 校验是否满足拼团条件
*
* @param activityId 活动编号
* @param userId 用户编号
* @param activityId 活动编号
* @param headId 团长编号
* @param skuId sku 编号
* @param count 数量
*/
void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count);
void validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count);
/**
* 创建开团记录
@ -41,14 +41,6 @@ public interface CombinationRecordApi {
*/
boolean isCombinationRecordSuccess(Long userId, Long orderId);
/**
* 更新拼团状态为成功
*
* @param userId 用户编号
* @param orderId 订单编号
*/
void updateRecordStatusToSuccess(Long userId, Long orderId);
/**
* 更新拼团状态为失败
*
@ -57,27 +49,18 @@ public interface CombinationRecordApi {
*/
void updateRecordStatusToFailed(Long userId, Long orderId);
/**
* 更新拼团状态为 进行中
*
* @param userId 用户编号
* @param orderId 订单编号
* @param startTime 开始时间
*/
void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime);
/**
* 下单前校验是否满足拼团活动条件
*
* 如果校验失败则抛出业务异常
*
* @param activityId 活动编号
* @param userId 用户编号
* @param activityId 活动编号
* @param headId 团长编号
* @param skuId sku 编号
* @param count 数量
* @return 拼团信息
*/
// TODO @puhuiuserId 放最前面然后应该还有个 headId 参数
CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count);
CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count);
}

View File

@ -80,7 +80,7 @@ public interface ErrorCodeConstants {
ErrorCode COMBINATION_RECORD_EXISTS = new ErrorCode(1_013_011_001, "拼团失败,已参与过该拼团");
ErrorCode COMBINATION_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1_013_011_002, "拼团失败,父拼团不存在");
ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1_013_011_003, "拼团失败,拼团人数已满");
ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1_013_011_004, "拼团失败,已参与其它拼团");
ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1_013_011_004, "拼团失败,原因:存在该活动正在进行的拼团记录");
ErrorCode COMBINATION_RECORD_FAILED_TIME_NOT_START = new ErrorCode(1_013_011_005, "拼团失败,活动未开始");
ErrorCode COMBINATION_RECORD_FAILED_TIME_END = new ErrorCode(1_013_011_006, "拼团失败,活动已经结束");
ErrorCode COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED = new ErrorCode(1_013_011_007, "拼团失败,原因:单次限购超出");

View File

@ -40,4 +40,8 @@ public enum CombinationRecordStatusEnum implements IntArrayValuable {
return ObjectUtil.equal(status, SUCCESS.getStatus());
}
public static boolean isInProgress(Integer status) {
return ObjectUtil.equal(status, IN_PROGRESS.getStatus());
}
}

View File

@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.promotion.api.combination;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_NOT_EXISTS;
/**
* 拼团活动 API 实现类
@ -21,8 +24,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
private CombinationRecordService recordService;
@Override
public void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count) {
recordService.validateCombinationRecord(activityId, userId, skuId, count);
public void validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
recordService.validateCombinationRecord(userId, activityId, headId, skuId, count);
}
@Override
@ -32,12 +35,12 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
@Override
public boolean isCombinationRecordSuccess(Long userId, Long orderId) {
return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus());
}
CombinationRecordDO combinationRecord = recordService.getCombinationRecord(userId, orderId);
if (combinationRecord == null) {
throw exception(COMBINATION_RECORD_NOT_EXISTS);
}
@Override
public void updateRecordStatusToSuccess(Long userId, Long orderId) {
recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId);
return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus());
}
@Override
@ -46,14 +49,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
}
@Override
public void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime) {
recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordStatusEnum.IN_PROGRESS.getStatus(),
userId, orderId, startTime);
}
@Override
public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) {
return recordService.validateJoinCombination(activityId, userId, skuId, count);
public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
return recordService.validateJoinCombination(userId, activityId, headId, skuId, count);
}
}

View File

@ -48,8 +48,9 @@ public class CombinationActivityBaseVO {
@NotNull(message = "开团人数不能为空")
private Integer userSize;
@Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Boolean virtualGroup = false; // TODO @puhui999这个字段界面没做呀
@Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
@NotNull(message = "虚拟成团不能为空")
private Boolean virtualGroup;
@Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "限制时长不能为空")

View File

@ -6,11 +6,14 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO;
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -35,6 +38,9 @@ public class AppCombinationRecordController {
@Resource
private CombinationRecordService combinationRecordService;
@Resource
@Lazy
private TradeOrderApi tradeOrderApi;
@GetMapping("/get-summary")
@Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页")
@ -96,9 +102,26 @@ public class AppCombinationRecordController {
return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords));
}
// TODO @puhui新增一个取消拼团的接口cancel
// 1. 需要先校验拼团记录未完成
// 2. Order 那增加一个 cancelPaidOrder 接口用于取消已支付的订单
// 3. order 完成后取消拼团记录另外如果它是团长则顺序下单时间继承
@GetMapping("/cancel")
@Operation(summary = "取消拼团")
@Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024")
public CommonResult<Boolean> cancelCombinationRecord(@RequestParam("id") Long id) {
Long userId = getLoginUserId();
// 1查找这条拼团记录
CombinationRecordDO record = combinationRecordService.getCombinationRecordByIdAndUser(userId, id);
if (record == null) {
return success(Boolean.FALSE);
}
// 1.1需要先校验拼团记录未完成
if (!CombinationRecordStatusEnum.isInProgress(record.getStatus())) {
return success(Boolean.FALSE);
}
// 2. 取消已支付的订单
tradeOrderApi.cancelPaidOrder(userId, record.getOrderId());
// 3. 取消拼团记录
combinationRecordService.cancelCombinationRecord(userId, record.getId(), record.getHeadId());
return success(Boolean.TRUE);
}
}

View File

@ -22,11 +22,13 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap
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;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@ -110,14 +112,19 @@ public interface CombinationActivityConvert {
CombinationActivityDO activity, MemberUserRespDTO user,
ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
return convert(reqDTO)
.setCount(reqDTO.getCount()).setUserCount(1)
.setHeadId(reqDTO.getHeadId()) // 显示性再设置一下
.setCount(reqDTO.getCount())
.setVirtualGroup(false)
.setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中
.setStartTime(LocalDateTime.now())
.setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration()))
.setUserSize(activity.getUserSize())
.setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录
.setNickname(user.getNickname())
.setAvatar(user.getAvatar())
.setSpuName(spu.getName())
.setPicUrl(sku.getPicUrl());
}
List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list);

View File

@ -32,12 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
CombinationRecordDO::getOrderId, orderId);
}
default List<CombinationRecordDO> selectListByUserIdAndStatus(Long userId, Integer status) {
return selectList(new LambdaQueryWrapperX<CombinationRecordDO>()
.eq(CombinationRecordDO::getUserId, userId)
.eq(CombinationRecordDO::getStatus, status));
}
/**
* 查询拼团记录
*
@ -106,7 +100,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
// 转换数据
return CollectionUtils.convertMap(result,
record -> MapUtil.getLong(record, "activityId"),
record -> MapUtil.getInt(record, "recordCount" ));
record -> MapUtil.getInt(record, "recordCount"));
}
static LocalDateTime[] builderQueryTime(Integer dateType) {

View File

@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import javax.annotation.Nullable;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -32,16 +31,18 @@ public interface CombinationRecordService {
void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId);
/**
* 校验是否满足拼团条件
* 如果不满足会抛出异常
* 下单前校验是否满足拼团活动条件
*
* 如果校验失败则抛出业务异常
*
* @param activityId 活动编号
* @param userId 用户编号
* @param activityId 活动编号
* @param headId 团长编号
* @param skuId sku 编号
* @param count 数量
* @return 返回拼团活动和拼团活动商品
* @return 拼团信息
*/
KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count);
KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count);
/**
* 创建拼团记录
@ -50,16 +51,6 @@ public interface CombinationRecordService {
*/
void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
/**
* 更新拼团状态和开始时间
*
* @param status 状态
* @param userId 用户编号
* @param orderId 订单编号
* @param startTime 开始时间
*/
void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime);
/**
* 获得拼团记录
*
@ -83,13 +74,14 @@ public interface CombinationRecordService {
*
* 如果校验失败则抛出业务异常
*
* @param activityId 活动编号
* @param userId 用户编号
* @param activityId 活动编号
* @param headId 团长编号
* @param skuId sku 编号
* @param count 数量
* @return 拼团信息
*/
CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count);
CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count);
/**
* 获取所有拼团记录数
@ -166,12 +158,32 @@ public interface CombinationRecordService {
* 拼团活动获得拼团记录数量 Map
*
* @param activityIds 活动记录编号数组
* @param status 拼团状态允许空
* @param headId 团长编号允许空目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 可以设置
* @param status 拼团状态允许空
* @param headId 团长编号允许空目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 可以设置
* @return 拼团记录数量 Map
*/
Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds,
@Nullable Integer status,
@Nullable Long headId);
/**
* 获取拼团记录
*
* @param userId 用户编号
* @param id 拼团记录编号
* @return 拼团记录
*/
CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id);
/**
* 取消拼团
*
* @param userId 用户编号
* @param id 拼团记录编号
* @param headId 团长编号
*/
void cancelCombinationRecord(Long userId, Long id, Long headId);
}

View File

@ -1,11 +1,10 @@
package cn.iocoder.yudao.module.promotion.service.combination;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
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.api.sku.ProductSkuApi;
@ -22,7 +21,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR
import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -30,13 +28,12 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
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.afterNow;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
// TODO 芋艿等拼团记录做完完整 review
@ -79,31 +76,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
recordMapper.updateById(record);
}
// TODO @芋艿在详细预览下
@Override
@Transactional(rollbackFor = Exception.class)
public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) {
CombinationRecordDO record = validateCombinationRecord(userId, orderId);
// 更新状态
record.setStatus(status);
// 更新开始时间
record.setStartTime(startTime);
recordMapper.updateById(record);
// 更新拼团参入人数
List<CombinationRecordDO> records = recordMapper.selectListByHeadIdAndStatus(record.getHeadId(), status);
if (CollUtil.isNotEmpty(records)) {
records.forEach(item -> {
item.setUserCount(records.size());
// 校验拼团是否满足要求
if (ObjectUtil.equal(records.size(), record.getUserSize())) {
item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus());
}
});
recordMapper.updateBatch(records);
}
}
private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) {
// 校验拼团是否存在
CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId);
@ -116,54 +88,76 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
// TODO @芋艿在详细预览下
@Override
public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(
Long activityId, Long userId, Long skuId, Integer count) {
// 1.1 校验拼团活动是否存在
Long userId, Long activityId, Long headId, Long skuId, Integer count) {
// 1 校验拼团活动是否存在
CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId);
// 1.2 校验活动是否开启
if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
// 1.1 校验活动是否开启
if (ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
}
// 2 校验是否超出单次限购数量
// 1.2校验活动开始时间
if (afterNow(activity.getStartTime())) {
throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START);
}
// 1.3 校验是否超出单次限购数量
if (count > activity.getSingleLimitCount()) {
throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
}
// 2.1校验活动商品是否存在
// 2父拼团是否存在,是否已经满了
if (headId != null) {
// 2.1查询进行中的父拼团
CombinationRecordDO record = recordMapper.selectOneByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
if (record == null) {
throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS);
}
// 2.2校验拼团是否满足要求
if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) {
throw exception(COMBINATION_RECORD_USER_FULL);
}
// 2.3校验拼团是否过期有父拼团的时候只校验父拼团的过期时间
if (beforeNow(record.getExpireTime())) {
throw exception(COMBINATION_RECORD_FAILED_TIME_END);
}
} else {
// 3校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束)
if (beforeNow(activity.getEndTime())) {
throw exception(COMBINATION_RECORD_FAILED_TIME_END);
}
}
// 4校验活动商品是否存在
CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId);
if (product == null) {
throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS);
}
// 2.2校验 sku 是否存在
// 5校验 sku 是否存在
ProductSkuRespDTO sku = productSkuApi.getSku(skuId);
if (sku == null) {
throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS);
}
// 2.3 校验库存是否充足
// 5.1校验库存是否充足
if (count > sku.getStock()) {
throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL);
}
// 3校验是否有拼团记录
// 6校验是否有拼团记录
List<CombinationRecordDO> recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId);
if (CollUtil.isEmpty(recordList)) {
return new KeyValue<>(activity, product);
}
// 4校验是否超出总限购数量
// 6.1校验用户是否有该活动正在进行的拼团
List<CombinationRecordDO> filtered = filterList(recordList, record -> CombinationRecordStatusEnum.isInProgress(record.getStatus()));
if (CollUtil.isNotEmpty(filtered)) {
throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED);
}
// 6.2校验是否超出总限购数量
Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount,
item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), i -> i, Integer::sum);
item -> CombinationRecordStatusEnum.isSuccess(item.getStatus())), i -> i, Integer::sum);
if ((sumValue + count) > activity.getTotalLimitCount()) {
throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED);
}
// 5校验拼团记录是否存在未支付的订单如果存在未支付的订单则不允许发起新的拼团
CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null));
if (record == null) {
return new KeyValue<>(activity, product);
}
// 5.1查询关联的订单是否已经支付
// 当前 activityId 已经有未支付的订单不允许在发起新的要么支付要么去掉先
// TODO 芋艿看看是不是可以删除掉
Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId());
if (ObjectUtil.equal(orderStatus, TradeOrderStatusEnum.UNPAID.getStatus())) {
throw exception(COMBINATION_RECORD_FAILED_ORDER_STATUS_UNPAID);
}
return new KeyValue<>(activity, product);
}
@ -173,47 +167,78 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Transactional(rollbackFor = Exception.class)
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
// 1校验拼团活动
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(
reqDTO.getActivityId(), reqDTO.getUserId(), reqDTO.getSkuId(), reqDTO.getCount());
CombinationActivityDO activity = keyValue.getKey();
// 2校验用户是否参加了其它拼团
List<CombinationRecordDO> recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
if (CollUtil.isNotEmpty(recordDOList)) {
throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED);
}
// 3校验活动是否开启
if (!LocalDateTimeUtils.beforeNow(activity.getStartTime())) {
throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START);
}
// 4校验当前活动是否过期
if (LocalDateTime.now().isAfter(activity.getEndTime())) {
throw exception(COMBINATION_RECORD_FAILED_TIME_END);
}
// 5父拼团是否存在,是否已经满了
if (reqDTO.getHeadId() != null) {
// 5.1查询进行中的父拼团
CombinationRecordDO record = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
if (record == null) {
throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS);
}
// 5.2校验拼团是否满足要求
if (ObjectUtil.equal(record.getUserCount(), record.getUserSize())) {
throw exception(COMBINATION_RECORD_USER_FULL);
}
}
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
// 6. 创建拼团记录
// 2. 组合数据创建拼团记录
MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId());
ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
// TODO @puhui999status 未设置headId 未设置
recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku));
CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
recordMapper.insert(recordDO);
// 3如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) {
recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP));
return;
}
// TODO 这里要不要弄成异步的
// 4更新拼团相关信息到订单
updateOrderCombinationInfo(recordDO.getOrderId(), recordDO.getActivityId(), recordDO.getId(), recordDO.getHeadId());
// 4更新拼团记录
updateCombinationRecords(keyValue.getKey(), reqDTO.getHeadId());
}
/**
* 更新拼团相关信息到订单
*
* @param orderId 订单编号
* @param activityId 拼团活动编号
* @param combinationRecordId 拼团记录编号
* @param headId 团长编号
*/
private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) {
tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId);
}
/**
* 更新拼团记录
*
* @param activity 活动
* @param headId 团长编号
*/
private void updateCombinationRecords(CombinationActivityDO activity, Long headId) {
// 团长
CombinationRecordDO recordHead = recordMapper.selectById(headId);
// 团员
List<CombinationRecordDO> records = getCombinationRecordListByHeadId(headId);
// 需要更新的记录
List<CombinationRecordDO> updateRecords = new ArrayList<>();
if (CollUtil.isEmpty(records)) {
return;
}
records.add(recordHead); // 加入团长团长也需要更新
boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize());
records.forEach(item -> {
CombinationRecordDO recordDO = new CombinationRecordDO();
recordDO.setId(item.getId());
recordDO.setUserCount(records.size());
// 校验拼团是否满足要求
if (isEqual) {
recordDO.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus());
}
updateRecords.add(recordDO);
});
recordMapper.updateBatch(updateRecords);
}
@Override
public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) {
// TODO puhui999:这里直接获得不适合调用校验的接口
return validateCombinationRecord(userId, orderId);
return recordMapper.selectByUserIdAndOrderId(userId, orderId);
}
@Override
@ -222,8 +247,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
}
@Override
public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) {
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(activityId, userId, skuId, count);
public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(userId, activityId, headId, skuId, count);
return new CombinationValidateJoinRespDTO()
.setActivityId(keyValue.getKey().getId())
.setName(keyValue.getKey().getName())
@ -282,4 +307,59 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId);
}
@Override
public CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id) {
return recordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelCombinationRecord(Long userId, Long id, Long headId) {
// 删除记录
recordMapper.deleteById(id);
// 需要更新的记录
List<CombinationRecordDO> updateRecords = new ArrayList<>();
// 如果它是团长则顺序下单时间继承
if (Objects.equals(headId, CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一团长
// 团员
List<CombinationRecordDO> list = getCombinationRecordListByHeadId(id);
if (CollUtil.isEmpty(list)) {
return;
}
// 按照创建时间升序排序
List<CombinationRecordDO> recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime);
CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位
recordsSort.forEach(item -> {
CombinationRecordDO recordDO = new CombinationRecordDO();
recordDO.setId(item.getId());
if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长
recordDO.setHeadId(CombinationRecordDO.HEAD_ID_GROUP);
} else {
recordDO.setHeadId(newHead.getId());
}
recordDO.setUserCount(recordsSort.size());
updateRecords.add(recordDO);
});
} else { // 情况二团员
// 团长
CombinationRecordDO recordHead = recordMapper.selectById(headId);
// 团员
List<CombinationRecordDO> records = getCombinationRecordListByHeadId(headId);
if (CollUtil.isEmpty(records)) {
return;
}
records.add(recordHead); // 加入团长团长数据也需要更新
records.forEach(item -> {
CombinationRecordDO recordDO = new CombinationRecordDO();
recordDO.setId(item.getId());
recordDO.setUserCount(records.size());
updateRecords.add(recordDO);
});
}
// 更新拼团记录
recordMapper.updateBatch(updateRecords);
}
}

View File

@ -30,15 +30,6 @@ public interface TradeOrderApi {
*/
TradeOrderRespDTO getOrder(Long id);
// TODO 芋艿看看是不是可以删除掉
/**
* 获取订单状态
*
* @param id 订单编号
* @return 订单状态
*/
Integer getOrderStatus(Long id);
/**
* 获取订单统计
*
@ -48,4 +39,22 @@ public interface TradeOrderApi {
*/
TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime);
/**
* 更新拼团相关信息到订单
*
* @param orderId 订单编号
* @param activityId 拼团活动编号
* @param combinationRecordId 拼团记录编号
* @param headId 团长编号
*/
void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
/**
* 取消支付订单
*
* @param userId 用户编号
* @param orderId 订单编号
*/
void cancelPaidOrder(Long userId, Long orderId);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.trade.enums.order;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@ -37,4 +38,20 @@ public enum TradeOrderTypeEnum implements IntArrayValuable {
return ARRAYS;
}
public static boolean isNormal(Integer type) {
return ObjectUtil.equal(type, NORMAL.getType());
}
public static boolean isSeckill(Integer type) {
return ObjectUtil.equal(type, SECKILL.getType());
}
public static boolean isBargain(Integer type) {
return ObjectUtil.equal(type, BARGAIN.getType());
}
public static boolean isCombination(Integer type) {
return ObjectUtil.equal(type, COMBINATION.getType());
}
}

View File

@ -3,20 +3,16 @@ package cn.iocoder.yudao.module.trade.api.order;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
/**
* 订单 API 接口实现类
*
@ -28,6 +24,8 @@ public class TradeOrderApiImpl implements TradeOrderApi {
@Resource
private TradeOrderQueryService tradeOrderQueryService;
@Resource
private TradeOrderUpdateService tradeOrderUpdateService;
@Override
public List<TradeOrderRespDTO> getOrderList(Collection<Long> ids) {
@ -39,18 +37,19 @@ public class TradeOrderApiImpl implements TradeOrderApi {
return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id));
}
@Override
public Integer getOrderStatus(Long id) {
TradeOrderDO order = tradeOrderQueryService.getOrder(id);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
return order.getStatus();
}
@Override
public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) {
return tradeOrderQueryService.getOrderSummary(beginTime, endTime);
}
@Override
public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) {
tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId);
}
@Override
public void cancelPaidOrder(Long userId, Long orderId) {
tradeOrderUpdateService.cancelPaidOrder(userId, orderId);
}
}

View File

@ -52,7 +52,6 @@ public class AppTradeOrderSettlementReqVO {
private Long seckillActivityId;
// ========== 拼团活动相关字段 ==========
// TODO @puhui999是不是拼团记录的编号哈
@Schema(description = "拼团活动编号", example = "1024")
private Long combinationActivityId;

View File

@ -170,4 +170,22 @@ public interface TradeOrderUpdateService {
*/
int createOrderItemCommentBySystem();
/**
* 更新拼团相关信息到订单
*
* @param orderId 订单编号
* @param activityId 拼团活动编号
* @param combinationRecordId 拼团记录编号
* @param headId 团长编号
*/
void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId);
/**
* 取消支付订单
*
* @param userId 用户编号
* @param orderId 订单编号
*/
void cancelPaidOrder(Long userId, Long orderId);
}

View File

@ -250,7 +250,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
/**
* 订单创建前执行前置逻辑
*
* @param order 订单
* @param order 订单
* @param orderItems 订单项
*/
private void beforeCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
@ -267,9 +267,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
* <p>
* 例如说优惠劵的扣减积分的扣减支付单的创建等等
*
* @param order 订单
* @param orderItems 订单项
* @param createReqVO 创建订单请求
* @param order 订单
* @param orderItems 订单项
* @param createReqVO 创建订单请求
*/
private void afterCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems,
AppTradeOrderCreateReqVO createReqVO) {
@ -331,7 +331,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
}
// 3订单支付成功后
tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order));
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);
tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order, orderItems));
// 4.1 增加用户积分赠送
addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId());
@ -624,12 +625,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
}
// 2. TODO 活动相关库存回滚需要活动 id活动 id 怎么获取app 端能否传过来回复从订单里拿呀
tradeOrderHandlers.forEach(handler -> handler.cancelOrder());
// 3. 回滚库存
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);
// 3. 回滚库存
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
// 3.1 活动相关的回滚
tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, orderItems));
// 4. 回滚优惠券
if (order.getCouponId() != null && order.getCouponId() > 0) {
@ -805,10 +805,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
// 2.2 如果全部退款则进行取消订单
getSelf().cancelOrderByAfterSale(order, orderRefundPrice);
// TODO @puhui999活动相关的回滚
// 3. 回滚库存
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(Collections.singletonList(orderItem)));
// 3.1 活动相关的回滚
tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, Collections.singletonList(orderItem)));
// 4.1 回滚积分扣减用户积分赠送的
reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId());
@ -908,6 +909,25 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
return count;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) {
tradeOrderMapper.updateById(
new TradeOrderDO().setId(orderId).setCombinationActivityId(activityId)
.setCombinationRecordId(combinationRecordId).setCombinationHeadId(headId));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelPaidOrder(Long userId, Long orderId) {
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL);
}
/**
* 创建单个订单的评论
*

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi;
import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
@ -26,9 +25,10 @@ public class TradeBargainHandler implements TradeOrderHandler {
@Override
public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) {
if (TradeOrderTypeEnum.isBargain(order.getType())) {
return;
}
// 扣减砍价活动的库存
bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(),
-orderItems.get(0).getCount());
@ -36,13 +36,20 @@ public class TradeBargainHandler implements TradeOrderHandler {
@Override
public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) {
if (TradeOrderTypeEnum.isBargain(order.getType())) {
return;
}
// 记录砍价记录对应的订单编号
bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId());
}
// TODO 芋艿取消订单时需要增加库存
@Override
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (TradeOrderTypeEnum.isBargain(order.getType())) {
return;
}
// TODO 芋艿取消订单时需要增加库存
}
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
@ -26,7 +25,7 @@ public class TradeCombinationHandler implements TradeOrderHandler {
@Override
public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
// 如果不是拼团订单则结束
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
if (TradeOrderTypeEnum.isCombination(order.getType())) {
return;
}
Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品");
@ -34,33 +33,30 @@ public class TradeCombinationHandler implements TradeOrderHandler {
// 获取商品信息
TradeOrderItemDO item = orderItems.get(0);
// 校验是否满足拼团活动相关限制
combinationRecordApi.validateCombinationRecord(order.getCombinationActivityId(), order.getUserId(), item.getSkuId(), item.getCount());
combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(),
order.getCombinationHeadId(), item.getSkuId(), item.getCount());
}
@Override
public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
// 如果不是拼团订单则结束
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
if (TradeOrderTypeEnum.isCombination(order.getType())) {
return;
}
Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品");
// 获取商品信息
TradeOrderItemDO item = orderItems.get(0);
// 创建拼团记录
// TODO puhui这里应该先不创建等支付好才去创建另外创建好后需要更新编号到订单
combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item));
}
@Override
public void afterPayOrder(TradeOrderDO order) {
// 如果不是拼团订单则结束
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (TradeOrderTypeEnum.isCombination(order.getType())) {
return;
}
// 更新拼团状态 TODO puhui999订单支付失败或订单支付过期删除这条拼团记录
combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), order.getPayTime());
}
}

View File

@ -33,12 +33,18 @@ public interface TradeOrderHandler {
* 支付订单后
*
* @param order 订单
* @param orderItems 订单项
*/
default void afterPayOrder(TradeOrderDO order) {}
default void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
}
/**
* 订单取消
*
* @param order 订单
* @param orderItems 订单项
*/
default void cancelOrder() {}
default void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
}
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
@ -23,12 +22,21 @@ public class TradeSeckillHandler implements TradeOrderHandler {
@Override
public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) {
if (TradeOrderTypeEnum.isSeckill(order.getType())) {
return;
}
// 扣减秒杀活动的库存
seckillActivityApi.updateSeckillStock(order.getSeckillActivityId(),
orderItems.get(0).getSkuId(), orderItems.get(0).getCount());
}
@Override
public void cancelOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
if (TradeOrderTypeEnum.isSeckill(order.getType())) {
return;
}
}
}

View File

@ -68,7 +68,6 @@ public class TradePriceCalculateReqBO {
private Long seckillActivityId;
// ========== 拼团活动相关字段 ==========
// TODO @puhui999是不是拼团记录的编号哈
/**
* 拼团活动编号
*/

View File

@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
// TODO @puhui999单测可以后补下
/**
* 拼团活动的 {@link TradePriceCalculator} 实现类
*
@ -35,7 +36,7 @@ public class TradeCombinationActivityPriceCalculator implements TradePriceCalcul
// 2. 校验是否可以参与拼团
TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0);
CombinationValidateJoinRespDTO combinationActivity = combinationRecordApi.validateJoinCombination(
param.getCombinationActivityId(), param.getUserId(),
param.getUserId(), param.getCombinationActivityId(), param.getCombinationHeadId(),
orderItem.getSkuId(), orderItem.getCount());
// 3.1 记录优惠明细