using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Data; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using MySystem.PxcModels; using System.Threading; using Library; using LitJson; namespace MySystem.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { return View(); } public IActionResult Error() { string isapi = Request.Headers["Api"].ToString(); if (isapi != "1") { if (Response.StatusCode == 500) { return Redirect("/public/errpage/pc/500.html"); } else if (Response.StatusCode == 502) { return Redirect("/public/errpage/pc/502.html"); } else if (Response.StatusCode == 404) { return Redirect("/public/errpage/pc/404.html"); } } return View(); } private static object o = new object(); public string addmer(string mid, int k = 0) { MerchantConfirmService.Instance.Start(mid, k); return "ok"; } public string cleartrade() { StatService.Instance.clear(); return "ok"; } public string stattrade(string d) { StatService.Instance.dosomething2(d); return "ok"; } public string setqrcode(int uid = 0) { return "ok"; } public string userqrcode(int uid) { WebCMSEntities db = new WebCMSEntities(); Users user = db.Users.FirstOrDefault(m => m.Id == uid); if (user != null) { MakeReferenceQrCodeService.Instance.Start(user.Id.ToString()); return "ok"; } db.Dispose(); return "fail"; } private void th1() { Thread th = new Thread(th1do); th.IsBackground = true; th.Start(); } private void th1do() { WebCMSEntities db = new WebCMSEntities(); Users user = db.Users.FirstOrDefault(m => m.Id == 2); if (user != null) { user.SeoTitle = "111111"; Thread.Sleep(5000); user.SeoDescription = "222222"; db.SaveChanges(); } db.Dispose(); } private void th2() { Thread th = new Thread(th2do); th.IsBackground = true; th.Start(); } private void th2do() { Thread.Sleep(2000); WebCMSEntities db = new WebCMSEntities(); Users user = db.Users.FirstOrDefault(m => m.Id == 2); if (user != null) { user.SeoKeyword = "看看有没有值写入"; db.SaveChanges(); } db.Dispose(); } public string chkact(int Id = 0) { if (Id > 0) { SycnSpActiveService.Instance.Start(Id); } return "ok"; } public string chktrade(int Id = 0) { if (Id > 0) { SycnSpTradeService.Instance.Start(Id); } return "ok"; } // 补激活奖励 public string setmeruser(string date) { StatService.Instance.dosomething1(date); return "ok"; } public string chkactprize(int Id = 0) { if (Id > 0) { StatService.Instance.dosomething3(Id); } return "ok"; } public string mutilactprize() { List ids = new List(); WebCMSEntities db = new WebCMSEntities(); SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities(); foreach (int id in ids) { PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id); if (pos != null) { SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle)); if (act != null) { pos.SeoKeyword = act.SeoTitle; db.SaveChanges(); StatService.Instance.dosomething3(pos.Id); } } } db.Dispose(); spdb.Dispose(); return "ok"; } public string checkOrder(int id) { AlipayPayBack2Service.Instance.checkOrder(id); return "ok"; } public string scanBind() { SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities(); PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities(); var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).OrderBy(m => m.Id).ToList(); foreach (var Bind in Binds) { var tran = db.Database.BeginTransaction(); try { PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo(); PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId); if (pos != null) { if (pos.BindingState == 0) { pos.BindingState = 1; pos.BindingTime = Bind.CreateTime; PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo); if (merFor == null) { merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo() { MerNo = Bind.MerNo, SnId = pos.Id, }).Entity; } db.SaveChanges(); tran.Commit(); function.WriteLog(pos.PosSn, "补充绑定数据"); } } } catch (Exception ex) { tran.Rollback(); function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常"); } tran.Dispose(); } spdb.SaveChanges(); spdb.Dispose(); db.SaveChanges(); db.Dispose(); return "ok"; } public string scanMerchant() { SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities(); PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities(); var Mers = spdb.Merchants.OrderBy(m => m.Id).ToList(); foreach (var Mer in Mers) { var tran = db.Database.BeginTransaction(); try { PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo(); PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo(); if (pos.BindingState == 1) { PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users(); int TopUserId = 0; if (!string.IsNullOrEmpty(user.ParentNav)) { TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]); } int BrandId = int.Parse(Mer.ProductType); if (Mer.MerNo.StartsWith("M900")) { BrandId = 3; } bool check = db.PosMerchantInfo.Any(m => m.KqMerNo == Mer.MerNo); if (!check) { PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo() { CreateDate = Mer.CreateTime, UpdateDate = Mer.UpdateTime, TopUserId = TopUserId, MerUserType = user.MerchantType, BrandId = BrandId, SnStoreId = pos.StoreId, SnType = pos.PosSnType, UserId = pos.UserId, MgrName = Mer.AgentName, MerStatus = 1, KqSnNo = Mer.SnNo, KqMerNo = Mer.MerNo, MerIdcardNo = Mer.MerIdcardNo, MerRealName = Mer.MerRealName, MerchantMobile = Mer.MerMobile, MerchantName = Mer.MerName, MerchantNo = Mer.MerNo.Length > 16 ? Mer.MerNo.Substring(0, 16) : Mer.MerNo, }).Entity; db.SaveChanges(); pos.BindMerchantId = add.Id; db.SaveChanges(); tran.Commit(); function.WriteLog(Mer.MerNo, "补充商户数据"); } } } catch (Exception ex) { tran.Rollback(); function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常"); } tran.Dispose(); } spdb.Dispose(); db.Dispose(); return "ok"; } public string scanTrade() { SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities(); PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities(); IQueryable trades = spdb.TradeRecord.OrderBy(m => m.Id); foreach (SpModels.TradeRecord trade in trades.ToList()) { bool op = true; if (trade.SerEntryMode == "N") { if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900) { op = false; PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo(); PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId); if (pos != null) { if (trade.SerEntryMode == "N" && trade.ProductType == "1") { pos.SeoKeyword = trade.TradeAmount.ToString("f2"); db.SaveChanges(); } } } } if (op) { PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo(); PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId); if (pos != null) { if (pos.BindMerchantId > 0) { PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users(); int TopUserId = 0; if (!string.IsNullOrEmpty(user.ParentNav)) { TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]); } bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo); if (!check) { decimal TradeAmount = trade.TradeAmount; int BankCardType = -1; int QrPayFlag = 0; if (pos.BrandId == 1 || pos.BrandId == 3) { TradeAmount = TradeAmount / 100; BankCardType = int.Parse(trade.BankCardType); if(trade.TradeType == "02") QrPayFlag = 1; } else if (pos.BrandId == 2) { if (trade.TradeType == "CREDIT_BY_CARD") { BankCardType = 1; } else if (trade.TradeType == "DEBIT_BY_CARD") { BankCardType = 0; } if(trade.TradeType == "CLOUD_PAY") QrPayFlag = 1; } int BrandId = int.Parse(trade.ProductType); if (trade.MerNo.StartsWith("M900")) { BrandId = 3; } db.TradeRecord.Add(new PxcModels.TradeRecord() { CreateDate = trade.CreateDate, UpdateDate = trade.UpdateDate, RecordNo = trade.TradeSerialNo, //单号 UserId = pos.UserId, //创客 MerchantId = pos.BindMerchantId, //商户 MerNo = trade.MerNo, //渠道商户编号 MerHelpFlag = 0, //是否属于扶持周期内商户 HelpMonthCount = 0, //扶持第几个月 MerBuddyType = user.MerchantType, //商户创客类型 SnNo = trade.TradeSnNo, //渠道SN号 // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期 TradeSerialNo = trade.ChannelSerial, //交易流水号 TradeAmount = TradeAmount, //交易金额 BankCardType = BankCardType, //银行卡类型 QrPayFlag = QrPayFlag, //云闪付标识 BrandId = BrandId, //品牌 Remark = trade.Remark, //备注 TopUserId = TopUserId, //顶级创客 MerUserId = pos.UserId, //商户直属创客 }); if (BankCardType == 1) { pos.CreditTrade += TradeAmount; } else if (BankCardType == 0) { pos.DebitCardTrade += TradeAmount; } if (pos.CreditTrade < 1000) { pos.IsPurchase = 99; } else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20)) { pos.IsPurchase = 0; pos.ActivationState = 1; pos.ActivationTime = DateTime.Now; PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId); if (merchant != null) { merchant.ActiveStatus = 1; merchant.MerStandardDate = DateTime.Now; db.SaveChanges(); } } db.SaveChanges(); function.WriteLog(trade.Id.ToString(), "补充交易数据"); } } } } } spdb.Dispose(); db.Dispose(); return "ok"; } // public string add100() // { // WebCMSEntities db = new WebCMSEntities(); // List uids = new List(); // uids.Add(1053); // foreach (int uid in uids) // { // int ParentUserId = uid; // int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机 // int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送) // if (machineCount + ActiveCount >= 3) // { // UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId); // if (account == null) // { // account = db.UserAccount.Add(new UserAccount() // { // Id = ParentUserId, // UserId = ParentUserId, // }).Entity; // db.SaveChanges(); // } // decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额 // decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额 // decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额 // account.BalanceAmount += 100; // account.TotalAmount += 100; // decimal AfterTotalAmount = account.TotalAmount; //变更后总金额 // decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额 // decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额 // UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord() // { // CreateDate = DateTime.Now, // UpdateDate = DateTime.Now, // UserId = ParentUserId, //创客 // ChangeType = 112, //变动类型 // ChangeAmount = 100, //变更金额 // BeforeTotalAmount = BeforeTotalAmount, //变更前总金额 // AfterTotalAmount = AfterTotalAmount, //变更后总金额 // BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额 // AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额 // BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额 // AfterBalanceAmount = AfterBalanceAmount, //变更后余额 // }).Entity; // db.SaveChanges(); // RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account); // //推荐下单上级获得30天的机具循环天数 // var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList(); // foreach (var subPos in posList) // { // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id); // if (pos != null) // { // pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30); // } // } // db.SaveChanges(); // } // } // db.Dispose(); // return "finish"; // } public string test() { // StatService.Instance.dosomething2("2022-03-31"); // StatService.Instance.dosomething2("2022-03-30"); // StatService.Instance.dosomething2("2022-03-29"); // StatService.Instance.dosomething2("2022-03-28"); // StatService.Instance.dosomething2("2022-03-27"); // StatService.Instance.dosomething2("2022-03-26"); // StatService.Instance.dosomething2("2022-03-25"); // StatService.Instance.dosomething2("2022-03-24"); // StatService.Instance.dosomething2("2022-03-23"); // StatService.Instance.dosomething2("2022-03-22"); // StatService.Instance.dosomething2("2022-03-21"); // StatService.Instance.dosomething2("2022-03-20"); // StatService.Instance.dosomething2("2022-03-19"); // StatService.Instance.dosomething2("2022-03-18"); // StatService.Instance.dosomething2("2022-03-17"); // StatService.Instance.dosomething2("2022-03-16"); // StatService.Instance.dosomething2("2022-03-15"); // StatService.Instance.dosomething2("2022-03-14"); // StatService.Instance.dosomething2("2022-03-13"); // StatService.Instance.dosomething2("2022-03-12"); // StatService.Instance.dosomething2("2022-03-11"); return "ok"; } } }