修复取消订单误释放商品

This commit is contained in:
yml2213
2026-08-02 16:38:02 +08:00
parent 921654e5b0
commit 0256bfd276
5 changed files with 237 additions and 2 deletions
+20 -1
View File
@@ -230,6 +230,19 @@ func clampRenterRetentionDays(value int) int {
return value
}
func hasActiveSiblingOrder(tx *gorm.DB, order model.RentalOrder) (bool, error) {
var count int64
err := tx.Model(&model.RentalOrder{}).
Where("id <> ? AND (listing_id = ? OR account_id = ?) AND status NOT IN ?",
order.ID,
order.ListingID,
order.AccountID,
[]string{"completed", "cancelled", "closed"},
).
Count(&count).Error
return count > 0, err
}
func (j *Job) handlePendingPaymentTimeout(ctx context.Context, now time.Time, cfg thresholds) (int, error) {
if cfg.PendingPaymentTimeoutMinutes <= 0 {
return 0, nil
@@ -260,7 +273,13 @@ func (j *Job) handlePendingPaymentTimeout(ctx context.Context, now time.Time, cf
}
order.Status = "cancelled"
order.HandoffStatus = "cancelled"
listing.InTransaction = false
active, err := hasActiveSiblingOrder(tx, order)
if err != nil {
return err
}
if !active {
listing.InTransaction = false
}
orderID := order.ID
if err := closePendingOrderPayments(tx, order.ID, "order_timeout"); err != nil {
return err