SycnSpActiveService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
  33. IQueryable<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.ActivateDate >= start && m.Status == 1).OrderByDescending(m => m.Id);
  34. foreach (ActivateRecord act in acts.ToList())
  35. {
  36. bool op = false;
  37. if (act.ActivateStatus == "00" && act.ProductType == "1")
  38. {
  39. op = true;
  40. }
  41. else if (act.ProductType == "2" || act.ProductType == "4" || act.ProductType == "6" || act.ProductType == "7" || act.ProductType == "8" || act.ProductType == "9")
  42. {
  43. op = true;
  44. }
  45. if (op)
  46. {
  47. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  48. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  49. if (pos != null)
  50. {
  51. // pos.ActivationState = 1;
  52. // pos.ActivationTime = DateTime.Now;
  53. if (pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 7 || pos.BrandId == 8 || pos.BrandId == 9)
  54. {
  55. pos.SeoKeyword = act.SeoTitle;
  56. // pos.IsPurchase = 0;
  57. db.SaveChanges();
  58. }
  59. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  60. if (edit != null)
  61. {
  62. edit.Status = 2;
  63. }
  64. // 激活奖励
  65. // ProfitHelper.Instance.StartListenActiveDo(pos);
  66. }
  67. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  68. if (pos != null)
  69. {
  70. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  71. if (edit != null)
  72. {
  73. edit.Status = 2;
  74. }
  75. }
  76. }
  77. }
  78. spdb.SaveChanges();
  79. spdb.Dispose();
  80. db.SaveChanges();
  81. db.Dispose();
  82. }
  83. catch (Exception ex)
  84. {
  85. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  86. }
  87. Thread.Sleep(1000);
  88. }
  89. }
  90. }
  91. }