Browse Source

修改统计收益程序算法,实时统计
分润增加盛付通,便于下个月统计

lichunlei 3 years ago
parent
commit
588a7c34d5
3 changed files with 128 additions and 23 deletions
  1. 1 1
      AppStart/Helper/Profit/ProfitHelper.cs
  2. 125 21
      AppStart/Helper/StatService.cs
  3. 2 1
      Startup.cs

+ 1 - 1
AppStart/Helper/Profit/ProfitHelper.cs

@@ -1772,7 +1772,7 @@ namespace MySystem
             }
             }
             function.WritePage("/ProfitStat/", Month + ".txt", DateTime.Now.ToString());
             function.WritePage("/ProfitStat/", Month + ".txt", DateTime.Now.ToString());
             WebCMSEntities db = new WebCMSEntities();
             WebCMSEntities db = new WebCMSEntities();
-            for (int i = 1; i <= 6; i++) //品牌
+            for (int i = 1; i <= 7; i++) //品牌
             {
             {
                 for (int j = 0; j <= 1; j++) //卡类型
                 for (int j = 0; j <= 1; j++) //卡类型
                 {
                 {

+ 125 - 21
AppStart/Helper/StatService.cs

@@ -32,7 +32,6 @@ namespace MySystem
                     // StartEverDayV2(doDate);
                     // StartEverDayV2(doDate);
                     dosomething4(doDate);
                     dosomething4(doDate);
                     ListenFluxRecord(doDate);
                     ListenFluxRecord(doDate);
-                    StatProfit(doDate);
                 }
                 }
                 string Msg = "success";
                 string Msg = "success";
                 jobInfo.Status = Msg == "success" ? 1 : 0;
                 jobInfo.Status = Msg == "success" ? 1 : 0;
@@ -1457,11 +1456,11 @@ namespace MySystem
                             }).Entity;
                             }).Entity;
                             db.SaveChanges();
                             db.SaveChanges();
                         }
                         }
-                        if (BankCardType == 0)
+                        if (BankCardType == 0 && selfStat.DirectDebitTradeAmt == 0)
                         {
                         {
                             selfStat.DirectDebitTradeAmt += TradeAmount;
                             selfStat.DirectDebitTradeAmt += TradeAmount;
                         }
                         }
-                        else if (BankCardType != 0)
+                        else if (BankCardType != 0 && selfStat.DirectTradeAmt == 0)
                         {
                         {
                             selfStat.DirectTradeAmt += TradeAmount;
                             selfStat.DirectTradeAmt += TradeAmount;
                         }
                         }
@@ -1500,11 +1499,11 @@ namespace MySystem
                                         }).Entity;
                                         }).Entity;
                                         db.SaveChanges();
                                         db.SaveChanges();
                                     }
                                     }
-                                    if (BankCardType == 0)
+                                    if (BankCardType == 0 && teamStat.NonDirectDebitTradeAmt == 0)
                                     {
                                     {
                                         teamStat.NonDirectDebitTradeAmt += TradeAmount;
                                         teamStat.NonDirectDebitTradeAmt += TradeAmount;
                                     }
                                     }
-                                    else if (BankCardType != 0)
+                                    else if (BankCardType != 0 && teamStat.NonDirectTradeAmt == 0)
                                     {
                                     {
                                         teamStat.NonDirectTradeAmt += TradeAmount;
                                         teamStat.NonDirectTradeAmt += TradeAmount;
                                     }
                                     }
@@ -1750,7 +1749,10 @@ namespace MySystem
             // }
             // }
             while (true)
             while (true)
             {
             {
-                StartPosActNumEverTime();
+                if(DateTime.Now.Hour >= 2)
+                {
+                    StartPosActNumEverTime();
+                }
                 Thread.Sleep(120000);
                 Thread.Sleep(120000);
             }
             }
         }
         }
@@ -1949,7 +1951,10 @@ namespace MySystem
             // }
             // }
             while (true)
             while (true)
             {
             {
-                StartNewUserNumEverTime();
+                if(DateTime.Now.Hour >= 2)
+                {
+                    StartNewUserNumEverTime();
+                }
                 Thread.Sleep(120000);
                 Thread.Sleep(120000);
             }
             }
         }
         }
@@ -2120,26 +2125,34 @@ namespace MySystem
 
 
 
 
         // 每天统计头一天的收益
         // 每天统计头一天的收益
-        public void StatProfit(string date)
+        public void StatProfit()
         {
         {
-            OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
-            Thread th = new Thread(StatProfitEverDay);
+            Thread th = new Thread(StatProfitDo);
             th.IsBackground = true;
             th.IsBackground = true;
             th.Start();
             th.Start();
         }
         }
-        // public void StatProfitDo()
-        // {
-        //     DateTime end = DateTime.Parse("2022-06-16 00:00:00");
-        //     DateTime check = DateTime.Parse("2022-06-16");
-        //     while (check <= end)
-        //     {
-        //         StatProfitEverDay(check.ToString("yyyy-MM-dd"));
-        //         Thread.Sleep(1000);
-        //         check = check.AddDays(1);
-        //     }
-        // }
+        public void StatProfitDo()
+        {
+            // DateTime end = DateTime.Parse("2022-06-16 00:00:00");
+            // DateTime check = DateTime.Parse("2022-06-16");
+            // while (check <= end)
+            // {
+            //     StatProfitEverDay(check.ToString("yyyy-MM-dd"));
+            //     Thread.Sleep(1000);
+            //     check = check.AddDays(1);
+            // }
+            while (true)
+            {
+                if(DateTime.Now.Hour >= 2)
+                {
+                    StatProfitEverDayEverTime();
+                }
+                Thread.Sleep(120000);
+            }
+        }
         public void StatProfitEverDay(object sender)
         public void StatProfitEverDay(object sender)
         {
         {
+            OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
             string date = sender.ToString();
             string date = sender.ToString();
             function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "执行昨天收益日志");
             function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "执行昨天收益日志");
             WebCMSEntities db = new WebCMSEntities();
             WebCMSEntities db = new WebCMSEntities();
@@ -2236,6 +2249,97 @@ namespace MySystem
             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", "执行昨天收益日志");
         }
         }
 
 
+        public void StatProfitEverDayEverTime()
+        {
+            OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "实时统计收益日志");
+            WebCMSEntities db = new WebCMSEntities();
+            try
+            {
+                string startId = function.ReadInstance("/UserAccountRecord/Id.txt");
+                if(string.IsNullOrEmpty(startId))
+                {
+                    startId = "160653";
+                }
+                DataTable idsDt = OtherMySqlConn.dtable("select Id from UserAccountRecord where Id>=" + startId + " and QueryCount=0 order by Id limit 1000");
+                if(idsDt.Rows.Count > 0)
+                {
+                    string ids = "";
+                    foreach (DataRow idsDr in idsDt.Rows)
+                    {
+                        ids += idsDr["Id"].ToString() + ",";
+                        startId = idsDr["Id"].ToString();
+                    }
+                    DataTable userDt = OtherMySqlConn.dtable("select UserId,ChangeType,ProductType,DATE_FORMAT(CreateDate, '%Y%m%d'),sum(ChangeAmount)  from UserAccountRecord where Id in (" + ids.TrimEnd(',') + ") group by UserId,ChangeType,ProductType,DATE_FORMAT(CreateDate, '%Y%m%d')");
+                    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());
+                            int ChangeType = int.Parse(userDr["ChangeType"].ToString());
+                            int ProductType = int.Parse(userDr["ProductType"].ToString());
+                            string TradeDate = userDr[3].ToString();
+                            decimal ProfitAmount = decimal.Parse(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";
+                            Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                            string ParentNav = user.ParentNav;
+                            UserRebateDetail selfStat = db.UserRebateDetail.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.RebateType == ChangeType && m.ProductType == ProductType && m.SeoTitle == "self");
+                            if (selfStat == null)
+                            {
+                                selfStat = db.UserRebateDetail.Add(new UserRebateDetail()
+                                {
+                                    UserId = UserId,
+                                    TradeMonth = TradeMonth,
+                                    TradeDate = TradeDate,
+                                    RebateType = ChangeType,
+                                    ProductType = ProductType,
+                                    SeoTitle = "self",
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            selfStat.CreditRewardAmount += ProfitAmount;
+                            ParentNav += "," + UserId + ",";
+                            if (!string.IsNullOrEmpty(ParentNav))
+                            {
+                                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                                foreach (string NavUserIdString in ParentNavList)
+                                {
+                                    int NavUserId = int.Parse(NavUserIdString);
+                                    UserRebateDetail teamStat = db.UserRebateDetail.FirstOrDefault(m => m.UserId == NavUserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.RebateType == ChangeType && m.ProductType == ProductType && m.SeoTitle == "team");
+                                    if (teamStat == null)
+                                    {
+                                        teamStat = db.UserRebateDetail.Add(new UserRebateDetail()
+                                        {
+                                            UserId = NavUserId,
+                                            TradeMonth = TradeMonth,
+                                            TradeDate = TradeDate,
+                                            RebateType = ChangeType,
+                                            ProductType = ProductType,
+                                            SeoTitle = "team",
+                                        }).Entity;
+                                        db.SaveChanges();
+                                    }
+                                    teamStat.CreditRewardAmount += ProfitAmount;
+                                }
+                            }
+                        }
+                        db.SaveChanges();
+                        OtherMySqlConn.op("update UserAccountRecord set QueryCount=1 where Id in (" + ids.TrimEnd(',') + ")");
+                        function.WritePage("/UserAccountRecord/", "Id.txt", startId);
+                    }
+                }
+            }
+            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", "实时统计收益日志");
+        }
 
 
 
 
 
 

+ 2 - 1
Startup.cs

@@ -203,10 +203,11 @@ namespace MySystem
             RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
             RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
             //必须打开的
             //必须打开的
 
 
+            // StatService.Instance.StartEverDay("2022-06-18");
             StatService.Instance.StartPosActNum(); //实时统计激活数
             StatService.Instance.StartPosActNum(); //实时统计激活数
             StatService.Instance.StartNewUserNum(); //实时统计新增创客数
             StatService.Instance.StartNewUserNum(); //实时统计新增创客数
+            StatService.Instance.StatProfit();
             // StatService.Instance.StartEverDayV2("");
             // StatService.Instance.StartEverDayV2("");
-            // StatService.Instance.StatProfit("");
             // RedPackageHelper.Instance.Start();
             // RedPackageHelper.Instance.Start();
             // StatService.Instance.StatUserLevel();
             // StatService.Instance.StatUserLevel();
             // ProfitHelper.Instance.StatProfit("202205"); //统计分润
             // ProfitHelper.Instance.StatProfit("202205"); //统计分润