UserDataDbconn.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. WebCMSEntities db = new WebCMSEntities();
  16. UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
  17. if (userData != null)
  18. {
  19. }
  20. return userData;
  21. }
  22. public int GetSelfMakerCount(int Id)
  23. {
  24. string key = "MakerCount:" + Id;
  25. if (RedisDbconn.Instance.Exists(key))
  26. {
  27. int obj = RedisDbconn.Instance.Get<int>(key);
  28. return obj;
  29. }
  30. WebCMSEntities db = new WebCMSEntities();
  31. UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
  32. if (userData != null)
  33. {
  34. RedisDbconn.Instance.Set(key, userData.FansCount);
  35. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  36. }
  37. return 0;
  38. }
  39. public int GetTeamMakerCount(int Id)
  40. {
  41. string key = "TeamMakerCount:" + Id;
  42. if (RedisDbconn.Instance.Exists(key))
  43. {
  44. int obj = RedisDbconn.Instance.Get<int>(key);
  45. return obj;
  46. }
  47. WebCMSEntities db = new WebCMSEntities();
  48. string IdString = "," + Id + ",";
  49. int MakerCount = db.Users.Count(m => m.ParentNav.Contains(IdString) && m.AuthFlag == 1);
  50. RedisDbconn.Instance.Set(key, MakerCount);
  51. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  52. return MakerCount;
  53. }
  54. public int GetSelfMakerCountForMonth(int Id, string TradeMonth)
  55. {
  56. string key = "AddMakerCount:" + Id + ":" + TradeMonth;
  57. if (RedisDbconn.Instance.Exists(key))
  58. {
  59. int obj = RedisDbconn.Instance.Get<int>(key);
  60. return obj;
  61. }
  62. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  63. DateTime end = start.AddMonths(1);
  64. WebCMSEntities db = new WebCMSEntities();
  65. int MakerCount = db.Users.Count(m => m.ParentUserId == Id && m.AuthDate >= start && m.AuthDate < end);
  66. RedisDbconn.Instance.Set(key, MakerCount);
  67. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  68. return MakerCount;
  69. }
  70. public int GetTeamMakerCountForMonth(int Id, string TradeMonth)
  71. {
  72. string key = "TeamAddMakerCount:" + Id + ":" + TradeMonth;
  73. if (RedisDbconn.Instance.Exists(key))
  74. {
  75. int obj = RedisDbconn.Instance.Get<int>(key);
  76. return obj;
  77. }
  78. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  79. DateTime end = start.AddMonths(1);
  80. WebCMSEntities db = new WebCMSEntities();
  81. string IdString = "," + Id + ",";
  82. int MakerCount = db.Users.Count(m => m.ParentNav.Contains(IdString) && m.AuthDate >= start && m.AuthDate < end);
  83. RedisDbconn.Instance.Set(key, MakerCount);
  84. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  85. return MakerCount;
  86. }
  87. public int GetPosActCount(int UserId, string TradeMonthOrDate = "")
  88. {
  89. int MakerCount = 0;
  90. WebCMSEntities db = new WebCMSEntities();
  91. if (string.IsNullOrEmpty(TradeMonthOrDate))
  92. {
  93. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoTitle == "self");
  94. if (check)
  95. {
  96. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  97. }
  98. }
  99. else
  100. {
  101. if (TradeMonthOrDate.Length == 8)
  102. {
  103. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self");
  104. if (check)
  105. {
  106. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  107. }
  108. }
  109. else
  110. {
  111. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self");
  112. if (check)
  113. {
  114. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  115. }
  116. }
  117. }
  118. return MakerCount;
  119. }
  120. public int GetSelfBrandPosActCount(int UserId, int BrandId, string TradeMonthOrDate = "")
  121. {
  122. int MakerCount = 0;
  123. WebCMSEntities db = new WebCMSEntities();
  124. if (TradeMonthOrDate.Length == 8)
  125. {
  126. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self");
  127. if (check)
  128. {
  129. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  130. }
  131. }
  132. else
  133. {
  134. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self");
  135. if (check)
  136. {
  137. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
  138. }
  139. }
  140. db.Dispose();
  141. return MakerCount;
  142. }
  143. public int GetTeamPosActCount(int UserId, string TradeMonthOrDate = "")
  144. {
  145. int MakerCount = 0;
  146. WebCMSEntities db = new WebCMSEntities();
  147. if (string.IsNullOrEmpty(TradeMonthOrDate))
  148. {
  149. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoTitle == "team");
  150. if (check)
  151. {
  152. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  153. }
  154. }
  155. else
  156. {
  157. if (TradeMonthOrDate.Length == 8)
  158. {
  159. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team");
  160. if (check)
  161. {
  162. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  163. }
  164. }
  165. else
  166. {
  167. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team");
  168. if (check)
  169. {
  170. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  171. }
  172. }
  173. }
  174. db.Dispose();
  175. return MakerCount;
  176. }
  177. public int GetTeamBrandPosActCount(int UserId, int BrandId, string TradeMonthOrDate = "")
  178. {
  179. int MakerCount = 0;
  180. WebCMSEntities db = new WebCMSEntities();
  181. if (TradeMonthOrDate.Length == 8)
  182. {
  183. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team");
  184. if (check)
  185. {
  186. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  187. }
  188. }
  189. else
  190. {
  191. bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team");
  192. if (check)
  193. {
  194. MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  195. }
  196. }
  197. db.Dispose();
  198. return MakerCount;
  199. }
  200. /// <summary>
  201. /// 获取来客吧区域代理交易额
  202. /// </summary>
  203. /// <param name="UserId">创客Id</param>
  204. /// <param name="TradeMonthOrDate">统计时间</param>
  205. /// <returns></returns>
  206. public decimal GetMpAgentTradeAmount(int UserId, string TradeMonthOrDate = "")
  207. {
  208. decimal TradeAmount = 0.00M;
  209. MpMainModels.WebCMSEntities mpdb = new MpMainModels.WebCMSEntities();
  210. MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
  211. if (TradeMonthOrDate.Length == 8)
  212. {
  213. bool check = mpdb.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
  214. bool check2 = mpdb2.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
  215. if (check)
  216. {
  217. TradeAmount = mpdb.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate).Sum(m => m.TotalAmount);
  218. }
  219. if (check2)
  220. {
  221. TradeAmount += mpdb2.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.TotalAmount);
  222. }
  223. }
  224. else
  225. {
  226. bool check = mpdb.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate);
  227. bool check2 = mpdb2.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
  228. if (check)
  229. {
  230. TradeAmount = mpdb.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.TotalAmount);
  231. }
  232. if (check2)
  233. {
  234. TradeAmount += mpdb2.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.TotalAmount);
  235. }
  236. }
  237. mpdb.Dispose();
  238. mpdb2.Dispose();
  239. return TradeAmount;
  240. }
  241. #endregion
  242. }
  243. }