TradeStatTimer.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Linq;
  6. using Microsoft.Extensions.Hosting;
  7. using MySystem;
  8. using MySystem.PxcModels;
  9. using LitJson;
  10. using Library;
  11. public class TradeStatTimer
  12. {
  13. public readonly static TradeStatTimer Instance = new TradeStatTimer();
  14. private TradeStatTimer()
  15. {
  16. }
  17. public void Start()
  18. {
  19. Thread th = new Thread(DoWorks);
  20. th.IsBackground = true;
  21. th.Start();
  22. }
  23. private void DoWorks()
  24. {
  25. while (true)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("TradeStatQueue");
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. JsonData jsonObj = JsonMapper.ToObject(content);
  31. string DateString = jsonObj["DateString"].ToString();
  32. int UserId = int.Parse(jsonObj["UserId"].ToString()); //创客ID
  33. int BrandId = int.Parse(jsonObj["BrandId"].ToString()); //品牌
  34. int BankCardType = int.Parse(jsonObj["BankCardType"].ToString()); //卡类型
  35. int MerchantId = int.Parse(jsonObj["MerchantId"].ToString()); //商户Id
  36. int QrPayFlag = int.Parse(jsonObj["QrPayFlag"].ToString()); //云闪付
  37. decimal TradeAmount = decimal.Parse(jsonObj["TradeAmount"].ToString()); //当日交易额
  38. string TradeMonth = DateTime.Parse(DateString).ToString("yyyyMM");
  39. string TradeDate = DateTime.Parse(DateString).ToString("yyyyMMdd");
  40. WebCMSEntities db = new WebCMSEntities();
  41. var tran = db.Database.BeginTransaction();
  42. try
  43. {
  44. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new PosMerchantInfo();
  45. MachineForMerNo machineFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo) ?? new MachineForMerNo();
  46. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  47. int MerchantTypeUserId = int.Parse(function.CheckInt(pos.SeoTitle));
  48. if (MerchantTypeUserId > 0)
  49. {
  50. Users merchantUser = db.Users.FirstOrDefault(m => m.Id == MerchantTypeUserId && m.MerchantType == 1);
  51. if (merchantUser != null)
  52. {
  53. UserId = MerchantTypeUserId;
  54. }
  55. }
  56. Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
  57. if (user != null)
  58. {
  59. if (user.AuthFlag == 1)
  60. {
  61. if (QrPayFlag == 1)
  62. {
  63. }
  64. else
  65. {
  66. }
  67. string ParentNav = user.ParentNav;
  68. if (UserId != pos.UserId)
  69. {
  70. user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
  71. if (user != null)
  72. {
  73. ParentNav = user.ParentNav;
  74. UserId = pos.UserId;
  75. }
  76. }
  77. if (!string.IsNullOrEmpty(ParentNav))
  78. {
  79. ParentNav += "," + UserId + ",";
  80. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  81. foreach (string UserIdString in ParentNavList)
  82. {
  83. int ParentUserId = int.Parse(UserIdString);
  84. if (QrPayFlag == 1)
  85. {
  86. }
  87. else
  88. {
  89. }
  90. }
  91. }
  92. }
  93. }
  94. tran.Commit();
  95. }
  96. catch (Exception ex)
  97. {
  98. function.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex.ToString(), "统计交易额异常");
  99. tran.Rollback();
  100. }
  101. tran.Dispose();
  102. db.Dispose();
  103. }
  104. else
  105. {
  106. Thread.Sleep(900000);
  107. }
  108. }
  109. }
  110. }