RecommandKingHelper.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.PxcModels;
  6. using Library;
  7. using LitJson;
  8. using System.Threading;
  9. namespace MySystem
  10. {
  11. public class RecommandKingHelper
  12. {
  13. public readonly static RecommandKingHelper Instance = new RecommandKingHelper();
  14. private RecommandKingHelper()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartFor);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartFor()
  23. {
  24. while (true)
  25. {
  26. if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 22)
  27. {
  28. Recommend();
  29. }
  30. Thread.Sleep(600000);
  31. }
  32. }
  33. public void Recommend()
  34. {
  35. string today = DateTime.Now.ToString("yyyy-MM-dd");
  36. string checkFlag = function.ReadInstance("/RecommandKing/" + today + ".txt");
  37. if(!string.IsNullOrEmpty(checkFlag))
  38. {
  39. return;
  40. }
  41. function.WritePage("/RecommandKing/", today + ".txt", DateTime.Now.ToString());
  42. List<int> MaxUserIds = new List<int>();
  43. List<int> Historys = new List<int>();
  44. Historys.Add(565);
  45. Historys.Add(139473);
  46. Historys.Add(173790);
  47. Historys.Add(174506);
  48. string TradeMonth = DateTime.Now.AddMonths(-0).ToString("yyyyMM");
  49. DateTime check = DateTime.Parse("2023-10-01 00:00:00");
  50. DateTime start = DateTime.Parse(DateTime.Now.AddMonths(-0).ToString("yyyy-MM") + "-01 00:00:00");
  51. DateTime end = start.AddMonths(1);
  52. CustomerSqlConn.op("delete from RecommendDirectUser where TradeMonth='" + TradeMonth + "'", MysqlConn.SqlConnStr);
  53. string PreTradeMonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  54. List<int> ProductIds = new List<int>();
  55. ProductIds.Add(10);
  56. ProductIds.Add(11);
  57. ProductIds.Add(77);
  58. ProductIds.Add(78);
  59. ProductIds.Add(79);
  60. ProductIds.Add(27);
  61. ProductIds.Add(28);
  62. ProductIds.Add(39);
  63. ProductIds.Add(40);
  64. WebCMSEntities db = new WebCMSEntities();
  65. ReadModels.WebCMSEntities readdb = new ReadModels.WebCMSEntities();
  66. //统计当月下单名单
  67. 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();
  68. foreach(int uid in uids)
  69. {
  70. int ActCount = 0;
  71. if(ActCount == 0)
  72. {
  73. if(readdb.UserTradeMonthSummary.Any(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team"))
  74. {
  75. ActCount += readdb.UserTradeMonthSummary.Where(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
  76. ActCount -= readdb.SimposMerchantInfo.Count(m => m.UserId == uid && m.Status < 0); //减去注销的用户
  77. }
  78. }
  79. if(ActCount == 0)
  80. {
  81. MpMainModels.WebCMSEntities mpdb = new MpMainModels.WebCMSEntities();
  82. ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
  83. mpdb.Dispose();
  84. }
  85. if(ActCount == 0)
  86. {
  87. MpMainModels2.WebCMSEntities mpdb = new MpMainModels2.WebCMSEntities();
  88. ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
  89. mpdb.Dispose();
  90. }
  91. if(ActCount > 0)
  92. {
  93. Users user = db.Users.FirstOrDefault(m => m.Id == uid);
  94. if(user != null)
  95. {
  96. string ParentNav = user.ParentNav;
  97. if(!string.IsNullOrEmpty(ParentNav))
  98. {
  99. string[] ParentNavList = ParentNav.Replace(",,", ",").Trim(',').Split(',');
  100. Array.Reverse(ParentNavList);
  101. bool PassFlag = true;
  102. foreach(string UserIdString in ParentNavList)
  103. {
  104. int UserId = int.Parse(UserIdString);
  105. if(MaxUserIds.Contains(UserId))
  106. {
  107. PassFlag = false;
  108. }
  109. //判断是否历史达标创客
  110. if(PassFlag)
  111. {
  112. if(db.RecommendDirectUser.Any(m => m.UserId == UserId && m.QueryCount >= 50) || Historys.Contains(UserId))
  113. {
  114. PassFlag = false;
  115. }
  116. }
  117. if(PassFlag)
  118. {
  119. RecommendDirectUser item = db.RecommendDirectUser.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth);
  120. if(item == null)
  121. {
  122. item = db.RecommendDirectUser.Add(new RecommendDirectUser()
  123. {
  124. UserId = UserId,
  125. TradeMonth = TradeMonth,
  126. }).Entity;
  127. db.SaveChanges();
  128. }
  129. item.QueryCount += 1;
  130. db.SaveChanges();
  131. if(item.QueryCount >= 50)
  132. {
  133. MaxUserIds.Add(UserId);
  134. PassFlag = false;
  135. }
  136. }
  137. //判断上月交易额是否满3000W
  138. if(PassFlag)
  139. {
  140. if(GetTradeAmt(UserId, PreTradeMonth) >= 30000000)
  141. {
  142. PassFlag = false;
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. db.Dispose();
  151. readdb.Dispose();
  152. }
  153. public decimal GetTradeAmt(int UserId, string TradeMonth)
  154. {
  155. ReadModels.WebCMSEntities rdb = new ReadModels.WebCMSEntities();
  156. MpMainModels.WebCMSEntities mpmaindb = new MpMainModels.WebCMSEntities();
  157. MpMainModels2.WebCMSEntities mpmaindb2 = new MpMainModels2.WebCMSEntities();
  158. decimal TradeAmount = 0;
  159. //创客团队交易额
  160. bool check = rdb.TradeDaySummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  161. if (check)
  162. {
  163. TradeAmount += rdb.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt + m.ProfitNonDirectTradeAmt + m.ProfitNonDirectDebitTradeAmt);
  164. }
  165. check = rdb.TradeDaySummary2.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  166. if (check)
  167. {
  168. TradeAmount += rdb.TradeDaySummary2.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.ProfitTradeAmt + m.ProfitDebitTradeAmt);
  169. }
  170. //码牌团队交易额(直联)
  171. check = mpmaindb.UserAmountSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  172. if (check)
  173. {
  174. TradeAmount += mpmaindb.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.IsAct == 1).Sum(m => m.TotalAmount) * 4;
  175. }
  176. //码牌团队交易额(银联)
  177. check = mpmaindb2.UserAmountSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  178. if (check)
  179. {
  180. TradeAmount += mpmaindb2.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.IsAct == 1).Sum(m => m.TotalAmount) * 4;
  181. }
  182. //广电卡扶持期按1万/张计入职级
  183. check = rdb.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId == 14);
  184. if (check)
  185. {
  186. TradeAmount += rdb.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId == 14).Sum(m => m.ActiveBuddyMerStatus) * 10000;
  187. }
  188. return TradeAmount;
  189. }
  190. }
  191. }