using Long.Common.Basedata; using Long.Dapper; namespace Long.DAO.Basedata { /// /// 系统用户-数据库 /// public class UserDatabase : Database, IUserDatabase { /// /// 通过登录名获取一条系统用户数据 /// /// 登录名 /// 用户 public async Task GetUserAsync(string userName) { string sql = "SELECT Id, Code, IsActive, UserName, Password, Email, Name, Gender, Age, `Language`, City, Province, Country, AvatarUrl, Phone, PromotionCode, ParentPromotionCode, PromotionLevel, CreatedBy, CreatedOn, LastModifiedBy, LastModifiedOn FROM user WHERE UserName = @UserName OR Email = @Email OR Phone = @Phone;"; return await GetFirstAsync(sql, new { UserName = userName, Email = userName, Phone = userName }); } /// /// 通过登录名获取一条系统用户数据 /// /// 登录名 /// 用户 public async Task GetByUserNameAsync(string userName) { string sql = "SELECT Id, Code, IsActive, UserName, Password, Email, Name, Gender, Age, `Language`, City, Province, Country, AvatarUrl, Phone, PromotionCode, ParentPromotionCode, PromotionLevel, CreatedBy, CreatedOn, LastModifiedBy, LastModifiedOn FROM user WHERE UserName = @UserName;"; return await GetFirstAsync(sql, new { UserName = userName }); } /// /// 通过推广码获取一条系统用户数据 /// /// 推广码 /// 用户 public async Task GetByPromotionCodeAsync(string promotionCode) { string sql = "SELECT Id, Code, IsActive, UserName, Password, Email, Name, Gender, Age, `Language`, City, Province, Country, AvatarUrl, Phone, PromotionCode, ParentPromotionCode, PromotionLevel, CreatedBy, CreatedOn, LastModifiedBy, LastModifiedOn FROM user WHERE PromotionCode = @PromotionCode;"; return await GetFirstAsync(sql, new { PromotionCode = promotionCode }); } /// /// 判断推广码是否重复 /// /// 推广码 /// 重复标记 public async Task PromotionCodeIsRepeatAsync(string promotionCode) { string sql = "SELECT Count(Id) FROM user WHERE PromotionCode = @PromotionCode;"; var count = await GetFirstAsync(sql, new { PromotionCode = promotionCode }); return count > 0 ? true : false; } /// /// 更新密码 /// /// 内码 /// 新密码 /// public async Task UpdatePassword(long id, string password) { string sql = "UPDATE User SET Password = @Password WHERE Id = @Id;"; return await UpdateAsync(sql, new { Id = id, Password = password }); } /// /// 判断用户是否存在 /// /// /// public async Task HasUser(long id) { return await CountAsync(id) > 0 ? true : false; } } }