接入分销订单支付退款与站点隔离
This commit is contained in:
@@ -91,7 +91,7 @@ func EnsureListingConversation(tx *gorm.DB, listing model.RentalListing, preferr
|
||||
// 4. 取二维码(带行锁)
|
||||
var qrcode *model.ChatQrCode
|
||||
var qrcodeImageURL string
|
||||
qrcodeObj, err := fetchUnusedQrCode(tx)
|
||||
qrcodeObj, err := fetchUnusedQrCodeForListing(tx, listing.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -301,12 +301,32 @@ func updateConversationLastMessage(tx *gorm.DB, conversationID uint64, message *
|
||||
}
|
||||
|
||||
func fetchUnusedQrCode(tx *gorm.DB) (*model.ChatQrCode, error) {
|
||||
return fetchUnusedQrCodeForSite(tx, nil)
|
||||
}
|
||||
|
||||
func fetchUnusedQrCodeForListing(tx *gorm.DB, listingID uint64) (*model.ChatQrCode, error) {
|
||||
var relation model.DistributionSiteAccount
|
||||
if err := tx.Where("listing_id = ? AND display_status = 'enabled'", listingID).Order("id ASC").First(&relation).Error; err == nil {
|
||||
return fetchUnusedQrCodeForSite(tx, &relation.SiteID)
|
||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// 兼容尚未执行分销迁移的环境,继续使用全局二维码池。
|
||||
return fetchUnusedQrCodeForSite(tx, nil)
|
||||
}
|
||||
return fetchUnusedQrCodeForSite(tx, nil)
|
||||
}
|
||||
|
||||
func fetchUnusedQrCodeForSite(tx *gorm.DB, siteID *uint64) (*model.ChatQrCode, error) {
|
||||
var qrcode model.ChatQrCode
|
||||
now := time.Now()
|
||||
|
||||
err := tx.Where("status = ?", QrCodeStatusUnused).
|
||||
query := tx.Where("status = ?", QrCodeStatusUnused).
|
||||
Where("expires_at IS NULL OR expires_at > ?", now).
|
||||
Order("id ASC").
|
||||
Order("id ASC")
|
||||
if siteID == nil {
|
||||
query = query.Where("distribution_site_id IS NULL")
|
||||
} else {
|
||||
query = query.Where("distribution_site_id = ?", *siteID)
|
||||
}
|
||||
err := query.
|
||||
Limit(1).
|
||||
Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
First(&qrcode).Error
|
||||
|
||||
Reference in New Issue
Block a user