SycnSpActiveService.cs 17 KB

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