UsersDbconnOld.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using System.Linq;
  5. using MySystem.MainModels;
  6. namespace MySystem
  7. {
  8. public class UsersDbconnOld
  9. {
  10. public readonly static UsersDbconnOld Instance = new UsersDbconnOld();
  11. #region 获取单个字段
  12. public Users Get(int Id)
  13. {
  14. // string key = "Users:" + Id;
  15. // if (RedisDbconn.Instance.Exists(key))
  16. // {
  17. // Users obj = RedisDbconn.Instance.Get<Users>(key);
  18. // if (obj != null)
  19. // {
  20. // return obj;
  21. // }
  22. // }
  23. WebCMSEntities db = new WebCMSEntities();
  24. Users order = db.Users.FirstOrDefault(m => m.Id == Id);
  25. if (order != null)
  26. {
  27. // RedisDbconn.Instance.Set(key, order);
  28. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  29. }
  30. db.Dispose();
  31. return order;
  32. }
  33. //个人新增创客
  34. public int GetNewUserCount(int UserId, string TradeMonth = "")
  35. {
  36. string key = "AddUser:" + UserId;
  37. if (!string.IsNullOrEmpty(TradeMonth))
  38. {
  39. key += ":" + TradeMonth;
  40. }
  41. if (RedisDbconn.Instance.Exists(key))
  42. {
  43. int obj = RedisDbconn.Instance.Get<int>(key);
  44. if (obj > 0)
  45. {
  46. return obj;
  47. }
  48. }
  49. int count = 0;
  50. WebCMSEntities db = new WebCMSEntities();
  51. if (!string.IsNullOrEmpty(TradeMonth))
  52. {
  53. if (TradeMonth.Length == 8)
  54. {
  55. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-" + TradeMonth.Substring(6, 2) + " 00:00:00");
  56. DateTime end = start.AddDays(1);
  57. count = db.Users.Count(m => m.ParentUserId == UserId && m.AuthDate >= start && m.AuthDate < end);
  58. }
  59. else
  60. {
  61. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  62. DateTime end = start.AddMonths(1);
  63. count = db.Users.Count(m => m.ParentUserId == UserId && m.AuthDate >= start && m.AuthDate < end);
  64. }
  65. }
  66. else
  67. {
  68. count = db.Users.Count(m => m.ParentUserId == UserId);
  69. }
  70. RedisDbconn.Instance.Set(key, count);
  71. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(100, 200));
  72. db.Dispose();
  73. return count;
  74. }
  75. //团队新增创客
  76. public int GetTeamNewUserCount(int UserId, string TradeMonth = "")
  77. {
  78. string key = "TeamAddUser:" + UserId;
  79. if (!string.IsNullOrEmpty(TradeMonth))
  80. {
  81. key += ":" + TradeMonth;
  82. }
  83. if (RedisDbconn.Instance.Exists(key))
  84. {
  85. int obj = RedisDbconn.Instance.Get<int>(key);
  86. if (obj > 0)
  87. {
  88. return obj;
  89. }
  90. }
  91. int count = 0;
  92. string UserIdString = "," + UserId + ",";
  93. WebCMSEntities db = new WebCMSEntities();
  94. if (!string.IsNullOrEmpty(TradeMonth))
  95. {
  96. if (TradeMonth.Length == 8)
  97. {
  98. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-" + TradeMonth.Substring(6, 2) + " 00:00:00");
  99. DateTime end = start.AddDays(1);
  100. count = db.Users.Count(m => m.ParentNav.Contains(UserIdString) && m.AuthDate >= start && m.AuthDate < end);
  101. }
  102. else
  103. {
  104. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  105. DateTime end = start.AddMonths(1);
  106. count = db.Users.Count(m => m.ParentNav.Contains(UserIdString) && m.AuthDate >= start && m.AuthDate < end);
  107. }
  108. }
  109. else
  110. {
  111. count = db.Users.Count(m => m.ParentNav.Contains(UserIdString));
  112. }
  113. RedisDbconn.Instance.Set(key, count);
  114. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(100, 200));
  115. db.Dispose();
  116. return count;
  117. }
  118. #endregion
  119. }
  120. }