Commit 6b5db0b9 authored by Junling Bu's avatar Junling Bu
Browse files

fix[litemall-wx-api]: mysql默认事务隔离级别是可重复读

parent 613d2dba
...@@ -730,23 +730,7 @@ public class WxOrderService { ...@@ -730,23 +730,7 @@ public class WxOrderService {
order.setPayTime(LocalDateTime.now()); order.setPayTime(LocalDateTime.now());
order.setOrderStatus(OrderUtil.STATUS_PAY); order.setOrderStatus(OrderUtil.STATUS_PAY);
if (orderService.updateWithOptimisticLocker(order) == 0) { if (orderService.updateWithOptimisticLocker(order) == 0) {
// 这里可能存在这样一个问题,用户支付和系统自动取消订单发生在同时 return WxPayNotifyResponse.fail("更新数据已失效");
// 如果数据库首先因为系统自动取消订单而更新了订单状态;
// 此时用户支付完成回调这里也要更新数据库,而由于乐观锁机制这里的更新会失败
// 因此,这里会重新读取数据库检查状态是否是订单自动取消,如果是则更新成支付状态。
order = orderService.findBySn(orderSn);
int updated = 0;
if (OrderUtil.isAutoCancelStatus(order)) {
order.setPayId(payId);
order.setPayTime(LocalDateTime.now());
order.setOrderStatus(OrderUtil.STATUS_PAY);
updated = orderService.updateWithOptimisticLocker(order);
}
// 如果updated是0,那么数据库更新失败
if (updated == 0) {
return WxPayNotifyResponse.fail("更新数据已失效");
}
} }
// 支付成功,有团购信息,更新团购信息 // 支付成功,有团购信息,更新团购信息
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment