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(); } } 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", "执行商户交易额日志"); } //统计团队交易额(小市场) public void teamTrade() { Dictionary userdic = new Dictionary(); WebCMSEntities db = new WebCMSEntities(); OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString(); function.WriteLog("start:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单"); DataTable dt = OtherMySqlConn.dtable("select UserId,sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectDebitTradeAmt+NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where TradeMonth='202208' and SeoTitle='team' group by UserId"); function.WriteLog("ready:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单"); foreach(DataRow dr in dt.Rows) { int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString())); decimal TradeAmount = decimal.Parse(function.CheckNum(dr[1].ToString())); userdic.Add(UserId, TradeAmount); } function.WriteLog("1:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单"); Dictionary userdic1 = userdic.Where(m => m.Value >= 3000000 && m.Value <= 10000000).ToDictionary(m => m.Key, m => m.Value); function.WriteLog("3000000:" + userdic1.Count(), "团队交易额名单"); foreach(int UserId in userdic1.Keys) { decimal curTotal = userdic1[UserId]; List ids = new List(); Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); int TopUserId = 0; if (!string.IsNullOrEmpty(self.ParentNav)) { string uidstring = self.ParentNav.Trim(',').Replace(",,", ","); string[] uidlist = uidstring.Split(','); if (uidlist.Length > 1) { TopUserId = int.Parse(function.CheckInt(uidlist[1])); } else { TopUserId = int.Parse(function.CheckInt(uidlist[0])); } } Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users(); var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList(); foreach(var user in users) { ids.Add(user.Id); } int index = 0; decimal totalAmt = 0; decimal maxAmt = 0; Dictionary dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value); foreach(int key in dic.Keys) { index += 1; if(index > 1) { totalAmt += dic[key]; } else { maxAmt = dic[key]; } } if(totalAmt >= 1200000) { function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额300万-1000万且小市场大于120万的名单"); } if(totalAmt >= curTotal * 0.4M) { function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额300万-1000万且小市场大于40%的名单"); } function.WriteLog(UserId.ToString(), "团队交易额名单"); } Dictionary userdic2 = userdic.Where(m => m.Value >= 10000000 && m.Value <= 100000000).ToDictionary(m => m.Key, m => m.Value); function.WriteLog("10000000:" + userdic2.Count(), "团队交易额名单"); foreach(int UserId in userdic2.Keys) { decimal curTotal = userdic2[UserId]; List ids = new List(); Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); int TopUserId = 0; if (!string.IsNullOrEmpty(self.ParentNav)) { string uidstring = self.ParentNav.Trim(',').Replace(",,", ","); string[] uidlist = uidstring.Split(','); if (uidlist.Length > 1) { TopUserId = int.Parse(function.CheckInt(uidlist[1])); } else { TopUserId = int.Parse(function.CheckInt(uidlist[0])); } } Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users(); var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList(); foreach(var user in users) { ids.Add(user.Id); } int index = 0; decimal totalAmt = 0; decimal maxAmt = 0; Dictionary dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value); foreach(int key in dic.Keys) { index += 1; if(index > 1) { totalAmt += dic[key]; } else { maxAmt = dic[key]; } } if(totalAmt >= 4000000) { function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1000万-1亿且小市场大于400万的名单"); } if(totalAmt >= curTotal * 0.4M) { function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1000万-1亿且小市场大于40%的名单"); } function.WriteLog(UserId.ToString(), "团队交易额名单"); } Dictionary userdic3 = userdic.Where(m => m.Value >= 100000000).ToDictionary(m => m.Key, m => m.Value); function.WriteLog("100000000:" + userdic3.Count(), "团队交易额名单"); foreach(int UserId in userdic3.Keys) { decimal curTotal = userdic3[UserId]; List ids = new List(); Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); int TopUserId = 0; if (!string.IsNullOrEmpty(self.ParentNav)) { string uidstring = self.ParentNav.Trim(',').Replace(",,", ","); string[] uidlist = uidstring.Split(','); if (uidlist.Length > 1) { TopUserId = int.Parse(function.CheckInt(uidlist[1])); } else { TopUserId = int.Parse(function.CheckInt(uidlist[0])); } } Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users(); var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList(); foreach(var user in users) { ids.Add(user.Id); } int index = 0; decimal totalAmt = 0; decimal maxAmt = 0; Dictionary dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value); foreach(int key in dic.Keys) { index += 1; if(index > 1) { totalAmt += dic[key]; } else { maxAmt = dic[key]; } } if(totalAmt >= 40000000) { function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1亿以上且小市场大于4000万的名单"); } if(totalAmt >= curTotal * 0.4M) { function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1亿以上且小市场大于40%的名单"); } function.WriteLog(UserId.ToString(), "团队交易额名单"); } db.Dispose(); function.WriteLog("end:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单"); } }