AddActService.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.BindingTime > DateTime.Now.AddDays(-CheckDays))
  59. {
  60. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  61. }
  62. }
  63. //发放大盟主奖励
  64. if(pos.LeaderUserId > 0 && 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.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. OpAmountItem item = new OpAmountItem()
  78. {
  79. UserId = pos.OpId,
  80. OperateType = 1,
  81. ChangeType = 9,
  82. Remark = "机具激活",
  83. UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3,
  84. UseValidForGetAmount = pos.OpReserve2,
  85. UseTotalAmt = pos.OpReserve1,
  86. UseValidAmount = pos.OpReserve3,
  87. DataType = 2,
  88. DataId = pos.Id,
  89. };
  90. RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
  91. }
  92. db.Dispose();
  93. }
  94. }
  95. catch (Exception ex)
  96. {
  97. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "划拨后检查机具激活状态并自动补录异常");
  98. }
  99. }
  100. else
  101. {
  102. Thread.Sleep(30000);
  103. }
  104. }
  105. }
  106. }
  107. }