SycnSpActiveService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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" || act.ProductType == "15")
  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 || pos.BrandId == 15 || pos.BrandId == 16)
  54. {
  55. pos.SeoKeyword = act.SeoTitle;
  56. if(pos.BrandId == 15 || pos.BrandId == 16)
  57. {
  58. pos.Detail = "";
  59. }
  60. // pos.IsPurchase = 0;
  61. db.SaveChanges();
  62. }
  63. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  64. if (edit != null)
  65. {
  66. edit.Status = 2;
  67. }
  68. // 激活奖励
  69. // ProfitHelper.Instance.StartListenActiveDo(pos);
  70. }
  71. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  72. if (pos != null)
  73. {
  74. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  75. if (edit != null)
  76. {
  77. edit.Status = 2;
  78. }
  79. }
  80. }
  81. }
  82. spdb.SaveChanges();
  83. spdb.Dispose();
  84. db.SaveChanges();
  85. db.Dispose();
  86. }
  87. catch (Exception ex)
  88. {
  89. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  90. }
  91. Thread.Sleep(1000);
  92. }
  93. }
  94. }
  95. }