修复取消订单误释放商品
This commit is contained in:
@@ -61,6 +61,50 @@ func releaseAssetsForRental(tx *gorm.DB, listing *model.RentalListing, account *
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "订单取消恢复上架")
|
||||
}
|
||||
|
||||
func terminalOrderStatuses() []string {
|
||||
return []string{orderStatusCompleted, orderStatusCancelled, orderStatusClosed}
|
||||
}
|
||||
|
||||
func hasActiveSiblingOrder(tx *gorm.DB, order *model.RentalOrder) (bool, error) {
|
||||
if order == nil {
|
||||
return false, nil
|
||||
}
|
||||
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,
|
||||
terminalOrderStatuses(),
|
||||
).
|
||||
Count(&count).Error
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
func hasActiveOrderForAssets(tx *gorm.DB, listingID uint64, accountID uint64, excludeOrderID uint64) (bool, error) {
|
||||
var count int64
|
||||
err := tx.Model(&model.RentalOrder{}).
|
||||
Where("id <> ? AND (listing_id = ? OR account_id = ?) AND status NOT IN ?",
|
||||
excludeOrderID,
|
||||
listingID,
|
||||
accountID,
|
||||
terminalOrderStatuses(),
|
||||
).
|
||||
Count(&count).Error
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
func releaseAssetsForRentalIfIdle(tx *gorm.DB, order *model.RentalOrder, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
active, err := hasActiveSiblingOrder(tx, order)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if active {
|
||||
return nil
|
||||
}
|
||||
return releaseAssetsForRental(tx, listing, account)
|
||||
}
|
||||
|
||||
func archiveAssets(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusOffline
|
||||
|
||||
Reference in New Issue
Block a user