WifiWarningService.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class WifiWarningService
  12. {
  13. public readonly static WifiWarningService Instance = new WifiWarningService();
  14. private WifiWarningService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. if(DateTime.Now.Hour > 2 && DateTime.Now.Hour < 4)
  29. {
  30. string chk = function.ReadInstance("/WifiWithhold/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
  31. if(string.IsNullOrEmpty(chk))
  32. {
  33. function.WritePage("/WifiWithhold/", "" + DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString());
  34. WifiWithhold();
  35. }
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. Utils.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "WIFI提醒异常");
  41. }
  42. Thread.Sleep(30000);
  43. }
  44. }
  45. //WIFI30天未完成申请时向预发创客增加一条预扣款
  46. private void WifiWithhold()
  47. {
  48. WebCMSEntities db = new WebCMSEntities();
  49. int Id = 0;
  50. bool op = true;
  51. while(op)
  52. {
  53. List<int> BrandIds = new List<int>();
  54. BrandIds.Add(23);
  55. BrandIds.Add(24);
  56. BrandIds.Add(25);
  57. BrandIds.Add(26);
  58. BrandIds.Add(32);
  59. DateTime time = DateTime.Now.AddDays(-30);
  60. List<PosMachinesTwo> WifiList = db.PosMachinesTwo.Where(m => m.Id > Id && BrandIds.Contains(m.BrandId) && m.ActivationState == 0 && m.TransferTime < time && m.Sort == 0).OrderBy(m => m.Id).Take(20).ToList();
  61. if(WifiList.Count > 0)
  62. {
  63. foreach(var Pos in WifiList)
  64. {
  65. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  66. {
  67. UserId = Pos.BuyUserId, //创客
  68. Title = "WIFI设备超时提醒", //标题
  69. Content = "<div class='f16'>尊敬的客小爽创客:<br />您好,您名下的部分WIFI设备已接收30天,超过35天未完成激活时将预扣您的创客余额。<br>为保障您的收益不受影响,请您尽快完成WIFI设备激活!</ div > ",//内容
  70. CreateDate = DateTime.Now,
  71. }));
  72. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Pos.Id);
  73. if(edit != null)
  74. {
  75. edit.Sort = 1;
  76. }
  77. Id = Pos.Id;
  78. }
  79. db.SaveChanges();
  80. }
  81. else
  82. {
  83. op = false;
  84. }
  85. }
  86. db.Dispose();
  87. }
  88. }
  89. }