StatTradeCheckService.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.KxsReadModels;
  9. namespace MySystem
  10. {
  11. public class StatTradeCheckService
  12. {
  13. public readonly static StatTradeCheckService Instance = new StatTradeCheckService();
  14. private StatTradeCheckService()
  15. { }
  16. // 统计交易额V2
  17. public void Start()
  18. {
  19. Thread th = new Thread(StartDo);
  20. th.IsBackground = true;
  21. th.Start();
  22. }
  23. public void StartDo()
  24. {
  25. while (true)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("StatTradeCheckQueue");
  28. if(!string.IsNullOrEmpty(content))
  29. {
  30. StatTradeAmountDo(content);
  31. Thread.Sleep(1);
  32. }
  33. else
  34. {
  35. Thread.Sleep(10000);
  36. }
  37. }
  38. }
  39. public void StatTradeAmountDo(string date)
  40. {
  41. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  42. try
  43. {
  44. int pageNum = 0;
  45. bool check = true;
  46. while(check)
  47. {
  48. string sql = "";
  49. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----start", "统计交易额日志");
  50. DataTable dt = CustomerSqlConn.dtable("select UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(TradeAmount),count(Id),SnNo,TradeDate from TradeRecord where Id>20000000 and ActStatus=1 and BrandId!=14 and UserId>0 and CreateDate>='" + date + " 00:00:00' and CreateDate<='" + date + " 23:59:59' group by UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),SnNo,TradeDate order by UserId limit " + pageNum + ",500", AppConfig.Base.TmpReadSqlConn);
  51. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----query", "统计交易额日志");
  52. if(dt.Rows.Count > 0)
  53. {
  54. foreach (DataRow dr in dt.Rows)
  55. {
  56. int UserId = int.Parse(dr["UserId"].ToString());
  57. string SnNo = dr["SnNo"].ToString();
  58. string BindingTime = dr["TradeDate"].ToString();
  59. string ParentNav = dr["ParentNav"].ToString();
  60. int BrandId = int.Parse(dr["BrandId"].ToString());
  61. int BankCardType = int.Parse(dr["BankCardType"].ToString());
  62. int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
  63. int MerHelpFlag = int.Parse(dr["MerHelpFlag"].ToString());
  64. int Version = int.Parse(dr["Version"].ToString());
  65. int CapFlag = int.Parse(dr["CapFlag"].ToString());
  66. int VipFlag = int.Parse(dr["VipFlag"].ToString());
  67. int PayType = int.Parse(dr["PayType"].ToString());
  68. string TradeDate = dr[10].ToString();
  69. decimal TradeAmount = decimal.Parse(dr[11].ToString());
  70. int TradeCount = 1;
  71. string TradeMonth = TradeDate.Substring(0, 6);
  72. ParentNav += "," + UserId + ",";
  73. string ParentNavString = ParentNav.Trim(',').Replace(",,", ",");
  74. string[] UserIdList = ParentNavString.Split(',');
  75. if(Version < 2)
  76. {
  77. //个人业绩
  78. decimal ProfitDirectDebitTradeAmt = 0;
  79. decimal ProfitDirectDebitCapTradeAmt = 0;
  80. decimal ProfitDirectDebitCapNum = 0;
  81. decimal HelpDirectDebitTradeAmt = 0;
  82. decimal HelpDirectDebitCapTradeAmt = 0;
  83. decimal HelpDirectDebitCapNum = 0;
  84. decimal NotHelpDirectDebitTradeAmt = 0;
  85. decimal NotHelpDirectDebitCapTradeAmt = 0;
  86. decimal NotHelpDirectDebitCapNum = 0;
  87. decimal ProfitDirectTradeAmt = 0;
  88. decimal HelpDirectTradeAmt = 0;
  89. decimal NotHelpDirectTradeAmt = 0;
  90. if (BankCardType == 0)
  91. {
  92. if (Version == 1)
  93. {
  94. ProfitDirectDebitTradeAmt += TradeAmount;
  95. if (CapFlag == 1)
  96. {
  97. ProfitDirectDebitCapTradeAmt += TradeAmount;
  98. ProfitDirectDebitCapNum += TradeCount;
  99. }
  100. }
  101. else if (MerHelpFlag == 1)
  102. {
  103. HelpDirectDebitTradeAmt += TradeAmount;
  104. if (CapFlag == 1)
  105. {
  106. HelpDirectDebitCapTradeAmt += TradeAmount;
  107. HelpDirectDebitCapNum += TradeCount;
  108. }
  109. }
  110. else
  111. {
  112. NotHelpDirectDebitTradeAmt += TradeAmount;
  113. if (CapFlag == 1)
  114. {
  115. NotHelpDirectDebitCapTradeAmt += TradeAmount;
  116. NotHelpDirectDebitCapNum += TradeCount;
  117. }
  118. }
  119. }
  120. else if (BankCardType != 0)
  121. {
  122. if (Version == 1)
  123. {
  124. ProfitDirectTradeAmt += TradeAmount;
  125. }
  126. else if (MerHelpFlag == 1)
  127. {
  128. HelpDirectTradeAmt += TradeAmount;
  129. }
  130. else
  131. {
  132. NotHelpDirectTradeAmt += TradeAmount;
  133. }
  134. }
  135. sql += InsertOrUpdate("TradeDaySummary", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  136. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  137. {
  138. sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  139. }
  140. else
  141. {
  142. sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  143. }
  144. //团队业绩
  145. foreach(string SubUserId in UserIdList)
  146. {
  147. decimal ProfitNonDirectDebitTradeAmt = 0;
  148. ProfitDirectDebitCapTradeAmt = 0;
  149. ProfitDirectDebitCapNum = 0;
  150. decimal HelpNonDirectDebitTradeAmt = 0;
  151. HelpDirectDebitCapTradeAmt = 0;
  152. HelpDirectDebitCapNum = 0;
  153. decimal NotHelpNonDirectDebitTradeAmt = 0;
  154. NotHelpDirectDebitCapTradeAmt = 0;
  155. NotHelpDirectDebitCapNum = 0;
  156. decimal ProfitNonDirectTradeAmt = 0;
  157. decimal HelpNonDirectTradeAmt = 0;
  158. decimal NotHelpNonDirectTradeAmt = 0;
  159. if (BankCardType == 0)
  160. {
  161. if (Version == 1)
  162. {
  163. ProfitNonDirectDebitTradeAmt += TradeAmount;
  164. if (CapFlag == 1)
  165. {
  166. ProfitDirectDebitCapTradeAmt += TradeAmount;
  167. ProfitDirectDebitCapNum += TradeCount;
  168. }
  169. }
  170. else if (MerHelpFlag == 1)
  171. {
  172. HelpNonDirectDebitTradeAmt += TradeAmount;
  173. if (CapFlag == 1)
  174. {
  175. HelpDirectDebitCapTradeAmt += TradeAmount;
  176. HelpDirectDebitCapNum += TradeCount;
  177. }
  178. }
  179. else
  180. {
  181. NotHelpNonDirectDebitTradeAmt += TradeAmount;
  182. if (CapFlag == 1)
  183. {
  184. NotHelpDirectDebitCapTradeAmt += TradeAmount;
  185. NotHelpDirectDebitCapNum += TradeCount;
  186. }
  187. }
  188. }
  189. else if (BankCardType != 0)
  190. {
  191. if (Version == 1)
  192. {
  193. ProfitNonDirectTradeAmt += TradeAmount;
  194. }
  195. else if (MerHelpFlag == 1)
  196. {
  197. HelpNonDirectTradeAmt += TradeAmount;
  198. }
  199. else
  200. {
  201. NotHelpNonDirectTradeAmt += TradeAmount;
  202. }
  203. }
  204. sql += InsertOrUpdate("TradeDaySummary", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  205. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  206. {
  207. sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  208. }
  209. else
  210. {
  211. sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  212. }
  213. }
  214. }
  215. else
  216. {
  217. decimal ProfitDebitTradeAmt = 0;
  218. decimal ProfitDebitCapTradeAmt = 0;
  219. decimal ProfitDebitCapNum = 0;
  220. decimal ProfitTradeAmt = 0;
  221. if (BankCardType == 0)
  222. {
  223. if (Version == 2)
  224. {
  225. ProfitDebitTradeAmt += TradeAmount;
  226. if (CapFlag == 1)
  227. {
  228. ProfitDebitCapTradeAmt += TradeAmount;
  229. ProfitDebitCapNum += TradeCount;
  230. }
  231. }
  232. }
  233. else if (BankCardType != 0)
  234. {
  235. if (Version == 2)
  236. {
  237. ProfitTradeAmt += TradeAmount;
  238. }
  239. }
  240. sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  241. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  242. {
  243. sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  244. }
  245. else
  246. {
  247. sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  248. }
  249. foreach(string SubUserId in UserIdList)
  250. {
  251. sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  252. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  253. {
  254. sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  255. }
  256. else
  257. {
  258. sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  259. }
  260. }
  261. }
  262. }
  263. pageNum += 1;
  264. }
  265. else
  266. {
  267. check = false;
  268. }
  269. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----end", "统计交易额日志");
  270. // function.WriteLog(sql, "SQL脚本");
  271. CustomerSqlConn.op(sql, AppConfig.Base.SqlConn);
  272. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----fiinsh\n\n", "统计交易额日志");
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  278. }
  279. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  280. }
  281. List<string> rediskeys = new List<string>();
  282. public string InsertOrUpdate(string table, string fields, string vals, string condition)
  283. {
  284. string sql = "";
  285. // string check = RedisDbconn.Instance.Get<string>("statreset:" + table + ":" + function.MD5_16(condition));
  286. // if(string.IsNullOrEmpty(check))
  287. if(!rediskeys.Contains(table + ":" + function.MD5_16(condition)))
  288. {
  289. rediskeys.Add(table + ":" + function.MD5_16(condition));
  290. // RedisDbconn.Instance.Set("statreset:" + table + ":" + function.MD5_16(condition), fields + "#cut#" + vals);
  291. // RedisDbconn.Instance.SetExpire("statreset:" + table + ":" + function.MD5_16(condition), 3600);
  292. string[] conditionList = condition.Split(new string[]{ " and " }, StringSplitOptions.None);
  293. foreach(string sub in conditionList)
  294. {
  295. string[] subCondition = sub.Split('=');
  296. fields += "," + subCondition[0];
  297. vals += "," + subCondition[1];
  298. }
  299. sql = "insert into " + table + " (" + fields + ") values (" + vals + ");\n";
  300. }
  301. else
  302. {
  303. string setVals = "";
  304. string[] fieldList = fields.Split(',');
  305. string[] valList = vals.Split(',');
  306. for (int i = 0; i < fieldList.Length; i++)
  307. {
  308. setVals += fieldList[i] + "=" + fieldList[i] + "+" + valList[i] + ",";
  309. }
  310. sql = "update " + table + " set " + setVals.TrimEnd(',') + " where " + condition + ";\n";
  311. }
  312. return sql;
  313. }
  314. public void StartCheck()
  315. {
  316. Thread th = new Thread(StartCheckDo);
  317. th.IsBackground = true;
  318. th.Start();
  319. }
  320. public void StartCheckDo()
  321. {
  322. while (true)
  323. {
  324. string content = RedisDbconn.Instance.RPop<string>("StatTradeCheck2Queue");
  325. if(!string.IsNullOrEmpty(content))
  326. {
  327. StatTradeAmountCheck2Do(content);
  328. StatTradeAmountCheck2BeforeDo(content);
  329. StatTradeAmountCheck2AfterDo(content);
  330. StatTradeAmountCheckDo(content);
  331. StatTradeAmountCheckBeforeDo(content);
  332. StatTradeAmountCheckAfterDo(content);
  333. Thread.Sleep(100);
  334. }
  335. else
  336. {
  337. Thread.Sleep(10000);
  338. }
  339. }
  340. }
  341. public void StatTradeAmountCheckDo(string date)
  342. {
  343. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  344. try
  345. {
  346. date = date.Replace("-", "");
  347. WebCMSEntities db = new WebCMSEntities();
  348. List<TradeDaySummary> list = db.TradeDaySummary.Where(m => m.TradeDate == date).ToList();
  349. List<int> uids = list.Select(m => m.UserId).Distinct().ToList();
  350. var users = db.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => uids.Contains(m.Id)).ToList();
  351. db.Dispose();
  352. foreach(TradeDaySummary sub in list.Where(m => m.SeoTitle == "team").ToList())
  353. {
  354. string puidstr = "," + sub.UserId + ",";
  355. List<int> subuids = users.Where(m => m.Id == sub.UserId || m.ParentNav.Contains(puidstr)).ToList().Select(m => m.Id).ToList();
  356. bool op = list.Any(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount);
  357. if(op)
  358. {
  359. decimal ProfitDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectTradeAmt);
  360. decimal HelpDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectTradeAmt);
  361. decimal NotHelpDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectTradeAmt);
  362. decimal ProfitDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitTradeAmt);
  363. decimal ProfitDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitCapTradeAmt);
  364. decimal ProfitDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitCapNum);
  365. decimal HelpDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitTradeAmt);
  366. decimal HelpDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitCapTradeAmt);
  367. decimal HelpDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitCapNum);
  368. decimal NotHelpDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitTradeAmt);
  369. decimal NotHelpDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitCapTradeAmt);
  370. decimal NotHelpDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitCapNum);
  371. string setField = "";
  372. if(sub.ProfitNonDirectTradeAmt != ProfitDirectTradeAmt)
  373. {
  374. setField += "ProfitNonDirectTradeAmt=" + ProfitDirectTradeAmt + ",";
  375. }
  376. if(sub.HelpNonDirectTradeAmt != HelpDirectTradeAmt)
  377. {
  378. setField += "HelpNonDirectTradeAmt=" + HelpDirectTradeAmt + ",";
  379. }
  380. if(sub.NotHelpNonDirectTradeAmt != NotHelpDirectTradeAmt)
  381. {
  382. setField += "NotHelpNonDirectTradeAmt=" + NotHelpDirectTradeAmt + ",";
  383. }
  384. if(sub.ProfitNonDirectDebitTradeAmt != ProfitDirectDebitTradeAmt)
  385. {
  386. setField += "ProfitNonDirectDebitTradeAmt=" + ProfitDirectDebitTradeAmt + ",";
  387. }
  388. if(sub.ProfitDirectDebitCapTradeAmt != ProfitDirectDebitCapTradeAmt)
  389. {
  390. setField += "ProfitDirectDebitCapTradeAmt=" + ProfitDirectDebitCapTradeAmt + ",";
  391. }
  392. if(sub.ProfitDirectDebitCapNum != ProfitDirectDebitCapNum)
  393. {
  394. setField += "ProfitDirectDebitCapNum=" + ProfitDirectDebitCapNum + ",";
  395. }
  396. if(sub.HelpNonDirectDebitTradeAmt != HelpDirectDebitTradeAmt)
  397. {
  398. setField += "HelpNonDirectDebitTradeAmt=" + HelpDirectDebitTradeAmt + ",";
  399. }
  400. if(sub.HelpDirectDebitCapTradeAmt != HelpDirectDebitCapTradeAmt)
  401. {
  402. setField += "HelpDirectDebitCapTradeAmt=" + HelpDirectDebitCapTradeAmt + ",";
  403. }
  404. if(sub.HelpDirectDebitCapNum != HelpDirectDebitCapNum)
  405. {
  406. setField += "HelpDirectDebitCapNum=" + HelpDirectDebitCapNum + ",";
  407. }
  408. if(sub.NotHelpNonDirectDebitTradeAmt != NotHelpDirectDebitTradeAmt)
  409. {
  410. setField += "NotHelpNonDirectDebitTradeAmt=" + NotHelpDirectDebitTradeAmt + ",";
  411. }
  412. if(sub.NotHelpDirectDebitCapTradeAmt != NotHelpDirectDebitCapTradeAmt)
  413. {
  414. setField += "NotHelpDirectDebitCapTradeAmt=" + NotHelpDirectDebitCapTradeAmt + ",";
  415. }
  416. if(sub.NotHelpDirectDebitCapNum != NotHelpDirectDebitCapNum)
  417. {
  418. setField += "NotHelpDirectDebitCapNum=" + NotHelpDirectDebitCapNum + ",";
  419. }
  420. if(!string.IsNullOrEmpty(setField))
  421. {
  422. function.WriteLog("UserId:" + sub.UserId + "; TradeDate:" + sub.TradeDate + "; BrandId:" + sub.BrandId + ";", "交易不一致的创客");
  423. function.WriteLog("update TradeDaySummary set " + setField.TrimEnd(',') + " where Id=" + sub.Id, "要执行的sql脚本");
  424. }
  425. }
  426. }
  427. }
  428. catch (Exception ex)
  429. {
  430. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  431. }
  432. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  433. }
  434. public void StatTradeAmountCheckBeforeDo(string date)
  435. {
  436. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  437. try
  438. {
  439. date = date.Replace("-", "");
  440. WebCMSEntities db = new WebCMSEntities();
  441. List<TradeDaySummaryBefore> list = db.TradeDaySummaryBefore.Where(m => m.TradeDate == date).ToList();
  442. List<int> uids = list.Select(m => m.UserId).Distinct().ToList();
  443. var users = db.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => uids.Contains(m.Id)).ToList();
  444. db.Dispose();
  445. foreach(TradeDaySummaryBefore sub in list.Where(m => m.SeoTitle == "team").ToList())
  446. {
  447. string puidstr = "," + sub.UserId + ",";
  448. List<int> subuids = users.Where(m => m.Id == sub.UserId || m.ParentNav.Contains(puidstr)).ToList().Select(m => m.Id).ToList();
  449. bool op = list.Any(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount);
  450. if(op)
  451. {
  452. decimal ProfitDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectTradeAmt);
  453. decimal HelpDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectTradeAmt);
  454. decimal NotHelpDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectTradeAmt);
  455. decimal ProfitDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitTradeAmt);
  456. decimal ProfitDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitCapTradeAmt);
  457. decimal ProfitDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitCapNum);
  458. decimal HelpDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitTradeAmt);
  459. decimal HelpDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitCapTradeAmt);
  460. decimal HelpDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitCapNum);
  461. decimal NotHelpDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitTradeAmt);
  462. decimal NotHelpDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitCapTradeAmt);
  463. decimal NotHelpDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitCapNum);
  464. string setField = "";
  465. if(sub.ProfitNonDirectTradeAmt != ProfitDirectTradeAmt)
  466. {
  467. setField += "ProfitNonDirectTradeAmt=" + ProfitDirectTradeAmt + ",";
  468. }
  469. if(sub.HelpNonDirectTradeAmt != HelpDirectTradeAmt)
  470. {
  471. setField += "HelpNonDirectTradeAmt=" + HelpDirectTradeAmt + ",";
  472. }
  473. if(sub.NotHelpNonDirectTradeAmt != NotHelpDirectTradeAmt)
  474. {
  475. setField += "NotHelpNonDirectTradeAmt=" + NotHelpDirectTradeAmt + ",";
  476. }
  477. if(sub.ProfitNonDirectDebitTradeAmt != ProfitDirectDebitTradeAmt)
  478. {
  479. setField += "ProfitNonDirectDebitTradeAmt=" + ProfitDirectDebitTradeAmt + ",";
  480. }
  481. if(sub.ProfitDirectDebitCapTradeAmt != ProfitDirectDebitCapTradeAmt)
  482. {
  483. setField += "ProfitDirectDebitCapTradeAmt=" + ProfitDirectDebitCapTradeAmt + ",";
  484. }
  485. if(sub.ProfitDirectDebitCapNum != ProfitDirectDebitCapNum)
  486. {
  487. setField += "ProfitDirectDebitCapNum=" + ProfitDirectDebitCapNum + ",";
  488. }
  489. if(sub.HelpNonDirectDebitTradeAmt != HelpDirectDebitTradeAmt)
  490. {
  491. setField += "HelpNonDirectDebitTradeAmt=" + HelpDirectDebitTradeAmt + ",";
  492. }
  493. if(sub.HelpDirectDebitCapTradeAmt != HelpDirectDebitCapTradeAmt)
  494. {
  495. setField += "HelpDirectDebitCapTradeAmt=" + HelpDirectDebitCapTradeAmt + ",";
  496. }
  497. if(sub.HelpDirectDebitCapNum != HelpDirectDebitCapNum)
  498. {
  499. setField += "HelpDirectDebitCapNum=" + HelpDirectDebitCapNum + ",";
  500. }
  501. if(sub.NotHelpNonDirectDebitTradeAmt != NotHelpDirectDebitTradeAmt)
  502. {
  503. setField += "NotHelpNonDirectDebitTradeAmt=" + NotHelpDirectDebitTradeAmt + ",";
  504. }
  505. if(sub.NotHelpDirectDebitCapTradeAmt != NotHelpDirectDebitCapTradeAmt)
  506. {
  507. setField += "NotHelpDirectDebitCapTradeAmt=" + NotHelpDirectDebitCapTradeAmt + ",";
  508. }
  509. if(sub.NotHelpDirectDebitCapNum != NotHelpDirectDebitCapNum)
  510. {
  511. setField += "NotHelpDirectDebitCapNum=" + NotHelpDirectDebitCapNum + ",";
  512. }
  513. if(!string.IsNullOrEmpty(setField))
  514. {
  515. function.WriteLog("UserId:" + sub.UserId + "; TradeDate:" + sub.TradeDate + "; BrandId:" + sub.BrandId + ";", "交易不一致的创客");
  516. function.WriteLog("update TradeDaySummaryBefore set " + setField.TrimEnd(',') + " where Id=" + sub.Id, "要执行的sql脚本");
  517. }
  518. }
  519. }
  520. }
  521. catch (Exception ex)
  522. {
  523. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  524. }
  525. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  526. }
  527. public void StatTradeAmountCheckAfterDo(string date)
  528. {
  529. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  530. try
  531. {
  532. date = date.Replace("-", "");
  533. WebCMSEntities db = new WebCMSEntities();
  534. List<TradeDaySummaryAfter> list = db.TradeDaySummaryAfter.Where(m => m.TradeDate == date).ToList();
  535. List<int> uids = list.Select(m => m.UserId).Distinct().ToList();
  536. var users = db.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => uids.Contains(m.Id)).ToList();
  537. db.Dispose();
  538. foreach(TradeDaySummaryAfter sub in list.Where(m => m.SeoTitle == "team").ToList())
  539. {
  540. string puidstr = "," + sub.UserId + ",";
  541. List<int> subuids = users.Where(m => m.Id == sub.UserId || m.ParentNav.Contains(puidstr)).ToList().Select(m => m.Id).ToList();
  542. bool op = list.Any(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount);
  543. if(op)
  544. {
  545. decimal ProfitDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectTradeAmt);
  546. decimal HelpDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectTradeAmt);
  547. decimal NotHelpDirectTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectTradeAmt);
  548. decimal ProfitDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitTradeAmt);
  549. decimal ProfitDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitCapTradeAmt);
  550. decimal ProfitDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDirectDebitCapNum);
  551. decimal HelpDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitTradeAmt);
  552. decimal HelpDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitCapTradeAmt);
  553. decimal HelpDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.HelpDirectDebitCapNum);
  554. decimal NotHelpDirectDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitTradeAmt);
  555. decimal NotHelpDirectDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitCapTradeAmt);
  556. decimal NotHelpDirectDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.NotHelpDirectDebitCapNum);
  557. string setField = "";
  558. if(sub.ProfitNonDirectTradeAmt != ProfitDirectTradeAmt)
  559. {
  560. setField += "ProfitNonDirectTradeAmt=" + ProfitDirectTradeAmt + ",";
  561. }
  562. if(sub.HelpNonDirectTradeAmt != HelpDirectTradeAmt)
  563. {
  564. setField += "HelpNonDirectTradeAmt=" + HelpDirectTradeAmt + ",";
  565. }
  566. if(sub.NotHelpNonDirectTradeAmt != NotHelpDirectTradeAmt)
  567. {
  568. setField += "NotHelpNonDirectTradeAmt=" + NotHelpDirectTradeAmt + ",";
  569. }
  570. if(sub.ProfitNonDirectDebitTradeAmt != ProfitDirectDebitTradeAmt)
  571. {
  572. setField += "ProfitNonDirectDebitTradeAmt=" + ProfitDirectDebitTradeAmt + ",";
  573. }
  574. if(sub.ProfitDirectDebitCapTradeAmt != ProfitDirectDebitCapTradeAmt)
  575. {
  576. setField += "ProfitDirectDebitCapTradeAmt=" + ProfitDirectDebitCapTradeAmt + ",";
  577. }
  578. if(sub.ProfitDirectDebitCapNum != ProfitDirectDebitCapNum)
  579. {
  580. setField += "ProfitDirectDebitCapNum=" + ProfitDirectDebitCapNum + ",";
  581. }
  582. if(sub.HelpNonDirectDebitTradeAmt != HelpDirectDebitTradeAmt)
  583. {
  584. setField += "HelpNonDirectDebitTradeAmt=" + HelpDirectDebitTradeAmt + ",";
  585. }
  586. if(sub.HelpDirectDebitCapTradeAmt != HelpDirectDebitCapTradeAmt)
  587. {
  588. setField += "HelpDirectDebitCapTradeAmt=" + HelpDirectDebitCapTradeAmt + ",";
  589. }
  590. if(sub.HelpDirectDebitCapNum != HelpDirectDebitCapNum)
  591. {
  592. setField += "HelpDirectDebitCapNum=" + HelpDirectDebitCapNum + ",";
  593. }
  594. if(sub.NotHelpNonDirectDebitTradeAmt != NotHelpDirectDebitTradeAmt)
  595. {
  596. setField += "NotHelpNonDirectDebitTradeAmt=" + NotHelpDirectDebitTradeAmt + ",";
  597. }
  598. if(sub.NotHelpDirectDebitCapTradeAmt != NotHelpDirectDebitCapTradeAmt)
  599. {
  600. setField += "NotHelpDirectDebitCapTradeAmt=" + NotHelpDirectDebitCapTradeAmt + ",";
  601. }
  602. if(sub.NotHelpDirectDebitCapNum != NotHelpDirectDebitCapNum)
  603. {
  604. setField += "NotHelpDirectDebitCapNum=" + NotHelpDirectDebitCapNum + ",";
  605. }
  606. if(!string.IsNullOrEmpty(setField))
  607. {
  608. function.WriteLog("UserId:" + sub.UserId + "; TradeDate:" + sub.TradeDate + "; BrandId:" + sub.BrandId + ";", "交易不一致的创客");
  609. function.WriteLog("update TradeDaySummaryAfter set " + setField.TrimEnd(',') + " where Id=" + sub.Id, "要执行的sql脚本");
  610. }
  611. }
  612. }
  613. }
  614. catch (Exception ex)
  615. {
  616. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  617. }
  618. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  619. }
  620. public void StatTradeAmountCheck2Do(string date)
  621. {
  622. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  623. try
  624. {
  625. date = date.Replace("-", "");
  626. WebCMSEntities db = new WebCMSEntities();
  627. List<TradeDaySummary2> list = db.TradeDaySummary2.Where(m => m.TradeDate == date).ToList();
  628. List<int> uids = list.Select(m => m.UserId).Distinct().ToList();
  629. var users = db.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => uids.Contains(m.Id)).ToList();
  630. db.Dispose();
  631. foreach(TradeDaySummary2 sub in list.Where(m => m.SeoTitle == "team").ToList())
  632. {
  633. string puidstr = "," + sub.UserId + ",";
  634. List<int> subuids = users.Where(m => m.Id == sub.UserId || m.ParentNav.Contains(puidstr)).ToList().Select(m => m.Id).ToList();
  635. bool op = list.Any(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount);
  636. if(op)
  637. {
  638. decimal ProfitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitTradeAmt);
  639. decimal ProfitDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitTradeAmt);
  640. decimal ProfitDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitCapTradeAmt);
  641. decimal ProfitDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitCapNum);
  642. if(sub.ProfitTradeAmt != ProfitTradeAmt || sub.ProfitDebitTradeAmt != ProfitDebitTradeAmt || sub.ProfitDebitCapTradeAmt != ProfitDebitCapTradeAmt || sub.ProfitDebitCapNum != ProfitDebitCapNum)
  643. {
  644. function.WriteLog("UserId:" + sub.UserId + "; TradeDate:" + sub.TradeDate + "; BrandId:" + sub.BrandId + "; ProfitTradeAmt:" + sub.ProfitTradeAmt + "-" + ProfitTradeAmt + "; ProfitDebitTradeAmt:" + sub.ProfitDebitTradeAmt + "-" + ProfitDebitTradeAmt + "; ProfitDebitCapTradeAmt:" + sub.ProfitDebitCapTradeAmt + "-" + ProfitDebitCapTradeAmt + "; ProfitDebitCapNum:" + sub.ProfitDebitCapNum + "-" + ProfitDebitCapNum + ";", "交易不一致的创客");
  645. function.WriteLog("update TradeDaySummary2 set ProfitTradeAmt=" + ProfitTradeAmt + ",ProfitDebitTradeAmt=" + ProfitDebitTradeAmt + ",ProfitDebitCapTradeAmt=" + ProfitDebitCapTradeAmt + ",ProfitDebitCapNum=" + ProfitDebitCapNum + " where Id=" + sub.Id, "要执行的sql脚本");
  646. }
  647. }
  648. }
  649. }
  650. catch (Exception ex)
  651. {
  652. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  653. }
  654. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  655. }
  656. public void StatTradeAmountCheck2BeforeDo(string date)
  657. {
  658. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  659. try
  660. {
  661. date = date.Replace("-", "");
  662. WebCMSEntities db = new WebCMSEntities();
  663. List<TradeDaySummary2Before> list = db.TradeDaySummary2Before.Where(m => m.TradeDate == date).ToList();
  664. List<int> uids = list.Select(m => m.UserId).Distinct().ToList();
  665. var users = db.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => uids.Contains(m.Id)).ToList();
  666. db.Dispose();
  667. foreach(TradeDaySummary2Before sub in list.Where(m => m.SeoTitle == "team").ToList())
  668. {
  669. string puidstr = "," + sub.UserId + ",";
  670. List<int> subuids = users.Where(m => m.Id == sub.UserId || m.ParentNav.Contains(puidstr)).ToList().Select(m => m.Id).ToList();
  671. bool op = list.Any(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount);
  672. if(op)
  673. {
  674. decimal ProfitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitTradeAmt);
  675. decimal ProfitDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitTradeAmt);
  676. decimal ProfitDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitCapTradeAmt);
  677. decimal ProfitDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitCapNum);
  678. if(sub.ProfitTradeAmt != ProfitTradeAmt || sub.ProfitDebitTradeAmt != ProfitDebitTradeAmt || sub.ProfitDebitCapTradeAmt != ProfitDebitCapTradeAmt || sub.ProfitDebitCapNum != ProfitDebitCapNum)
  679. {
  680. function.WriteLog("UserId:" + sub.UserId + "; TradeDate:" + sub.TradeDate + "; BrandId:" + sub.BrandId + "; ProfitTradeAmt:" + sub.ProfitTradeAmt + "-" + ProfitTradeAmt + "; ProfitDebitTradeAmt:" + sub.ProfitDebitTradeAmt + "-" + ProfitDebitTradeAmt + "; ProfitDebitCapTradeAmt:" + sub.ProfitDebitCapTradeAmt + "-" + ProfitDebitCapTradeAmt + "; ProfitDebitCapNum:" + sub.ProfitDebitCapNum + "-" + ProfitDebitCapNum + ";", "交易不一致的创客");
  681. function.WriteLog("update TradeDaySummary2Before set ProfitTradeAmt=" + ProfitTradeAmt + ",ProfitDebitTradeAmt=" + ProfitDebitTradeAmt + ",ProfitDebitCapTradeAmt=" + ProfitDebitCapTradeAmt + ",ProfitDebitCapNum=" + ProfitDebitCapNum + " where Id=" + sub.Id, "要执行的sql脚本");
  682. }
  683. }
  684. }
  685. }
  686. catch (Exception ex)
  687. {
  688. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  689. }
  690. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  691. }
  692. public void StatTradeAmountCheck2AfterDo(string date)
  693. {
  694. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  695. try
  696. {
  697. date = date.Replace("-", "");
  698. WebCMSEntities db = new WebCMSEntities();
  699. List<TradeDaySummary2After> list = db.TradeDaySummary2After.Where(m => m.TradeDate == date).ToList();
  700. List<int> uids = list.Select(m => m.UserId).Distinct().ToList();
  701. var users = db.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => uids.Contains(m.Id)).ToList();
  702. db.Dispose();
  703. foreach(TradeDaySummary2After sub in list.Where(m => m.SeoTitle == "team").ToList())
  704. {
  705. string puidstr = "," + sub.UserId + ",";
  706. List<int> subuids = users.Where(m => m.Id == sub.UserId || m.ParentNav.Contains(puidstr)).ToList().Select(m => m.Id).ToList();
  707. bool op = list.Any(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount);
  708. if(op)
  709. {
  710. decimal ProfitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitTradeAmt);
  711. decimal ProfitDebitTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitTradeAmt);
  712. decimal ProfitDebitCapTradeAmt = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitCapTradeAmt);
  713. decimal ProfitDebitCapNum = list.Where(m => subuids.Contains(m.UserId) && m.BrandId == sub.BrandId && m.TradeDate == sub.TradeDate && m.SeoTitle == "self" && m.PayType == sub.PayType && m.VipFlag == sub.VipFlag && m.QueryCount == sub.QueryCount).Sum(m => m.ProfitDebitCapNum);
  714. if(sub.ProfitTradeAmt != ProfitTradeAmt || sub.ProfitDebitTradeAmt != ProfitDebitTradeAmt || sub.ProfitDebitCapTradeAmt != ProfitDebitCapTradeAmt || sub.ProfitDebitCapNum != ProfitDebitCapNum)
  715. {
  716. function.WriteLog("UserId:" + sub.UserId + "; TradeDate:" + sub.TradeDate + "; BrandId:" + sub.BrandId + "; ProfitTradeAmt:" + sub.ProfitTradeAmt + "-" + ProfitTradeAmt + "; ProfitDebitTradeAmt:" + sub.ProfitDebitTradeAmt + "-" + ProfitDebitTradeAmt + "; ProfitDebitCapTradeAmt:" + sub.ProfitDebitCapTradeAmt + "-" + ProfitDebitCapTradeAmt + "; ProfitDebitCapNum:" + sub.ProfitDebitCapNum + "-" + ProfitDebitCapNum + ";", "交易不一致的创客");
  717. function.WriteLog("update TradeDaySummary2After set ProfitTradeAmt=" + ProfitTradeAmt + ",ProfitDebitTradeAmt=" + ProfitDebitTradeAmt + ",ProfitDebitCapTradeAmt=" + ProfitDebitCapTradeAmt + ",ProfitDebitCapNum=" + ProfitDebitCapNum + " where Id=" + sub.Id, "要执行的sql脚本");
  718. }
  719. }
  720. }
  721. }
  722. catch (Exception ex)
  723. {
  724. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  725. }
  726. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  727. }
  728. }
  729. }