fix[litemall-wx-api]: mysql默认事务隔离级别是可重复读
This commit is contained in:
@@ -730,23 +730,7 @@ public class WxOrderService {
|
||||
order.setPayTime(LocalDateTime.now());
|
||||
order.setOrderStatus(OrderUtil.STATUS_PAY);
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
// 这里可能存在这样一个问题,用户支付和系统自动取消订单发生在同时
|
||||
// 如果数据库首先因为系统自动取消订单而更新了订单状态;
|
||||
// 此时用户支付完成回调这里也要更新数据库,而由于乐观锁机制这里的更新会失败
|
||||
// 因此,这里会重新读取数据库检查状态是否是订单自动取消,如果是则更新成支付状态。
|
||||
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("更新数据已失效");
|
||||
}
|
||||
return WxPayNotifyResponse.fail("更新数据已失效");
|
||||
}
|
||||
|
||||
// 支付成功,有团购信息,更新团购信息
|
||||
|
||||
Reference in New Issue
Block a user