修复取消订单误释放商品
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user