UsersDbconnOld.cs 4.2 KB

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