SycnSpActiveService.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  37. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  38. if (pos != null)
  39. {
  40. PxcModels.KqProducts kqproduct = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  41. if (kqproduct.SingleDepositApi == 1)
  42. {
  43. pos.SeoKeyword = act.SeoTitle;
  44. if(pos.BrandId == 15 || pos.BrandId == 16) //来客吧
  45. {
  46. pos.Detail = ""; //清除激活奖励标记
  47. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString()); //发开机奖励
  48. }
  49. db.SaveChanges();
  50. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  51. StatService.Instance.PreActPrize(db, pos, merchant, act.SeoTitle);
  52. }
  53. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  54. if (edit != null)
  55. {
  56. edit.Status = 2;
  57. }
  58. }
  59. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  60. if (pos != null)
  61. {
  62. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  63. if (edit != null)
  64. {
  65. edit.Status = 2;
  66. }
  67. }
  68. }
  69. spdb.SaveChanges();
  70. spdb.Dispose();
  71. db.SaveChanges();
  72. db.Dispose();
  73. }
  74. catch (Exception ex)
  75. {
  76. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  77. }
  78. Thread.Sleep(1000);
  79. }
  80. }
  81. }
  82. }