Procházet zdrojové kódy

修改推荐王逻辑

lcl před 11 měsíci
rodič
revize
2a684d0c80

+ 196 - 52
AppStart/Helper/RecommandKingHelper.cs

@@ -6,6 +6,7 @@ using MySystem.PxcModels;
 using Library;
 using LitJson;
 using System.Threading;
+using GraphQL;
 
 namespace MySystem
 {
@@ -36,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);
@@ -63,6 +64,8 @@ namespace MySystem
             ProductIds.Add(28);
             ProductIds.Add(39);
             ProductIds.Add(40);
+            List<RecommandKingItem> users = new List<RecommandKingItem>();
+            Dictionary<int, decimal> PreMonthAmt = GetTradeAmtList(PreTradeMonth);
             WebCMSEntities db = new WebCMSEntities();
             ReadModels.WebCMSEntities readdb = new ReadModels.WebCMSEntities();
             //统计当月下单名单
@@ -98,58 +101,96 @@ namespace MySystem
                     Users user = db.Users.FirstOrDefault(m => m.Id == uid);
                     if(user != null)
                     {
-                        string ParentNav = user.ParentNav;
-                        if(!string.IsNullOrEmpty(ParentNav))
+                        if(!users.Any(m => m.UserId == user.Id))
                         {
-                            string[] ParentNavList = ParentNav.Replace(",,", ",").Trim(',').Split(',');
-                            Array.Reverse(ParentNavList);
-                            bool PassFlag = true;
-                            foreach(string UserIdString in ParentNavList)
+                            users.Add(new RecommandKingItem()
                             {
-                                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;
-                                    }
-                                }
-                            }
+                                UserId = user.Id,
+                                ParentUserId = user.ParentUserId,
+                                ParentNav = user.ParentNav,
+                                PreAmount = PreMonthAmt.ContainsKey(user.Id) ? PreMonthAmt[user.Id] : 0,
+                            });
                         }
+
+                        // 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.ParentNav).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);
+            }
+
+            int num = 0;
+            foreach(RecommandKingItem user in users)
+            {
+                num += 1;
+                RecommendDirectUser item = db.RecommendDirectUser.FirstOrDefault(m => m.UserId == user.UserId && m.TradeMonth == TradeMonth);
+                if(item == null)
+                {
+                    item = db.RecommendDirectUser.Add(new RecommendDirectUser()
+                    {
+                        UserId = user.UserId,
+                        TradeMonth = TradeMonth,
+                        QueryCount = user.ActCount,
+                    }).Entity;
+                    if(num % 200 == 0)
+                    {
+                        db.SaveChanges();
+                    }
+                }
+            }
+            db.SaveChanges();
             db.Dispose();
             readdb.Dispose();
         }
@@ -191,5 +232,108 @@ namespace MySystem
             }
             return TradeAmount;
         }
+
+        public Dictionary<int, decimal> GetTradeAmtList(string TradeMonth)
+        {
+            Dictionary<int, decimal> dic = new Dictionary<int, decimal>();
+            ReadModels.WebCMSEntities rdb = new ReadModels.WebCMSEntities();
+            MpMainModels.WebCMSEntities mpmaindb = new MpMainModels.WebCMSEntities();
+            MpMainModels2.WebCMSEntities mpmaindb2 = new MpMainModels2.WebCMSEntities();
+            //创客团队交易额
+            bool check = rdb.TradeDaySummary.Any(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team");
+            if (check)
+            {
+                var list = rdb.TradeDaySummary.Where(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team").ToList().GroupBy(m => m.UserId);
+                foreach(var item in list)
+                {
+                    int UserId = item.Key;
+                    decimal Amt = item.Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt + m.ProfitNonDirectTradeAmt + m.ProfitNonDirectDebitTradeAmt);
+                    if(!dic.ContainsKey(UserId))
+                    {
+                        dic.Add(UserId, Amt);
+                    }
+                    else
+                    {
+                        dic[UserId] += Amt;
+                    }
+                }
+            }
+            check = rdb.TradeDaySummary2.Any(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team");
+            if (check)
+            {
+                var list = rdb.TradeDaySummary2.Where(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team").ToList().GroupBy(m => m.UserId);
+                foreach(var item in list)
+                {
+                    int UserId = item.Key;
+                    decimal Amt = item.Sum(m => m.ProfitTradeAmt + m.ProfitDebitTradeAmt);
+                    if(!dic.ContainsKey(UserId))
+                    {
+                        dic.Add(UserId, Amt);
+                    }
+                    else
+                    {
+                        dic[UserId] += Amt;
+                    }
+                }
+            }
+            //码牌团队交易额(直联)
+            check = mpmaindb.UserAmountSummary.Any(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team");
+            if (check)
+            {
+                var list = mpmaindb.UserAmountSummary.Where(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.IsAct == 1).ToList().GroupBy(m => m.UserId);
+                foreach(var item in list)
+                {
+                    int UserId = item.Key;
+                    decimal Amt = item.Sum(m => m.TotalAmount) * 4;
+                    if(!dic.ContainsKey(UserId))
+                    {
+                        dic.Add(UserId, Amt);
+                    }
+                    else
+                    {
+                        dic[UserId] += Amt;
+                    }
+                }
+            }
+            //码牌团队交易额(银联)
+            check = mpmaindb2.UserAmountSummary.Any(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team");
+            if (check)
+            {
+                var list = mpmaindb2.UserAmountSummary.Where(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.IsAct == 1).ToList().GroupBy(m => m.UserId);
+                foreach(var item in list)
+                {
+                    int UserId = item.Key;
+                    decimal Amt = item.Sum(m => m.TotalAmount) * 4;
+                    if(!dic.ContainsKey(UserId))
+                    {
+                        dic.Add(UserId, Amt);
+                    }
+                    else
+                    {
+                        dic[UserId] += Amt;
+                    }
+                }
+            }
+            //广电卡扶持期按1万/张计入职级
+            check = rdb.UserTradeMonthSummary.Any(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId == 14);
+            if (check)
+            {
+                var list = rdb.UserTradeMonthSummary.Where(m => m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId == 14).ToList().GroupBy(m => m.UserId);
+                foreach(var item in list)
+                {
+                    int UserId = item.Key;
+                    decimal Amt = item.Sum(m => m.ActiveBuddyMerStatus) * 10000;
+                    if(!dic.ContainsKey(UserId))
+                    {
+                        dic.Add(UserId, Amt);
+                    }
+                    else
+                    {
+                        dic[UserId] += Amt;
+                    }
+                }
+            }
+            return dic;
+        }
     }
 }

+ 11 - 0
AppStart/Tables/RecommandKingItem.cs

@@ -0,0 +1,11 @@
+namespace MySystem
+{
+    public class RecommandKingItem
+    {
+        public int UserId { get; set; }
+        public int ParentUserId { get; set; }
+        public string ParentNav { get; set; }
+        public int ActCount { get; set; }
+        public decimal PreAmount { get; set; }
+    }
+}

+ 5 - 3
Startup.cs

@@ -166,10 +166,12 @@ 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()