ConsumerOrdersStatService.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using MySystem.PxcModels;
  7. namespace MySystem
  8. {
  9. public class ConsumerOrdersStatService
  10. {
  11. public readonly static ConsumerOrdersStatService Instance = new ConsumerOrdersStatService();
  12. private ConsumerOrdersStatService()
  13. { }
  14. public void Start(JobMqMsg jobInfo)
  15. {
  16. string content = "";
  17. try
  18. {
  19. dosomething();
  20. string Msg = "success";
  21. jobInfo.Status = Msg == "success" ? 1 : 0;
  22. jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
  23. RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
  24. }
  25. catch (Exception ex)
  26. {
  27. if (!string.IsNullOrEmpty(content))
  28. {
  29. Dictionary<string, string> data = new Dictionary<string, string>();
  30. data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  31. data.Add("ErrMsg", ex.ToString());
  32. TendisDbconn.Instance.AddList("public_err", data);
  33. }
  34. else
  35. {
  36. TendisDbconn.Instance.AddList("public_service", DateTime.Now.ToString() + ":" + ex.ToString());
  37. }
  38. }
  39. }
  40. public void dosomething()
  41. {
  42. bool op = true;
  43. while (op)
  44. {
  45. int OrderId = TendisDbconn.Instance.RPop<int>("ConsumerOrdersStat");
  46. if (OrderId > 0)
  47. {
  48. WebCMSEntities db = new WebCMSEntities();
  49. using (var tran = db.Database.BeginTransaction())
  50. {
  51. try
  52. {
  53. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == OrderId);
  54. if (order != null)
  55. {
  56. order.PayMoney = order.PayMoney * 10000M;
  57. string TradeMonth = order.UpdateDate.Value.ToString("yyyyMM");
  58. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId);
  59. if (merchant != null)
  60. {
  61. BothdisDbconn.Instance.AddNumber("TotalAmount:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
  62. // 微信/支付宝
  63. if (order.PayMode == 1)
  64. {
  65. BothdisDbconn.Instance.AddInt("TotalOrder:Alipay:" + merchant.UserId + ":" + TradeMonth);
  66. }
  67. else
  68. {
  69. BothdisDbconn.Instance.AddInt("TotalOrder:WeChat:" + merchant.UserId + ":" + TradeMonth);
  70. }
  71. // 活动、非活动
  72. if (order.IsAct == 1)
  73. {
  74. BothdisDbconn.Instance.AddNumber("TotalAmount:Active:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
  75. }
  76. else
  77. {
  78. BothdisDbconn.Instance.AddNumber("TotalAmount:UnActive:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
  79. }
  80. // 遍历上级,累加团队数据
  81. int UserId = merchant.UserId;
  82. int Level = 0;
  83. while (UserId > 0)
  84. {
  85. Level += 1;
  86. Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
  87. if (user != null)
  88. {
  89. if (Level >= 1)
  90. {
  91. BothdisDbconn.Instance.AddNumber("TeamTotalAmount:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
  92. // 微信/支付宝
  93. if (order.PayMode == 1)
  94. {
  95. BothdisDbconn.Instance.AddInt("TeamTotalOrder:Alipay:" + merchant.UserId + ":" + TradeMonth);
  96. }
  97. else
  98. {
  99. BothdisDbconn.Instance.AddInt("TeamTotalOrder:WeChat:" + merchant.UserId + ":" + TradeMonth);
  100. }
  101. // 活动、非活动
  102. if (order.IsAct == 1)
  103. {
  104. BothdisDbconn.Instance.AddNumber("TeamTotalAmount:Active:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
  105. }
  106. else
  107. {
  108. BothdisDbconn.Instance.AddNumber("TeamTotalAmount:UnActive:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
  109. }
  110. }
  111. UserId = user.ParentUserId;
  112. }
  113. else
  114. {
  115. UserId = 0;
  116. }
  117. }
  118. // 判断激活商户,从绑定音箱码开始,30天内,活动交易额满1000为激活
  119. if (merchant.BindStatus == 1 && merchant.BindDate > DateTime.Now.AddDays(-30))
  120. {
  121. }
  122. }
  123. tran.Commit();
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. tran.Rollback();
  129. TendisDbconn.Instance.AddList("public_service", DateTime.Now.ToString() + ":" + ex.ToString());
  130. }
  131. }
  132. db.Dispose();
  133. }
  134. else
  135. {
  136. op = false;
  137. }
  138. }
  139. }
  140. }
  141. }