Browse Source

调整推荐王算法

lcl 11 months ago
parent
commit
a33cd609f0
2 changed files with 48 additions and 45 deletions
  1. 47 45
      AppStart/Helper/RecommandKingHelper.cs
  2. 1 0
      AppStart/Tables/RecommandKingItem.cs

+ 47 - 45
AppStart/Helper/RecommandKingHelper.cs

@@ -51,6 +51,7 @@ namespace MySystem
             Historys.Add(127023);
             string TradeMonth = DateTime.Now.AddMonths(-0).ToString("yyyyMM");
             DateTime check = DateTime.Parse("2023-10-01 00:00:00");
+            DateTime checke = DateTime.Parse("2024-04-29 00:00:00");
             DateTime start = DateTime.Parse(DateTime.Now.AddMonths(-0).ToString("yyyy-MM") + "-01 00:00:00");
             DateTime end = start.AddMonths(1);
             CustomerSqlConn.op("delete from RecommendDirectUser where TradeMonth='" + TradeMonth + "'", MysqlConn.SqlConnStr);
@@ -66,17 +67,18 @@ namespace MySystem
             ProductIds.Add(39);
             ProductIds.Add(40);
             List<RecommandKingItem> users = new List<RecommandKingItem>();
-            Dictionary<int, decimal> PreMonthAmt = GetTradeAmtList(PreTradeMonth);
+            // Dictionary<int, decimal> PreMonthAmt = GetTradeAmtList(PreTradeMonth);
             WebCMSEntities db = new WebCMSEntities();
             ReadModels.WebCMSEntities readdb = new ReadModels.WebCMSEntities();
             MpMainModels.WebCMSEntities mpdb = new MpMainModels.WebCMSEntities();
             MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
             //统计当月下单名单
-            List<int> checkIds = readdb.Users.Where(m => (m.ParentNav.Contains(",609,") || m.Id == 609) && m.AuthFlag == 1).ToList().Select(m => m.Id).ToList();
-            List<int> uids = readdb.Orders.Where(m => m.PayDate >= check && m.Status > 0 && m.Sort == 0 && m.UserId > 1 && checkIds.Contains(m.UserId) && ProductIds.Contains(m.ProductId)).ToList().Select(m => m.UserId).Distinct().ToList();
+            // List<int> checkIds = readdb.Users.Where(m => (m.ParentNav.Contains(",609,") || m.Id == 609) && m.AuthFlag == 1).ToList().Select(m => m.Id).ToList();
+            var orders = readdb.Orders.Where(m => m.PayDate >= check && m.PayDate < checke && m.Status > 0 && m.Sort == 0 && m.UserId > 1 && ProductIds.Contains(m.ProductId)).ToList();
+            List<int> uids = orders.Select(m => m.UserId).Distinct().ToList();
             foreach(int uid in uids)
             {
-                Users user = db.Users.FirstOrDefault(m => m.Id == uid);
+                ReadModels.Users user = readdb.Users.FirstOrDefault(m => m.Id == uid);
                 if(user != null)
                 {
                     if(!users.Any(m => m.UserId == user.Id))
@@ -86,24 +88,56 @@ namespace MySystem
                             UserId = user.Id,
                             ParentUserId = user.ParentUserId,
                             ParentNav = user.ParentNav,
-                            PreAmount = PreMonthAmt.ContainsKey(user.Id) ? PreMonthAmt[user.Id] : 0,
+                            // PreAmount = PreMonthAmt.ContainsKey(user.Id) ? PreMonthAmt[user.Id] : 0,
                             Level = user.ParentNav.Replace(",,", ",").Trim(',').Split(',').Length + 1,
+                            UserLevel = user.UserLevel,
                             Kind = 1,
                             Op = false,
                         });
                     }
                 }
             }
+            foreach(RecommandKingItem user in users)
+            {
+                int uid = user.UserId;
+                int ActCount = 0;
+                if(ActCount == 0)
+                {
+                    if(readdb.UserTradeMonthSummary.Any(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "self"))
+                    {
+                        ActCount += readdb.UserTradeMonthSummary.Where(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
+                        // if(readdb.UserSimActSummary.Any(m => m.UserId == uid && m.Kind == 1))
+                        // {
+                        //     ActCount -= readdb.UserSimActSummary.Where(m => m.UserId == uid && m.Kind == 1).Sum(m => m.ActCount); //减去注销的用户
+                        // }
+                    }
+                }
+                // if(ActCount == 0)
+                // {
+                //     ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
+                // }
+                // if(ActCount == 0)
+                // {
+                //     ActCount += mpdb2.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
+                // }
+                if(ActCount > 0)
+                {
+                    user.Op = true;
+                    function.WriteLog(user.UserId.ToString(), "推荐王达标创客名单");
+                }
+                // RedisDbconn.Instance.AddList("userstmp2024", user);
+            }
+            // int Cou = RedisDbconn.Instance.GetList<RecommandKingItem>("userstmp2024", 1, 99999999).Count(m => m.Op);
             foreach(int uid in uids)
             {
-                Users user = db.Users.FirstOrDefault(m => m.Id == uid);
+                ReadModels.Users user = readdb.Users.FirstOrDefault(m => m.Id == uid);
                 if(user != null)
                 {
                     string[] ParentIds = user.ParentNav.Replace(",,", ",").Trim(',').Split(',');
                     foreach(string ParentId in ParentIds)
                     {
                         int ParentUserId = int.Parse(ParentId);
-                        Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId && m.Id > 1);
+                        ReadModels.Users puser = readdb.Users.FirstOrDefault(m => m.Id == ParentUserId && m.Id > 1);
                         if(puser != null)
                         {
                             if(!users.Any(m => m.UserId == puser.Id))
@@ -113,8 +147,9 @@ namespace MySystem
                                     UserId = puser.Id,
                                     ParentUserId = puser.ParentUserId,
                                     ParentNav = puser.ParentNav,
-                                    PreAmount = PreMonthAmt.ContainsKey(puser.Id) ? PreMonthAmt[puser.Id] : 0,
+                                    // PreAmount = PreMonthAmt.ContainsKey(puser.Id) ? PreMonthAmt[puser.Id] : 0,
                                     Level = puser.ParentNav.Replace(",,", ",").Trim(',').Split(',').Length + 1,
+                                    UserLevel = puser.UserLevel,
                                     Kind = 2,
                                     Op = false,
                                 });
@@ -123,39 +158,6 @@ namespace MySystem
                     }
                 }
             }
-            foreach(RecommandKingItem user in users)
-            {
-                if(user.Kind == 1)
-                {
-                    int uid = user.UserId;
-                    int ActCount = 0;
-                    if(ActCount == 0)
-                    {
-                        if(readdb.UserTradeMonthSummary.Any(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "self"))
-                        {
-                            ActCount += readdb.UserTradeMonthSummary.Where(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
-                            if(readdb.UserSimActSummary.Any(m => m.UserId == uid && m.Kind == 1))
-                            {
-                                ActCount -= readdb.UserSimActSummary.Where(m => m.UserId == uid && m.Kind == 1).Sum(m => m.ActCount); //减去注销的用户
-                            }
-                        }
-                    }
-                    if(ActCount == 0)
-                    {
-                        ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
-                    }
-                    if(ActCount == 0)
-                    {
-                        ActCount += mpdb2.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
-                    }
-                    if(ActCount > 0)
-                    {
-                        user.Op = true;
-                        function.WriteLog(user.UserId.ToString(), "推荐王达标创客名单");
-                    }
-                }
-            }
-            // users = RedisDbconn.Instance.GetList<RecommandKingItem>("userstmp2024", 1, 99999999);
             users = users.OrderBy(m => m.Level).ToList();
             foreach(RecommandKingItem user in users)
             {
@@ -169,21 +171,21 @@ namespace MySystem
             {
                 string UserIdStr = "," + user.UserId + ",";
                 function.WriteLog(user.UserId.ToString(), "推荐王最终的达标创客数量分析");
-                if(users.Any(m => m.ParentNav.Contains(UserIdStr) && (m.ChkActCount >= 50 || m.PreAmount >= 30000000 || Historys.Contains(m.UserId))))
+                if(users.Any(m => m.ParentNav.Contains(UserIdStr) && (m.ChkActCount >= 50 || m.UserLevel >= 5 || Historys.Contains(m.UserId))))
                 {
                     List<RecommandKingItem> subs = users.Where(m => m.ParentUserId == user.UserId).ToList();
                     foreach(RecommandKingItem sub in subs)
                     {
                         function.WriteLog(sub.UserId + ":" + sub.ActCount, "推荐王最终的达标创客数量分析");
                         string subUserIdStr = "," + sub.UserId + ",";
-                        if(sub.ChkActCount >= 50 || sub.PreAmount >= 30000000 || Historys.Contains(sub.UserId))
+                        if(sub.ChkActCount >= 50 || sub.UserLevel >= 5 || Historys.Contains(sub.UserId))
                         {
                             user.ActCount -= sub.ChkActCount;
                             function.WriteLog("减去" + sub.ChkActCount, "推荐王最终的达标创客数量分析");
                         }
-                        else if(users.Any(m => m.ParentNav.Contains(subUserIdStr) && (m.ChkActCount >= 50 || m.PreAmount >= 30000000 || Historys.Contains(sub.UserId))))
+                        else if(users.Any(m => m.ParentNav.Contains(subUserIdStr) && (m.ChkActCount >= 50 || m.UserLevel >= 5 || Historys.Contains(sub.UserId))))
                         {
-                            RecommandKingItem tar = users.Where(m => m.ParentNav.Contains(subUserIdStr) && (m.ChkActCount >= 50 || m.PreAmount >= 30000000)).OrderBy(m => m.Level).FirstOrDefault();
+                            RecommandKingItem tar = users.Where(m => m.ParentNav.Contains(subUserIdStr) && (m.ChkActCount >= 50 || m.UserLevel >= 5)).OrderBy(m => m.Level).FirstOrDefault();
                             user.ActCount -= tar.ChkActCount;
                             function.WriteLog("减去" + tar.UserId + ":" + sub.ChkActCount, "推荐王最终的达标创客数量分析");
                         }

+ 1 - 0
AppStart/Tables/RecommandKingItem.cs

@@ -9,6 +9,7 @@
         public int ChkActCount { get; set; }
         public decimal PreAmount { get; set; }
         public int Level { get; set; }
+        public int UserLevel { get; set; }
         public int Kind { get; set; }
         public bool Op { get; set; }
     }