UserTradeDaySummaryDbconn.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 UserTradeDaySummaryDbconn
  9. {
  10. public readonly static UserTradeDaySummaryDbconn Instance = new UserTradeDaySummaryDbconn();
  11. public UserTradeDaySummaryDbconn()
  12. { }
  13. // TODO:读取很慢,感觉redis没生效
  14. #region 获取单个字段
  15. //个人业绩
  16. public decimal GetTrade(int UserId, string kind = "self")
  17. {
  18. // string key = "TotalAmount:" + UserId; //总交易
  19. // if (kind == "team")
  20. // {
  21. // key = "Team" + key;
  22. // }
  23. // string obj = RedisDbconn.Instance.Get<string>(key);
  24. // if (!string.IsNullOrEmpty(obj))
  25. // {
  26. // return decimal.Parse(function.CheckNum(obj));
  27. // }
  28. decimal amt = 0;
  29. WebCMSEntities db = new WebCMSEntities();
  30. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.SeoTitle == kind);
  31. if (check)
  32. {
  33. if (kind == "self")
  34. {
  35. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  36. }
  37. else if (kind == "team")
  38. {
  39. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  40. }
  41. }
  42. // RedisDbconn.Instance.Set(key, amt);
  43. db.Dispose();
  44. return amt;
  45. }
  46. public decimal GetDateTrade(int UserId, string TradeDate, string kind = "self")
  47. {
  48. // if (UserId == 598)
  49. // {
  50. // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).TotalAmt;
  51. // }
  52. // string key = "TotalAmount:" + UserId + ":" + TradeDate; //总交易
  53. // if (kind == "team")
  54. // {
  55. // key = "Team" + key;
  56. // }
  57. // string obj = RedisDbconn.Instance.Get<string>(key);
  58. // if (!string.IsNullOrEmpty(obj))
  59. // {
  60. // return decimal.Parse(function.CheckNum(obj));
  61. // }
  62. decimal amt = 0;
  63. WebCMSEntities db = new WebCMSEntities();
  64. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind);
  65. if (check)
  66. {
  67. if (kind == "self")
  68. {
  69. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  70. }
  71. else if (kind == "team")
  72. {
  73. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  74. }
  75. }
  76. // RedisDbconn.Instance.Set(key, amt);
  77. db.Dispose();
  78. return amt;
  79. }
  80. public decimal GetMonthTrade(int UserId, string TradeMonth, string kind = "self")
  81. {
  82. // if (UserId == 598)
  83. // {
  84. // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).TotalAmt;
  85. // }
  86. // string key = "TotalAmount:" + UserId + ":" + TradeMonth; //总交易
  87. // if (kind == "team")
  88. // {
  89. // key = "Team" + key;
  90. // }
  91. // string obj = RedisDbconn.Instance.Get<string>(key);
  92. // if (!string.IsNullOrEmpty(obj))
  93. // {
  94. // return decimal.Parse(function.CheckNum(obj));
  95. // }
  96. decimal amt = 0;
  97. WebCMSEntities db = new WebCMSEntities();
  98. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind);
  99. if (check)
  100. {
  101. if (kind == "self")
  102. {
  103. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  104. }
  105. else if (kind == "team")
  106. {
  107. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  108. }
  109. }
  110. // RedisDbconn.Instance.Set(key, amt);
  111. db.Dispose();
  112. return amt;
  113. }
  114. public decimal GetDateTradeForBrand(int UserId, string TradeDate, int BrandId, string kind = "self")
  115. {
  116. // if (UserId == 598)
  117. // {
  118. // var item = UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).Brands.FirstOrDefault(m => m.Id == BrandId);
  119. // if (item != null)
  120. // {
  121. // return item.Amt;
  122. // }
  123. // return 0;
  124. // }
  125. // string key = "TotalAmount:" + UserId + ":" + BrandId + ":" + TradeDate; //总交易
  126. // if (kind == "team")
  127. // {
  128. // key = "Team" + key;
  129. // }
  130. // string obj = RedisDbconn.Instance.Get<string>(key);
  131. // if (!string.IsNullOrEmpty(obj))
  132. // {
  133. // return decimal.Parse(function.CheckNum(obj));
  134. // }
  135. decimal amt = 0;
  136. WebCMSEntities db = new WebCMSEntities();
  137. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.
  138. SeoTitle == kind);
  139. if (check)
  140. {
  141. if (kind == "self")
  142. {
  143. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  144. }
  145. else if (kind == "team")
  146. {
  147. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  148. }
  149. }
  150. // RedisDbconn.Instance.Set(key, amt);
  151. db.Dispose();
  152. return amt;
  153. }
  154. public decimal GetMonthTradeForBrand(int UserId, string TradeMonth, int BrandId, string kind = "self")
  155. {
  156. // if (UserId == 598)
  157. // {
  158. // var item = UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).Brands.FirstOrDefault(m => m.Id == BrandId);
  159. // if (item != null)
  160. // {
  161. // return item.Amt;
  162. // }
  163. // return 0;
  164. // }
  165. // string key = "TotalAmount:" + UserId + ":" + BrandId + ":" + TradeMonth; //总交易
  166. // if (kind == "team")
  167. // {
  168. // key = "Team" + key;
  169. // }
  170. // string obj = RedisDbconn.Instance.Get<string>(key);
  171. // if (!string.IsNullOrEmpty(obj))
  172. // {
  173. // return decimal.Parse(function.CheckNum(obj));
  174. // }
  175. decimal amt = 0;
  176. WebCMSEntities db = new WebCMSEntities();
  177. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind);
  178. if (check)
  179. {
  180. if (kind == "self")
  181. {
  182. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  183. }
  184. else if (kind == "team")
  185. {
  186. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  187. }
  188. }
  189. // RedisDbconn.Instance.Set(key, amt);
  190. db.Dispose();
  191. return amt;
  192. }
  193. public decimal GetDateTradeForCloud(int UserId, string TradeDate, int QrPayFlag, string kind = "self")
  194. {
  195. // if (UserId == 598)
  196. // {
  197. // if (QrPayFlag == 1)
  198. // {
  199. // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).QrAmt;
  200. // }
  201. // else
  202. // {
  203. // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).PosAmt;
  204. // }
  205. // }
  206. // string key = "TotalPosAmount:" + UserId + ":" + TradeDate; //总交易
  207. // if (QrPayFlag == 1)
  208. // {
  209. // key = "TotalCloudPayAmount:" + UserId + ":" + TradeDate; //总交易
  210. // }
  211. // if (kind == "team")
  212. // {
  213. // key = "Team" + key;
  214. // }
  215. // string obj = RedisDbconn.Instance.Get<string>(key);
  216. // if (!string.IsNullOrEmpty(obj))
  217. // {
  218. // return decimal.Parse(function.CheckNum(obj));
  219. // }
  220. decimal amt = 0;
  221. WebCMSEntities db = new WebCMSEntities();
  222. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind);
  223. if (check)
  224. {
  225. if (kind == "self")
  226. {
  227. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  228. }
  229. else if (kind == "team")
  230. {
  231. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  232. }
  233. }
  234. // RedisDbconn.Instance.Set(key, amt);
  235. db.Dispose();
  236. return amt;
  237. }
  238. public decimal GetMonthTradeForCloud(int UserId, string TradeMonth, int QrPayFlag, string kind = "self")
  239. {
  240. // if (UserId == 598)
  241. // {
  242. // if (QrPayFlag == 1)
  243. // {
  244. // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).QrAmt;
  245. // }
  246. // else
  247. // {
  248. // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).PosAmt;
  249. // }
  250. // }
  251. // string key = "TotalPosAmount:" + UserId + ":" + TradeMonth; //总交易
  252. // if (QrPayFlag == 1)
  253. // {
  254. // key = "TotalCloudPayAmount:" + UserId + ":" + TradeMonth; //总交易
  255. // }
  256. // if (kind == "team")
  257. // {
  258. // key = "Team" + key;
  259. // }
  260. // string obj = RedisDbconn.Instance.Get<string>(key);
  261. // if (!string.IsNullOrEmpty(obj))
  262. // {
  263. // return decimal.Parse(function.CheckNum(obj));
  264. // }
  265. decimal amt = 0;
  266. WebCMSEntities db = new WebCMSEntities();
  267. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.
  268. SeoTitle == kind);
  269. if (check)
  270. {
  271. if (kind == "self")
  272. {
  273. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
  274. }
  275. else if (kind == "team")
  276. {
  277. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  278. }
  279. }
  280. // RedisDbconn.Instance.Set(key, amt);
  281. db.Dispose();
  282. return amt;
  283. }
  284. #endregion
  285. }
  286. }