SycnSpActiveService.cs 14 KB

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