浏览代码

增加重置分表交易方法

lcl 1 年之前
父节点
当前提交
f2cbab740d
共有 4 个文件被更改,包括 38 次插入140 次删除
  1. 21 63
      AppStart/Helper/StatService.cs
  2. 4 64
      Controllers/HomeController.cs
  3. 10 10
      Startup.cs
  4. 3 3
      appsettings.json

+ 21 - 63
AppStart/Helper/StatService.cs

@@ -289,84 +289,42 @@ namespace MySystem
         }
 
 
-        public void test()
+        public void Other()
         {
-            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "实时执行创客激活数日志");
+            string connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计商户和创客交易额日志");
             WebCMSEntities db = new WebCMSEntities();
             KxsMainModels.WebCMSEntities maindb = new KxsMainModels.WebCMSEntities();
             try
             {
-                DataTable idsDt = CustomerSqlConn.dtable("select 646 Id", AppConfig.Base.SqlConn);
-                if(idsDt.Rows.Count > 0)
+                string start = "2023-09-01 00:00:00";
+                string end = DateTime.Now.ToString("2023-09-22 11:38:00");
+                DataTable selfDt = CustomerSqlConn.dtable("select UserId,MerchantId,SnNo,PayMode,IsAct,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(PayMoney),count(Id),sum(MaxDivi),sum(MerchantActualAmount) from ConsumerOrders where MerchantId>0 and CreateDate>='" + start + "' and CreateDate<'" + end + "' group by UserId,MerchantId,SnNo,PayMode,IsAct,DATE_FORMAT(CreateDate,'%Y%m%d')", connstr);
+                if (selfDt.Rows.Count > 0)
                 {
-                    string ids = "";
-                    foreach (DataRow idsDr in idsDt.Rows)
+                    function.WriteLog("统计人数:" + selfDt.Rows.Count + "\n\n", "统计商户和创客交易额日志");
+                    foreach (DataRow selfDr in selfDt.Rows)
                     {
-                        ids += idsDr["Id"].ToString() + ",";
-                    }
-                    DataTable userDt = CustomerSqlConn.dtable("select UserId,DATE_FORMAT(SignDate,'%Y%m%d'),count(Id) from MerchantInfo where Id in (" + ids.TrimEnd(',') + ") group by UserId,DATE_FORMAT(SignDate,'%Y%m%d')", AppConfig.Base.SqlConn);
-                    if (userDt.Rows.Count > 0)
-                    {
-                        function.WriteLog("人数:" + userDt.Rows.Count + "\n\n", "实时执行创客激活数日志");
-                        foreach (DataRow userDr in userDt.Rows)
-                        {
-                            int UserId = int.Parse(userDr["UserId"].ToString());
-                            string TradeDate = userDr[1].ToString();
-                            int ActCount = int.Parse(function.CheckInt(userDr[2].ToString()));
-                            string TradeMonth = TradeDate.Substring(0, 6);
-                            string date = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2);
-                            string start = date + " 00:00:00";
-                            string end = DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00";
-                            KxsMainModels.Users user = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new KxsMainModels.Users();
-                            string ParentNav = user.ParentNav;
-                            UserTradeMonthSummary selfStat = db.UserTradeMonthSummary.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoKeyword == TradeDate && m.SeoTitle == "self");
-                            if (selfStat == null)
-                            {
-                                selfStat = db.UserTradeMonthSummary.Add(new UserTradeMonthSummary()
-                                {
-                                    UserId = UserId,
-                                    TradeMonth = TradeMonth,
-                                    SeoKeyword = TradeDate,
-                                    SeoTitle = "self",
-                                }).Entity;
-                                db.SaveChanges();
-                            }
-                            selfStat.ActiveBuddyMerStatus += ActCount;
-                            ParentNav += "," + UserId + ",";
-                            if (!string.IsNullOrEmpty(ParentNav))
-                            {
-                                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                                foreach (string NavUserIdString in ParentNavList)
-                                {
-                                    int NavUserId = int.Parse(NavUserIdString);
-                                    UserTradeMonthSummary teamStat = db.UserTradeMonthSummary.FirstOrDefault(m => m.UserId == NavUserId && m.TradeMonth == TradeMonth && m.SeoKeyword == TradeDate && m.SeoTitle == "team");
-                                    if (teamStat == null)
-                                    {
-                                        teamStat = db.UserTradeMonthSummary.Add(new UserTradeMonthSummary()
-                                        {
-                                            UserId = NavUserId,
-                                            TradeMonth = TradeMonth,
-                                            SeoKeyword = TradeDate,
-                                            SeoTitle = "team",
-                                        }).Entity;
-                                        db.SaveChanges();
-                                    }
-                                    teamStat.ActiveBuddyMerStatus += ActCount;
-                                }
-                            }
-                        }
-                        db.SaveChanges();
-                        CustomerSqlConn.op("update MerchantInfo set ActStat=1 where Id in (" + ids.TrimEnd(',') + ")", AppConfig.Base.SqlConn);
+                        int MerchantId = int.Parse(selfDr["MerchantId"].ToString());
+                        int PayMode = int.Parse(selfDr["PayMode"].ToString());
+                        int IsAct = int.Parse(selfDr["IsAct"].ToString());
+                        string TradeDate = selfDr[5].ToString();
+                        decimal TradeAmount = decimal.Parse(selfDr[6].ToString());
+                        int TradeCount = int.Parse(selfDr[7].ToString());
+                        decimal ActualAmount = decimal.Parse(selfDr[9].ToString());
+
+                        string jsonString = "{\"TradeDate\":\"" + TradeDate + "\",\"PayMoney\":\"" + TradeAmount + "\",\"TradeCount\":\"" + TradeCount + "\",\"MerchantActualAmount\":\"" + ActualAmount + "\",\"MerchantId\":\"" + MerchantId + "\",\"PayMode\":\"" + PayMode + "\",\"IsAct\":\"" + IsAct + "\"}";
+                        RedisDbconn.Instance.AddList("StatMerchantTradeSummaryQueue", jsonString);
                     }
                 }
             }
             catch (Exception ex)
             {
-                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "实时执行创客激活数异常");
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户和创客交易额异常");
             }
             db.Dispose();
             maindb.Dispose();
-            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "实时执行创客激活数日志");
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "统计商户和创客交易额日志");
         }
     }
 }

+ 4 - 64
Controllers/HomeController.cs

@@ -47,7 +47,7 @@ namespace MySystem.Controllers
             }
             return View();
         }
-        public string tmp()
+        public string Tmp()
         {
             string result = "";
             // string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
@@ -67,70 +67,10 @@ namespace MySystem.Controllers
             return result;
         }
 
-        public string test(int UserId, decimal Amount)
+        public string Test()
         {
-            // StatHelpProfitService.Instance.ResetMaxTradeAmountGo("202301");
-            string result = "";
-            // string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
-            // // int UserId = 145842;
-            // Dictionary<string, decimal> dic = new Dictionary<string, decimal>();
-            // dic.Add("31", Amount);
-            // foreach(string day in dic.Keys)
-            // {
-            //     DataTable dt = CustomerSqlConn.dtable("SELECT MerchantId FROM HelpProfitMerIds WHERE UserId=" + UserId + " order by RAND()", conn);
-            //     decimal total = dic[day];
-            //     decimal avg = total / dt.Rows.Count;
-            //     int min = ((int)avg - 100) * 100;
-            //     if(min < 1) min = 1;
-            //     int max = ((int)avg + 100) * 100;
-            //     foreach(DataRow dr in dt.Rows)
-            //     {
-            //         string MerchantId = dr["MerchantId"].ToString();
-            //         decimal amount = (decimal)function.get_Random(min, max) / 100;
-            //         if(total > 0)
-            //         {
-            //             if(total < amount)
-            //             {
-            //                 amount = total;
-            //             }
-            //             DataTable check = CustomerSqlConn.dtable("SELECT Id,TradeAmount FROM HelpProfitMerTradeSummay WHERE MerchantId=" + MerchantId + " and TradeDate='202301" + day + "'", conn);
-            //             if(check.Rows.Count > 0)
-            //             {
-            //                 if(day == "30")
-            //                 {
-            //                     decimal today = decimal.Parse(check.Rows[0]["TradeAmount"].ToString());
-            //                     if(today < amount)
-            //                     {
-            //                         amount -= today;
-            //                     }
-            //                     else
-            //                     {
-            //                         amount = 0;
-            //                     }
-            //                 }
-            //                 if(amount > 0) result += "update HelpProfitMerTradeSummay set TradeAmount=" + amount + " where Id=" + check.Rows[0]["Id"].ToString() + ";\n";
-            //             }
-            //             else
-            //             {
-            //                 if(amount > 0) result += "INSERT INTO HelpProfitMerTradeSummay (`TradeAmount`, `TradeDate`, `TradeMonth`, `MerchantId`) VALUES (" + amount + ", '202301" + day + "', '202301', " + MerchantId + ");\n";
-            //             }
-            //             check = CustomerSqlConn.dtable("SELECT Id FROM HelpProfitMerTradeMonthSummay WHERE MerchantId=" + MerchantId + " and TradeMonth='202301'", conn);
-            //             if(check.Rows.Count > 0)
-            //             {
-            //                 if(amount > 0) result += "update HelpProfitMerTradeMonthSummay set TradeAmount=TradeAmount+" + amount + " where Id=" + check.Rows[0][0].ToString() + ";\n";
-            //             }
-            //             else
-            //             {
-            //                 if(amount > 0) result += "INSERT INTO HelpProfitMerTradeMonthSummay (`TradeAmount`, `TradeMonth`, `MerchantId`) VALUES (" + amount + ", '202301', " + MerchantId + ");\n";
-            //             }
-            //             total -= amount;
-            //         }
-            //         else
-            //         {
-            //             break;
-            //         }
-            //     }
-            // }
+            string result = "ok";
+            StatService.Instance.Other();
             return result;
         }
     }

+ 10 - 10
Startup.cs

@@ -112,17 +112,17 @@ namespace MySystem
             
             #region 必须打开的
 
-            //老平台
-            StatService.Instance.Start(); //实时统计交易额
-            StatService.Instance.StartPosActNum(); //实时统计激活数            
-            StatNewService.Instance.StartMer(); //实时统计商户交易额
-            StatNewService.Instance.CreateTable(); //生成新的分表
+            // //老平台
+            // StatService.Instance.Start(); //实时统计交易额
+            // StatService.Instance.StartPosActNum(); //实时统计激活数            
+            // StatNewService.Instance.StartMer(); //实时统计商户交易额
+            // StatNewService.Instance.CreateTable(); //生成新的分表
 
-            //好哒
-            StatService2.Instance.Start(); //实时统计交易额
-            StatService2.Instance.StartPosActNum(); //实时统计激活数            
-            StatNewService2.Instance.StartMer(); //实时统计商户交易额
-            StatNewService2.Instance.CreateTable(); //生成新的分表
+            // //好哒
+            // StatService2.Instance.Start(); //实时统计交易额
+            // StatService2.Instance.StartPosActNum(); //实时统计激活数            
+            // StatNewService2.Instance.StartMer(); //实时统计商户交易额
+            // StatNewService2.Instance.CreateTable(); //生成新的分表
 
             #endregion
 

+ 3 - 3
appsettings.json

@@ -20,9 +20,9 @@
     "KxsSqlConnStr": "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;",
     "SqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer;charset=utf8;",
     "SqlConnStr2": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer2;charset=utf8;",
-    "StatSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateStatServer;password=lB6DfB3BufvLGh1h;database=QrCodePlateStatServer;charset=utf8;",
-    "StatSqlConnStr2": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateStatServer;password=lB6DfB3BufvLGh1h;database=QrCodePlateStatServer2;charset=utf8;",
-    "RedisConnStr": "redis:6379,password=kxsmp@2023,DefaultDatabase=0,poolsize=500,preheat=50,asyncPipeline=true",
+    "StatSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateStatServer;charset=utf8;",
+    "StatSqlConnStr2": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateStatServer2;charset=utf8;",
+    "RedisConnStr": "8.137.99.48:6379,password=kxsmp@2023,DefaultDatabase=0,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",
     "AndroidAppVersion": "1.0.0",
     "OSSKey": "iL9dWgBunZRwGbHQ",