修复取消订单误释放商品

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
+15 -1
View File
@@ -33,6 +33,13 @@ func (r *Repository) Create(ctx context.Context, renterID uint64, req CreateRequ
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&account, listing.AccountID).Error; err != nil {
return err
}
active, err := hasActiveOrderForAssets(tx, listing.ID, account.ID, 0)
if err != nil {
return err
}
if active {
return ErrListingUnavailable
}
snapshot, err := makeAccountSnapshot(account, listing)
if err != nil {
return err
@@ -219,6 +226,13 @@ func (r *Repository) ConfirmPaidFromChannelTx(tx *gorm.DB, orderID uint64) (uint
if listing.Status != listingStatusPublished || listing.ReviewStatus != listingReviewStatusApproved || !listing.InTransaction {
return 0, ErrListingUnavailable
}
active, err := hasActiveSiblingOrder(tx, order)
if err != nil {
return 0, err
}
if active {
return 0, ErrListingUnavailable
}
// 租客已通过外部渠道付款,这里不写租客钱包流水。
orderID = order.ID
@@ -354,7 +368,7 @@ func (r *Repository) Cancel(ctx context.Context, userID uint64, orderID uint64)
return err
}
}
if err := releaseAssetsForRental(tx, listing, account); err != nil {
if err := releaseAssetsForRentalIfIdle(tx, &order, listing, account); err != nil {
return err
}
if err := closePendingOrderPayments(tx, order.ID, "order_cancel"); err != nil {