SycnSpActiveService.cs 12 KB

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