LeaderAmountMonthChangeQueue.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.Models;
  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)
  30. if (DateTime.Now.Hour < 18)
  31. {
  32. try
  33. {
  34. string check = function.ReadInstance("/LeaderAmountMonthChange/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  35. if (string.IsNullOrEmpty(check))
  36. {
  37. function.WritePage("/LeaderAmountMonthChange/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  38. WebCMSEntities db = new WebCMSEntities();
  39. var leaders = db.Leaders.Select(m => new { m.UserId, m.ExpiredDate }).ToList();
  40. foreach (var item in leaders)
  41. {
  42. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == item.UserId) ?? new UserAccount();
  43. var leaderInfo = db.Leaders.FirstOrDefault(m => m.Id == item.UserId) ?? new Leaders();
  44. db.LeaderReconRecord.Add(new LeaderReconRecord()
  45. {
  46. CreateDate = DateTime.Now,
  47. UserId = item.UserId,
  48. StatMonth = DateTime.Now.ToString("yyyy-MM"),
  49. ReserveAmount = userAccount.LeaderReserve,
  50. BalanceAmount = userAccount.LeaderBalanceAmount
  51. });
  52. db.SaveChanges();
  53. }
  54. }
  55. }
  56. catch (Exception ex)
  57. {
  58. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月一号记录上月盟主储蓄金和可提现余额线程异常");
  59. }
  60. }
  61. Thread.Sleep(1000);
  62. }
  63. }
  64. }