fix(listing): 分销站商品审核按所属租户可见
分销站商品按站点归属租户参与审核;商品管理、审核详情及首页待审数量统一租户范围。
This commit is contained in:
@@ -38,7 +38,7 @@ func (r *Repository) ListAdmin(ctx context.Context, query AdminListQuery) (*Admi
|
||||
|
||||
if hasAdminAssetFilters(query) {
|
||||
var rows []listingRow
|
||||
err := r.applyAdminListFilters(r.baseQuery(ctx), query).
|
||||
err := r.applyAdminListFilters(tenancy.ApplyListingTenantScope(ctx, r.baseQuery(ctx), "l"), query).
|
||||
Order("l.id DESC").
|
||||
Scan(&rows).Error
|
||||
if err != nil {
|
||||
@@ -67,7 +67,7 @@ func (r *Repository) ListAdmin(ctx context.Context, query AdminListQuery) (*Admi
|
||||
}, nil
|
||||
}
|
||||
|
||||
db := r.applyAdminListFilters(r.baseQuery(ctx), query)
|
||||
db := r.applyAdminListFilters(tenancy.ApplyListingTenantScope(ctx, r.baseQuery(ctx), "l"), query)
|
||||
offset := (page - 1) * pageSize
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
@@ -83,7 +83,7 @@ func (r *Repository) ListAdmin(ctx context.Context, query AdminListQuery) (*Admi
|
||||
if page == 1 && len(rows) < pageSize {
|
||||
total = int64(len(rows))
|
||||
} else {
|
||||
countDB := r.applyAdminListFilters(r.db.WithContext(ctx).Table("rental_listings AS l"), query)
|
||||
countDB := r.applyAdminListFilters(tenancy.ApplyListingTenantScope(ctx, r.db.WithContext(ctx).Table("rental_listings AS l"), "l"), query)
|
||||
if err := countDB.Count(&total).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func yuanToAdminCent(value float64) int64 {
|
||||
}
|
||||
|
||||
func (r *Repository) FindAdmin(ctx context.Context, listingID uint64) (*ListingDTO, error) {
|
||||
query := applyListingSourceTenantScope(ctx, r.baseQuery(ctx), "l")
|
||||
query := tenancy.ApplyListingTenantScope(ctx, r.baseQuery(ctx), "l")
|
||||
var row listingRow
|
||||
if err := query.Where("l.id = ?", listingID).First(&row).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -260,25 +260,9 @@ func (r *Repository) baseQuery(ctx context.Context) *gorm.DB {
|
||||
)`)
|
||||
}
|
||||
|
||||
func applyListingSourceTenantScope(ctx context.Context, query *gorm.DB, alias string) *gorm.DB {
|
||||
tenantID := tenancy.IDFromContext(ctx)
|
||||
if tenantID == 0 {
|
||||
return query
|
||||
}
|
||||
column := "source_tenant_id"
|
||||
distributionColumn := "distribution_site_id"
|
||||
if alias != "" {
|
||||
column = alias + "." + column
|
||||
distributionColumn = alias + "." + distributionColumn
|
||||
}
|
||||
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) {
|
||||
var listing model.RentalListing
|
||||
query := applyListingSourceTenantScope(ctx, tx.Where("id = ?", listingID), "")
|
||||
query := tenancy.ApplyListingTenantScope(ctx, tx.Where("id = ?", listingID), "")
|
||||
if err := query.Clauses(clause.Locking{Strength: "UPDATE"}).First(&listing).Error; err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user