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(StartEverDay); 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"); // 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.Id == pos.BindMerchantId) ?? 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 && checkPos.UserId != checkPos.BuyUserId) // { // user.MerchantType = 1; // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == checkPos.BindMerchantId) ?? new PosMerchantInfo(); // merchant.UserId = user.Id; // 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"); // DataTable dt = OtherMySqlConn.dtable("select PosSn,UserId from PosMachinesTwo where UserId in (select Id from Users where MerchantType=1);"); // foreach (DataRow dr in dt.Rows) // { // string PosSn = dr["PosSn"].ToString(); // string UserId = dr["UserId"].ToString(); // OtherMySqlConn.op("update TradeRecord set UserId=" + UserId + " where SnNo='" + PosSn + "' and CreateDate>='2022-04-01 00:00:00'"); // } // OtherMySqlConn.connstr = ""; // StatService.Instance.StartEverDay2(); } public void StartEverDay() { OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString(); DateTime end = DateTime.Parse("2022-04-19 00:00:00"); DateTime check = DateTime.Parse("2022-03-11"); while (check <= end) { StatMerchantTrade(check.ToString("yyyy-MM-dd")); check = check.AddDays(1); } } private void StatMerchantTrade(string date) { function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "执行商户交易额日志"); WebCMSEntities db = new WebCMSEntities(); try { 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')"); foreach (DataRow selfDr in selfdt.Rows) { int BrandId = int.Parse(selfDr["BrandId"].ToString()); int MerchantId = int.Parse(selfDr["MerchantId"].ToString()); string TradeDate = selfDr["TradeDate"].ToString(); TradeDate = TradeDate.Replace("-", ""); string TradeMonth = TradeDate.Substring(0, 6); decimal TradeAmount = decimal.Parse(selfDr["TradeAmount"].ToString()); PosMerchantTradeSummay merStat = db.PosMerchantTradeSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId); if (merStat == null) { merStat = db.PosMerchantTradeSummay.Add(new PosMerchantTradeSummay() { MerchantId = MerchantId, TradeMonth = TradeMonth, TradeDate = TradeDate, BrandId = BrandId, }).Entity; db.SaveChanges(); } merStat.TradeAmount += TradeAmount; db.SaveChanges(); RedisDbconn.Instance.Clear("MerTotalAmount:" + MerchantId); RedisDbconn.Instance.Clear("MerTotalAmount:" + MerchantId + ":" + TradeMonth); //商户当月交易 RedisDbconn.Instance.Clear("MerTotalAmount:" + MerchantId + ":" + TradeDate); //商户当日交易 } } catch (Exception ex) { function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额"); } db.Dispose(); function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行商户交易额日志"); } }