SycnSpActiveService.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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()
  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(-2);
  21. List<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.ActivateDate >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
  22. foreach (ActivateRecord act in acts)
  23. {
  24. if (act.ActivateStatus == "00")
  25. {
  26. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  27. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 0);
  28. if (pos != null)
  29. {
  30. // pos.ActivationState = 1;
  31. // pos.ActivationTime = DateTime.Now;
  32. pos.SeoTitle = act.SeoTitle;
  33. db.SaveChanges();
  34. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
  35. RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.PosSn, pos);
  36. // PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  37. // if (merchant != null)
  38. // {
  39. // merchant.ActiveStatus = 1;
  40. // merchant.MerStandardDate = DateTime.Now;
  41. // db.SaveChanges();
  42. // RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
  43. // }
  44. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  45. if (edit != null)
  46. {
  47. edit.Status = 2;
  48. }
  49. // 激活奖励
  50. // ProfitHelper.Instance.StartListenActiveDo(pos);
  51. }
  52. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  53. if (pos != null)
  54. {
  55. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  56. if (edit != null)
  57. {
  58. edit.Status = 2;
  59. }
  60. }
  61. }
  62. }
  63. spdb.SaveChanges();
  64. spdb.Dispose();
  65. db.SaveChanges();
  66. db.Dispose();
  67. }
  68. }
  69. }