using System; using System.Collections.Generic; using System.Threading; using System.Linq; using System.Data; using MySystem; using MySystem.PxcModels; using Library; public class TestHelper { public readonly static TestHelper Instance = new TestHelper(); private TestHelper() { } public void Start() { Thread th = new Thread(domerchantType); th.IsBackground = true; th.Start(); } private void DoWorks() { // WebCMSEntities db = new WebCMSEntities(); // bool op = true; // while (op) // { // WebCMSEntities db = new WebCMSEntities(); // int StartId = RedisDbconn.Instance.Get("SetCertUserId"); // 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(); // if (list.Count > 0) // { // foreach (var sub in list) // { // Users user = db.Users.FirstOrDefault(m => m.Id == sub.Id && string.IsNullOrEmpty(m.CertId)); // if (user != null) // { // DataTable dt = dbconn.dtable("select CertId from TmpCert where MakerCode='" + user.MakerCode + "'"); // if (dt.Rows.Count > 0) // { // string CertId = dt.Rows[0]["CertId"].ToString(); // user.CertId = CertId; // } // RedisDbconn.Instance.Set("SetCertUserId", sub.Id); // } // } // db.SaveChanges(); // db.Dispose(); // } // else // { // op = false; // } // Thread.Sleep(10); // } // IQueryable users = db.Users.Where(m => m.AuthFlag == 1).OrderBy(m => m.Id); // foreach (Users user in users.ToList()) // { // 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/"); // path = path.Replace("//", "/"); // string resultpath = "/bsserver_com/static/ReferenceQrCode/" + function.MD5_16(user.Id.ToString() + "8745") + "Pic.png"; // MakeReferenceQrCodeService.Instance.MakeQRCode(function.getPath("/static/QrCodeBg.png"), function.getPath(path), function.getPath(resultpath), user); // resultpath = resultpath.Replace("bsserver_com/", ""); // user.ReferenceQrCode = resultpath; // db.SaveChanges(); // RedisDbconn.Instance.Set("Users:" + user.Id, user); // function.WriteLog(user.Id.ToString(), "生成邀请二维码"); // } // function.WriteLog("finish", "生成邀请二维码"); // bool op = true; // while (op) // { // int startId = RedisDbconn.Instance.Get("RemoveUserId"); // List uids = db.Users.Select(m => m.Id).Where(m => m > startId && m > 1).OrderBy(m => m).Take(100).ToList(); // if (uids.Count > 0) // { // foreach (int uid in uids) // { // DoUsers(db, uid); // RedisDbconn.Instance.Set("RemoveUserId", uid); // } // Thread.Sleep(200); // } // else // { // op = false; // } // } // db.Dispose(); } public void DoUsers(WebCMSEntities db, int uid) { Users user = db.Users.FirstOrDefault(m => m.Id == uid); if (user != null) { string Mobile = function.CheckNull(user.Mobile); if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11) { string ParentNav = user.ParentNav; if (!string.IsNullOrEmpty(ParentNav)) { string NewParentNav = ""; int NewParentUserId = 1; string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(','); Array.Reverse(ParentNavList); int i = 0; foreach (string ParentId in ParentNavList) { int puid = int.Parse(ParentId); Users puser = db.Users.FirstOrDefault(m => m.Id == puid); if (puser != null) { Mobile = function.CheckNull(puser.Mobile); if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11) { i += 1; NewParentNav = "," + ParentId + "," + NewParentNav; if (i == 1) { NewParentUserId = puid; } } } } if (string.IsNullOrEmpty(NewParentNav)) { NewParentNav = ",1,"; } user.ParentNav = NewParentNav; user.ParentUserId = NewParentUserId; } else { user.ParentNav = ",1,"; user.ParentUserId = 1; } db.SaveChanges(); } } } private void domerchantType() { OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString(); OtherMySqlConn.op("update PosMerchantInfo set MerUserType=0"); OtherMySqlConn.op("update Users set MerchantType=0"); OtherMySqlConn.connstr = ""; bool op = true; while (op) { MySystem.SpModels.WebCMSEntities spdb = new MySystem.SpModels.WebCMSEntities(); WebCMSEntities db = new WebCMSEntities(); DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"); int startId = int.Parse(function.CheckInt(RedisDbconn.Instance.Get("BindRecordId"))); List binds = spdb.BindRecord.Where(m => m.Id > startId && m.CreateTime < end).OrderBy(m => m.Id).Take(200).ToList(); if (binds.Count > 0) { foreach (MySystem.SpModels.BindRecord bind in binds) { string Mobile = bind.MerNewSnNo; string MerNo = bind.MerNo; string BeforeNum = ""; string AfterNum = ""; if (Mobile.Contains("****") && Mobile.Length == 11) { BeforeNum = Mobile.Substring(0, 3); AfterNum = Mobile.Substring(7); } string Name = bind.MerName; if (bind.ProductType == "2") { if (Name.Contains("-")) { Name = Name.Split('-')[1]; } else if (Name.Contains("_")) { Name = Name.Split('_')[1]; } } else if (bind.ProductType == "4") { Name = bind.SeoTitle; } Users user = db.Users.FirstOrDefault(m => m.Mobile.StartsWith(BeforeNum) && m.Mobile.EndsWith(AfterNum) && m.RealName == Name && m.AuthFlag == 1 && m.MerchantType == 0); if (user != null) { PosMachinesTwo checkPos = db.PosMachinesTwo.FirstOrDefault(m => m.UserId == user.Id); if (checkPos == null) { MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == bind.MerSnNo) ?? new MachineForSnNo(); PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.UserId != user.Id); if (pos != null) { pos.UserId = user.Id; user.MerchantType = 1; PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo(); merchant.UserId = user.Id; merchant.MerUserType = 1; pos.SeoTitle = user.Id.ToString(); // 记录商户型创客的Id RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos); db.SaveChanges(); RedisDbconn.Instance.Set("Users:" + user.Id, user); RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant); } } else { int count = db.PosMachinesTwo.Count(m => m.UserId == user.Id); if (count == 1) { user.MerchantType = 1; PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo(); merchant.MerUserType = 1; checkPos.SeoTitle = user.Id.ToString(); // 记录商户型创客的Id RedisDbconn.Instance.Set("PosMachinesTwo:" + checkPos.Id, checkPos); db.SaveChanges(); RedisDbconn.Instance.Set("Users:" + user.Id, user); RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant); } } } RedisDbconn.Instance.Set("BindRecordId", bind.Id.ToString()); } } else { op = false; } spdb.Dispose(); db.Dispose(); RedisDbconn.Instance.Clear("BindRecordId"); } } }