TestHelper.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. public class TestHelper
  10. {
  11. public readonly static TestHelper Instance = new TestHelper();
  12. private TestHelper()
  13. {
  14. }
  15. public void Start()
  16. {
  17. Thread th = new Thread(StartEverDay);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void StartEverDay()
  22. {
  23. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  24. DateTime end = DateTime.Parse("2022-04-19 00:00:00");
  25. DateTime check = DateTime.Parse("2022-03-11");
  26. while (check <= end)
  27. {
  28. StatMerchantTrade(check.ToString("yyyy-MM-dd"));
  29. check = check.AddDays(1);
  30. }
  31. }
  32. private void StatMerchantTrade(string date)
  33. {
  34. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "执行商户交易额日志");
  35. WebCMSEntities db = new WebCMSEntities();
  36. try
  37. {
  38. DataTable selfdt = OtherMySqlConn.dtable("select MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d') as TradeDate,sum(TradeAmount) as TradeAmount from TradeRecord group by MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d') order by MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d')");
  39. foreach (DataRow selfDr in selfdt.Rows)
  40. {
  41. int BrandId = int.Parse(selfDr["BrandId"].ToString());
  42. int MerchantId = int.Parse(selfDr["MerchantId"].ToString());
  43. string TradeDate = selfDr["TradeDate"].ToString();
  44. TradeDate = TradeDate.Replace("-", "");
  45. string TradeMonth = TradeDate.Substring(0, 6);
  46. decimal TradeAmount = decimal.Parse(selfDr["TradeAmount"].ToString());
  47. PosMerchantTradeSummay merStat = db.PosMerchantTradeSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId);
  48. if (merStat == null)
  49. {
  50. merStat = db.PosMerchantTradeSummay.Add(new PosMerchantTradeSummay()
  51. {
  52. MerchantId = MerchantId,
  53. TradeMonth = TradeMonth,
  54. TradeDate = TradeDate,
  55. BrandId = BrandId,
  56. }).Entity;
  57. db.SaveChanges();
  58. }
  59. merStat.TradeAmount += TradeAmount;
  60. db.SaveChanges();
  61. }
  62. }
  63. catch (Exception ex)
  64. {
  65. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额");
  66. }
  67. db.Dispose();
  68. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行商户交易额日志");
  69. }
  70. //统计团队交易额(小市场)
  71. public void teamTrade()
  72. {
  73. Dictionary<int, decimal> userdic = new Dictionary<int, decimal>();
  74. WebCMSEntities db = new WebCMSEntities();
  75. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  76. function.WriteLog("start:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
  77. DataTable dt = OtherMySqlConn.dtable("select UserId,sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectDebitTradeAmt+NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where TradeMonth='202208' and SeoTitle='team' group by UserId");
  78. function.WriteLog("ready:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
  79. foreach(DataRow dr in dt.Rows)
  80. {
  81. int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
  82. decimal TradeAmount = decimal.Parse(function.CheckNum(dr[1].ToString()));
  83. userdic.Add(UserId, TradeAmount);
  84. }
  85. function.WriteLog("1:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
  86. Dictionary<int, decimal> userdic1 = userdic.Where(m => m.Value >= 3000000 && m.Value <= 10000000).ToDictionary(m => m.Key, m => m.Value);
  87. function.WriteLog("3000000:" + userdic1.Count(), "团队交易额名单");
  88. foreach(int UserId in userdic1.Keys)
  89. {
  90. decimal curTotal = userdic1[UserId];
  91. List<int> ids = new List<int>();
  92. Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  93. int TopUserId = 0;
  94. if (!string.IsNullOrEmpty(self.ParentNav))
  95. {
  96. string uidstring = self.ParentNav.Trim(',').Replace(",,", ",");
  97. string[] uidlist = uidstring.Split(',');
  98. if (uidlist.Length > 1)
  99. {
  100. TopUserId = int.Parse(function.CheckInt(uidlist[1]));
  101. }
  102. else
  103. {
  104. TopUserId = int.Parse(function.CheckInt(uidlist[0]));
  105. }
  106. }
  107. Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  108. var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList();
  109. foreach(var user in users)
  110. {
  111. ids.Add(user.Id);
  112. }
  113. int index = 0;
  114. decimal totalAmt = 0;
  115. decimal maxAmt = 0;
  116. Dictionary<int, decimal> dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value);
  117. foreach(int key in dic.Keys)
  118. {
  119. index += 1;
  120. if(index > 1)
  121. {
  122. totalAmt += dic[key];
  123. }
  124. else
  125. {
  126. maxAmt = dic[key];
  127. }
  128. }
  129. if(totalAmt >= 1200000)
  130. {
  131. function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额300万-1000万且小市场大于120万的名单");
  132. }
  133. if(totalAmt >= curTotal * 0.4M)
  134. {
  135. function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额300万-1000万且小市场大于40%的名单");
  136. }
  137. function.WriteLog(UserId.ToString(), "团队交易额名单");
  138. }
  139. Dictionary<int, decimal> userdic2 = userdic.Where(m => m.Value >= 10000000 && m.Value <= 100000000).ToDictionary(m => m.Key, m => m.Value);
  140. function.WriteLog("10000000:" + userdic2.Count(), "团队交易额名单");
  141. foreach(int UserId in userdic2.Keys)
  142. {
  143. decimal curTotal = userdic2[UserId];
  144. List<int> ids = new List<int>();
  145. Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  146. int TopUserId = 0;
  147. if (!string.IsNullOrEmpty(self.ParentNav))
  148. {
  149. string uidstring = self.ParentNav.Trim(',').Replace(",,", ",");
  150. string[] uidlist = uidstring.Split(',');
  151. if (uidlist.Length > 1)
  152. {
  153. TopUserId = int.Parse(function.CheckInt(uidlist[1]));
  154. }
  155. else
  156. {
  157. TopUserId = int.Parse(function.CheckInt(uidlist[0]));
  158. }
  159. }
  160. Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  161. var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList();
  162. foreach(var user in users)
  163. {
  164. ids.Add(user.Id);
  165. }
  166. int index = 0;
  167. decimal totalAmt = 0;
  168. decimal maxAmt = 0;
  169. Dictionary<int, decimal> dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value);
  170. foreach(int key in dic.Keys)
  171. {
  172. index += 1;
  173. if(index > 1)
  174. {
  175. totalAmt += dic[key];
  176. }
  177. else
  178. {
  179. maxAmt = dic[key];
  180. }
  181. }
  182. if(totalAmt >= 4000000)
  183. {
  184. function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1000万-1亿且小市场大于400万的名单");
  185. }
  186. if(totalAmt >= curTotal * 0.4M)
  187. {
  188. function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1000万-1亿且小市场大于40%的名单");
  189. }
  190. function.WriteLog(UserId.ToString(), "团队交易额名单");
  191. }
  192. Dictionary<int, decimal> userdic3 = userdic.Where(m => m.Value >= 100000000).ToDictionary(m => m.Key, m => m.Value);
  193. function.WriteLog("100000000:" + userdic3.Count(), "团队交易额名单");
  194. foreach(int UserId in userdic3.Keys)
  195. {
  196. decimal curTotal = userdic3[UserId];
  197. List<int> ids = new List<int>();
  198. Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  199. int TopUserId = 0;
  200. if (!string.IsNullOrEmpty(self.ParentNav))
  201. {
  202. string uidstring = self.ParentNav.Trim(',').Replace(",,", ",");
  203. string[] uidlist = uidstring.Split(',');
  204. if (uidlist.Length > 1)
  205. {
  206. TopUserId = int.Parse(function.CheckInt(uidlist[1]));
  207. }
  208. else
  209. {
  210. TopUserId = int.Parse(function.CheckInt(uidlist[0]));
  211. }
  212. }
  213. Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  214. var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList();
  215. foreach(var user in users)
  216. {
  217. ids.Add(user.Id);
  218. }
  219. int index = 0;
  220. decimal totalAmt = 0;
  221. decimal maxAmt = 0;
  222. Dictionary<int, decimal> dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value);
  223. foreach(int key in dic.Keys)
  224. {
  225. index += 1;
  226. if(index > 1)
  227. {
  228. totalAmt += dic[key];
  229. }
  230. else
  231. {
  232. maxAmt = dic[key];
  233. }
  234. }
  235. if(totalAmt >= 40000000)
  236. {
  237. function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1亿以上且小市场大于4000万的名单");
  238. }
  239. if(totalAmt >= curTotal * 0.4M)
  240. {
  241. function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1亿以上且小市场大于40%的名单");
  242. }
  243. function.WriteLog(UserId.ToString(), "团队交易额名单");
  244. }
  245. db.Dispose();
  246. function.WriteLog("end:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
  247. }
  248. }