mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-12 17:21:52 +08:00
trade:1、重构 order handler 的参数;2、增加砍价商品的价格计算
This commit is contained in:
@@ -1,19 +1,30 @@
|
||||
package cn.iocoder.yudao.module.promotion.api.bargain;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainRecordCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 砍价活动 API 实现类 TODO @puhui999
|
||||
* 砍价活动 API 实现类
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Service
|
||||
public class BargainRecordApiImpl implements BargainRecordApi {
|
||||
|
||||
@Resource
|
||||
private BargainRecordService bargainRecordService;
|
||||
|
||||
@Override
|
||||
public void createBargainRecord(BargainRecordCreateReqDTO reqDTO) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) {
|
||||
return bargainRecordService.validateJoinBargain(userId, bargainRecordId, skuId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.dataobject.bargain;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -43,7 +44,6 @@ public class BargainRecordDO extends BaseDO {
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
private Long spuId;
|
||||
|
||||
/**
|
||||
* 商品 SKU 编号
|
||||
*/
|
||||
@@ -53,19 +53,19 @@ public class BargainRecordDO extends BaseDO {
|
||||
* 砍价底价,单位分
|
||||
*/
|
||||
private Integer bargainPrice;
|
||||
|
||||
/**
|
||||
* 商品原价,单位分
|
||||
*/
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 应付金额,单位分
|
||||
*/
|
||||
private Integer payPrice;
|
||||
|
||||
/**
|
||||
* 状态1 - 砍价中;2- 砍价成功;3 - 砍价失败
|
||||
* 砍价状态
|
||||
*
|
||||
* 枚举 {@link BargainRecordStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
@@ -81,7 +81,9 @@ public class BargainRecordDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*
|
||||
* 到达该时间时,其他用户无法帮助砍价,但是还是允许下单
|
||||
*/
|
||||
private Data expireTime;
|
||||
private LocalDateTime expireTime;
|
||||
|
||||
}
|
||||
|
@@ -12,4 +12,9 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
|
||||
|
||||
default BargainRecordDO selectByIdAndUserId(Long id, Long userId) {
|
||||
return selectOne(BargainRecordDO::getId, id,
|
||||
BargainRecordDO::getUserId, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.bargain;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO;
|
||||
|
||||
/**
|
||||
* 砍价记录 service 接口
|
||||
*
|
||||
@@ -8,6 +10,16 @@ package cn.iocoder.yudao.module.promotion.service.bargain;
|
||||
*/
|
||||
public interface BargainRecordService {
|
||||
|
||||
// TODO
|
||||
/**
|
||||
* 【下单前】校验是否参与砍价活动
|
||||
* <p>
|
||||
* 如果校验失败,则抛出业务异常
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param bargainRecordId 砍价活动编号
|
||||
* @param skuId SKU 编号
|
||||
* @return 砍价信息
|
||||
*/
|
||||
BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId);
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,24 @@
|
||||
package cn.iocoder.yudao.module.promotion.service.bargain;
|
||||
|
||||
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.dal.dataobject.bargain.BargainActivityDO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainRecordMapper;
|
||||
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
|
||||
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;
|
||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 砍价记录 Service 实现类
|
||||
*
|
||||
@@ -11,4 +27,46 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Service
|
||||
@Validated
|
||||
public class BargainRecordServiceImpl implements BargainRecordService {
|
||||
|
||||
@Resource
|
||||
private BargainActivityService bargainActivityService;
|
||||
|
||||
@Resource
|
||||
private BargainRecordMapper bargainRecordMapper;
|
||||
|
||||
// TODO puhui999:create 时,需要校验下限购数量;
|
||||
|
||||
@Override
|
||||
public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) {
|
||||
// 1.1 拼团记录不存在
|
||||
BargainRecordDO record = bargainRecordMapper.selectByIdAndUserId(bargainRecordId, userId);
|
||||
if (record == null) {
|
||||
throw exception(BARGAIN_RECORD_NOT_EXISTS);
|
||||
}
|
||||
// 1.2 拼团记录未在进行中
|
||||
if (ObjUtil.notEqual(record.getStatus(), BargainRecordStatusEnum.IN_PROGRESS)) {
|
||||
throw exception(BARGAIN_JOIN_RECORD_NOT_IN_PROGRESS);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -107,15 +107,6 @@ public interface SeckillActivityService {
|
||||
*/
|
||||
PageResult<SeckillActivityDO> getSeckillActivityAppPageByConfigId(AppSeckillActivityPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获取秒杀活动商品信息
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param skuIds sku 编号
|
||||
* @return 秒杀活动商品信息列表
|
||||
*/
|
||||
List<SeckillProductDO> getSeckillActivityProductList(Long id, Collection<Long> skuIds);
|
||||
|
||||
/**
|
||||
* 校验是否参与秒杀商品
|
||||
*
|
||||
@@ -124,6 +115,7 @@ public interface SeckillActivityService {
|
||||
* @param activityId 活动编号
|
||||
* @param skuId SKU 编号
|
||||
* @param count 数量
|
||||
* @return 秒杀信息
|
||||
*/
|
||||
SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count);
|
||||
|
||||
|
@@ -278,18 +278,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
return seckillActivityMapper.selectPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SeckillProductDO> getSeckillActivityProductList(Long id, Collection<Long> skuIds) {
|
||||
|
||||
// 2、校验活动商品是否存在
|
||||
List<SeckillProductDO> productList = filterList(seckillProductMapper.selectListByActivityId(id),
|
||||
item -> skuIds.contains(item.getSkuId()));
|
||||
if (CollectionUtil.isEmpty(productList)) {
|
||||
throw exception(SKU_NOT_EXISTS);
|
||||
}
|
||||
return productList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count) {
|
||||
// 1.1 校验秒杀活动是否存在
|
||||
|
Reference in New Issue
Block a user