trade:完成交易订单的收货逻辑
parent
66abe4a84b
commit
7056d89b0c
|
@ -27,6 +27,7 @@ public interface ErrorCodeConstants {
|
|||
ErrorCode ORDER_UPDATE_PAID_FAIL_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1011000015, "交易订单更新支付状态失败,支付单状态不是【支付成功】状态");
|
||||
ErrorCode ORDER_UPDATE_PAID_FAIL_PAY_PRICE_NOT_MATCH = new ErrorCode(1011000016, "交易订单更新支付状态失败,支付单金额不匹配");
|
||||
ErrorCode ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED = new ErrorCode(1011000017, "交易订单发货失败,订单不是【待发货】状态");
|
||||
ErrorCode ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1011000018, "交易订单收货失败,订单不是【待收货】状态");
|
||||
|
||||
// ========== After Sale 模块 1-011-000-000 ==========
|
||||
ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在");
|
||||
|
|
|
@ -75,6 +75,15 @@ public enum TradeOrderStatusEnum implements IntArrayValuable {
|
|||
return ObjectUtil.equal(UNDELIVERED.getStatus(), status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定状态,是否正处于【已发货】状态
|
||||
*
|
||||
* @param status 指定状态
|
||||
* @return 是否
|
||||
*/
|
||||
public static boolean isDelivered(Integer status) {
|
||||
return ObjectUtil.equals(status, DELIVERED.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定状态,是否正处于【已取消】状态
|
||||
|
|
|
@ -13,4 +13,9 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
|
|||
.eq(TradeOrderDO::getId, id).eq(TradeOrderDO::getStatus, status));
|
||||
}
|
||||
|
||||
default TradeOrderDO selectByIdAndUserId(Long id, Long userId) {
|
||||
return selectOne(TradeOrderDO::getId, id,
|
||||
TradeOrderDO::getUserId, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,14 +41,22 @@ public interface TradeOrderService {
|
|||
*/
|
||||
void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO);
|
||||
|
||||
/**
|
||||
* 【会员】收货交易订单
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param id 订单编号
|
||||
*/
|
||||
void receiveOrder(Long userId, Long id);
|
||||
|
||||
/**
|
||||
* 获得指定用户,指定的交易订单
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param orderId 交易订单编号
|
||||
* @param id 交易订单编号
|
||||
* @return 交易订单
|
||||
*/
|
||||
TradeOrderDO getOrder(Long userId, Long orderId);
|
||||
TradeOrderDO getOrder(Long userId, Long id);
|
||||
|
||||
// =================== Order Item ===================
|
||||
|
||||
|
|
|
@ -315,6 +315,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
|||
return new KeyValue<>(order, payOrder);
|
||||
}
|
||||
|
||||
// TODO 芋艿:如果无需发货,需要怎么存储?
|
||||
@Override
|
||||
public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) {
|
||||
// 校验并获得交易订单(可发货)
|
||||
|
@ -365,8 +366,52 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TradeOrderDO getOrder(Long userId, Long orderId) {
|
||||
TradeOrderDO order = tradeOrderMapper.selectById(orderId);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void receiveOrder(Long userId, Long id) {
|
||||
// 校验并获得交易订单(可收货)
|
||||
TradeOrderDO order = validateOrderReceivable(userId, id);
|
||||
|
||||
// 更新 TradeOrderDO 状态为已完成
|
||||
int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(),
|
||||
new TradeOrderDO().setStatus(TradeOrderStatusEnum.COMPLETED.getStatus())
|
||||
.setDeliveryStatus(TradeOrderDeliveryStatusEnum.RECEIVED.getStatus()).setReceiveTime(LocalDateTime.now()));
|
||||
if (updateCount == 0) {
|
||||
throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED);
|
||||
}
|
||||
|
||||
// TODO 芋艿:OrderLog
|
||||
|
||||
// TODO 芋艿:lili 发送订单变化的消息
|
||||
|
||||
// TODO 芋艿:lili 发送商品被购买完成的数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验交易订单满足可售货的条件
|
||||
*
|
||||
* 1. 交易订单待收货
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param id 交易订单编号
|
||||
* @return 交易订单
|
||||
*/
|
||||
private TradeOrderDO validateOrderReceivable(Long userId, Long id) {
|
||||
// 校验订单是否存在
|
||||
TradeOrderDO order = tradeOrderMapper.selectByIdAndUserId(id, userId);
|
||||
if (order == null) {
|
||||
throw exception(ORDER_NOT_FOUND);
|
||||
}
|
||||
// 校验订单是否是待收货状态
|
||||
if (!TradeOrderStatusEnum.isDelivered(order.getStatus())
|
||||
|| ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.DELIVERED.getStatus())) {
|
||||
throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED);
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeOrderDO getOrder(Long userId, Long id) {
|
||||
TradeOrderDO order = tradeOrderMapper.selectById(id);
|
||||
if (order != null
|
||||
&& ObjectUtil.notEqual(order.getUserId(), userId)) {
|
||||
return null;
|
||||
|
|
|
@ -295,4 +295,26 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
|
|||
assertNotNull(dbOrder.getDeliveryTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveOrder() {
|
||||
// mock 数据(TradeOrder)
|
||||
TradeOrderDO order = randomPojo(TradeOrderDO.class, o -> {
|
||||
o.setId(1L).setUserId(10L).setStatus(TradeOrderStatusEnum.DELIVERED.getStatus());
|
||||
o.setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setReceiveTime(null);
|
||||
});
|
||||
tradeOrderMapper.insert(order);
|
||||
// 准备参数
|
||||
Long id = 1L;
|
||||
Long userId = 10L;
|
||||
// mock 方法(支付单)
|
||||
|
||||
// 调用
|
||||
tradeOrderService.receiveOrder(userId, id);
|
||||
// 断言
|
||||
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
|
||||
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());
|
||||
assertEquals(dbOrder.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.RECEIVED.getStatus());
|
||||
assertNotNull(dbOrder.getReceiveTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS "trade_order" (
|
|||
"delivery_template_id" bigint,
|
||||
"logistics_id" bigint,
|
||||
"logistics_no" varchar,
|
||||
"delivery_status" bit NOT NULL,
|
||||
"delivery_status" smallint NOT NULL,
|
||||
"delivery_time" datetime,
|
||||
"receive_time" datetime,
|
||||
"receiver_name" varchar NOT NULL,
|
||||
|
|
Loading…
Reference in New Issue