StatTimerService.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using MySystem.PxcModels;
  8. namespace MySystem
  9. {
  10. public class StatTimerService
  11. {
  12. public readonly static StatTimerService Instance = new StatTimerService();
  13. private StatTimerService()
  14. { }
  15. public void Start(JobMqMsg jobInfo)
  16. {
  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. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
  28. }
  29. }
  30. public void dosomething()
  31. {
  32. WebCMSEntities db = new WebCMSEntities();
  33. string yesterday = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  34. string today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  35. // 统计商户激活数据
  36. DataTable dt = dbconn.dtable("select UserId,BrandId,MerStandardDate from PosMerchantInfo where MerStandardDate>='" + yesterday + "' and MerStandardDate<'" + today + "' and QueryCount=0");
  37. dbconn.op("update PosMerchantInfo set QueryCount=1 where MerStandardDate>='" + yesterday + "' and MerStandardDate<'" + today + "' and QueryCount=0");
  38. foreach (DataRow dr in dt.Rows)
  39. {
  40. DateTime date = DateTime.Parse(dr["MerStandardDate"].ToString());
  41. string TradeMonth = date.ToString("yyyyMM");
  42. string TradeDate = date.ToString("yyyyMMdd");
  43. int UserId = int.Parse(dr["UserId"].ToString()); //创客ID
  44. int BrandId = int.Parse(dr["BrandId"].ToString()); //品牌
  45. int MerchantCount = 1;
  46. int Level = 0;
  47. while (UserId > 0)
  48. {
  49. Level += 1;
  50. Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
  51. if (user != null)
  52. {
  53. if (user.AuthFlag == 1)
  54. {
  55. if (Level == 1)
  56. {
  57. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  58. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  59. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  60. RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  61. }
  62. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  63. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  64. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
  65. RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
  66. }
  67. UserId = user.ParentUserId;
  68. }
  69. else
  70. {
  71. UserId = 0;
  72. }
  73. }
  74. }
  75. db.Dispose();
  76. }
  77. }
  78. }