WifiWithholdService.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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)
  29. {
  30. string chk = function.ReadInstance("/WifiWithholdDo/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
  31. if(string.IsNullOrEmpty(chk))
  32. {
  33. function.WritePage("/WifiWithholdDo/", "" + 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 = 0;
  67. if(Pos.BrandId == 23)
  68. {
  69. ChargeAmount = 30;
  70. }
  71. if(Pos.BrandId == 24)
  72. {
  73. ChargeAmount = 120;
  74. }
  75. if(Pos.BrandId == 25)
  76. {
  77. ChargeAmount = 200;
  78. }
  79. if(Pos.BrandId == 26)
  80. {
  81. ChargeAmount = 750;
  82. }
  83. bool check = db.ToChargeBackRecord.Any(m => m.SeoDescription.Contains(Pos.PosSn) && (m.Status == 3 || m.Status == 0));
  84. if(!check)
  85. {
  86. db.ToChargeBackRecord.Add(new ToChargeBackRecord
  87. {
  88. CreateDate = DateTime.Now,
  89. SeoTitle = "系统",
  90. SeoDescription = "WIFI超时未激活扣款",
  91. Remark = "WIFI超时未激活扣款",
  92. ChargeType = 1,
  93. ChargeAmount = ChargeAmount,
  94. UserId = Pos.BuyUserId,
  95. Field1 = Pos.PosSn,
  96. });
  97. //增加账户预扣总额
  98. Utils.Instance.ToChargeAmount(Pos.BuyUserId, ChargeAmount);
  99. }
  100. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Pos.Id);
  101. if(edit != null)
  102. {
  103. edit.Sort = 2;
  104. }
  105. Id = Pos.Id;
  106. }
  107. db.SaveChanges();
  108. }
  109. else
  110. {
  111. op = false;
  112. }
  113. }
  114. db.Dispose();
  115. }
  116. }
  117. }