SycnSpActiveService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.SpModels;
  5. using Library;
  6. using LitJson;
  7. using System.Threading;
  8. namespace MySystem
  9. {
  10. public class SycnSpActiveService
  11. {
  12. public readonly static SycnSpActiveService Instance = new SycnSpActiveService();
  13. private SycnSpActiveService()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(StartDo);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void StartDo()
  22. {
  23. while (true)
  24. {
  25. try
  26. {
  27. WebCMSEntities spdb = new WebCMSEntities();
  28. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  29. string Month = DateTime.Now.ToString("yyyyMM");
  30. string Date = DateTime.Now.ToString("yyyyMMdd");
  31. DateTime start = DateTime.Now.AddDays(-5);
  32. IQueryable<ActivateRecord> acts = spdb.ActivateRecord;
  33. acts = acts.Where(m => m.ActivateDate >= start && m.Status == 1);
  34. acts = acts.OrderByDescending(m => m.Id);
  35. foreach (ActivateRecord act in acts.ToList())
  36. {
  37. bool op = false;
  38. if (act.ActivateStatus == "00" && act.ProductType == "1")
  39. {
  40. op = true;
  41. }
  42. else if (act.ProductType == "2" || act.ProductType == "4")
  43. {
  44. op = true;
  45. }
  46. if (op)
  47. {
  48. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  49. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  50. if (pos != null)
  51. {
  52. // pos.ActivationState = 1;
  53. // pos.ActivationTime = DateTime.Now;
  54. if (pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5)
  55. {
  56. pos.SeoKeyword = act.SeoTitle;
  57. db.SaveChanges();
  58. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
  59. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.PosSn, pos);
  60. }
  61. // PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  62. // if (merchant != null)
  63. // {
  64. // merchant.ActiveStatus = 1;
  65. // merchant.MerStandardDate = DateTime.Now;
  66. // db.SaveChanges();
  67. // RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
  68. // }
  69. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  70. if (edit != null)
  71. {
  72. edit.Status = 2;
  73. }
  74. // 激活奖励
  75. // ProfitHelper.Instance.StartListenActiveDo(pos);
  76. }
  77. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  78. if (pos != null)
  79. {
  80. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  81. if (edit != null)
  82. {
  83. edit.Status = 2;
  84. }
  85. }
  86. }
  87. }
  88. spdb.SaveChanges();
  89. spdb.Dispose();
  90. db.SaveChanges();
  91. db.Dispose();
  92. }
  93. catch (Exception ex)
  94. {
  95. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  96. }
  97. Thread.Sleep(1000);
  98. }
  99. }
  100. }
  101. }