mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-11 16:51:53 +08:00
订单:重构拼团下单流程更改为订单支付后再创建拼团记录
This commit is contained in:
@@ -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,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -52,7 +52,6 @@ public class AppTradeOrderSettlementReqVO {
|
||||
private Long seckillActivityId;
|
||||
|
||||
// ========== 拼团活动相关字段 ==========
|
||||
// TODO @puhui999:是不是拼团记录的编号哈?
|
||||
@Schema(description = "拼团活动编号", example = "1024")
|
||||
private Long combinationActivityId;
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
@@ -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());
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单个订单的评论
|
||||
*
|
||||
|
@@ -39,29 +39,18 @@ public class TradeCombinationHandler implements TradeOrderHandler {
|
||||
}
|
||||
|
||||
@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())) {
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -33,8 +33,10 @@ public interface TradeOrderHandler {
|
||||
* 支付订单后
|
||||
*
|
||||
* @param order 订单
|
||||
* @param orderItems 订单项
|
||||
*/
|
||||
default void afterPayOrder(TradeOrderDO order) {}
|
||||
default void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单取消
|
||||
|
@@ -68,7 +68,6 @@ public class TradePriceCalculateReqBO {
|
||||
private Long seckillActivityId;
|
||||
|
||||
// ========== 拼团活动相关字段 ==========
|
||||
// TODO @puhui999:是不是拼团记录的编号哈?
|
||||
/**
|
||||
* 拼团活动编号
|
||||
*/
|
||||
|
Reference in New Issue
Block a user