|
@@ -6,6 +6,7 @@ using MySystem.PxcModels;
|
|
|
using Library;
|
|
|
using LitJson;
|
|
|
using System.Threading;
|
|
|
+using GraphQL;
|
|
|
|
|
|
namespace MySystem
|
|
|
{
|
|
@@ -26,7 +27,7 @@ namespace MySystem
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
|
- if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 22)
|
|
|
+ if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 23)
|
|
|
{
|
|
|
Recommend();
|
|
|
}
|
|
@@ -49,8 +50,10 @@ namespace MySystem
|
|
|
Historys.Add(139473);
|
|
|
Historys.Add(173790);
|
|
|
Historys.Add(174506);
|
|
|
+ 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);
|
|
@@ -65,111 +68,153 @@ 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();
|
|
|
+ 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 && ProductIds.Contains(m.ProductId)).ToList().Select(m => m.UserId).Distinct().ToList();
|
|
|
- uids = readdb.Users.Where(m => uids.Contains(m.Id)).OrderByDescending(m => m.ParentNav).ToList().Select(m => m.Id).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.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)
|
|
|
{
|
|
|
+ ReadModels.Users user = readdb.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,
|
|
|
+ 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 == "team"))
|
|
|
+ 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 == "team").Sum(m => m.ActiveBuddyMerStatus);
|
|
|
- ActCount -= readdb.SimposMerchantInfo.Count(m => m.UserId == uid && m.Status < 0); //减去注销的用户
|
|
|
+ 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)
|
|
|
{
|
|
|
- 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();
|
|
|
+ ActCount += mpdb2.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
|
|
|
}
|
|
|
if(ActCount > 0)
|
|
|
{
|
|
|
- Users user = db.Users.FirstOrDefault(m => m.Id == uid);
|
|
|
- if(user != null)
|
|
|
+ user.Op = true;
|
|
|
+ function.WriteLog(user.UserId.ToString(), "推荐王达标创客名单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach(int uid in uids)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
{
|
|
|
- string ParentNav = user.ParentNav;
|
|
|
- if(!string.IsNullOrEmpty(ParentNav))
|
|
|
+ int ParentUserId = int.Parse(ParentId);
|
|
|
+ ReadModels.Users puser = readdb.Users.FirstOrDefault(m => m.Id == ParentUserId && m.Id > 1);
|
|
|
+ if(puser != null)
|
|
|
{
|
|
|
- string[] ParentNavList = ParentNav.Replace(",,", ",").Trim(',').Split(',');
|
|
|
- Array.Reverse(ParentNavList);
|
|
|
- bool PassFlag = true;
|
|
|
- bool UpLevelClear = false;
|
|
|
- foreach(string UserIdString in ParentNavList)
|
|
|
+ if(!users.Any(m => m.UserId == puser.Id))
|
|
|
{
|
|
|
- int UserId = int.Parse(UserIdString);
|
|
|
- if(UpLevelClear && !ReduceUserId.Contains(UserId))
|
|
|
- {
|
|
|
- RecommendDirectUser item = list.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth);
|
|
|
- if(item == null)
|
|
|
- {
|
|
|
- item = new RecommendDirectUser()
|
|
|
- {
|
|
|
- UserId = UserId,
|
|
|
- TradeMonth = TradeMonth,
|
|
|
- };
|
|
|
- list.Add(item);
|
|
|
- }
|
|
|
- item.QueryCount -= 49;
|
|
|
- ReduceUserId.Add(UserId);
|
|
|
- }
|
|
|
- //判断是否历史达标创客
|
|
|
- if(PassFlag)
|
|
|
+ users.Add(new RecommandKingItem()
|
|
|
{
|
|
|
- if(list.Any(m => m.UserId == UserId && m.QueryCount >= 50) || Historys.Contains(UserId))
|
|
|
- {
|
|
|
- PassFlag = false;
|
|
|
- }
|
|
|
- }
|
|
|
- if(PassFlag)
|
|
|
- {
|
|
|
- RecommendDirectUser item = list.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth);
|
|
|
- if(item == null)
|
|
|
- {
|
|
|
- item = new RecommendDirectUser()
|
|
|
- {
|
|
|
- UserId = UserId,
|
|
|
- TradeMonth = TradeMonth,
|
|
|
- };
|
|
|
- list.Add(item);
|
|
|
- }
|
|
|
- item.QueryCount += 1;
|
|
|
- if(item.QueryCount >= 50)
|
|
|
- {
|
|
|
- PassFlag = false;
|
|
|
- UpLevelClear = true;
|
|
|
- }
|
|
|
- }
|
|
|
- //判断上月交易额是否满3000W
|
|
|
- if(PassFlag)
|
|
|
- {
|
|
|
- if(GetTradeAmt(UserId, PreTradeMonth) >= 30000000)
|
|
|
- {
|
|
|
- PassFlag = false;
|
|
|
- }
|
|
|
- }
|
|
|
+ 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,
|
|
|
+ UserLevel = puser.UserLevel,
|
|
|
+ Kind = 2,
|
|
|
+ Op = false,
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- foreach(RecommendDirectUser sub in list)
|
|
|
+ users = users.OrderByDescending(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;
|
|
|
+ function.WriteLog(user.UserId + ":" + Count, "推荐王总的达标创客数量");
|
|
|
+ // RedisDbconn.Instance.AddList("userstmp2024", user);
|
|
|
+ }
|
|
|
+ // users = RedisDbconn.Instance.GetList<RecommandKingItem>("userstmp2024", 1, 999999).OrderByDescending(m => m.Level).ToList();
|
|
|
+ users = users.OrderByDescending(m => m.Level).ToList();
|
|
|
+ foreach(RecommandKingItem user in users)
|
|
|
+ {
|
|
|
+ function.WriteLog(user.UserId.ToString() + "-" + user.UserLevel, "推荐王最终的达标创客数量分析");
|
|
|
+ int ActCount = 0;
|
|
|
+ List<RecommandKingItem> subs = users.Where(m => m.ParentUserId == user.UserId).ToList();
|
|
|
+ foreach(RecommandKingItem sub in subs)
|
|
|
+ {
|
|
|
+ function.WriteLog(sub.UserId + ":" + sub.ActCount, "推荐王最终的达标创客数量分析");
|
|
|
+ if(sub.ActCount < 50 && sub.UserLevel < 5 && !Historys.Contains(sub.UserId))
|
|
|
+ {
|
|
|
+ ActCount += sub.ActCount;
|
|
|
+ if(sub.Op) ActCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ user.ActCount = ActCount;
|
|
|
+ function.WriteLog("\n\n\n", "推荐王最终的达标创客数量分析");
|
|
|
+ }
|
|
|
+
|
|
|
+ int num = 0;
|
|
|
+ foreach(RecommandKingItem user in users)
|
|
|
{
|
|
|
- db.RecommendDirectUser.Add(sub);
|
|
|
+ if(!Historys.Contains(user.UserId))
|
|
|
+ {
|
|
|
+ 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 > 50 ? 50 : user.ActCount,
|
|
|
+ }).Entity;
|
|
|
+ if(num % 200 == 0)
|
|
|
+ {
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
db.SaveChanges();
|
|
|
db.Dispose();
|
|
|
readdb.Dispose();
|
|
|
+ mpdb.Dispose();
|
|
|
+ mpdb2.Dispose();
|
|
|
}
|
|
|
|
|
|
public decimal GetTradeAmt(int UserId, string TradeMonth)
|
|
@@ -209,5 +254,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;
|
|
|
+ }
|
|
|
}
|
|
|
}
|