fix(tenant): 收紧双站后台边界并补齐货架管理
This commit is contained in:
@@ -324,7 +324,7 @@ func applyTenantOfferVisibility(ctx context.Context, db *gorm.DB) *gorm.DB {
|
||||
return db.Joins(
|
||||
"INNER JOIN tenant_listing_offers AS tlo ON tlo.listing_id = l.id AND tlo.tenant_id = ? AND tlo.display_status = 'enabled'",
|
||||
tenantID,
|
||||
)
|
||||
).Where("(l.distribution_site_id IS NULL OR l.distribution_site_id = 0)")
|
||||
}
|
||||
|
||||
func (r *Repository) applyTenantOfferPrices(ctx context.Context, items []ListingDTO) error {
|
||||
|
||||
@@ -266,10 +266,14 @@ func applyListingSourceTenantScope(ctx context.Context, query *gorm.DB, alias st
|
||||
return query
|
||||
}
|
||||
column := "source_tenant_id"
|
||||
distributionColumn := "distribution_site_id"
|
||||
if alias != "" {
|
||||
column = alias + "." + column
|
||||
distributionColumn = alias + "." + distributionColumn
|
||||
}
|
||||
return query.Where(column+" = ?", tenantID)
|
||||
return query.
|
||||
Where(column+" = ?", tenantID).
|
||||
Where("(" + distributionColumn + " IS NULL OR " + distributionColumn + " = 0)")
|
||||
}
|
||||
|
||||
func (r *Repository) findForReviewUpdate(ctx context.Context, tx *gorm.DB, listingID uint64) (*model.RentalListing, *model.GameAccount, error) {
|
||||
|
||||
@@ -18,7 +18,10 @@ func (r *Repository) FindTenantOffer(ctx context.Context, listingID uint64) (*Te
|
||||
return nil, ErrTenantRequired
|
||||
}
|
||||
var listing model.RentalListing
|
||||
if err := r.db.WithContext(ctx).Select("id, price_cent").First(&listing, listingID).Error; err != nil {
|
||||
if err := r.db.WithContext(ctx).
|
||||
Select("id, price_cent").
|
||||
Where("id = ? AND (distribution_site_id IS NULL OR distribution_site_id = 0)", listingID).
|
||||
First(&listing).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var offer model.TenantListingOffer
|
||||
@@ -50,7 +53,10 @@ func (r *Repository) UpdateTenantOffer(
|
||||
return nil, ErrInvalidPrice
|
||||
}
|
||||
var listing model.RentalListing
|
||||
if err := r.db.WithContext(ctx).Select("id, price_cent").First(&listing, listingID).Error; err != nil {
|
||||
if err := r.db.WithContext(ctx).
|
||||
Select("id, price_cent").
|
||||
Where("id = ? AND (distribution_site_id IS NULL OR distribution_site_id = 0)", listingID).
|
||||
First(&listing).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, ErrListingNotFound
|
||||
}
|
||||
|
||||
@@ -29,6 +29,13 @@ func TestPublicListingUsesCurrentTenantOffer(t *testing.T) {
|
||||
if err := db.Create(&other).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
legacySite := model.DistributionSite{
|
||||
ID: 999, SiteCode: "legacy_listing_offer", SiteName: "历史分销测试站",
|
||||
Domain: "legacy-listing-offer.example.com", Status: "active",
|
||||
}
|
||||
if err := db.Create(&legacySite).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
owner := model.User{TenantID: dachui.ID, Phone: "13100000001", Status: "active"}
|
||||
if err := db.Create(&owner).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -57,6 +64,20 @@ func TestPublicListingUsesCurrentTenantOffer(t *testing.T) {
|
||||
if err := db.Create(&offers).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
legacySiteID := legacySite.ID
|
||||
legacyListing := model.RentalListing{
|
||||
SourceTenantID: dachui.ID, ListingNo: "L-LEGACY-DIST",
|
||||
AccountID: account.ID, OwnerID: owner.ID, PriceCent: 9000,
|
||||
Status: "published", ReviewStatus: "approved", DistributionSiteID: &legacySiteID,
|
||||
}
|
||||
if err := db.Create(&legacyListing).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.TenantListingOffer{
|
||||
TenantID: jieyou.ID, ListingID: legacyListing.ID, DisplayStatus: "enabled",
|
||||
}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
repo := NewRepository(db, nil)
|
||||
|
||||
dachuiResult, err := repo.ListPublic(listingTenantContext(dachui.ID), PublicListQuery{})
|
||||
|
||||
Reference in New Issue
Block a user