SycnSpActiveService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. MpMainModels2.WebCMSEntities mpdb = new MpMainModels2.WebCMSEntities();
  30. string Month = DateTime.Now.ToString("yyyyMM");
  31. string Date = DateTime.Now.ToString("yyyyMMdd");
  32. DateTime start = DateTime.Now.AddDays(-5);
  33. DateTime end = DateTime.Now.AddMinutes(-1);
  34. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
  35. IQueryable<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.CreateDate >= start && m.CreateDate < end && m.Status == 1).OrderByDescending(m => m.Id);
  36. foreach (ActivateRecord act in acts.ToList())
  37. {
  38. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  39. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  40. if(pos == null)
  41. {
  42. pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == act.SnNo);
  43. }
  44. if (pos != null)
  45. {
  46. PxcModels.KqProducts kqproduct = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  47. if (kqproduct.SingleDepositApi == 1)
  48. {
  49. if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
  50. pos.SeoKeyword = act.SeoTitle;
  51. if(pos.BrandId == 15 || pos.BrandId == 16) //来客吧
  52. {
  53. pos.Detail = ""; //清除激活奖励标记
  54. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString()); //发开机奖励
  55. }
  56. db.SaveChanges();
  57. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  58. if(pos.BrandId < 18 || pos.BrandId > 21) //来客吧
  59. {
  60. StatService.Instance.PreActPrize(db, pos, merchant, act.SeoTitle);
  61. }
  62. }
  63. if(pos.BrandId == 7 || pos.BrandId == 12 || pos.BrandId == 13 || pos.BrandId == 15 || pos.BrandId == 16 || pos.BrandId == 22)
  64. {
  65. decimal CheckMoney = kqproduct.ActTradeAmount > 0 ? kqproduct.ActTradeAmount : 1000;
  66. int CheckDays = 30;
  67. SycnSpTradeService.Instance.ActPos(db, pos, CheckMoney, CheckDays);
  68. if(pos.ActivationState == 1)
  69. {
  70. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  71. DateTime now = DateTime.Now;
  72. function.WriteLog("大盟主---Deposit:" + Deposit + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "押金推送发放奖励监控");
  73. 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)
  74. {
  75. function.WriteLog("大盟主奖发放", "押金推送发放奖励监控");
  76. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  77. }
  78. //发放运营中心奖励
  79. if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100)
  80. {
  81. function.WriteLog("运营中心奖发放", "押金推送发放奖励监控");
  82. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  83. }
  84. }
  85. }
  86. if(pos.BrandId == 18 || pos.BrandId == 19 || pos.BrandId == 20 || pos.BrandId == 21)
  87. {
  88. int CheckDays = 30;
  89. DateTime now = DateTime.Now;
  90. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  91. if(pos.BindingTime > now.AddDays(-CheckDays))
  92. {
  93. pos.PrizeParams = pos.SeoKeyword;
  94. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  95. MpMainModels2.MerchantAddInfo merchantAddInfo = mpdb.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == merchant.KqMerNo) ?? new MpMainModels2.MerchantAddInfo();
  96. decimal Prize = 0;
  97. if(pos.BindingTime > DateTime.Parse("2024-07-02 00:00:00"))
  98. {
  99. if(Deposit == 198)
  100. {
  101. if(merchantAddInfo.SubjectType == "SUBJECT_TYPE_SMALL")
  102. {
  103. Prize = 0;
  104. }
  105. else
  106. {
  107. Prize = 120;
  108. }
  109. }
  110. else if(Deposit == 249)
  111. {
  112. if(merchantAddInfo.SubjectType == "SUBJECT_TYPE_SMALL")
  113. {
  114. Prize = 50;
  115. }
  116. else
  117. {
  118. Prize = 150;
  119. }
  120. }
  121. else if(Deposit == 228)
  122. {
  123. if(merchantAddInfo.SubjectType == "SUBJECT_TYPE_SMALL")
  124. {
  125. Prize = 0;
  126. }
  127. else
  128. {
  129. Prize = 110;
  130. }
  131. }
  132. else if(Deposit == 380)
  133. {
  134. if(merchantAddInfo.SubjectType == "SUBJECT_TYPE_SMALL")
  135. {
  136. Prize = 100;
  137. }
  138. else
  139. {
  140. Prize = 200;
  141. }
  142. }
  143. else if(Deposit == 399)
  144. {
  145. if(merchantAddInfo.SubjectType == "SUBJECT_TYPE_SMALL")
  146. {
  147. Prize = 0;
  148. }
  149. else
  150. {
  151. Prize = 150;
  152. }
  153. }
  154. }
  155. else
  156. {
  157. if(Deposit == 198) Prize = 70;
  158. if(Deposit == 249) Prize = 100;
  159. if(Deposit == 228) Prize = 61;
  160. if(Deposit == 380) Prize = 151;
  161. if(Deposit == 399) Prize = 100;
  162. }
  163. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  164. int TopUserId = 0;
  165. if (!string.IsNullOrEmpty(user.ParentNav))
  166. {
  167. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  168. }
  169. pos.ActivationState = 1;
  170. pos.ActivationTime = now;
  171. merchant.ActiveStatus = 1;
  172. merchant.MerStandardDate = now;
  173. db.SaveChanges();
  174. if (Prize > 0)
  175. {
  176. StatService.Instance.doActiveReward(db, merchant, pos, pos.BuyUserId, user.ParentNav, TopUserId, Prize);
  177. }
  178. if (pos.CardType < 100)
  179. {
  180. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  181. }
  182. if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.CardType < 100)
  183. {
  184. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  185. }
  186. //发放运营中心奖励
  187. if (Deposit > 0 && pos.CardType < 100)
  188. {
  189. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  190. }
  191. }
  192. else
  193. {
  194. pos.ActivationState = 1;
  195. pos.ActivationTime = now;
  196. merchant.ActiveStatus = 1;
  197. merchant.MerStandardDate = now;
  198. db.SaveChanges();
  199. }
  200. }
  201. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  202. if (edit != null)
  203. {
  204. edit.Status = 2;
  205. }
  206. }
  207. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  208. if (pos != null)
  209. {
  210. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  211. if (edit != null)
  212. {
  213. edit.Status = 2;
  214. }
  215. }
  216. }
  217. spdb.SaveChanges();
  218. spdb.Dispose();
  219. db.SaveChanges();
  220. db.Dispose();
  221. mpdb.Dispose();
  222. }
  223. catch (Exception ex)
  224. {
  225. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  226. }
  227. Thread.Sleep(1000);
  228. }
  229. }
  230. }
  231. }