SetSftFeeService.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading;
  6. using MySystem.PxcModels;
  7. using Library;
  8. namespace MySystem
  9. {
  10. /// <summary>
  11. /// 设置机具费率标记并推送消息
  12. /// </summary>
  13. public class SetSftFeeService
  14. {
  15. public readonly static SetSftFeeService Instance = new SetSftFeeService();
  16. private SetSftFeeService()
  17. { }
  18. public void Start()
  19. {
  20. Thread th = new Thread(doSomething);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void doSomething()
  25. {
  26. while (true)
  27. {
  28. if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 22)
  29. {
  30. try
  31. {
  32. string check = function.ReadInstance("/SftFee/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  33. if (string.IsNullOrEmpty(check))
  34. {
  35. function.WritePage("/SftFee/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  36. WebCMSEntities db = new WebCMSEntities();
  37. var date = DateTime.Now.AddDays(-420);
  38. var checkDate = DateTime.Parse("2024-06-01 00:00:00").AddDays(-426);
  39. bool op = true;
  40. int StartId = 0;
  41. while(op)
  42. {
  43. var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.PosSn, m.Status, m.BindingState, m.BindingTime, m.UpFeeFlag, m.DownFeeFlag, m.DownFee, m.BrandId, m.IsSupplement }).Where(m => m.Id > StartId && m.Status > -1 && m.BindingTime <= date && m.BindingState == 1 && m.BrandId == 7 && m.IsSupplement == 0).OrderBy(m => m.Id).Take(100).ToList();
  44. function.WriteLog(DateTime.Now.ToString(), "420天盛付通费率加万2");
  45. function.WriteLog(posList.Count.ToString(), "420天盛付通费率加万2");
  46. if(posList.Count > 0)
  47. {
  48. //循环修改机具费率调升标记
  49. //统计需要推送消息的用户Id
  50. foreach (var item in posList)
  51. {
  52. if(item.BindingTime >= checkDate)
  53. {
  54. string Fee = "";
  55. string AddRate = "";
  56. if(item.UpFeeFlag == 1 && item.DownFeeFlag == 0)
  57. {
  58. Fee = "0.65";
  59. AddRate = "3";
  60. }
  61. else if(item.UpFeeFlag == 1 && item.DownFeeFlag == 1 && item.DownFee == 0.63M)
  62. {
  63. Fee = "0.65";
  64. AddRate = "0";
  65. }
  66. else if(item.UpFeeFlag == 1 && item.DownFeeFlag == 1 && item.DownFee == 0.6M)
  67. {
  68. Fee = "0.62";
  69. AddRate = "0";
  70. }
  71. string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + Fee + "\",\"AddRate\": \"" + AddRate + "\",\"Kind\": \"4\",\"OpMan\": \"系统\"}";
  72. function.WriteLog(item.PosSn + "-Fee:" + Fee + "-AddRate:" + AddRate, "420天盛付通费率加万2");
  73. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  74. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == item.Id);
  75. if(pos != null)
  76. {
  77. pos.IsSupplement = 1;
  78. db.SaveChanges();
  79. }
  80. }
  81. StartId = item.Id;
  82. }
  83. }
  84. else
  85. {
  86. op = false;
  87. }
  88. }
  89. db.Dispose();
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "425天盛付通费率加万2异常");
  95. }
  96. }
  97. Thread.Sleep(800000);
  98. }
  99. }
  100. }
  101. }