mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
code review:订单部分逻辑
This commit is contained in:
parent
bdd81e4cbc
commit
e8bdd8349c
@ -59,6 +59,7 @@ public class ProductSkuRespDTO {
|
||||
* 商品体积,单位:m^3 平米
|
||||
*/
|
||||
private Double volume;
|
||||
// TODO @puhui999:firstBrokeragePrice ;尴尬,我当时打错了;secondBrokeragePrice
|
||||
/**
|
||||
* 一级分销的佣金,单位:分
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.api.combination;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO;
|
||||
|
||||
// TODO @puhui999:是不是改成 CombinationActivityApi
|
||||
/**
|
||||
* 拼团活动 Api 接口
|
||||
*
|
||||
@ -14,6 +15,7 @@ public interface CombinationApi {
|
||||
*
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
// TODO @puhui999:应该是更新哇?还是校验哈;
|
||||
void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO);
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import javax.validation.constraints.NotNull;
|
||||
@Data
|
||||
public class CombinationActivityUpdateStockReqDTO {
|
||||
|
||||
// TODO @puhui999:是不是一个 activityId、count、skuId 参数就完事啦。
|
||||
|
||||
@NotNull(message = "活动编号不能为空")
|
||||
private Long activityId;
|
||||
|
||||
|
@ -13,6 +13,8 @@ import javax.validation.constraints.NotNull;
|
||||
@Data
|
||||
public class CombinationRecordCreateReqDTO {
|
||||
|
||||
// TODO @puhui999:注释还是要的哈
|
||||
|
||||
@NotNull(message = "拼团活动编号不能为空")
|
||||
private Long activityId;
|
||||
|
||||
|
@ -13,6 +13,8 @@ import javax.validation.constraints.NotNull;
|
||||
@Data
|
||||
public class SeckillActivityUpdateStockReqDTO {
|
||||
|
||||
// TODO @puhui999:可以不用 dto,直接 activityId、skuId、count 即可
|
||||
|
||||
@NotNull(message = "活动编号不能为空")
|
||||
private Long activityId;
|
||||
|
||||
|
@ -39,7 +39,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
|
||||
default int updateActivityStock(Long id, int count) {
|
||||
return update(null, new LambdaUpdateWrapper<BargainActivityDO>()
|
||||
.eq(BargainActivityDO::getId, id)
|
||||
.gt(BargainActivityDO::getStock, 0)
|
||||
.gt(BargainActivityDO::getStock, 0) // TODO @puhui999:不是 > 0,是要大于 count 哈
|
||||
.setSql("stock = stock - " + count));
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
|
||||
default int updateActivityStock(Long id, int count) {
|
||||
return update(null, new LambdaUpdateWrapper<SeckillProductDO>()
|
||||
.eq(SeckillProductDO::getId, id)
|
||||
.gt(SeckillProductDO::getStock, 0)
|
||||
.gt(SeckillProductDO::getStock, 0) // TODO @puhui999:不是 > 0,是要大于 count 哈
|
||||
.setSql("stock = stock - " + count));
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,8 @@ public class BargainActivityServiceImpl implements BargainActivityService {
|
||||
}
|
||||
|
||||
// 更新砍价库存
|
||||
int row = bargainActivityMapper.updateActivityStock(id, count);
|
||||
if (row == 0) {
|
||||
int updateCount = bargainActivityMapper.updateActivityStock(id, count);
|
||||
if (updateCount == 0) {
|
||||
throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
}
|
||||
|
@ -215,23 +215,29 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
|
||||
|
||||
@Override
|
||||
public void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO) {
|
||||
// 1、校验拼团活动是否存在
|
||||
// 1.1 校验拼团活动是否存在
|
||||
CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId());
|
||||
// 1.1、校验活动是否开启
|
||||
// 1.2 校验活动是否开启
|
||||
if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
|
||||
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
|
||||
}
|
||||
// 1.2、校验是否超出单次限购数量
|
||||
// 1.3 校验是否超出单次限购数量
|
||||
if (activity.getSingleLimitCount() < reqDTO.getCount()) {
|
||||
throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
|
||||
}
|
||||
// 1.3、校验是否超出总限购数量
|
||||
List<CombinationRecordDO> recordList = combinationRecordService.getRecordListByUserIdAndActivityId(getLoginUserId(), reqDTO.getActivityId());
|
||||
|
||||
// 2. 校验是否超出总限购数量
|
||||
// TODO @puhui999:userId 应该接口传递哈;要保证 service 无状态
|
||||
List<CombinationRecordDO> recordList = combinationRecordService.getRecordListByUserIdAndActivityId(
|
||||
getLoginUserId(), reqDTO.getActivityId());
|
||||
// TODO @puhui999:最好 if true return;减少括号层数
|
||||
if (CollUtil.isNotEmpty(recordList)) {
|
||||
// 过滤出拼团成功的
|
||||
// TODO @puhui999:count 要不存一个在 record 里?
|
||||
List<Long> skuIds = convertList(recordList, CombinationRecordDO::getSkuId,
|
||||
item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus()));
|
||||
Integer countSum = tradeOrderApi.getOrderItemCountSumByOrderIdAndSkuId(convertList(recordList, CombinationRecordDO::getOrderId,
|
||||
Integer countSum = tradeOrderApi.getOrderItemCountSumByOrderIdAndSkuId(convertList(recordList,
|
||||
CombinationRecordDO::getOrderId,
|
||||
item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds);
|
||||
if (activity.getTotalLimitCount() < countSum) {
|
||||
throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED);
|
||||
|
@ -128,6 +128,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
}
|
||||
|
||||
// 2. 创建拼团记录
|
||||
// TODO @puhui999:可以把 user、spu、sku 一起放 convert 里哈;
|
||||
CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO);
|
||||
record.setVirtualGroup(false);
|
||||
record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration()));
|
||||
|
@ -34,25 +34,12 @@ public interface SeckillActivityService {
|
||||
*/
|
||||
void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新秒杀活动
|
||||
*
|
||||
* @param activityDO 秒杀活动
|
||||
*/
|
||||
void updateSeckillActivity(SeckillActivityDO activityDO);
|
||||
|
||||
/**
|
||||
* 更新秒杀库存
|
||||
*
|
||||
* @param updateStockReqDTO 更新信息
|
||||
*/
|
||||
void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO);
|
||||
/**
|
||||
* 更新秒杀活动商品
|
||||
*
|
||||
* @param productList 活动商品列表
|
||||
*/
|
||||
void updateSeckillActivityProductList(List<SeckillProductDO> productList);
|
||||
|
||||
/**
|
||||
* 关闭秒杀活动
|
||||
|
@ -145,11 +145,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
updateSeckillProduct(updateObj, updateReqVO.getProducts());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSeckillActivity(SeckillActivityDO activityDO) {
|
||||
seckillActivityMapper.updateById(activityDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) {
|
||||
@ -171,23 +166,18 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
}
|
||||
|
||||
// 3、更新活动商品库存
|
||||
int itemRow = seckillProductMapper.updateActivityStock(product.getId(), updateStockReqDTO.getItem().getCount());
|
||||
if (itemRow == 0) {
|
||||
int updateCount = seckillProductMapper.updateActivityStock(product.getId(), updateStockReqDTO.getItem().getCount());
|
||||
if (updateCount == 0) {
|
||||
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
|
||||
// 4、更新活动库存
|
||||
int row = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), updateStockReqDTO.getCount());
|
||||
if (row == 0) {
|
||||
updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), updateStockReqDTO.getCount());
|
||||
if (updateCount == 0) {
|
||||
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSeckillActivityProductList(List<SeckillProductDO> productList) {
|
||||
seckillProductMapper.updateBatch(productList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新秒杀商品
|
||||
*
|
||||
|
@ -34,7 +34,6 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEn
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
|
||||
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
|
||||
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
|
||||
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
|
||||
@ -281,7 +280,7 @@ public interface TradeOrderConvert {
|
||||
return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId())
|
||||
.setBasePrice(item.getPayPrice() * item.getCount())
|
||||
.setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:标题类似:木晴冰雪成功购买云时代的JVM原理与实战;茫农成功购买深入拆解消息队列47讲
|
||||
.setFirstFixedPrice(sku.getFirstBrokerageRecord()).getSecondBrokerageRecord(sku.getSecondBrokerageRecord());
|
||||
.setFirstFixedPrice(sku.getFirstBrokerageRecord()).setSecondFixedPrice(sku.getSecondBrokerageRecord());
|
||||
}
|
||||
|
||||
@Mapping(target = "activityId", source = "reqBO.seckillActivityId")
|
||||
|
@ -542,11 +542,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
int orderPayPrice = order.getAdjustPrice() != null ? (order.getPayPrice() - order.getAdjustPrice())
|
||||
+ reqVO.getAdjustPrice() : order.getPayPrice() + reqVO.getAdjustPrice();
|
||||
update.setPayPrice(orderPayPrice);
|
||||
// TODO @芋艿:改价时,赠送的积分,要不要做改动???
|
||||
tradeOrderMapper.updateById(update);
|
||||
// TODO @芋艿:改价时,赠送的积分,要不要做改动???
|
||||
|
||||
// TODO @puhui999:应该是按照 payPrice 分配;并且要考虑取余问题;payPrice 也要考虑,item 里的
|
||||
// TODO:先按 adjustPrice 实现,没明白 payPrice 怎么搞哈哈哈
|
||||
// TODO @puhui999:就是对比新老 adjustPrice 的差值,然后计算补充的 adjustPrice 最终值;另外,可以不用区分 items.size 是不是 > 1 哈;应该是一致的逻辑;分摊的逻辑,有点类似 dividePrice 方法噢;
|
||||
// 5、更新 TradeOrderItem
|
||||
if (items.size() > 1) {
|
||||
// TradeOrderItemDO 需要做 adjustPrice 的分摊
|
||||
|
Loading…
Reference in New Issue
Block a user