lcl 11 months ago
parent
commit
651709a702
4 changed files with 123 additions and 120 deletions
  1. 106 108
      AppStart/Helper/RecommandKingHelper.cs
  2. 3 0
      AppStart/Tables/RecommandKingItem.cs
  3. 9 7
      Startup.cs
  4. 5 5
      appsettings.Development.json

+ 106 - 108
AppStart/Helper/RecommandKingHelper.cs

@@ -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);
@@ -68,119 +68,115 @@ namespace MySystem
             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> 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)
+            // 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();
+            // foreach(int uid in uids)
+            // {
+            //     Users user = db.Users.FirstOrDefault(m => m.Id == uid);
+            //     if(user != null)
+            //     {
+            //         if(!users.Any(m => m.UserId == user.Id))
+            //         {
+            //             users.Add(new RecommandKingItem()
+            //             {
+            //                 UserId = user.Id,
+            //                 ParentUserId = user.ParentUserId,
+            //                 ParentNav = user.ParentNav,
+            //                 PreAmount = PreMonthAmt.ContainsKey(user.Id) ? PreMonthAmt[user.Id] : 0,
+            //                 Level = user.ParentNav.Replace(",,", ",").Trim(',').Split(',').Length + 1,
+            //                 Kind = 1,
+            //                 Op = false,
+            //             });
+            //         }
+            //         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);
+            //             if(puser != null)
+            //             {
+            //                 if(!users.Any(m => m.UserId == puser.Id))
+            //                 {
+            //                     users.Add(new RecommandKingItem()
+            //                     {
+            //                         UserId = puser.Id,
+            //                         ParentUserId = puser.ParentUserId,
+            //                         ParentNav = puser.ParentNav,
+            //                         PreAmount = PreMonthAmt.ContainsKey(puser.Id) ? PreMonthAmt[puser.Id] : 0,
+            //                         Level = puser.ParentNav.Replace(",,", ",").Trim(',').Split(',').Length + 1,
+            //                         Kind = 2,
+            //                         Op = false,
+            //                     });
+            //                 }
+            //             }
+            //         }
+            //     }
+            // }
+            // 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 == "team"))
+            //             {
+            //                 ActCount += readdb.UserTradeMonthSummary.Where(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team").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;
+            //         }
+            //     }
+            //     RedisDbconn.Instance.AddList("userstmp2024", user);
+            // }
+            users = RedisDbconn.Instance.GetList<RecommandKingItem>("userstmp2024", 1, 99999999);
+            users = users.OrderBy(m => m.Level).ToList();
+            foreach(RecommandKingItem user in users)
+            {
+                string UserIdStr = "," + user.UserId + ",";
+                int Count = users.Count(m => m.ParentNav.Contains(UserIdStr) && m.Op);
+                user.ActCount = Count;
+                user.ChkActCount = Count;
+            }
+            foreach(RecommandKingItem user in users)
             {
-                int ActCount = 0;
-                if(ActCount == 0)
+                string UserIdStr = "," + user.UserId + ",";
+                if(users.Any(m => m.ParentNav.Contains(UserIdStr) && (m.ChkActCount >= 50 || m.PreAmount >= 30000000)))
                 {
-                    if(readdb.UserTradeMonthSummary.Any(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team"))
+                    List<RecommandKingItem> subs = users.Where(m => m.ParentUserId == user.UserId).ToList();
+                    foreach(RecommandKingItem sub in subs)
                     {
-                        ActCount += readdb.UserTradeMonthSummary.Where(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
-                        if(readdb.UserSimActSummary.Any(m => m.UserId == uid && m.Kind == 1))
+                        string subUserIdStr = "," + sub.UserId + ",";
+                        if(sub.ChkActCount >= 50 || sub.PreAmount >= 30000000 || Historys.Contains(sub.UserId))
                         {
-                            ActCount -= readdb.UserSimActSummary.Where(m => m.UserId == uid && m.Kind == 1).Sum(m => m.ActCount); //减去注销的用户
+                            user.ActCount -= sub.ChkActCount;
                         }
-                    }
-                }
-                if(ActCount == 0)
-                {
-                    MpMainModels.WebCMSEntities mpdb = new MpMainModels.WebCMSEntities();
-                    ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
-                    mpdb.Dispose();
-                }
-                if(ActCount == 0)
-                {
-                    MpMainModels2.WebCMSEntities mpdb = new MpMainModels2.WebCMSEntities();
-                    ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
-                    mpdb.Dispose();
-                }
-                if(ActCount > 0)
-                {
-                    Users user = db.Users.FirstOrDefault(m => m.Id == uid);
-                    if(user != null)
-                    {
-                        if(!users.Any(m => m.UserId == user.Id))
+                        else if(users.Any(m => m.ParentNav.Contains(subUserIdStr) && (m.ChkActCount >= 50 || m.PreAmount >= 30000000)))
                         {
-                            users.Add(new RecommandKingItem()
-                            {
-                                UserId = user.Id,
-                                ParentUserId = user.ParentUserId,
-                                ParentNav = user.ParentNav,
-                                PreAmount = PreMonthAmt.ContainsKey(user.Id) ? PreMonthAmt[user.Id] : 0,
-                                Level = user.ParentNav.Replace(",,", ",").Trim(',').Split(',').Length + 1
-                            });
+                            RecommandKingItem tar = users.Where(m => m.ParentNav.Contains(subUserIdStr) && (m.ChkActCount >= 50 || m.PreAmount >= 30000000)).OrderBy(m => m.Level).FirstOrDefault();
+                            user.ActCount -= tar.ChkActCount;
                         }
-
-                        // string ParentNav = user.ParentNav;
-                        // if(!string.IsNullOrEmpty(ParentNav))
-                        // {
-                        //     string[] ParentNavList = ParentNav.Replace(",,", ",").Trim(',').Split(',');
-                        //     Array.Reverse(ParentNavList);
-                        //     bool PassFlag = true;
-                        //     foreach(string UserIdString in ParentNavList)
-                        //     {
-                        //         int UserId = int.Parse(UserIdString);
-                        //         //判断是否历史达标创客
-                        //         if(PassFlag)
-                        //         {
-                        //             if(db.RecommendDirectUser.Any(m => m.UserId == UserId && m.TradeMonth != TradeMonth && m.QueryCount >= 50) || Historys.Contains(UserId))
-                        //             {
-                        //                 PassFlag = false;
-                        //             }
-                        //         }
-                        //         if(PassFlag)
-                        //         {
-                        //             if(db.RecommendDirectUser.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.QueryCount >= 50))
-                        //             {
-                        //                 PassFlag = false;
-                        //             }
-                        //         }
-                        //         if(PassFlag)
-                        //         {
-                        //             RecommendDirectUser item = db.RecommendDirectUser.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth);
-                        //             if(item == null)
-                        //             {
-                        //                 item = db.RecommendDirectUser.Add(new RecommendDirectUser()
-                        //                 {
-                        //                     UserId = UserId,
-                        //                     TradeMonth = TradeMonth,
-                        //                 }).Entity;
-                        //                 db.SaveChanges();
-                        //             }
-                        //             item.QueryCount += 1;
-                        //             db.SaveChanges();
-                        //         }
-                        //         //判断上月交易额是否满3000W
-                        //         if(PassFlag)
-                        //         {
-                        //             if(GetTradeAmt(UserId, PreTradeMonth) >= 30000000)
-                        //             {
-                        //                 PassFlag = false;
-                        //             }
-                        //         }
-                        //     }
-                        // }
                     }
                 }
             }
-            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 + ",";
-                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;
             foreach(RecommandKingItem user in users)
@@ -204,6 +200,8 @@ namespace MySystem
             db.SaveChanges();
             db.Dispose();
             readdb.Dispose();
+            mpdb.Dispose();
+            mpdb2.Dispose();
         }
 
         public decimal GetTradeAmt(int UserId, string TradeMonth)

+ 3 - 0
AppStart/Tables/RecommandKingItem.cs

@@ -6,7 +6,10 @@
         public int ParentUserId { get; set; }
         public string ParentNav { get; set; }
         public int ActCount { get; set; }
+        public int ChkActCount { get; set; }
         public decimal PreAmount { get; set; }
         public int Level { get; set; }
+        public int Kind { get; set; }
+        public bool Op { get; set; }
     }
 }

+ 9 - 7
Startup.cs

@@ -166,20 +166,22 @@ 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)

+ 5 - 5
appsettings.Development.json

@@ -17,14 +17,14 @@
     "Host": "http://localhost:5047/",
     "SourceHost": "http://bs.kexiaoshuang.com/",
     "Database": "KxsMainServer",
-    "SqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsProfitServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
-    "Pxc1SqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsProfitServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
-    "ReadSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsProfitServer;charset=utf8;",
+    "SqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsMainServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
+    "Pxc1SqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsMainServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
+    "ReadSqlConnStr": "server=rr-2vc53lrwpwm1ewscogo.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;DefaultCommandTimeout=600;",
     "MainSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsStatServer;charset=utf8;",
     "SpSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsSpServer;charset=utf8;",
     "OpSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsOpServer;charset=utf8;",
-    "MpSqlConnStr": "server=47.109.31.237;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer;charset=utf8;",
-    "MpSqlConnStr2": "server=47.109.31.237;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer2;charset=utf8;",
+    "MpSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer;charset=utf8;",
+    "MpSqlConnStr2": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer2;charset=utf8;",
     "RdsStatSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsStatServer;charset=utf8;",
     "RedisConnStr": "47.108.62.166:6379,password=klm@redis,DefaultDatabase=1,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",