Browse Source

统计激活数

lcl 1 year ago
parent
commit
5144a8ea7b
2 changed files with 115 additions and 1 deletions
  1. 113 0
      AppStart/Helper/StatService.cs
  2. 2 1
      Startup.cs

+ 113 - 0
AppStart/Helper/StatService.cs

@@ -190,5 +190,118 @@ namespace MySystem
             maindb.Dispose();
             function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "统计商户和创客交易额日志");
         }
+
+        // 统计创客激活数
+        public void StartPosActNum()
+        {
+            Thread th = new Thread(StartPosActNumFor);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartPosActNumFor()
+        {
+            while (true)
+            {
+                if(DateTime.Now.Hour >= 3)
+                {
+                    StartPosActNumEverTime();
+                }
+                Thread.Sleep(120000);
+            }
+        }
+        public void StartPosActNumEverTime()
+        {
+            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 Id from PosMachinesTwo where QueryCount=0 and ActivationState=1 and ActivationTime is not null and BuyUserId>0 limit 50", AppConfig.Base.SqlConn);
+                if(idsDt.Rows.Count > 0)
+                {
+                    string ids = "";
+                    foreach (DataRow idsDr in idsDt.Rows)
+                    {
+                        ids += idsDr["Id"].ToString() + ",";
+                    }
+                    DataTable userDt = CustomerSqlConn.dtable("select BuyUserId,StoreId,DATE_FORMAT(ActivationTime, '%Y%m%d'),count(Id) from PosMachinesTwo where Id in (" + ids.TrimEnd(',') + ") group by BuyUserId,StoreId,DATE_FORMAT(ActivationTime, '%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["BuyUserId"].ToString());
+                            int StoreId = int.Parse(userDr["StoreId"].ToString());
+                            string TradeDate = userDr[3].ToString();
+                            int ActCount = int.Parse(function.CheckInt(userDr[4].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;
+                                }
+                            }
+
+                            //统计分仓激活数
+                            StoreSnActivateSummary storeStat = db.StoreSnActivateSummary.FirstOrDefault(m => m.StoreId == StoreId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate);
+                            if (storeStat == null)
+                            {
+                                storeStat = db.StoreSnActivateSummary.Add(new StoreSnActivateSummary()
+                                {
+                                    StoreId = StoreId,
+                                    TradeMonth = TradeMonth,
+                                    TradeDate = TradeDate,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            storeStat.ActivateNum += ActCount;
+                        }
+                        db.SaveChanges();
+                        CustomerSqlConn.op("update PosMachinesTwo set QueryCount=1 where Id in (" + ids.TrimEnd(',') + ")", AppConfig.Base.SqlConn);
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                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", "实时执行创客激活数日志");
+        }
     }
 }

+ 2 - 1
Startup.cs

@@ -111,7 +111,8 @@ namespace MySystem
             });
             
             //必须打开的
-            StatService.Instance.Start(); //实时统计
+            StatService.Instance.Start(); //实时统计交易额
+            StatService.Instance.StartPosActNum(); //实时统计激活数
             //必须打开的
 
         }