UserTradeDaySummaryVsDbconn.cs 14 KB

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