LeaderAmountMonthChangeQueue.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. using LitJson;
  10. /// <summary>
  11. /// 每月一号记录上月盟主储蓄金和可提现余额
  12. /// </summary>
  13. public class LeaderAmountMonthChangeQueue
  14. {
  15. public readonly static LeaderAmountMonthChangeQueue Instance = new LeaderAmountMonthChangeQueue();
  16. private LeaderAmountMonthChangeQueue()
  17. {
  18. }
  19. public void Start()
  20. {
  21. Thread th = new Thread(StartDo);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. private void StartDo()
  26. {
  27. while (true)
  28. {
  29. if (DateTime.Now.Day == 1 && DateTime.Now.Hour > 1 && DateTime.Now.Hour < 10)
  30. {
  31. try
  32. {
  33. string check = function.ReadInstance("/LeaderAmountMonthChange/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  34. if (string.IsNullOrEmpty(check))
  35. {
  36. function.WritePage("/LeaderAmountMonthChange/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  37. WebCMSEntities db = new WebCMSEntities();
  38. var leaders = db.Leaders.Select(m => new { m.UserId, m.ExpiredDate }).ToList();
  39. foreach (var item in leaders)
  40. {
  41. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == item.UserId) ?? new UserAccount();
  42. var leaderInfo = db.Leaders.FirstOrDefault(m => m.Id == item.UserId) ?? new Leaders();
  43. db.LeaderReconRecord.Add(new LeaderReconRecord()
  44. {
  45. CreateDate = DateTime.Now,
  46. UserId = item.UserId,
  47. StatMonth = DateTime.Now.ToString("yyyy-MM"),
  48. ReserveAmount = userAccount.LeaderReserve,
  49. BalanceAmount = userAccount.LeaderBalanceAmount
  50. });
  51. db.SaveChanges();
  52. }
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月一号记录上月盟主储蓄金和可提现余额线程异常");
  58. }
  59. }
  60. Thread.Sleep(60000);
  61. }
  62. }
  63. }