RecommandKingHelper.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 < 6)
  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. function.WritePage("/RecommandKing/", today + ".txt", DateTime.Now.ToString());
  40. }
  41. List<int> Historys = new List<int>();
  42. Historys.Add(565);
  43. Historys.Add(139473);
  44. Historys.Add(173790);
  45. Historys.Add(174506);
  46. string TradeMonth = DateTime.Now.AddMonths(-0).ToString("yyyyMM");
  47. DateTime check = DateTime.Parse("2023-10-01 00:00:00");
  48. DateTime start = DateTime.Parse(DateTime.Now.AddMonths(-0).ToString("yyyy-MM") + "-01 00:00:00");
  49. DateTime end = start.AddMonths(1);
  50. CustomerSqlConn.op("delete from RecommendDirectUser where TradeMonth='" + TradeMonth + "'", MysqlConn.SqlConnStr);
  51. string PreTradeMonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  52. List<int> ProductIds = new List<int>();
  53. ProductIds.Add(10);
  54. ProductIds.Add(11);
  55. ProductIds.Add(77);
  56. ProductIds.Add(78);
  57. ProductIds.Add(79);
  58. ProductIds.Add(27);
  59. ProductIds.Add(28);
  60. ProductIds.Add(39);
  61. ProductIds.Add(40);
  62. WebCMSEntities db = new WebCMSEntities();
  63. ReadModels.WebCMSEntities readdb = new ReadModels.WebCMSEntities();
  64. //统计当月下单名单
  65. 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();
  66. foreach(int uid in uids)
  67. {
  68. int ActCount = 0;
  69. if(ActCount == 0)
  70. {
  71. if(readdb.UserTradeMonthSummary.Any(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId != 14))
  72. {
  73. ActCount += readdb.UserTradeMonthSummary.Where(m => m.UserId == uid && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId != 14).Sum(m => m.ActiveBuddyMerStatus);
  74. }
  75. }
  76. if(ActCount == 0)
  77. {
  78. MpMainModels.WebCMSEntities mpdb = new MpMainModels.WebCMSEntities();
  79. ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
  80. mpdb.Dispose();
  81. }
  82. if(ActCount == 0)
  83. {
  84. MpMainModels2.WebCMSEntities mpdb = new MpMainModels2.WebCMSEntities();
  85. ActCount += mpdb.MerchantDepositOrder.Count(m => m.UserId == uid && m.CreateDate >= start && m.CreateDate < end && m.Status > 0 && m.UserId == uid);
  86. mpdb.Dispose();
  87. }
  88. if(ActCount > 0)
  89. {
  90. Users user = db.Users.FirstOrDefault(m => m.Id == uid);
  91. if(user != null)
  92. {
  93. string ParentNav = user.ParentNav;
  94. if(!string.IsNullOrEmpty(ParentNav))
  95. {
  96. string[] ParentNavList = ParentNav.Replace(",,", ",").Trim(',').Split(',');
  97. Array.Reverse(ParentNavList);
  98. bool PassFlag = true;
  99. foreach(string UserIdString in ParentNavList)
  100. {
  101. int UserId = int.Parse(UserIdString);
  102. //判断是否历史达标创客
  103. if(PassFlag)
  104. {
  105. if(db.RecommendDirectUser.Any(m => m.UserId == UserId && m.TradeMonth != TradeMonth && m.QueryCount >= 50) || Historys.Contains(UserId))
  106. {
  107. PassFlag = false;
  108. }
  109. }
  110. if(PassFlag)
  111. {
  112. RecommendDirectUser item = db.RecommendDirectUser.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth);
  113. if(item == null)
  114. {
  115. item = db.RecommendDirectUser.Add(new RecommendDirectUser()
  116. {
  117. UserId = UserId,
  118. TradeMonth = TradeMonth,
  119. }).Entity;
  120. db.SaveChanges();
  121. }
  122. item.QueryCount += 1;
  123. db.SaveChanges();
  124. }
  125. //判断上月交易额是否满3000W
  126. if(PassFlag)
  127. {
  128. if(GetTradeAmt(UserId, PreTradeMonth) >= 30000000)
  129. {
  130. PassFlag = false;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. db.Dispose();
  139. readdb.Dispose();
  140. }
  141. public decimal GetTradeAmt(int UserId, string TradeMonth)
  142. {
  143. ReadModels.WebCMSEntities rdb = new ReadModels.WebCMSEntities();
  144. MpMainModels.WebCMSEntities mpmaindb = new MpMainModels.WebCMSEntities();
  145. MpMainModels2.WebCMSEntities mpmaindb2 = new MpMainModels2.WebCMSEntities();
  146. decimal TradeAmount = 0;
  147. //创客团队交易额
  148. bool check = rdb.TradeDaySummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  149. if (check)
  150. {
  151. 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);
  152. }
  153. check = rdb.TradeDaySummary2.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  154. if (check)
  155. {
  156. TradeAmount += rdb.TradeDaySummary2.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.ProfitTradeAmt + m.ProfitDebitTradeAmt);
  157. }
  158. //码牌团队交易额(直联)
  159. check = mpmaindb.UserAmountSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  160. if (check)
  161. {
  162. TradeAmount += mpmaindb.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.IsAct == 1).Sum(m => m.TotalAmount) * 4;
  163. }
  164. //码牌团队交易额(银联)
  165. check = mpmaindb2.UserAmountSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
  166. if (check)
  167. {
  168. TradeAmount += mpmaindb2.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.IsAct == 1).Sum(m => m.TotalAmount) * 4;
  169. }
  170. //广电卡扶持期按1万/张计入职级
  171. check = rdb.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId == 14);
  172. if (check)
  173. {
  174. TradeAmount += rdb.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == "team" && m.BrandId == 14).Sum(m => m.ActiveBuddyMerStatus) * 10000;
  175. }
  176. return TradeAmount;
  177. }
  178. }
  179. }