diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 77dd3884c..87fc27857 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -88,17 +88,16 @@ public interface ErrorCodeConstants { // ========== 砍价活动 1-013-012-000 ========== ErrorCode BARGAIN_ACTIVITY_NOT_EXISTS = new ErrorCode(1_013_012_000, "砍价活动不存在"); ErrorCode BARGAIN_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1_013_012_001, "存在商品参加了其它砍价活动"); - ErrorCode BARGAIN_ACTIVITY_STATUS_DISABLE = new ErrorCode(1_013_012_002, "砍价活动已关闭不能修改"); + ErrorCode BARGAIN_ACTIVITY_STATUS_DISABLE = new ErrorCode(1_013_012_002, "砍价活动已关闭,不能修改"); ErrorCode BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1_013_012_003, "砍价活动未关闭或未结束,不能删除"); - ErrorCode BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1_013_012_004, "砍价失败,原因:该砍价活动库存不足"); + ErrorCode BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH = new ErrorCode(1_013_012_004, "砍价活动库存不足"); + ErrorCode BARGAIN_ACTIVITY_STATUS_CLOSED = new ErrorCode(1_013_012_005, "砍价活动已关闭"); + ErrorCode BARGAIN_ACTIVITY_TIME_END = new ErrorCode(1_013_012_006, "砍价活动已经结束"); // ========== 砍价记录 1-013-013-000 ========== ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1_013_013_000, "砍价记录不存在"); - ErrorCode BARGAIN_RECORD_EXISTS = new ErrorCode(1_013_013_001, "砍价失败,已参与过该砍价"); - ErrorCode BARGAIN_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1_013_013_002, "砍价失败,父砍价不存在"); - ErrorCode BARGAIN_RECORD_USER_FULL = new ErrorCode(1_013_013_003, "砍价失败,砍价人数已满"); - ErrorCode BARGAIN_JOIN_RECORD_NOT_IN_PROGRESS = new ErrorCode(1_013_013_004, "砍价失败,砍价记录不在进行中"); - ErrorCode BARGAIN_JOIN_FAILED_ACTIVITY_TIME_END = new ErrorCode(1_013_013_005, "砍价失败,活动已经结束"); - ErrorCode BARGAIN_JOIN_ACTIVITY_STATUS_CLOSED = new ErrorCode(1_013_013_006, "砍价失败,原因:砍价活动已关闭"); + ErrorCode BARGAIN_RECORD_CREATE_FAIL_EXISTS = new ErrorCode(1_013_013_001, "参与失败,您已经参与当前砍价活动"); + ErrorCode BARGAIN_RECORD_CREATE_FAIL_LIMIT = new ErrorCode(1_013_013_002, "参与失败,您已达到当前砍价活动的参与上限"); + ErrorCode BARGAIN_JOIN_RECORD_NOT_SUCCESS = new ErrorCode(1_013_013_004, "下单失败,砍价未成功"); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/bargain/BargainRecordStatusEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/bargain/BargainRecordStatusEnum.java index 35d9eb93e..d5c22a7c5 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/bargain/BargainRecordStatusEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/bargain/BargainRecordStatusEnum.java @@ -17,7 +17,7 @@ public enum BargainRecordStatusEnum implements IntArrayValuable { IN_PROGRESS(1, "砍价中"), SUCCESS(2, "砍价成功"), - FAILED(3, "砍价失败"), + FAILED(3, "砍价失败"), // 活动到期时,会自动将到期的砍价全部设置为过期 ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BargainRecordStatusEnum::getStatus).toArray(); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.http b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.http new file mode 100644 index 000000000..46cbe3c8e --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.http @@ -0,0 +1,9 @@ +### /promotion/bargain-record/create 创建砍价记录 +POST {{appApi}}/promotion/bargain-record/create +Authorization: Bearer {{appToken}} +Content-Type: application/json +tenant-id: {{appTenentId}} + +{ + "activityId": 1 +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java index bb2bf584f..a172226ea 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java @@ -4,19 +4,23 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO; +import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.time.Duration; import java.util.ArrayList; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "用户 App - 砍价记录") @RestController @@ -24,6 +28,9 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppBargainRecordController { + @Resource + private BargainRecordService bargainRecordService; + @GetMapping("/get-summary") @Operation(summary = "获得砍价记录的概要信息", description = "用于小程序首页") // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 @@ -137,9 +144,11 @@ public class AppBargainRecordController { } @PostMapping("/create") - @Operation(summary = "创建砍价记录", description = "参与拼团活动") + @Operation(summary = "创建砍价记录", description = "参与砍价活动") + @PreAuthenticated public CommonResult createBargainRecord(@RequestBody AppBargainRecordCreateReqVO reqVO) { - return success(1L); + Long recordId = bargainRecordService.createBargainRecord(getLoginUserId(), reqVO); + return success(recordId); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java index 1bb8b2838..a6b3d686d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java @@ -60,24 +60,29 @@ public class BargainActivityDO extends BaseDO { */ private Long skuId; /** - * 砍价起始价格,单位分 + * 砍价起始价格,单位:分 */ private Integer bargainFirstPrice; /** * 砍价底价,单位:分 */ - private Integer bargainPrice; + private Integer bargainMinPrice; /** * 砍价活动库存 */ private Integer stock; /** - * 达到该人数,才能砍到低价 + * 砍价人数 + * + * 需要多少人,砍价才能成功,即 {@link BargainRecordDO#getStatus()} 更新为 {@link BargainRecordDO#getStatus()} 成功状态 */ private Integer userSize; /** - * 最大帮砍次数 + * 帮砍次数 + * + * 单个活动,用户可以帮砍的次数。 + * 例如说:帮砍次数为 1 时,A 和 B 同时将该活动链接发给 C,C 只能帮其中一个人砍价。 */ private Integer bargainCount; @@ -93,6 +98,9 @@ public class BargainActivityDO extends BaseDO { * 用户每次砍价的最大金额,单位:分 */ private Integer randomMaxPrice; + + // ========== 统计字段 ========== + /** * 砍价成功数量 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainRecordDO.java index 665a16df6..44479c206 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainRecordDO.java @@ -29,17 +29,17 @@ public class BargainRecordDO extends BaseDO { */ @TableId private Long id; - - /** - * 砍价活动编号 - */ - private Long activityId; - /** * 用户编号 */ private Long userId; + /** + * 砍价活动编号 + * + * 关联 {@link BargainActivityDO#getId()} 字段 + */ + private Long activityId; /** * 商品 SPU 编号 */ @@ -50,17 +50,13 @@ public class BargainRecordDO extends BaseDO { private Long skuId; /** - * 砍价底价,单位:分 + * 砍价起始价格,单位:分 + */ + private Integer bargainFirstPrice; + /** + * 当前砍价,单位:分 */ private Integer bargainPrice; - /** - * 商品原价,单位:分 - */ - private Integer price; - /** - * 应付金额,单位:分 - */ - private Integer payPrice; /** * 砍价状态 @@ -68,22 +64,14 @@ public class BargainRecordDO extends BaseDO { * 枚举 {@link BargainRecordStatusEnum} */ private Integer status; - - /** - * 订单编号 - */ - private Long orderId; - /** * 结束时间 */ private LocalDateTime endTime; /** - * 过期时间 - * - * 到达该时间时,其他用户无法帮助砍价,但是还是允许下单 + * 订单编号 */ - private LocalDateTime expireTime; + private Long orderId; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java index 6a5ac93e2..019c487e3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java @@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 砍价记录 Mapper * @@ -17,4 +20,20 @@ public interface BargainRecordMapper extends BaseMapperX { BargainRecordDO::getUserId, userId); } + default List selectListByUserIdAndActivityIdAndStatus( + Long userId, Long activityId, Integer status) { + return selectList(new LambdaQueryWrapper<>(BargainRecordDO.class) + .eq(BargainRecordDO::getUserId, userId) + .eq(BargainRecordDO::getActivityId, activityId) + .eq(BargainRecordDO::getStatus, status)); + } + + default Long selectCountByUserIdAndActivityIdAndStatus( + Long userId, Long activityId, Integer status) { + return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class) + .eq(BargainRecordDO::getUserId, userId) + .eq(BargainRecordDO::getActivityId, activityId) + .eq(BargainRecordDO::getStatus, status)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java index 9a0c17af9..23de02815 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java @@ -55,6 +55,14 @@ public interface BargainActivityService { */ BargainActivityDO getBargainActivity(Long id); + /** + * 校验砍价活动,是否可以参与(发起砍价、下单、帮好友砍价) + * + * @param id 编号 + * @return 砍价活动 + */ + BargainActivityDO validateBargainActivityCanJoin(Long id); + /** * 获得砍价活动分页 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 8ed971f73..aad2b1416 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.bargain; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -82,13 +83,13 @@ public class BargainActivityServiceImpl implements BargainActivityService { throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); } if (count > activity.getStock()) { - throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); + throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); } // 更新砍价库存 int updateCount = bargainActivityMapper.updateStock(id, count); if (updateCount == 0) { - throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); + throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); } } @@ -138,6 +139,21 @@ public class BargainActivityServiceImpl implements BargainActivityService { return bargainActivityMapper.selectById(id); } + @Override + public BargainActivityDO validateBargainActivityCanJoin(Long id) { + BargainActivityDO activity = bargainActivityMapper.selectById(id); + if (activity == null) { + throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); + } + if (ObjUtil.notEqual(activity.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { + throw exception(BARGAIN_ACTIVITY_STATUS_CLOSED); + } + if (activity.getStock() <= 0) { + throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); + } + return activity; + } + @Override public PageResult getBargainActivityPage(BargainActivityPageReqVO pageReqVO) { return bargainActivityMapper.selectPage(pageReqVO); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java index 4bb6acb6b..718de1501 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain; import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordCreateReqVO; /** * 砍价记录 service 接口 @@ -10,6 +11,15 @@ import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinResp */ public interface BargainRecordService { + /** + * 【会员】创建砍价记录(参与参加活动) + * + * @param userId 用户编号 + * @param reqVO 创建信息 + * @return 砍价记录编号 + */ + Long createBargainRecord(Long userId, AppBargainRecordCreateReqVO reqVO); + /** * 【下单前】校验是否参与砍价活动 *

diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java index f2fdfe996..3df31d3a3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.module.promotion.service.bargain; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ObjUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordCreateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainRecordMapper; @@ -13,7 +13,6 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; - import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -34,7 +33,30 @@ public class BargainRecordServiceImpl implements BargainRecordService { @Resource private BargainRecordMapper bargainRecordMapper; - // TODO puhui999:create 时,需要校验下限购数量; + @Override + public Long createBargainRecord(Long userId, AppBargainRecordCreateReqVO reqVO) { + // 1. 校验砍价活动 + BargainActivityDO activity = bargainActivityService.validateBargainActivityCanJoin(reqVO.getActivityId()); + + // 2.1 校验当前是否已经有参与中的砍价活动 + if (CollUtil.isNotEmpty(bargainRecordMapper.selectListByUserIdAndActivityIdAndStatus( + userId, reqVO.getActivityId(), BargainRecordStatusEnum.IN_PROGRESS.getStatus()))) { + throw exception(BARGAIN_RECORD_CREATE_FAIL_EXISTS); + } + // 2.2 是否超过参与的上限 + if (bargainRecordMapper.selectCountByUserIdAndActivityIdAndStatus( + userId, reqVO.getActivityId(), BargainRecordStatusEnum.SUCCESS.getStatus()) >= activity.getTotalLimitCount()) { + throw exception(BARGAIN_RECORD_CREATE_FAIL_LIMIT); + } + + // 3. 创建砍价记录 + BargainRecordDO record = BargainRecordDO.builder().userId(userId) + .activityId(reqVO.getActivityId()).spuId(activity.getSpuId()).skuId(activity.getSkuId()) + .bargainFirstPrice(activity.getBargainFirstPrice()).bargainPrice(activity.getBargainFirstPrice()) + .status(BargainRecordStatusEnum.IN_PROGRESS.getStatus()).build(); + bargainRecordMapper.insert(record); + return record.getId(); + } @Override public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) { @@ -45,28 +67,14 @@ public class BargainRecordServiceImpl implements BargainRecordService { } // 1.2 拼团记录未在进行中 if (ObjUtil.notEqual(record.getStatus(), BargainRecordStatusEnum.IN_PROGRESS)) { - throw exception(BARGAIN_JOIN_RECORD_NOT_IN_PROGRESS); + throw exception(BARGAIN_JOIN_RECORD_NOT_SUCCESS); } - // 2.1 砍价活动不存在 - BargainActivityDO activity = bargainActivityService.getBargainActivity(record.getActivityId()); - if (activity == null) { - throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); - } - if (ObjUtil.notEqual(activity.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { - throw exception(BARGAIN_JOIN_ACTIVITY_STATUS_CLOSED); - } + // 2. 校验砍价活动 + BargainActivityDO activity = bargainActivityService.validateBargainActivityCanJoin(record.getActivityId()); Assert.isTrue(Objects.equals(skuId, activity.getSkuId()), "砍价商品不匹配"); // 防御性校验 - // 2.2 活动已过期 - if (LocalDateTimeUtils.isBetween(activity.getStartTime(), activity.getEndTime())) { - throw exception(BARGAIN_JOIN_FAILED_ACTIVITY_TIME_END); - } - // 2.3 库存不足 - if (activity.getStock() <= 0) { - throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); - } return new BargainValidateJoinRespDTO().setActivityId(activity.getId()).setName(activity.getName()) - .setBargainPrice(record.getPayPrice()); + .setBargainPrice(record.getBargainPrice()); } }