SycnSpActiveService.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. DateTime end = DateTime.Now.AddMinutes(-1);
  33. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
  34. IQueryable<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.ActivateDate >= start && m.ActivateDate < end && m.Status == 1).OrderByDescending(m => m.Id);
  35. foreach (ActivateRecord act in acts.ToList())
  36. {
  37. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
  38. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  39. if (pos != null)
  40. {
  41. PxcModels.KqProducts kqproduct = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  42. if (kqproduct.SingleDepositApi == 1)
  43. {
  44. pos.SeoKeyword = act.SeoTitle;
  45. if(pos.BrandId == 15 || pos.BrandId == 16) //来客吧
  46. {
  47. pos.Detail = ""; //清除激活奖励标记
  48. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString()); //发开机奖励
  49. }
  50. db.SaveChanges();
  51. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  52. StatService.Instance.PreActPrize(db, pos, merchant, act.SeoTitle);
  53. }
  54. if(pos.BrandId == 12 || pos.BrandId == 13 || pos.BrandId == 15 || pos.BrandId == 16)
  55. {
  56. decimal CheckMoney = kqproduct.ActTradeAmount > 0 ? kqproduct.ActTradeAmount : 1000;
  57. int CheckDays = 30;
  58. SycnSpTradeService.Instance.ActPos(db, pos, CheckMoney, CheckDays);
  59. }
  60. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  61. if (edit != null)
  62. {
  63. edit.Status = 2;
  64. }
  65. }
  66. pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
  67. if (pos != null)
  68. {
  69. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  70. if (edit != null)
  71. {
  72. edit.Status = 2;
  73. }
  74. }
  75. }
  76. spdb.SaveChanges();
  77. spdb.Dispose();
  78. db.SaveChanges();
  79. db.Dispose();
  80. }
  81. catch (Exception ex)
  82. {
  83. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  84. }
  85. Thread.Sleep(1000);
  86. }
  87. }
  88. }
  89. }