LeaderPrizeService.cs 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. WebCMSEntities db = new WebCMSEntities();
  33. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
  34. if (pos != null)
  35. {
  36. decimal ChangeAmount = 10;
  37. if(pos.BrandId == 14)
  38. {
  39. ChangeAmount = 19 * 0.15M;
  40. }
  41. int LeaderUserId = pos.LeaderUserId;
  42. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == LeaderUserId);
  43. if (account == null)
  44. {
  45. account = db.UserAccount.Add(new UserAccount()
  46. {
  47. Id = LeaderUserId,
  48. UserId = LeaderUserId,
  49. }).Entity;
  50. db.SaveChanges();
  51. }
  52. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  53. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  54. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  55. account.BalanceAmount += ChangeAmount;
  56. account.TotalAmount += ChangeAmount;
  57. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  58. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  59. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  60. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  61. {
  62. CreateDate = DateTime.Now,
  63. UpdateDate = DateTime.Now,
  64. UserId = LeaderUserId, //创客
  65. ChangeType = 116, //变动类型
  66. ChangeAmount = ChangeAmount, //变更金额
  67. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  68. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  69. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  70. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  71. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  72. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  73. QueryCount = PosId,
  74. }).Entity;
  75. db.SaveChanges();
  76. }
  77. db.Dispose();
  78. }
  79. catch (Exception ex)
  80. {
  81. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "大盟主奖励异常");
  82. }
  83. Thread.Sleep(100);
  84. }
  85. else
  86. {
  87. Thread.Sleep(60000);
  88. }
  89. }
  90. }
  91. }
  92. }