WifiWithholdService.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 WifiWithholdService
  12. {
  13. public readonly static WifiWithholdService Instance = new WifiWithholdService();
  14. private WifiWithholdService()
  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 > 3 && DateTime.Now.Hour < 5 && DateTime.Now >= DateTime.Parse("2024-10-30 00:00:00"))
  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. DateTime end = DateTime.Parse(DateTime.Now.AddDays(-29).ToString("yyyy-MM-dd") + " 00:00:00");
  50. int Id = 0;
  51. bool op = true;
  52. while(op)
  53. {
  54. List<int> BrandIds = new List<int>();
  55. BrandIds.Add(23);
  56. BrandIds.Add(24);
  57. BrandIds.Add(25);
  58. BrandIds.Add(26);
  59. DateTime time = DateTime.Now.AddDays(-35);
  60. List<PosMachinesTwo> WifiList = db.PosMachinesTwo.Where(m => m.Id > Id && BrandIds.Contains(m.BrandId) && m.ActivationState == 0 && m.TransferTime < time && m.Sort == 1).OrderBy(m => m.Id).Take(20).ToList();
  61. if(WifiList.Count > 0)
  62. {
  63. foreach(var Pos in WifiList)
  64. {
  65. KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == Pos.BrandId) ?? new KqProducts();
  66. decimal ChargeAmount = decimal.Parse(function.CheckNum(Pos.SeoKeyword));
  67. db.ToChargeBackRecord.Add(new ToChargeBackRecord
  68. {
  69. CreateDate = DateTime.Now,
  70. SeoTitle = "系统",
  71. SeoDescription = "WIFI超时未激活扣款",
  72. Remark = "WIFI超时未激活扣款",
  73. ChargeType = 1,
  74. ChargeAmount = ChargeAmount,
  75. UserId = Pos.BuyUserId,
  76. Field1 = Pos.PosSn,
  77. });
  78. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Pos.Id);
  79. if(edit != null)
  80. {
  81. edit.Sort = 2;
  82. }
  83. //增加账户预扣总额
  84. Utils.Instance.ToChargeAmount(Pos.BuyUserId, ChargeAmount);
  85. Id = Pos.Id;
  86. }
  87. db.SaveChanges();
  88. }
  89. else
  90. {
  91. op = false;
  92. }
  93. }
  94. db.Dispose();
  95. }
  96. }
  97. }