From c485c6e04de2f1d1a0db144e32c44f15c3bfadfd Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 7 Oct 2023 16:30:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=EF=BC=9A=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E4=B8=8B=E5=8D=95=E6=B5=81=E7=A8=8B=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E5=90=8E?= =?UTF-8?q?=E5=86=8D=E5=88=9B=E5=BB=BA=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 18 --- .../combination/CombinationRecordApiImpl.java | 12 -- .../CombinationActivityConvert.java | 9 +- .../combination/CombinationRecordMapper.java | 6 - .../combination/CombinationRecordService.java | 11 -- .../CombinationRecordServiceImpl.java | 112 ++++++++++-------- .../module/trade/api/order/TradeOrderApi.java | 19 +-- .../trade/api/order/TradeOrderApiImpl.java | 22 ++-- .../vo/AppTradeOrderSettlementReqVO.java | 1 - .../order/TradeOrderUpdateService.java | 10 ++ .../order/TradeOrderUpdateServiceImpl.java | 19 ++- .../handler/TradeCombinationHandler.java | 15 +-- .../order/handler/TradeOrderHandler.java | 4 +- .../price/bo/TradePriceCalculateReqBO.java | 1 - 14 files changed, 118 insertions(+), 141 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index 06a24f305..a086ecb4d 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/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 import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; import javax.validation.Valid; -import java.time.LocalDateTime; // TODO @芋艿:后面也再撸撸这几个接口 @@ -42,14 +41,6 @@ public interface CombinationRecordApi { */ boolean isCombinationRecordSuccess(Long userId, Long orderId); - /** - * 更新拼团状态为【成功】 - * - * @param userId 用户编号 - * @param orderId 订单编号 - */ - void updateRecordStatusToSuccess(Long userId, Long orderId); - /** * 更新拼团状态为【失败】 * @@ -58,15 +49,6 @@ public interface CombinationRecordApi { */ void updateRecordStatusToFailed(Long userId, Long orderId); - /** - * 更新拼团状态为 进行中 - * - * @param userId 用户编号 - * @param orderId 订单编号 - * @param startTime 开始时间 - */ - void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime); - /** * 【下单前】校验是否满足拼团活动条件 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index b30bdab8d..75e5591d3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordSe 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; @@ -44,22 +43,11 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus()); } - @Override - public void updateRecordStatusToSuccess(Long userId, Long orderId) { - recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId); - } - @Override public void updateRecordStatusToFailed(Long userId, Long orderId) { recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId); } - @Override - public void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime) { - recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), - userId, orderId, startTime); - } - @Override public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { return recordService.validateJoinCombination(userId, activityId, headId, skuId, count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 6b1316e71..d2e8fe9ff 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/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 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 convertAppList(List list); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index 494b89974..6226cb2eb 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/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 selectListByUserIdAndStatus(Long userId, Integer status) { - return selectList(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getUserId, userId) - .eq(CombinationRecordDO::getStatus, status)); - } - /** * 查询拼团记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 80408560b..3e8a97c0e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/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 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; @@ -52,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); - /** * 获得拼团记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 6a9a53a80..47e7c552a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -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,7 +28,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Nullable; import javax.annotation.Resource; -import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -80,30 +78,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { recordMapper.updateById(record); } - @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 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); @@ -143,15 +117,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) { throw exception(COMBINATION_RECORD_USER_FULL); } - // 2.3、校验拼团是否过期 + // 2.3、校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间) if (beforeNow(record.getExpireTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_END); } - } - - // 3、校验当前活动是否结束 - if (beforeNow(activity.getEndTime())) { - throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } else { + // 3、校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束) + if (beforeNow(activity.getEndTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } } // 4、校验活动商品是否存在 @@ -187,19 +161,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); } - // 7、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团) - CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null)); - if (record == null) { - return new KeyValue<>(activity, product); - } - // 7.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); } @@ -215,9 +176,62 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku)); - // TODO @puhui999:status 未设置;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 为它自己 + if (reqDTO.getHeadId() == null) { + recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(recordDO.getId())); + 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) { + List records = recordMapper.selectList(CombinationRecordDO::getHeadId, headId); + List updateRecords = new ArrayList<>(); + + if (CollUtil.isEmpty(records)) { + return; + } + + 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 diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 0a6620c14..0d72a75e8 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/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 { */ TradeOrderRespDTO getOrder(Long id); - // TODO 芋艿:看看是不是可以删除掉; - /** - * 获取订单状态 - * - * @param id 订单编号 - * @return 订单状态 - */ - Integer getOrderStatus(Long id); - /** * 获取订单统计 * @@ -48,4 +39,14 @@ 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); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 39f554e29..ed1ee1f26 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/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; 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 getOrderList(Collection ids) { @@ -39,18 +37,14 @@ 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); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java index 153e09905..e8ed038ff 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java +++ b/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 { private Long seckillActivityId; // ========== 拼团活动相关字段 ========== - // TODO @puhui999:是不是拼团记录的编号哈? @Schema(description = "拼团活动编号", example = "1024") private Long combinationActivityId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index ffadb15e4..bc8413b3d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -170,4 +170,14 @@ public interface TradeOrderUpdateService { */ int createOrderItemCommentBySystem(); + /** + * 更新拼团相关信息到订单 + * + * @param orderId 订单编号 + * @param activityId 拼团活动编号 + * @param combinationRecordId 拼团记录编号 + * @param headId 团长编号 + */ + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index df6767a05..a0bd13f44 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/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 { /** * 订单创建前,执行前置逻辑 * - * @param order 订单 + * @param order 订单 * @param orderItems 订单项 */ private void beforeCreateTradeOrder(TradeOrderDO order, List orderItems) { @@ -267,9 +267,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { *

* 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 * - * @param order 订单 - * @param orderItems 订单项 - * @param createReqVO 创建订单请求 + * @param order 订单 + * @param orderItems 订单项 + * @param createReqVO 创建订单请求 */ private void afterCreateTradeOrder(TradeOrderDO order, List orderItems, AppTradeOrderCreateReqVO createReqVO) { @@ -331,7 +331,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // 3、订单支付成功后 - tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order)); + List orderItems = tradeOrderItemMapper.selectListByOrderId(id); + tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order, orderItems)); // 4.1 增加用户积分(赠送) addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); @@ -909,6 +910,14 @@ 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)); + } + /** * 创建单个订单的评论 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 95262f95c..f34da9616 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -39,29 +39,18 @@ public class TradeCombinationHandler implements TradeOrderHandler { } @Override - public void afterOrderCreate(TradeOrderDO order, List orderItems) { + public void afterPayOrder(TradeOrderDO order, List orderItems) { // 如果不是拼团订单则结束 if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), 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())) { - return; - } - - // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 - combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), order.getPayTime()); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index eb00c9121..81c41650a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -33,8 +33,10 @@ public interface TradeOrderHandler { * 支付订单后 * * @param order 订单 + * @param orderItems 订单项 */ - default void afterPayOrder(TradeOrderDO order) {} + default void afterPayOrder(TradeOrderDO order, List orderItems) { + } /** * 订单取消 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java index dac92e743..295dcd3bc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java +++ b/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 { private Long seckillActivityId; // ========== 拼团活动相关字段 ========== - // TODO @puhui999:是不是拼团记录的编号哈? /** * 拼团活动编号 */