SycnSpActiveService.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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(!Utils.Instance.IsHaoDa(pos.BrandId)) //来客吧
  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 = act.ActivateDate == null ? DateTime.Now : act.ActivateDate.Value;
  99. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  100. if(pos.BindingTime > now.AddDays(-CheckDays))
  101. {
  102. string SubjectType = act.Field2;
  103. pos.PrizeParams = pos.SeoKeyword;
  104. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  105. MpMainModels2.MerchantAddInfo merchantAddInfo = mpdb.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == merchant.KqMerNo) ?? new MpMainModels2.MerchantAddInfo();
  106. decimal Prize = 0;
  107. bool PrizeFlag = true;
  108. if(pos.BindingTime > DateTime.Parse("2024-07-02 00:00:00"))
  109. {
  110. if(Deposit == 198)
  111. {
  112. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  113. {
  114. Prize = 0;
  115. }
  116. else
  117. {
  118. Prize = 120;
  119. }
  120. }
  121. else if(Deposit == 249)
  122. {
  123. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  124. {
  125. Prize = 50;
  126. PrizeFlag = false;
  127. }
  128. else
  129. {
  130. Prize = 150;
  131. }
  132. }
  133. else if(Deposit == 228)
  134. {
  135. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  136. {
  137. Prize = 0;
  138. }
  139. else
  140. {
  141. Prize = 110;
  142. }
  143. }
  144. else if(Deposit == 380)
  145. {
  146. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  147. {
  148. Prize = 100;
  149. PrizeFlag = false;
  150. }
  151. else
  152. {
  153. Prize = 200;
  154. }
  155. }
  156. else if(Deposit == 299)
  157. {
  158. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  159. {
  160. Prize = 0;
  161. }
  162. else
  163. {
  164. if(pos.BrandId == 29)
  165. {
  166. Prize = 100;
  167. }
  168. }
  169. }
  170. else if(Deposit == 399)
  171. {
  172. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  173. {
  174. Prize = 0;
  175. }
  176. else
  177. {
  178. if(pos.BrandId == 29)
  179. {
  180. Prize = 200;
  181. }
  182. else
  183. {
  184. Prize = 150;
  185. }
  186. }
  187. }
  188. else if(Deposit == 499)
  189. {
  190. if(SubjectType == "000001" || string.IsNullOrEmpty(SubjectType))
  191. {
  192. Prize = 0;
  193. }
  194. else
  195. {
  196. if(pos.BrandId == 29)
  197. {
  198. Prize = 300;
  199. }
  200. else
  201. {
  202. Prize = 150;
  203. }
  204. }
  205. }
  206. }
  207. else
  208. {
  209. if(Deposit == 198) Prize = 70;
  210. if(Deposit == 249) Prize = 100;
  211. if(Deposit == 228) Prize = 61;
  212. if(Deposit == 380) Prize = 151;
  213. if(Deposit == 399) Prize = 100;
  214. }
  215. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  216. int TopUserId = 0;
  217. if (!string.IsNullOrEmpty(user.ParentNav))
  218. {
  219. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  220. }
  221. pos.ActivationState = 1;
  222. pos.ActivationTime = now;
  223. merchant.ActiveStatus = 1;
  224. merchant.MerStandardDate = now;
  225. db.SaveChanges();
  226. if (!string.IsNullOrEmpty(act.Field1))
  227. {
  228. string PassDateString = act.Field1.Substring(0, 4) + "-" + act.Field1.Substring(4, 2) + "-" + act.Field1.Substring(6, 2);
  229. if(DateTime.Parse(PassDateString).AddDays(30) < DateTime.Now)
  230. {
  231. Prize = 0;
  232. }
  233. }
  234. if (Prize > 0)
  235. {
  236. StatService.Instance.doActiveReward(db, merchant, pos, pos.BuyUserId, user.ParentNav, TopUserId, Prize);
  237. }
  238. if (pos.CardType < 100 && Prize > 0 && PrizeFlag)
  239. {
  240. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  241. }
  242. if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.CardType < 100 && Prize > 0 && PrizeFlag)
  243. {
  244. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  245. }
  246. //发放运营中心奖励
  247. if (Deposit > 0 && pos.CardType < 100 && Prize > 0 && PrizeFlag)
  248. {
  249. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  250. }
  251. //发放奖励MQ
  252. PrizeSetHelper.Do("5", pos.PosSn);
  253. }
  254. else
  255. {
  256. pos.ActivationState = 1;
  257. pos.ActivationTime = now;
  258. merchant.ActiveStatus = 1;
  259. merchant.MerStandardDate = now;
  260. db.SaveChanges();
  261. }
  262. }
  263. else
  264. {
  265. //发放奖励MQ
  266. PrizeSetHelper.Do("1", pos.PosSn);
  267. }
  268. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  269. if (edit != null)
  270. {
  271. edit.Status = 2;
  272. }
  273. }
  274. else
  275. {
  276. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  277. if (edit != null)
  278. {
  279. edit.Status = 2;
  280. }
  281. }
  282. pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == act.SnNo && m.ActivationState == 1);
  283. if (pos != null)
  284. {
  285. //发放奖励MQ
  286. PrizeSetHelper.Do("1", pos.PosSn);
  287. }
  288. }
  289. spdb.SaveChanges();
  290. spdb.Dispose();
  291. db.SaveChanges();
  292. db.Dispose();
  293. mpdb.Dispose();
  294. }
  295. catch (Exception ex)
  296. {
  297. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  298. }
  299. Thread.Sleep(1000);
  300. }
  301. }
  302. }
  303. }