diff --git a/src/main/java/com/cultural/heritage/service/order/RefundRecordService.java b/src/main/java/com/cultural/heritage/service/order/RefundRecordService.java index 90d985a..c2ca2d7 100644 --- a/src/main/java/com/cultural/heritage/service/order/RefundRecordService.java +++ b/src/main/java/com/cultural/heritage/service/order/RefundRecordService.java @@ -12,4 +12,5 @@ public interface RefundRecordService extends IService { * 获取查询条件 */ QueryWrapper getQueryWrapper(RefundRecordQueryRequest refundRecordQueryRequest); + } diff --git a/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java b/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java index 7988140..6e83961 100644 --- a/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java @@ -412,6 +412,21 @@ public class WeChatServiceImpl implements WeChatService { updateWrapper.eq("orderItemId", orderItemId).set("orderItemStatus", OrderStatusConstant.PAYMENT_REFUNDED); boolean update = pendingServiceOrderService.update(updateWrapper); ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "服务类订单待处理记录状态更新失败"); + // 如果退款的是订单中最后一个订单明细,则修改订单状态 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("outTradeNo", orderNumber); + long refundCount = refundRecordService.count(queryWrapper); + + QueryWrapper orderItemsQueryWrapper = new QueryWrapper<>(); + orderItemsQueryWrapper.eq("orderId", order.getId()); + long orderItemCount = orderItemService.count(orderItemsQueryWrapper); + + UpdateWrapper orderUpdateWrapper = new UpdateWrapper<>(); + if (refundCount == orderItemCount) { + orderUpdateWrapper.eq("id", order.getId()).set("orderStatus", OrderStatusConstant.PAYMENT_REFUNDED); + boolean result = orderService.update(orderUpdateWrapper); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "订单状态更新失败"); + } } else { // 恢复商品库存 OrderItems orderItems = orderItemService.getById(orderItemId);