SycnSpActiveService.cs 3.7 KB

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