UserDataDbconn.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem.MainModels;
  7. namespace MySystem
  8. {
  9. public class UserDataDbconn
  10. {
  11. public readonly static UserDataDbconn Instance = new UserDataDbconn();
  12. #region 获取单个字段
  13. public UserData Get(int Id)
  14. {
  15. // string key = "UserData:" + Id;
  16. // if (RedisDbconn.Instance.Exists(key))
  17. // {
  18. // UserData obj = RedisDbconn.Instance.Get<UserData>(key);
  19. // if (obj != null)
  20. // {
  21. // return obj;
  22. // }
  23. // }
  24. WebCMSEntities db = new WebCMSEntities();
  25. UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
  26. if (userData != null)
  27. {
  28. // RedisDbconn.Instance.Set(key, userData);
  29. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  30. }
  31. return userData;
  32. }
  33. public int GetSelfMakerCount(int Id)
  34. {
  35. string key = "MakerCount:" + Id;
  36. if (RedisDbconn.Instance.Exists(key))
  37. {
  38. int obj = RedisDbconn.Instance.Get<int>(key);
  39. return obj;
  40. }
  41. WebCMSEntities db = new WebCMSEntities();
  42. UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
  43. if (userData != null)
  44. {
  45. RedisDbconn.Instance.Set(key, userData.FansCount);
  46. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  47. }
  48. return 0;
  49. }
  50. public int GetTeamMakerCount(int Id)
  51. {
  52. string key = "TeamMakerCount:" + Id;
  53. if (RedisDbconn.Instance.Exists(key))
  54. {
  55. int obj = RedisDbconn.Instance.Get<int>(key);
  56. return obj;
  57. }
  58. WebCMSEntities db = new WebCMSEntities();
  59. string IdString = "," + Id + ",";
  60. int MakerCount = db.Users.Count(m => m.ParentNav.Contains(IdString) && m.AuthFlag == 1);
  61. RedisDbconn.Instance.Set(key, MakerCount);
  62. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  63. return MakerCount;
  64. }
  65. public int GetSelfMakerCountForMonth(int Id, string TradeMonth)
  66. {
  67. string key = "AddMakerCount:" + Id + ":" + TradeMonth;
  68. if (RedisDbconn.Instance.Exists(key))
  69. {
  70. int obj = RedisDbconn.Instance.Get<int>(key);
  71. return obj;
  72. }
  73. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  74. DateTime end = start.AddMonths(1);
  75. WebCMSEntities db = new WebCMSEntities();
  76. int MakerCount = db.Users.Count(m => m.ParentUserId == Id && m.AuthDate >= start && m.AuthDate < end);
  77. RedisDbconn.Instance.Set(key, MakerCount);
  78. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  79. return MakerCount;
  80. }
  81. public int GetTeamMakerCountForMonth(int Id, string TradeMonth)
  82. {
  83. string key = "TeamAddMakerCount:" + Id + ":" + TradeMonth;
  84. if (RedisDbconn.Instance.Exists(key))
  85. {
  86. int obj = RedisDbconn.Instance.Get<int>(key);
  87. return obj;
  88. }
  89. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  90. DateTime end = start.AddMonths(1);
  91. WebCMSEntities db = new WebCMSEntities();
  92. string IdString = "," + Id + ",";
  93. int MakerCount = db.Users.Count(m => m.ParentNav.Contains(IdString) && m.AuthDate >= start && m.AuthDate < end);
  94. RedisDbconn.Instance.Set(key, MakerCount);
  95. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  96. return MakerCount;
  97. }
  98. public int GetPosActCount(int UserId, string TradeMonthOrDate = "")
  99. {
  100. int MakerCount = 0;
  101. // string key = "TotalPosMerchant:" + Id;
  102. // if (RedisDbconn.Instance.Exists(key))
  103. // {
  104. // int obj = RedisDbconn.Instance.Get<int>(key);
  105. // return obj;
  106. // }
  107. // WebCMSEntities db = new WebCMSEntities();
  108. // string condi = "";
  109. // if (!string.IsNullOrEmpty(TradeMonth))
  110. // {
  111. // string start = TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00";
  112. // string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
  113. // condi += " and ActivationTime>='" + start + "' and ActivationTime<'" + end + "'";
  114. // }
  115. // OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  116. // DataTable dt = OtherMySqlConn.dtable("select count(Id) from PosMachinesTwo where BuyUserId=" + Id + " and ActivationState=1 and UserId>0" + condi);
  117. // if (dt.Rows.Count > 0)
  118. // {
  119. // MakerCount = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  120. // }
  121. // RedisDbconn.Instance.Set(key, MakerCount);
  122. // OtherMySqlConn.connstr = "";
  123. WebCMSEntities db = new WebCMSEntities();
  124. if(string.IsNullOrEmpty(TradeMonthOrDate))
  125. {
  126. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoTitle == "self");
  127. if (check)
  128. {
  129. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  130. }
  131. }
  132. else
  133. {
  134. if(TradeMonthOrDate.Length == 8)
  135. {
  136. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self");
  137. if (check)
  138. {
  139. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  140. }
  141. }
  142. else
  143. {
  144. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self");
  145. if (check)
  146. {
  147. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  148. }
  149. }
  150. }
  151. return MakerCount;
  152. }
  153. public int GetTeamPosActCount(int UserId, string TradeMonthOrDate = "")
  154. {
  155. int MakerCount = 0;
  156. // string key = "TeamTotalPosMerchant:" + Id;
  157. // if (RedisDbconn.Instance.Exists(key))
  158. // {
  159. // int obj = RedisDbconn.Instance.Get<int>(key);
  160. // return obj;
  161. // }
  162. // WebCMSEntities db = new WebCMSEntities();
  163. // string condi = "";
  164. // if (!string.IsNullOrEmpty(TradeMonth))
  165. // {
  166. // string start = TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00";
  167. // string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
  168. // condi += " and ActivationTime>='" + start + "' and ActivationTime<'" + end + "'";
  169. // }
  170. // OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  171. // DataTable dt = OtherMySqlConn.dtable("select count(Id) from PosMachinesTwo where BuyUserId in (select Id from Users where ParentNav like '%," + Id + ",%' or Id=" + Id + ") and ActivationState=1 and UserId>0" + condi);
  172. // if (dt.Rows.Count > 0)
  173. // {
  174. // MakerCount = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  175. // }
  176. // RedisDbconn.Instance.Set(key, MakerCount);
  177. // OtherMySqlConn.connstr = "";
  178. WebCMSEntities db = new WebCMSEntities();
  179. if(string.IsNullOrEmpty(TradeMonthOrDate))
  180. {
  181. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoTitle == "team");
  182. if (check)
  183. {
  184. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  185. }
  186. }
  187. else
  188. {
  189. if(TradeMonthOrDate.Length == 8)
  190. {
  191. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team");
  192. if (check)
  193. {
  194. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  195. }
  196. }
  197. else
  198. {
  199. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team");
  200. if (check)
  201. {
  202. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  203. }
  204. }
  205. }
  206. db.Dispose();
  207. return MakerCount;
  208. }
  209. public int GetTeamBrandPosActCount(int UserId, int BrandId, string TradeMonthOrDate = "")
  210. {
  211. int MakerCount = 0;
  212. WebCMSEntities db = new WebCMSEntities();
  213. if(TradeMonthOrDate.Length == 8)
  214. {
  215. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team");
  216. if (check)
  217. {
  218. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  219. }
  220. }
  221. else
  222. {
  223. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team");
  224. if (check)
  225. {
  226. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  227. }
  228. }
  229. db.Dispose();
  230. return MakerCount;
  231. }
  232. #endregion
  233. }
  234. }