SycnSpActiveService.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if (act.ActivateStatus == "00")
  34. {
  35. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  36. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  37. if (pos != null)
  38. {
  39. // pos.ActivationState = 1;
  40. // pos.ActivationTime = DateTime.Now;
  41. pos.SeoKeyword = act.SeoTitle;
  42. db.SaveChanges();
  43. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
  44. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.PosSn, pos);
  45. // PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  46. // if (merchant != null)
  47. // {
  48. // merchant.ActiveStatus = 1;
  49. // merchant.MerStandardDate = DateTime.Now;
  50. // db.SaveChanges();
  51. // RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
  52. // }
  53. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  54. if (edit != null)
  55. {
  56. edit.Status = 2;
  57. }
  58. // 激活奖励
  59. // ProfitHelper.Instance.StartListenActiveDo(pos);
  60. }
  61. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  62. if (pos != null)
  63. {
  64. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  65. if (edit != null)
  66. {
  67. edit.Status = 2;
  68. }
  69. }
  70. }
  71. }
  72. spdb.SaveChanges();
  73. spdb.Dispose();
  74. db.SaveChanges();
  75. db.Dispose();
  76. }
  77. }
  78. }