SycnSpActiveService.cs 17 KB

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