fix: 修复门店租户写入与跨租户查看

This commit is contained in:
2026-01-19 20:22:12 +08:00
parent abd5752ad1
commit 30e54e2bea
13 changed files with 192 additions and 39 deletions

View File

@@ -19,9 +19,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
/// <inheritdoc />
public Task<Store?> FindByIdAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
{
return context.Stores
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.Id == storeId)
var query = context.Stores.AsNoTracking();
if (tenantId <= 0)
{
query = query.IgnoreQueryFilters()
.Where(x => x.DeletedAt == null);
}
else
{
query = query.Where(x => x.TenantId == tenantId);
}
return query
.Where(x => x.Id == storeId)
.FirstOrDefaultAsync(cancellationToken);
}
@@ -44,11 +54,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
StoreBusinessStatus? businessStatus,
StoreOwnershipType? ownershipType,
string? keyword,
bool ignoreTenantFilter = false,
CancellationToken cancellationToken = default)
{
var query = context.Stores
.AsNoTracking()
.Where(x => x.TenantId == tenantId);
var query = context.Stores.AsNoTracking();
if (ignoreTenantFilter)
{
query = query.IgnoreQueryFilters()
.Where(x => x.DeletedAt == null);
}
else
{
query = query.Where(x => x.TenantId == tenantId);
}
if (merchantId.HasValue)
{
@@ -153,9 +171,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
/// <inheritdoc />
public async Task<IReadOnlyList<StoreBusinessHour>> GetBusinessHoursAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
{
var hours = await context.StoreBusinessHours
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.StoreId == storeId)
var query = context.StoreBusinessHours.AsNoTracking();
if (tenantId <= 0)
{
query = query.IgnoreQueryFilters()
.Where(x => x.DeletedAt == null);
}
else
{
query = query.Where(x => x.TenantId == tenantId);
}
var hours = await query
.Where(x => x.StoreId == storeId)
.OrderBy(x => x.DayOfWeek)
.ThenBy(x => x.StartTime)
.ToListAsync(cancellationToken);
@@ -166,9 +194,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
/// <inheritdoc />
public Task<StoreFee?> GetStoreFeeAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
{
return context.StoreFees
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.StoreId == storeId)
var query = context.StoreFees.AsNoTracking();
if (tenantId <= 0)
{
query = query.IgnoreQueryFilters()
.Where(x => x.DeletedAt == null);
}
else
{
query = query.Where(x => x.TenantId == tenantId);
}
return query
.Where(x => x.StoreId == storeId)
.FirstOrDefaultAsync(cancellationToken);
}
@@ -188,9 +226,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
/// <inheritdoc />
public async Task<IReadOnlyList<StoreQualification>> GetQualificationsAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
{
var qualifications = await context.StoreQualifications
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.StoreId == storeId)
var query = context.StoreQualifications.AsNoTracking();
if (tenantId <= 0)
{
query = query.IgnoreQueryFilters()
.Where(x => x.DeletedAt == null);
}
else
{
query = query.Where(x => x.TenantId == tenantId);
}
var qualifications = await query
.Where(x => x.StoreId == storeId)
.OrderBy(x => x.SortOrder)
.ThenBy(x => x.QualificationType)
.ToListAsync(cancellationToken);
@@ -259,9 +307,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
/// <inheritdoc />
public async Task<IReadOnlyList<StoreDeliveryZone>> GetDeliveryZonesAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
{
var zones = await context.StoreDeliveryZones
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.StoreId == storeId)
var query = context.StoreDeliveryZones.AsNoTracking();
if (tenantId <= 0)
{
query = query.IgnoreQueryFilters()
.Where(x => x.DeletedAt == null);
}
else
{
query = query.Where(x => x.TenantId == tenantId);
}
var zones = await query
.Where(x => x.StoreId == storeId)
.OrderBy(x => x.SortOrder)
.ToListAsync(cancellationToken);