SycnSpActiveService.cs 16 KB

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