BusinessTradeSummaryDbconn.cs 18 KB

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