TestHelper.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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(domerchantType);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. private void DoWorks()
  22. {
  23. // WebCMSEntities db = new WebCMSEntities();
  24. // bool op = true;
  25. // while (op)
  26. // {
  27. // WebCMSEntities db = new WebCMSEntities();
  28. // int StartId = RedisDbconn.Instance.Get<int>("SetCertUserId");
  29. // var list = db.Users.Select(m => new { m.Id, m.CertId }).Where(m => m.Id > StartId && string.IsNullOrEmpty(m.CertId)).OrderBy(m => m.Id).Take(20).ToList();
  30. // if (list.Count > 0)
  31. // {
  32. // foreach (var sub in list)
  33. // {
  34. // Users user = db.Users.FirstOrDefault(m => m.Id == sub.Id && string.IsNullOrEmpty(m.CertId));
  35. // if (user != null)
  36. // {
  37. // DataTable dt = dbconn.dtable("select CertId from TmpCert where MakerCode='" + user.MakerCode + "'");
  38. // if (dt.Rows.Count > 0)
  39. // {
  40. // string CertId = dt.Rows[0]["CertId"].ToString();
  41. // user.CertId = CertId;
  42. // }
  43. // RedisDbconn.Instance.Set("SetCertUserId", sub.Id);
  44. // }
  45. // }
  46. // db.SaveChanges();
  47. // db.Dispose();
  48. // }
  49. // else
  50. // {
  51. // op = false;
  52. // }
  53. // Thread.Sleep(10);
  54. // }
  55. // IQueryable<Users> users = db.Users.Where(m => m.AuthFlag == 1).OrderBy(m => m.Id);
  56. // foreach (Users user in users.ToList())
  57. // {
  58. // string path = function.CreateQRCode2(ConfigurationManager.AppSettings["SourceHost"].ToString() + "p/user-inviteregist-1?Id=" + user.Id, function.MD5_16(user.Id.ToString() + "8745"), "/bsserver_com/static/ReferenceQrCode/");
  59. // path = path.Replace("//", "/");
  60. // string resultpath = "/bsserver_com/static/ReferenceQrCode/" + function.MD5_16(user.Id.ToString() + "8745") + "Pic.png";
  61. // MakeReferenceQrCodeService.Instance.MakeQRCode(function.getPath("/static/QrCodeBg.png"), function.getPath(path), function.getPath(resultpath), user);
  62. // resultpath = resultpath.Replace("bsserver_com/", "");
  63. // user.ReferenceQrCode = resultpath;
  64. // db.SaveChanges();
  65. // RedisDbconn.Instance.Set("Users:" + user.Id, user);
  66. // function.WriteLog(user.Id.ToString(), "生成邀请二维码");
  67. // }
  68. // function.WriteLog("finish", "生成邀请二维码");
  69. // bool op = true;
  70. // while (op)
  71. // {
  72. // int startId = RedisDbconn.Instance.Get<int>("RemoveUserId");
  73. // List<int> uids = db.Users.Select(m => m.Id).Where(m => m > startId && m > 1).OrderBy(m => m).Take(100).ToList();
  74. // if (uids.Count > 0)
  75. // {
  76. // foreach (int uid in uids)
  77. // {
  78. // DoUsers(db, uid);
  79. // RedisDbconn.Instance.Set("RemoveUserId", uid);
  80. // }
  81. // Thread.Sleep(200);
  82. // }
  83. // else
  84. // {
  85. // op = false;
  86. // }
  87. // }
  88. // db.Dispose();
  89. }
  90. public void DoUsers(WebCMSEntities db, int uid)
  91. {
  92. Users user = db.Users.FirstOrDefault(m => m.Id == uid);
  93. if (user != null)
  94. {
  95. string Mobile = function.CheckNull(user.Mobile);
  96. if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11)
  97. {
  98. string ParentNav = user.ParentNav;
  99. if (!string.IsNullOrEmpty(ParentNav))
  100. {
  101. string NewParentNav = "";
  102. int NewParentUserId = 1;
  103. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  104. Array.Reverse(ParentNavList);
  105. int i = 0;
  106. foreach (string ParentId in ParentNavList)
  107. {
  108. int puid = int.Parse(ParentId);
  109. Users puser = db.Users.FirstOrDefault(m => m.Id == puid);
  110. if (puser != null)
  111. {
  112. Mobile = function.CheckNull(puser.Mobile);
  113. if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11)
  114. {
  115. i += 1;
  116. NewParentNav = "," + ParentId + "," + NewParentNav;
  117. if (i == 1)
  118. {
  119. NewParentUserId = puid;
  120. }
  121. }
  122. }
  123. }
  124. if (string.IsNullOrEmpty(NewParentNav))
  125. {
  126. NewParentNav = ",1,";
  127. }
  128. user.ParentNav = NewParentNav;
  129. user.ParentUserId = NewParentUserId;
  130. }
  131. else
  132. {
  133. user.ParentNav = ",1,";
  134. user.ParentUserId = 1;
  135. }
  136. db.SaveChanges();
  137. }
  138. }
  139. }
  140. private void domerchantType()
  141. {
  142. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  143. OtherMySqlConn.op("update PosMerchantInfo set MerUserType=0");
  144. OtherMySqlConn.op("update Users set MerchantType=0");
  145. OtherMySqlConn.connstr = "";
  146. bool op = true;
  147. while (op)
  148. {
  149. MySystem.SpModels.WebCMSEntities spdb = new MySystem.SpModels.WebCMSEntities();
  150. WebCMSEntities db = new WebCMSEntities();
  151. DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  152. int startId = int.Parse(function.CheckInt(RedisDbconn.Instance.Get<string>("BindRecordId")));
  153. List<MySystem.SpModels.BindRecord> binds = spdb.BindRecord.Where(m => m.Id > startId && m.CreateTime < end).OrderBy(m => m.Id).Take(200).ToList();
  154. if (binds.Count > 0)
  155. {
  156. foreach (MySystem.SpModels.BindRecord bind in binds)
  157. {
  158. string Mobile = bind.MerNewSnNo;
  159. string MerNo = bind.MerNo;
  160. string BeforeNum = "";
  161. string AfterNum = "";
  162. if (Mobile.Contains("****") && Mobile.Length == 11)
  163. {
  164. BeforeNum = Mobile.Substring(0, 3);
  165. AfterNum = Mobile.Substring(7);
  166. }
  167. string Name = bind.MerName;
  168. if (bind.ProductType == "2")
  169. {
  170. if (Name.Contains("-"))
  171. {
  172. Name = Name.Split('-')[1];
  173. }
  174. else if (Name.Contains("_"))
  175. {
  176. Name = Name.Split('_')[1];
  177. }
  178. }
  179. else if (bind.ProductType == "4")
  180. {
  181. Name = bind.SeoTitle;
  182. }
  183. Users user = db.Users.FirstOrDefault(m => m.Mobile.StartsWith(BeforeNum) && m.Mobile.EndsWith(AfterNum) && m.RealName == Name && m.AuthFlag == 1 && m.MerchantType == 0);
  184. if (user != null)
  185. {
  186. PosMachinesTwo checkPos = db.PosMachinesTwo.FirstOrDefault(m => m.UserId == user.Id);
  187. if (checkPos == null)
  188. {
  189. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == bind.MerSnNo) ?? new MachineForSnNo();
  190. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.UserId != user.Id);
  191. if (pos != null)
  192. {
  193. pos.UserId = user.Id;
  194. user.MerchantType = 1;
  195. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  196. merchant.UserId = user.Id;
  197. merchant.MerUserType = 1;
  198. pos.SeoTitle = user.Id.ToString(); // 记录商户型创客的Id
  199. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
  200. db.SaveChanges();
  201. RedisDbconn.Instance.Set("Users:" + user.Id, user);
  202. RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
  203. }
  204. }
  205. else
  206. {
  207. int count = db.PosMachinesTwo.Count(m => m.UserId == user.Id);
  208. if (count == 1)
  209. {
  210. user.MerchantType = 1;
  211. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  212. merchant.MerUserType = 1;
  213. checkPos.SeoTitle = user.Id.ToString(); // 记录商户型创客的Id
  214. RedisDbconn.Instance.Set("PosMachinesTwo:" + checkPos.Id, checkPos);
  215. db.SaveChanges();
  216. RedisDbconn.Instance.Set("Users:" + user.Id, user);
  217. RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
  218. }
  219. }
  220. }
  221. RedisDbconn.Instance.Set("BindRecordId", bind.Id.ToString());
  222. }
  223. }
  224. else
  225. {
  226. op = false;
  227. }
  228. spdb.Dispose();
  229. db.Dispose();
  230. RedisDbconn.Instance.Clear("BindRecordId");
  231. }
  232. }
  233. }