StoreApplyHelper.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 StoreApplyHelper
  11. {
  12. public readonly static StoreApplyHelper Instance = new StoreApplyHelper();
  13. private StoreApplyHelper()
  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. WebCMSEntities db = new WebCMSEntities();
  27. try
  28. {
  29. if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
  30. {
  31. string check = function.ReadInstance("/StoreApply/" + DateTime.Now.ToString("yyyyMM") + ".txt");
  32. if(string.IsNullOrEmpty(check))
  33. {
  34. function.WritePage("/StoreApply/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.ToString());
  35. db.SaveChanges();
  36. }
  37. }
  38. }
  39. catch (Exception ex)
  40. {
  41. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "计算分仓申请机具额度异常");
  42. }
  43. db.Dispose();
  44. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算分仓申请机具额度日志");
  45. Thread.Sleep(60000);
  46. }
  47. }
  48. public void StartEverTime()
  49. {
  50. Thread th = new Thread(StartEverTimeDo);
  51. th.IsBackground = true;
  52. th.Start();
  53. }
  54. private void StartEverTimeDo()
  55. {
  56. while (true)
  57. {
  58. WebCMSEntities db = new WebCMSEntities();
  59. try
  60. {
  61. string data = RedisDbconn.Instance.Get<string>("StoreApplyQueue");
  62. if(!string.IsNullOrEmpty(data))
  63. {
  64. JsonData jsonObj = JsonMapper.ToObject(data);
  65. if(jsonObj["Kind"].ToString() == "1")
  66. {
  67. int OrderId = int.Parse(jsonObj["Data"]["OrderId"].ToString());
  68. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
  69. if(order != null)
  70. {
  71. decimal TotalPrice = order.TotalPrice;
  72. UserAccount account = db.UserAccount.FirstOrDefault();
  73. }
  74. }
  75. db.SaveChanges();
  76. }
  77. }
  78. catch (Exception ex)
  79. {
  80. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "分仓向总仓申请机具线程异常");
  81. }
  82. db.Dispose();
  83. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "分仓向总仓申请机具线程日志");
  84. Thread.Sleep(60000);
  85. }
  86. }
  87. }