feat: add public tenant packages listing and sort order

This commit is contained in:
2025-12-11 23:57:04 +08:00
parent cf9927c078
commit c7df64f2e1
28 changed files with 731 additions and 5 deletions

View File

@@ -25,13 +25,16 @@ public sealed class EfTenantRepository(TakeoutAppDbContext context) : ITenantRep
string? keyword,
CancellationToken cancellationToken = default)
{
// 1. 构建基础查询
var query = context.Tenants.AsNoTracking();
// 2. 按状态过滤
if (status.HasValue)
{
query = query.Where(x => x.Status == status.Value);
}
// 3. 按关键字过滤
if (!string.IsNullOrWhiteSpace(keyword))
{
keyword = keyword.Trim();
@@ -41,6 +44,7 @@ public sealed class EfTenantRepository(TakeoutAppDbContext context) : ITenantRep
EF.Functions.ILike(x.ContactName ?? string.Empty, $"%{keyword}%"));
}
// 4. 排序返回
return await query
.OrderByDescending(x => x.CreatedAt)
.ToListAsync(cancellationToken);
@@ -66,6 +70,13 @@ public sealed class EfTenantRepository(TakeoutAppDbContext context) : ITenantRep
return context.Tenants.AnyAsync(x => x.Code == normalized, cancellationToken);
}
/// <inheritdoc />
public Task<bool> ExistsByContactPhoneAsync(string phone, CancellationToken cancellationToken = default)
{
var normalized = phone.Trim();
return context.Tenants.AnyAsync(x => x.ContactPhone == normalized, cancellationToken);
}
/// <inheritdoc />
public Task<TenantVerificationProfile?> GetVerificationProfileAsync(long tenantId, CancellationToken cancellationToken = default)
{
@@ -77,15 +88,18 @@ public sealed class EfTenantRepository(TakeoutAppDbContext context) : ITenantRep
/// <inheritdoc />
public async Task UpsertVerificationProfileAsync(TenantVerificationProfile profile, CancellationToken cancellationToken = default)
{
// 1. 查询现有实名资料
var existing = await context.TenantVerificationProfiles
.FirstOrDefaultAsync(x => x.TenantId == profile.TenantId, cancellationToken);
if (existing == null)
{
// 2. 不存在则新增
await context.TenantVerificationProfiles.AddAsync(profile, cancellationToken);
return;
}
// 3. 存在则更新当前值
profile.Id = existing.Id;
context.Entry(existing).CurrentValues.SetValues(profile);
}