UserTradeDaySummaryDbconnV2.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 UserTradeDaySummaryDbconnV2
  9. {
  10. public readonly static UserTradeDaySummaryDbconnV2 Instance = new UserTradeDaySummaryDbconnV2();
  11. public UserTradeDaySummaryDbconnV2()
  12. { }
  13. // TODO:读取很慢,感觉redis没生效
  14. #region 获取单个字段
  15. //个人业绩
  16. public decimal GetTrade(int UserId, int BankCardType, 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.UserTradeDaySummary.Any(m => m.UserId == UserId && m.SeoTitle == kind);
  31. if (check)
  32. {
  33. if (kind == "self")
  34. {
  35. if (BankCardType == 0)
  36. {
  37. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.DirectDebitTradeAmt);
  38. }
  39. else
  40. {
  41. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.DirectTradeAmt);
  42. }
  43. }
  44. else if (kind == "team")
  45. {
  46. if (BankCardType == 0)
  47. {
  48. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.NonDirectDebitTradeAmt);
  49. }
  50. else
  51. {
  52. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.NonDirectTradeAmt);
  53. }
  54. }
  55. }
  56. // RedisDbconn.Instance.Set(key, amt);
  57. db.Dispose();
  58. return amt;
  59. }
  60. public decimal GetDateTrade(int UserId, string TradeDate, int BankCardType, string kind = "self")
  61. {
  62. // if (UserId == 598)
  63. // {
  64. // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).TotalAmt;
  65. // }
  66. // string key = "TotalAmount:" + UserId + ":" + TradeDate; //总交易
  67. // if (kind == "team")
  68. // {
  69. // key = "Team" + key;
  70. // }
  71. // string obj = RedisDbconn.Instance.Get<string>(key);
  72. // if (!string.IsNullOrEmpty(obj))
  73. // {
  74. // return decimal.Parse(function.CheckNum(obj));
  75. // }
  76. decimal amt = 0;
  77. WebCMSEntities db = new WebCMSEntities();
  78. bool check = db.UserTradeDaySummary.Any(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind);
  79. if (check)
  80. {
  81. if (kind == "self")
  82. {
  83. if (BankCardType == 0)
  84. {
  85. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.DirectDebitTradeAmt);
  86. }
  87. else
  88. {
  89. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.DirectTradeAmt);
  90. }
  91. }
  92. else if (kind == "team")
  93. {
  94. if (BankCardType == 0)
  95. {
  96. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.NonDirectDebitTradeAmt);
  97. }
  98. else
  99. {
  100. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.NonDirectTradeAmt);
  101. }
  102. }
  103. }
  104. // RedisDbconn.Instance.Set(key, amt);
  105. db.Dispose();
  106. return amt;
  107. }
  108. public decimal GetMonthTrade(int UserId, string TradeMonth, int BankCardType, string kind = "self")
  109. {
  110. // if (UserId == 598)
  111. // {
  112. // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).TotalAmt;
  113. // }
  114. // string key = "TotalAmount:" + UserId + ":" + TradeMonth; //总交易
  115. // if (kind == "team")
  116. // {
  117. // key = "Team" + key;
  118. // }
  119. // string obj = RedisDbconn.Instance.Get<string>(key);
  120. // if (!string.IsNullOrEmpty(obj))
  121. // {
  122. // return decimal.Parse(function.CheckNum(obj));
  123. // }
  124. decimal amt = 0;
  125. WebCMSEntities db = new WebCMSEntities();
  126. bool check = db.UserTradeDaySummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind);
  127. if (check)
  128. {
  129. if (kind == "self")
  130. {
  131. if (BankCardType == 0)
  132. {
  133. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.DirectDebitTradeAmt);
  134. }
  135. else
  136. {
  137. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.DirectTradeAmt);
  138. }
  139. }
  140. else if (kind == "team")
  141. {
  142. if (BankCardType == 0)
  143. {
  144. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.NonDirectDebitTradeAmt);
  145. }
  146. else
  147. {
  148. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.NonDirectTradeAmt);
  149. }
  150. }
  151. }
  152. // RedisDbconn.Instance.Set(key, amt);
  153. db.Dispose();
  154. return amt;
  155. }
  156. public decimal GetDateTradeForBrand(int UserId, string TradeDate, int BrandId, int BankCardType, string kind = "self")
  157. {
  158. // if (UserId == 598)
  159. // {
  160. // var item = UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).Brands.FirstOrDefault(m => m.Id == BrandId);
  161. // if (item != null)
  162. // {
  163. // return item.Amt;
  164. // }
  165. // return 0;
  166. // }
  167. // string key = "TotalAmount:" + UserId + ":" + BrandId + ":" + TradeDate; //总交易
  168. // if (kind == "team")
  169. // {
  170. // key = "Team" + key;
  171. // }
  172. // string obj = RedisDbconn.Instance.Get<string>(key);
  173. // if (!string.IsNullOrEmpty(obj))
  174. // {
  175. // return decimal.Parse(function.CheckNum(obj));
  176. // }
  177. decimal amt = 0;
  178. WebCMSEntities db = new WebCMSEntities();
  179. bool check = db.UserTradeDaySummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.
  180. SeoTitle == kind);
  181. if (check)
  182. {
  183. if (kind == "self")
  184. {
  185. if (BankCardType == 0)
  186. {
  187. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.DirectDebitTradeAmt);
  188. }
  189. else
  190. {
  191. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.DirectTradeAmt);
  192. }
  193. }
  194. else if (kind == "team")
  195. {
  196. if (BankCardType == 0)
  197. {
  198. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.NonDirectDebitTradeAmt);
  199. }
  200. else
  201. {
  202. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.NonDirectTradeAmt);
  203. }
  204. }
  205. }
  206. // RedisDbconn.Instance.Set(key, amt);
  207. db.Dispose();
  208. return amt;
  209. }
  210. public decimal GetMonthTradeForBrand(int UserId, string TradeMonth, int BrandId, int BankCardType, string kind = "self")
  211. {
  212. // if (UserId == 598)
  213. // {
  214. // var item = UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).Brands.FirstOrDefault(m => m.Id == BrandId);
  215. // if (item != null)
  216. // {
  217. // return item.Amt;
  218. // }
  219. // return 0;
  220. // }
  221. // string key = "TotalAmount:" + UserId + ":" + BrandId + ":" + TradeMonth; //总交易
  222. // if (kind == "team")
  223. // {
  224. // key = "Team" + key;
  225. // }
  226. // string obj = RedisDbconn.Instance.Get<string>(key);
  227. // if (!string.IsNullOrEmpty(obj))
  228. // {
  229. // return decimal.Parse(function.CheckNum(obj));
  230. // }
  231. decimal amt = 0;
  232. WebCMSEntities db = new WebCMSEntities();
  233. bool check = db.UserTradeDaySummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.
  234. SeoTitle == kind);
  235. if (check)
  236. {
  237. if (kind == "self")
  238. {
  239. if (BankCardType == 0)
  240. {
  241. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.DirectDebitTradeAmt);
  242. }
  243. else
  244. {
  245. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.DirectTradeAmt);
  246. }
  247. }
  248. else if (kind == "team")
  249. {
  250. if (BankCardType == 0)
  251. {
  252. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.NonDirectDebitTradeAmt);
  253. }
  254. else
  255. {
  256. amt = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.NonDirectTradeAmt);
  257. }
  258. }
  259. }
  260. // RedisDbconn.Instance.Set(key, amt);
  261. db.Dispose();
  262. return amt;
  263. }
  264. public decimal GetDateTradeForCloud(int UserId, string TradeDate, int QrPayFlag, int BankCardType, string kind = "self")
  265. {
  266. // if (UserId == 598)
  267. // {
  268. // if (QrPayFlag == 1)
  269. // {
  270. // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).QrAmt;
  271. // }
  272. // else
  273. // {
  274. // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).PosAmt;
  275. // }
  276. // }
  277. // string key = "TotalPosAmount:" + UserId + ":" + TradeDate; //总交易
  278. // if (QrPayFlag == 1)
  279. // {
  280. // key = "TotalCloudPayAmount:" + UserId + ":" + TradeDate; //总交易
  281. // }
  282. // if (kind == "team")
  283. // {
  284. // key = "Team" + key;
  285. // }
  286. // string obj = RedisDbconn.Instance.Get<string>(key);
  287. // if (!string.IsNullOrEmpty(obj))
  288. // {
  289. // return decimal.Parse(function.CheckNum(obj));
  290. // }
  291. decimal amt = 0;
  292. WebCMSEntities db = new WebCMSEntities();
  293. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.
  294. SeoTitle == kind);
  295. if (check)
  296. {
  297. if (kind == "self")
  298. {
  299. if (BankCardType == 0)
  300. {
  301. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectDebitTradeAmt + m.NotHelpDirectDebitTradeAmt);
  302. }
  303. else
  304. {
  305. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.NotHelpDirectTradeAmt);
  306. }
  307. }
  308. else if (kind == "team")
  309. {
  310. if (BankCardType == 0)
  311. {
  312. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  313. }
  314. else
  315. {
  316. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  317. }
  318. }
  319. }
  320. // RedisDbconn.Instance.Set(key, amt);
  321. db.Dispose();
  322. return amt;
  323. }
  324. public decimal GetMonthTradeForCloud(int UserId, string TradeMonth, int QrPayFlag, int BankCardType, string kind = "self")
  325. {
  326. // if (UserId == 598)
  327. // {
  328. // if (QrPayFlag == 1)
  329. // {
  330. // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).QrAmt;
  331. // }
  332. // else
  333. // {
  334. // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).PosAmt;
  335. // }
  336. // }
  337. // string key = "TotalPosAmount:" + UserId + ":" + TradeMonth; //总交易
  338. // if (QrPayFlag == 1)
  339. // {
  340. // key = "TotalCloudPayAmount:" + UserId + ":" + TradeMonth; //总交易
  341. // }
  342. // if (kind == "team")
  343. // {
  344. // key = "Team" + key;
  345. // }
  346. // string obj = RedisDbconn.Instance.Get<string>(key);
  347. // if (!string.IsNullOrEmpty(obj))
  348. // {
  349. // return decimal.Parse(function.CheckNum(obj));
  350. // }
  351. decimal amt = 0;
  352. WebCMSEntities db = new WebCMSEntities();
  353. bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.
  354. SeoTitle == kind);
  355. if (check)
  356. {
  357. if (kind == "self")
  358. {
  359. if (BankCardType == 0)
  360. {
  361. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectDebitTradeAmt + m.NotHelpDirectDebitTradeAmt);
  362. }
  363. else
  364. {
  365. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.NotHelpDirectTradeAmt);
  366. }
  367. }
  368. else if (kind == "team")
  369. {
  370. if (BankCardType == 0)
  371. {
  372. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectDebitTradeAmt);
  373. }
  374. else
  375. {
  376. amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  377. }
  378. }
  379. }
  380. // RedisDbconn.Instance.Set(key, amt);
  381. db.Dispose();
  382. return amt;
  383. }
  384. #endregion
  385. }
  386. }