SycnSpTradeService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 SycnSpTradeService
  11. {
  12. public readonly static SycnSpTradeService Instance = new SycnSpTradeService();
  13. private SycnSpTradeService()
  14. { }
  15. //激活逻辑
  16. public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "")
  17. {
  18. DateTime now = DateTime.Now;
  19. if(!string.IsNullOrEmpty(ActivationTime))
  20. {
  21. now = DateTime.Parse(ActivationTime);
  22. }
  23. DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
  24. int minute = 30;
  25. if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
  26. {
  27. pos.ActivationState = 1;
  28. pos.ActivationTime = now;
  29. if(pos.CardType == 101)
  30. {
  31. pos.IsPurchase = 1;
  32. }
  33. Utils.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控");
  34. Utils.WriteLog("PrizeFlag:" + PrizeFlag, "开机奖励在激活中监控");
  35. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  36. if (merchant != null)
  37. {
  38. Utils.WriteLog("查询到商户", "开机奖励在激活中监控");
  39. merchant.ActiveStatus = 1;
  40. merchant.MerStandardDate = now;
  41. db.SaveChanges();
  42. Utils.WriteLog("商户" + merchant.KqMerNo, "开机奖励在激活中监控");
  43. //发放开机奖励
  44. Utils.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控");
  45. if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  46. {
  47. Utils.WriteLog("开机奖发放", "开机奖励在激活中监控");
  48. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  49. if(pos.BrandId == 14)
  50. {
  51. if(pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now))
  52. {
  53. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  54. }
  55. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  56. }
  57. }
  58. }
  59. //发放大盟主奖励
  60. Utils.WriteLog("大盟主---PrizeFlag:" + PrizeFlag + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "开机奖励在激活中监控");
  61. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  62. 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 && PrizeFlag)
  63. {
  64. Utils.WriteLog("大盟主奖发放", "开机奖励在激活中监控");
  65. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  66. }
  67. //发放运营中心奖励
  68. if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  69. {
  70. Utils.WriteLog("运营中心奖发放", "开机奖励在激活中监控");
  71. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  72. }
  73. if(pos.CardType < 100)
  74. {
  75. // AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
  76. //统计激活数
  77. RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
  78. //运营中心额度变更
  79. OpAmountItem item = new OpAmountItem()
  80. {
  81. UserId = pos.OpId,
  82. OperateType = 1,
  83. ChangeType = 9,
  84. Remark = "机具激活",
  85. UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3,
  86. UseValidForGetAmount = pos.OpReserve2,
  87. UseTotalAmt = pos.OpReserve1,
  88. UseValidAmount = pos.OpReserve3,
  89. DataType = 2,
  90. DataId = pos.Id,
  91. };
  92. RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
  93. }
  94. //清理预扣款
  95. RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
  96. }
  97. }
  98. }
  99. }