LeaderPrizeService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class LeaderPrizeService
  12. {
  13. public readonly static LeaderPrizeService Instance = new LeaderPrizeService();
  14. private LeaderPrizeService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. while (true)
  25. {
  26. string data = RedisDbconn.Instance.RPop<string>("LeaderPrizeQueue");
  27. if (!string.IsNullOrEmpty(data))
  28. {
  29. try
  30. {
  31. int PosId = int.Parse(function.CheckInt(data));
  32. using (WebCMSEntities db = new WebCMSEntities())
  33. {
  34. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
  35. if (pos != null)
  36. {
  37. int LeaderUserId = pos.LeaderUserId;
  38. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == LeaderUserId);
  39. if (account == null)
  40. {
  41. account = db.UserAccount.Add(new UserAccount()
  42. {
  43. Id = LeaderUserId,
  44. UserId = LeaderUserId,
  45. }).Entity;
  46. db.SaveChanges();
  47. }
  48. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  49. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  50. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  51. account.BalanceAmount += 100;
  52. account.TotalAmount += 100;
  53. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  54. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  55. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  56. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  57. {
  58. CreateDate = DateTime.Now,
  59. UpdateDate = DateTime.Now,
  60. UserId = LeaderUserId, //创客
  61. ChangeType = 116, //变动类型
  62. ChangeAmount = 5, //变更金额
  63. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  64. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  65. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  66. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  67. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  68. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  69. QueryCount = PosId,
  70. }).Entity;
  71. db.SaveChanges();
  72. }
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "大盟主奖励异常");
  78. }
  79. }
  80. else
  81. {
  82. Thread.Sleep(5000);
  83. }
  84. }
  85. }
  86. }
  87. }