SycnSpActiveService.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.ActivateStatus == "SUCCESS" && 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. pos.SeoKeyword = act.SeoTitle;
  51. db.SaveChanges();
  52. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
  53. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.PosSn, pos);
  54. // PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  55. // if (merchant != null)
  56. // {
  57. // merchant.ActiveStatus = 1;
  58. // merchant.MerStandardDate = DateTime.Now;
  59. // db.SaveChanges();
  60. // RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
  61. // }
  62. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  63. if (edit != null)
  64. {
  65. edit.Status = 2;
  66. }
  67. // 激活奖励
  68. // ProfitHelper.Instance.StartListenActiveDo(pos);
  69. }
  70. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  71. if (pos != null)
  72. {
  73. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  74. if (edit != null)
  75. {
  76. edit.Status = 2;
  77. }
  78. }
  79. }
  80. }
  81. spdb.SaveChanges();
  82. spdb.Dispose();
  83. db.SaveChanges();
  84. db.Dispose();
  85. }
  86. }
  87. }