using Microsoft.Extensions.Logging; using QYZH.InteractiveMagazine.IService; using QYZH.InteractiveMagazine.IService.Dto; using QYZH.InteractiveMagazine.Models.Common; using QYZH.InteractiveMagazine.Models.Dto; using QYZH.InteractiveMagazine.Models.Entity; using QYZH.InteractiveMagazine.Repository; using SqlSugar; namespace QYZH.InteractiveMagazine.Service; public class UsersService(BaseRepository usersRepository, ILogger _logger) : BaseRepository, IUsersService { /// /// 分页查询用户列表 /// public async Task>> GetListAsync(UsersQueryInput input) { var page = Queryable() .WhereIF(!string.IsNullOrEmpty(input.WxUserId), u => u.OpenId == input.WxUserId) .OrderBy(u => u.Id, OrderByType.Desc) .ToPage(input); return BaseResponse>.Success(page); } /// /// 获取用户详情 /// public async Task> GetDetailAsync(long id) { var user = await GetByIdAsync(u => u.Id == id); if (user == null) { return BaseResponse.Fail("用户不存在"); } return BaseResponse.Success(user); } /// /// 更新用户状态 /// public async Task UpdateStatusAsync(long id, UpdateUserStatusInput input) { var exists = await Queryable().AnyAsync(u => u.Id == id); if (!exists) { return BaseResponse.Fail("用户不存在"); } var statusValue = input.Status == 1 ? "Active" : "Disabled"; var result = await UpdateAsync( u => new Users { Status = statusValue }, u => u.Id == id ); return result ? BaseResponse.Success() : BaseResponse.Fail("更新失败"); } }