WifiRefundHelper.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. using LitJson;
  10. public class WifiRefundHelper
  11. {
  12. public readonly static WifiRefundHelper Instance = new WifiRefundHelper();
  13. private WifiRefundHelper()
  14. {
  15. }
  16. public void Start()
  17. {
  18. Thread th = new Thread(DoWorks);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void DoWorks()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("WifiRefundQueue");
  29. if(!string.IsNullOrEmpty(content))
  30. {
  31. DoSomething(content);
  32. }
  33. else
  34. {
  35. Thread.Sleep(60000);
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "WIFI退款异常");
  41. }
  42. }
  43. }
  44. public void DoSomething(string OrderNo)
  45. {
  46. WebCMSEntities db = new WebCMSEntities();
  47. WifiTradeRecord edit = db.WifiTradeRecord.FirstOrDefault(m => m.OrderNo == OrderNo);
  48. if(edit != null)
  49. {
  50. edit.DoMonths = edit.Duration + 1;
  51. edit.Status = -1;
  52. db.SaveChanges();
  53. }
  54. db.Dispose();
  55. }
  56. }