AddActService.cs 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class AddActService
  12. {
  13. public readonly static AddActService Instance = new AddActService();
  14. private AddActService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. while (true)
  25. {
  26. string data = RedisDbconn.Instance.RPop<string>("AddActQueue");
  27. if (!string.IsNullOrEmpty(data))
  28. {
  29. try
  30. {
  31. int PosId = int.Parse(function.CheckInt(data));
  32. WebCMSEntities db = new WebCMSEntities();
  33. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
  34. if(pos != null)
  35. {
  36. decimal CheckMoney = 1000;
  37. int CheckDays = 30;
  38. DateTime now = DateTime.Now;
  39. //判断激活条件并激活
  40. DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
  41. if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-30) < pos.BindingTime)
  42. {
  43. pos.ActivationState = 1;
  44. pos.ActivationTime = DateTime.Now;
  45. function.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控");
  46. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  47. if (merchant != null)
  48. {
  49. merchant.ActiveStatus = 1;
  50. merchant.MerStandardDate = DateTime.Now;
  51. db.SaveChanges();
  52. function.WriteLog("商户" + merchant.KqMerNo, "开机奖励在激活中监控");
  53. // 推荐王逻辑(激活)
  54. string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + pos.BuyUserId + "\",\"PosId\":\"" + pos.Id + "\",\"TradeMonth\":\"" + DateTime.Now.ToString("yyyyMM") + "\"}}";
  55. RedisDbconn.Instance.AddList("RecommendActStatQueue", SendData);
  56. //发放开机奖励
  57. function.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控");
  58. if(pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
  59. {
  60. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  61. }
  62. }
  63. //发放大盟主奖励
  64. if(pos.LeaderUserId > 0 && pos.IsFirst == 1 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
  65. {
  66. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  67. }
  68. //发放运营中心奖励
  69. if(pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
  70. {
  71. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  72. }
  73. AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
  74. //统计激活数
  75. RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + DateTime.Now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
  76. }
  77. db.Dispose();
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "划拨后检查机具激活状态并自动补录异常");
  83. }
  84. }
  85. else
  86. {
  87. Thread.Sleep(30000);
  88. }
  89. }
  90. }
  91. }
  92. }