StatDataService.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.Models;
  9. namespace MySystem
  10. {
  11. public class StatDataService
  12. {
  13. public readonly static StatDataService Instance = new StatDataService();
  14. private StatDataService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething2);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. bool op = true;
  25. while (op)
  26. {
  27. try
  28. {
  29. string UserId = function.ReadInstance("/stat/UserIdFlag.txt");
  30. if (string.IsNullOrEmpty(UserId))
  31. {
  32. UserId = "0";
  33. }
  34. WebCMSEntities db = new WebCMSEntities();
  35. DataTable dt = dbconn.dtable("select * from TmpUsers where Id>" + UserId + " order by Id limit 1000");
  36. foreach (DataRow dr in dt.Rows)
  37. {
  38. string Id = dr["Id"].ToString();
  39. string MakerCode = dr["MakerCode"].ToString();
  40. string RealName = dr["RealName"].ToString();
  41. string Mobile = dr["Mobile"].ToString();
  42. string UpRealName = dr["UpRealName"].ToString();
  43. string UpMakerCode = dr["UpMakerCode"].ToString();
  44. string TopRealName = dr["TopRealName"].ToString();
  45. string TopMakerCode = dr["TopMakerCode"].ToString();
  46. string UserLevel = dr["UserLevel"].ToString();
  47. if (string.IsNullOrEmpty(UserLevel))
  48. {
  49. UserLevel = "K1";
  50. }
  51. string Withdraw = dr["Withdraw"].ToString();
  52. string CreateDate = dr["CreateDate"].ToString();
  53. ulong AuthFlag = 0;
  54. DateTime AuthDate = DateTime.Parse("1900-01-01");
  55. if (!string.IsNullOrEmpty(RealName))
  56. {
  57. AuthFlag = 1;
  58. AuthDate = DateTime.Now;
  59. }
  60. Users user = db.Users.Add(new Users()
  61. {
  62. LoginPwd = function.MD532(Mobile.Substring(7)),
  63. MakerCode = MakerCode,
  64. RealName = RealName,
  65. Mobile = Mobile,
  66. UserLevel = int.Parse(UserLevel.Replace("K", "")),
  67. SettleAmount = decimal.Parse(Withdraw),
  68. CreateDate = DateTime.Parse(CreateDate),
  69. SeoTitle = UpMakerCode,
  70. AuthFlag = AuthFlag,
  71. AuthDate = AuthDate,
  72. }).Entity;
  73. db.SaveChanges();
  74. // UserForMobile userFor = db.UserForMobile.FirstOrDefault(m => m.Mobile == Mobile);
  75. // if (userFor == null)
  76. // {
  77. // userFor = new UserForMobile()
  78. // {
  79. // Mobile = Mobile,
  80. // };
  81. // db.SaveChanges();
  82. // }
  83. // userFor.UserId = user.Id;
  84. // UserForMakerCode userForCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  85. // if (userForCode == null)
  86. // {
  87. // userForCode = new UserForMakerCode()
  88. // {
  89. // MakerCode = MakerCode,
  90. // };
  91. // db.SaveChanges();
  92. // }
  93. // userForCode.UserId = user.Id;
  94. // db.SaveChanges();
  95. function.WritePage("/stat/", "UserIdFlag.txt", Id);
  96. }
  97. }
  98. catch (Exception ex)
  99. {
  100. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "导数据异常");
  101. }
  102. Thread.Sleep(200);
  103. }
  104. }
  105. public void dosomething2()
  106. {
  107. bool op = true;
  108. while (op)
  109. {
  110. try
  111. {
  112. string UserId = function.ReadInstance("/stat/UIdFlag.txt");
  113. if (string.IsNullOrEmpty(UserId))
  114. {
  115. UserId = "0";
  116. }
  117. int Uid = int.Parse(UserId);
  118. WebCMSEntities db = new WebCMSEntities();
  119. List<int> userids = db.Users.Select(m => m.Id).Where(m => m > Uid).OrderBy(m => m).Take(100).ToList();
  120. foreach (int userid in userids)
  121. {
  122. int ParentUserId = userid;
  123. string NavString = "";
  124. while (ParentUserId > 0)
  125. {
  126. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId);
  127. if (puser != null)
  128. {
  129. NavString = "," + ParentUserId + "," + NavString;
  130. ParentUserId = puser.ParentUserId;
  131. }
  132. else
  133. {
  134. ParentUserId = 0;
  135. }
  136. }
  137. if (!string.IsNullOrEmpty(NavString))
  138. {
  139. string[] useridlist = NavString.Trim(',').Replace(",,", ",").Split(',');
  140. foreach (string useridstring in useridlist)
  141. {
  142. int SubUserId = int.Parse(useridstring);
  143. Users subUser = db.Users.FirstOrDefault(m => m.Id == SubUserId);
  144. if (subUser != null)
  145. {
  146. subUser.ParentNav = NavString.Substring(0, NavString.IndexOf("," + useridstring + ","));
  147. }
  148. }
  149. }
  150. db.SaveChanges();
  151. function.WritePage("/stat/", "UIdFlag.txt", userid.ToString());
  152. }
  153. db.SaveChanges();
  154. db.Dispose();
  155. }
  156. catch (Exception ex)
  157. {
  158. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "执行上下级异常");
  159. }
  160. Thread.Sleep(200);
  161. }
  162. }
  163. public void StatCreatorData(int UserId, ConsumerOrders order)
  164. {
  165. string DateString = order.UpdateDate.Value.ToString("yyyyMMdd");
  166. string MonthString = order.UpdateDate.Value.ToString("yyyyMM");
  167. // RedisDbconn.Instance.AddNumber("TradeStat:" + UserId + ":" + DateString, order.PayMoney);
  168. // RedisDbconn.Instance.AddNumber("TradeStat:" + UserId + ":" + MonthString, order.PayMoney);
  169. }
  170. }
  171. }