Browse Source

改造推荐王算法

lcl 11 months ago
parent
commit
20c2451523
3 changed files with 30 additions and 20 deletions
  1. 22 11
      AppStart/Helper/RecommandKingHelper.cs
  2. 1 0
      AppStart/Tables/RecommandKingItem.cs
  3. 7 9
      Startup.cs

+ 22 - 11
AppStart/Helper/RecommandKingHelper.cs

@@ -27,7 +27,7 @@ namespace MySystem
         {
             while (true)
             {
-                if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 12)
+                if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 23)
                 {
                     Recommend();
                 }
@@ -37,12 +37,12 @@ namespace MySystem
         public void Recommend()
         {
             string today = DateTime.Now.ToString("yyyy-MM-dd");
-            // string checkFlag = function.ReadInstance("/RecommandKing/" + today + ".txt");
-            // if(!string.IsNullOrEmpty(checkFlag))
-            // {
-            //     return;
-            // }
-            // function.WritePage("/RecommandKing/", today + ".txt", DateTime.Now.ToString());
+            string checkFlag = function.ReadInstance("/RecommandKing/" + today + ".txt");
+            if(!string.IsNullOrEmpty(checkFlag))
+            {
+                return;
+            }
+            function.WritePage("/RecommandKing/", today + ".txt", DateTime.Now.ToString());
             List<int> Historys = new List<int>();
             Historys.Add(565);
             Historys.Add(139473);
@@ -69,7 +69,7 @@ namespace MySystem
             WebCMSEntities db = new WebCMSEntities();
             ReadModels.WebCMSEntities readdb = new ReadModels.WebCMSEntities();
             //统计当月下单名单
-            List<int> uids = readdb.Orders.Where(m => m.PayDate >= check && m.Status > 0 && m.Sort == 0 && ProductIds.Contains(m.ProductId)).ToList().Select(m => m.UserId).Distinct().ToList();
+            List<int> uids = readdb.Orders.Where(m => m.PayDate >= check && m.Status > 0 && m.Sort == 0 && m.UserId > 1 && ProductIds.Contains(m.ProductId)).ToList().Select(m => m.UserId).Distinct().ToList();
             foreach(int uid in uids)
             {
                 int ActCount = 0;
@@ -109,6 +109,7 @@ namespace MySystem
                                 ParentUserId = user.ParentUserId,
                                 ParentNav = user.ParentNav,
                                 PreAmount = PreMonthAmt.ContainsKey(user.Id) ? PreMonthAmt[user.Id] : 0,
+                                Level = user.ParentNav.Replace(",,", ",").Trim(',').Split(',').Length + 1
                             });
                         }
 
@@ -164,11 +165,21 @@ namespace MySystem
                     }
                 }
             }
-            users = users.OrderByDescending(m => m.ParentNav).ToList();
+            users = users.OrderByDescending(m => m.Level).ToList();
+            List<RecommandKingItem> users2 = users.OrderBy(m => m.Level).ToList();
             foreach(RecommandKingItem user in users)
             {
                 string UserIdStr = "," + user.UserId + ",";
-                user.ActCount = users.Count(m => m.ParentNav.Contains(UserIdStr) && m.ActCount < 50 && m.PreAmount < 30000000);
+                RecommandKingItem lookSub = users2.FirstOrDefault(m => m.ParentNav.Contains(UserIdStr) && (m.ActCount >= 50 || m.PreAmount >= 30000000));
+                if(lookSub != null)
+                {
+                    string ParentNav = lookSub.ParentNav + "," + lookSub.UserId + ",";
+                    user.ActCount = users.Count(m => m.ParentNav.Contains(UserIdStr) && !m.ParentNav.StartsWith(ParentNav) && m.UserId != lookSub.UserId && m.ActCount < 50 && m.PreAmount < 30000000);
+                }
+                else
+                {
+                    user.ActCount = users.Count(m => m.ParentNav.Contains(UserIdStr) && m.ActCount < 50 && m.PreAmount < 30000000);
+                }
             }
 
             int num = 0;
@@ -182,7 +193,7 @@ namespace MySystem
                     {
                         UserId = user.UserId,
                         TradeMonth = TradeMonth,
-                        QueryCount = user.ActCount,
+                        QueryCount = user.ActCount > 50 ? 50 : user.ActCount,
                     }).Entity;
                     if(num % 200 == 0)
                     {

+ 1 - 0
AppStart/Tables/RecommandKingItem.cs

@@ -7,5 +7,6 @@
         public string ParentNav { get; set; }
         public int ActCount { get; set; }
         public decimal PreAmount { get; set; }
+        public int Level { get; set; }
     }
 }

+ 7 - 9
Startup.cs

@@ -166,22 +166,20 @@ namespace MySystem
             // }
             // if(Library.ConfigurationManager.EnvironmentFlag == 2)
             // {
-                // LeaderCompPrizeHelper.Instance.Start(); //领导人达标奖
-                // RecommandKingHelper.Instance.Start(); //推荐王
-                // AddSourcePosSnHelper.Instance.Start(); //补来源机具
+                LeaderCompPrizeHelper.Instance.Start(); //领导人达标奖
+                RecommandKingHelper.Instance.Start(); //推荐王
+                AddSourcePosSnHelper.Instance.Start(); //补来源机具
             // }
-
-            RecommandKingHelper.Instance.Recommend();
         }
 
         private void InitMain()
         {
             string conn = Configuration["Setting:SqlConnStr"];
             string dbName = "KxsMainServer";
-            // if(Library.ConfigurationManager.EnvironmentFlag == 2)
-            // {
-            //     dbName = "KxsProfitServer";
-            // }
+            if(Library.ConfigurationManager.EnvironmentFlag == 2)
+            {
+                dbName = "KxsProfitServer";
+            }
             Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
             System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = '" + dbName + "'", conn);
             foreach (System.Data.DataRow subtable in tablecollection.Rows)