SetSftFeeService.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading;
  6. using MySystem.Models;
  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 < 19)
  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(-420);
  39. bool op = true;
  40. int StartId = 0;
  41. while(op)
  42. {
  43. var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.Status, m.BindingState, m.BindingTime, m.UpFeeFlag, m.DownFeeFlag, m.BrandId }).Where(m => m.Id > StartId && m.Status > -1 && m.BindingTime <= date && m.BindingState == 1 && m.BrandId == 7 && m.BindingTime >= checkDate).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. string Fee = "0.62";
  53. function.WriteLog(item.Id.ToString(), "420天盛付通费率加万2");
  54. string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + Fee + "\",\"Kind\": \"4\",\"OpMan\": \""+"系统"+"\"}";
  55. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  56. StartId = item.Id;
  57. }
  58. }
  59. else
  60. {
  61. op = false;
  62. }
  63. }
  64. db.Dispose();
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "425天盛付通费率加万2异常");
  70. }
  71. }
  72. Thread.Sleep(800000);
  73. }
  74. }
  75. }
  76. }