fix(优惠券中心):用户查询优惠券逻辑优化,回调更新订单状态
This commit is contained in:
+59
@@ -45,6 +45,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Order information
|
||||
@@ -1149,4 +1150,62 @@ public class OrderController {
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单状态为已支付(优惠券核销成功后调用)")
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo) {
|
||||
log.info("优惠券核销成功,更新订单状态为已支付,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
log.error("订单不存在,orderNo: {}", orderNo);
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
// 检查订单当前状态
|
||||
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())) {
|
||||
// 更新订单状态为已支付排队中
|
||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||
// 设置支付类型为优惠券支付
|
||||
order.setPayType(2); // 2表示优惠券支付
|
||||
// 设置支付时间
|
||||
order.setPayTime(new Date());
|
||||
|
||||
boolean result = orderService.updateOrder(order);
|
||||
if (result) {
|
||||
log.info("订单状态更新成功,orderNo: {}, 新状态: {}", orderNo, OrderStatus.PAID.getId());
|
||||
return Result.succeed("订单状态更新成功");
|
||||
} else {
|
||||
log.error("订单状态更新失败,orderNo: {}", orderNo);
|
||||
return Result.failed("订单状态更新失败");
|
||||
}
|
||||
} else {
|
||||
log.warn("订单状态不正确,无法更新为已支付,orderNo: {}, 当前状态: {}",
|
||||
orderNo, order.getOrderStatus());
|
||||
return Result.failed("订单状态不正确,无法更新为已支付");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单状态异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("更新订单状态异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "根据订单号获取订单信息")
|
||||
@GetMapping("/order/{orderNo}")
|
||||
public Result<Order> getOrderByOrderNo(@PathVariable("orderNo") String orderNo) {
|
||||
log.info("根据订单号获取订单信息,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
return Result.succeed(order);
|
||||
} catch (Exception e) {
|
||||
log.error("获取订单信息异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("获取订单信息异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user