1.fix update_time autofill
This commit is contained in:
2026-05-15 11:56:26 +08:00
parent 497371794e
commit 8770e216ba
2 changed files with 18 additions and 23 deletions

View File

@@ -152,7 +152,7 @@ public class IPaymentServiceImpl implements IPaymentService {
userOrder.setOrderStatus(OrderStatus.PAID.getCode());
userOrder.setPaymentTime(DateUtil.now());
userOrder.setUpdateTime(DateUtil.now());
boolean updated = commonUserOrderService.saveOrUpdate(userOrder);
boolean updated = commonUserOrderService.updateById(userOrder);
if (!updated) {
throw new ServiceException("支付失败");
}

View File

@@ -400,30 +400,26 @@ public class CommonUserOrderServiceImpl extends BaseServiceImpl<CommonUserOrderM
@Override
@Transactional(rollbackFor = Exception.class)
public boolean confirmPayment(Long id) {
boolean updated = update(Wrappers.lambdaUpdate(CommonUserOrderEntity.class)
.set(CommonUserOrderEntity::getOrderStatus, OrderStatus.PAID.getCode())
.set(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.PAID.getCode())
.set(CommonUserOrderEntity::getPaymentTime, new Date())
.eq(CommonUserOrderEntity::getId, id)
.eq(CommonUserOrderEntity::getPaymentType, PaymentType.OFFLINE.getCode())
.eq(CommonUserOrderEntity::getOrderStatus, OrderStatus.PENDING_PAYMENT.getCode())
.eq(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.UNPAID.getCode())
.eq(CommonUserOrderEntity::getIsDeleted, 0)
);
if (!updated) {
// 可能已被处理过,或状态不符 → 幂等返回 true(避免报错)
log.warn("订单 {} 无需处理或已处理", id);
return true; // ⭐ 幂等:已成功过就不要再失败
}
CommonUserOrderEntity order = getById(id);
if (order == null) {
throw new IllegalStateException("订单更新成功但查询不到,id=" + id);
throw new IllegalStateException("无效订单" + id);
}
// userPointService.grantPointsByUserOrder(order);
if(order.getOrderStatus().equals(OrderStatus.PENDING_PAYMENT.getCode()) && order.getPaymentType().equals(PaymentType.OFFLINE.getCode()) && order.getPaymentStatus().equals(PaymentStatus.UNPAID.getCode())){
order.setOrderStatus(OrderStatus.PAID.getCode());
order.setPaymentStatus(PaymentStatus.PAID.getCode());
order.setPaymentTime(new Date());
boolean updated = this.updateById(order);
if (!updated) {
// 可能已被处理过,或状态不符 → 幂等返回 true(避免报错)
log.warn("订单 {} 无需处理或已处理", id);
return true; // ⭐ 幂等:已成功过就不要再失败
}
eventPublisher.publishEvent(new PaymentSuccessEvent(id, order.getUserId(), BusinessModule.SELF_OPERATED_MALL));
eventPublisher.publishEvent(new PaymentSuccessEvent(id, order.getUserId(), BusinessModule.SELF_OPERATED_MALL));
return true;
return true;
}
throw new ServiceException("操作失败");
}
@Override
@@ -431,13 +427,12 @@ public class CommonUserOrderServiceImpl extends BaseServiceImpl<CommonUserOrderM
public boolean fillExpress(Long id, String expressNo) {
CommonUserOrderEntity userOrder = getById(id);
if (userOrder == null) {
throw new ServiceException("无效订单");
throw new IllegalStateException("无效订单");
}
if (userOrder.getOrderStatus().equals(OrderStatus.PAID.getCode()) && userOrder.getPaymentStatus().equals(PaymentStatus.PAID.getCode()) && userOrder.getIsDeleted().equals(0)) {
userOrder.setExpressNo(expressNo);
userOrder.setOrderStatus(OrderStatus.SHIPPED.getCode());
userOrder.setUpdateTime(new Date());
boolean updated = updateById(userOrder);
boolean updated = this.updateById(userOrder);
if (!updated) {
throw new ServiceException("状态更新无效,id=" + id);
}