trade:删除订单的实现

This commit is contained in:
YunaiV 2023-09-23 20:23:28 +08:00
parent a9485ad6bf
commit 1da14a3f53
5 changed files with 48 additions and 16 deletions

View File

@ -31,6 +31,7 @@ public interface ErrorCodeConstants {
ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价"); ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价");
ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化"); ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化");
ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在"); ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在");
ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1011000029, "交易订单删除失败,订单不是【已取消】状态");
// ========== After Sale 模块 1011000100 ========== // ========== After Sale 模块 1011000100 ==========
ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在");

View File

@ -17,6 +17,7 @@ public enum TradeOrderOperateTypeEnum {
MEMBER_RECEIVE(30, "用户已收货"), MEMBER_RECEIVE(30, "用户已收货"),
MEMBER_COMMENT(31, "用户评价"), MEMBER_COMMENT(31, "用户评价"),
MEMBER_CANCEL(40, "取消订单"), MEMBER_CANCEL(40, "取消订单"),
MEMBER_DELETE(41, "删除订单"),
; ;
/** /**

View File

@ -156,7 +156,7 @@ public class AppTradeOrderController {
@Operation(summary = "删除交易订单") @Operation(summary = "删除交易订单")
@Parameter(name = "id", description = "交易订单编号") @Parameter(name = "id", description = "交易订单编号")
public CommonResult<Boolean> deleteOrder(@RequestParam("id") Long id) { public CommonResult<Boolean> deleteOrder(@RequestParam("id") Long id) {
// TODO @芋艿未实现mock tradeOrderUpdateService.deleteOrder(getLoginUserId(), id);
return success(true); return success(true);
} }

View File

@ -62,6 +62,22 @@ public interface TradeOrderUpdateService {
*/ */
void receiveOrder(Long userId, Long id); void receiveOrder(Long userId, Long id);
/**
* 会员取消订单
*
* @param userId 用户编号
* @param id 订单编号
*/
void cancelOrder(Long userId, Long id);
/**
* 会员删除订单
*
* @param userId 用户编号
* @param id 订单编号
*/
void deleteOrder(Long userId, Long id);
/** /**
* 管理员交易订单备注 * 管理员交易订单备注
* *
@ -117,11 +133,4 @@ public interface TradeOrderUpdateService {
*/ */
Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO); Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO);
/**
* 会员取消订单
*
* @param userId 用户ID
* @param id 订单编号
*/
void cancelOrder(Long userId, Long id);
} }

View File

@ -716,17 +716,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL)
public void cancelOrder(Long userId, Long id) { public void cancelOrder(Long userId, Long id) {
// 校验存在 // 1.1 校验存在
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
if (order == null) { if (order == null) {
throw exception(ORDER_NOT_FOUND); throw exception(ORDER_NOT_FOUND);
} }
// 校验状态 // 1.2 校验状态
if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) { if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) {
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
} }
// 1. 更新 TradeOrderDO 状态为已取消 // 2. 更新 TradeOrderDO 状态为已取消
int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(),
new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus())
.setCancelTime(LocalDateTime.now()) .setCancelTime(LocalDateTime.now())
@ -735,25 +735,46 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
} }
// TODO 活动相关库存回滚需要活动 id活动 id 怎么获取app 端能否传过来回复从订单里拿呀 // 3. TODO 活动相关库存回滚需要活动 id活动 id 怎么获取app 端能否传过来回复从订单里拿呀
tradeOrderHandlers.forEach(handler -> handler.rollback()); tradeOrderHandlers.forEach(handler -> handler.rollback());
// 2. 回滚库存 // 4. 回滚库存
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id); List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
// 3. 回滚优惠券 // 5. 回滚优惠券
if (order.getCouponId() > 0) { if (order.getCouponId() > 0) {
couponApi.returnUsedCoupon(order.getCouponId()); couponApi.returnUsedCoupon(order.getCouponId());
} }
// 4. 回滚积分积分是支付成功后才增加的吧 回复每个项目不同目前看下来确认收货貌似更合适我再看看其它项目的业务选择 // 6. 回滚积分积分是支付成功后才增加的吧 回复每个项目不同目前看下来确认收货貌似更合适我再看看其它项目的业务选择
// TODO @疯狂有赞是可配置支付 or 确认收货我们按照支付好列然后这里的退积分指的是下单时的积分抵扣 // TODO @疯狂有赞是可配置支付 or 确认收货我们按照支付好列然后这里的退积分指的是下单时的积分抵扣
// 5. 增加订单日志 // 7. 增加订单日志
TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus()); TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus());
} }
@Override
@Transactional(rollbackFor = Exception.class)
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_DELETE)
public void deleteOrder(Long userId, Long id) {
// 1.1 校验存在
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
// 1.2 校验状态
if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus())) {
throw exception(ORDER_DELETE_FAIL_STATUS_NOT_CANCEL);
}
// 2. 删除订单
tradeOrderMapper.deleteById(id);
// 3. 记录日志
TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus());
}
/** /**
* 判断指定订单的所有订单项是不是都售后成功 * 判断指定订单的所有订单项是不是都售后成功
* *