SycnSpActiveService.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.SpModels;
  5. using Library;
  6. using LitJson;
  7. using System.Threading;
  8. namespace MySystem
  9. {
  10. public class SycnSpActiveService
  11. {
  12. public readonly static SycnSpActiveService Instance = new SycnSpActiveService();
  13. private SycnSpActiveService()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(StartDo);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void StartDo()
  22. {
  23. while (true)
  24. {
  25. try
  26. {
  27. WebCMSEntities spdb = new WebCMSEntities();
  28. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  29. string Month = DateTime.Now.ToString("yyyyMM");
  30. string Date = DateTime.Now.ToString("yyyyMMdd");
  31. DateTime start = DateTime.Now.AddDays(-5);
  32. DateTime end = DateTime.Now.AddMinutes(-1);
  33. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
  34. IQueryable<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.ActivateDate >= start && m.ActivateDate < end && m.Status == 1).OrderByDescending(m => m.Id);
  35. foreach (ActivateRecord act in acts.ToList())
  36. {
  37. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  38. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  39. if (pos != null)
  40. {
  41. PxcModels.KqProducts kqproduct = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  42. if (kqproduct.SingleDepositApi == 1)
  43. {
  44. pos.SeoKeyword = act.SeoTitle;
  45. if(pos.BrandId == 15 || pos.BrandId == 16) //来客吧
  46. {
  47. pos.Detail = ""; //清除激活奖励标记
  48. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString()); //发开机奖励
  49. }
  50. db.SaveChanges();
  51. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  52. if(pos.BrandId < 18 || pos.BrandId > 21) //来客吧
  53. {
  54. StatService.Instance.PreActPrize(db, pos, merchant, act.SeoTitle);
  55. }
  56. }
  57. if(pos.BrandId == 7 || pos.BrandId == 12 || pos.BrandId == 13 || pos.BrandId == 15 || pos.BrandId == 16)
  58. {
  59. decimal CheckMoney = kqproduct.ActTradeAmount > 0 ? kqproduct.ActTradeAmount : 1000;
  60. int CheckDays = 30;
  61. SycnSpTradeService.Instance.ActPos(db, pos, CheckMoney, CheckDays);
  62. if(pos.ActivationState == 1)
  63. {
  64. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  65. DateTime now = DateTime.Now;
  66. function.WriteLog("大盟主---Deposit:" + Deposit + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "押金推送发放奖励监控");
  67. if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100)
  68. {
  69. function.WriteLog("大盟主奖发放", "押金推送发放奖励监控");
  70. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  71. }
  72. //发放运营中心奖励
  73. if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100)
  74. {
  75. function.WriteLog("运营中心奖发放", "押金推送发放奖励监控");
  76. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  77. }
  78. }
  79. }
  80. if(pos.BrandId == 18 || pos.BrandId == 19 || pos.BrandId == 20 || pos.BrandId == 21)
  81. {
  82. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  83. decimal Prize = 0;
  84. if(Deposit == 198) Prize = 70;
  85. if(Deposit == 249) Prize = 100;
  86. if(Deposit == 228) Prize = 61;
  87. if(Deposit == 380) Prize = 151;
  88. if(Deposit == 399) Prize = 100;
  89. if(Prize > 0)
  90. {
  91. DateTime now = DateTime.Now;
  92. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  93. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  94. int TopUserId = 0;
  95. if (!string.IsNullOrEmpty(user.ParentNav))
  96. {
  97. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  98. }
  99. pos.ActivationState = 1;
  100. pos.ActivationTime = now;
  101. merchant.ActiveStatus = 1;
  102. merchant.MerStandardDate = now;
  103. StatService.Instance.doActiveReward(db, merchant, pos, pos.BuyUserId, user.ParentNav, TopUserId, Prize);
  104. if(pos.CardType < 100)
  105. {
  106. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  107. }
  108. if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.CardType < 100)
  109. {
  110. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  111. }
  112. //发放运营中心奖励
  113. if (Deposit > 0 && pos.CardType < 100)
  114. {
  115. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  116. }
  117. }
  118. }
  119. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  120. if (edit != null)
  121. {
  122. edit.Status = 2;
  123. }
  124. }
  125. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  126. if (pos != null)
  127. {
  128. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  129. if (edit != null)
  130. {
  131. edit.Status = 2;
  132. }
  133. }
  134. }
  135. spdb.SaveChanges();
  136. spdb.Dispose();
  137. db.SaveChanges();
  138. db.Dispose();
  139. }
  140. catch (Exception ex)
  141. {
  142. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  143. }
  144. Thread.Sleep(1000);
  145. }
  146. }
  147. }
  148. }