UserDatabase.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Long.Common.Basedata;
  2. using Long.Dapper;
  3. namespace Long.DAO.Basedata
  4. {
  5. /// <summary>
  6. /// 系统用户-数据库
  7. /// </summary>
  8. public class UserDatabase : Database<User>, IUserDatabase
  9. {
  10. /// <summary>
  11. /// 通过登录名获取一条系统用户数据
  12. /// </summary>
  13. /// <param name="userName">登录名</param>
  14. /// <returns>用户</returns>
  15. public async Task<User> GetUserAsync(string userName)
  16. {
  17. 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;";
  18. return await GetFirstAsync(sql, new {
  19. UserName = userName,
  20. Email = userName,
  21. Phone = userName
  22. });
  23. }
  24. /// <summary>
  25. /// 通过登录名获取一条系统用户数据
  26. /// </summary>
  27. /// <param name="userName">登录名</param>
  28. /// <returns>用户</returns>
  29. public async Task<User> GetByUserNameAsync(string userName)
  30. {
  31. 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;";
  32. return await GetFirstAsync(sql, new { UserName = userName });
  33. }
  34. /// <summary>
  35. /// 通过推广码获取一条系统用户数据
  36. /// </summary>
  37. /// <param name="promotionCode">推广码</param>
  38. /// <returns>用户</returns>
  39. public async Task<User> GetByPromotionCodeAsync(string promotionCode)
  40. {
  41. 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;";
  42. return await GetFirstAsync(sql, new { PromotionCode = promotionCode });
  43. }
  44. /// <summary>
  45. /// 判断推广码是否重复
  46. /// </summary>
  47. /// <param name="promotionCode">推广码</param>
  48. /// <returns>重复标记</returns>
  49. public async Task<bool> PromotionCodeIsRepeatAsync(string promotionCode)
  50. {
  51. string sql = "SELECT Count(Id) FROM user WHERE PromotionCode = @PromotionCode;";
  52. var count = await GetFirstAsync<int>(sql, new { PromotionCode = promotionCode });
  53. return count > 0 ? true : false;
  54. }
  55. /// <summary>
  56. /// 更新密码
  57. /// </summary>
  58. /// <param name="id">内码</param>
  59. /// <param name="password">新密码</param>
  60. /// <returns></returns>
  61. public async Task<int> UpdatePassword(long id, string password)
  62. {
  63. string sql = "UPDATE User SET Password = @Password WHERE Id = @Id;";
  64. return await UpdateAsync(sql, new { Id = id, Password = password });
  65. }
  66. /// <summary>
  67. /// 判断用户是否存在
  68. /// </summary>
  69. /// <param name="id"></param>
  70. /// <returns></returns>
  71. public async Task<bool> HasUser(long id)
  72. {
  73. return await CountAsync(id) > 0 ? true : false;
  74. }
  75. }
  76. }