WifiWarningService.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. function.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. DateTime time = DateTime.Now.AddDays(-30);
  59. 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();
  60. if(WifiList.Count > 0)
  61. {
  62. foreach(var Pos in WifiList)
  63. {
  64. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  65. {
  66. UserId = Pos.BuyUserId, //创客
  67. Title = "WIFI设备超时提醒", //标题
  68. Content = "<div class='f16'>尊敬的客小爽创客:<br />您好,您名下的部分WIFI设备已接收30天,超过35天未完成激活时将预扣您的创客余额。<br>为保障您的收益不受影响,请您尽快完成WIFI设备激活!</ div > ",//内容
  69. CreateDate = DateTime.Now,
  70. }));
  71. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Pos.Id);
  72. if(edit != null)
  73. {
  74. edit.Sort = 1;
  75. }
  76. Id = Pos.Id;
  77. }
  78. db.SaveChanges();
  79. }
  80. else
  81. {
  82. op = false;
  83. }
  84. }
  85. db.Dispose();
  86. }
  87. }
  88. }