ActPrizeCheckService.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Threading;
  7. using MySystem.PxcModels;
  8. namespace MySystem
  9. {
  10. public class ActPrizeCheckService
  11. {
  12. public readonly static ActPrizeCheckService Instance = new ActPrizeCheckService();
  13. private ActPrizeCheckService()
  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. string content = RedisDbconn.Instance.RPop<string>("ActiveRewardFailQueue");
  26. if(!string.IsNullOrEmpty(content))
  27. {
  28. try
  29. {
  30. DoSomething(content);
  31. }
  32. catch(Exception ex)
  33. {
  34. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "实时监听无商户号未发奖励异常");
  35. }
  36. }
  37. Thread.Sleep(20000);
  38. }
  39. }
  40. public void DoSomething(string content)
  41. {
  42. JsonData jsonObj = JsonMapper.ToObject(content);
  43. int PosId = int.Parse(function.CheckInt(jsonObj["PosId"].ToString()));
  44. string UserId = jsonObj["UserId"].ToString();
  45. decimal ActPrize = decimal.Parse(function.CheckNum(jsonObj["ActPrize"].ToString()));
  46. int ChangeType = int.Parse(function.CheckInt(jsonObj["ChangeType"].ToString()));
  47. int ActType = int.Parse(function.CheckInt(jsonObj["ActType"].ToString()));
  48. WebCMSEntities db = new WebCMSEntities();
  49. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
  50. if(pos != null)
  51. {
  52. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  53. if(merchant != null)
  54. {
  55. if(!string.IsNullOrEmpty(merchant.KqMerNo))
  56. {
  57. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  58. int GetUserId = user.Id;
  59. string ParentNav = user.ParentNav;
  60. int TopUserId = 0;
  61. if (!string.IsNullOrEmpty(ParentNav))
  62. {
  63. TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  64. }
  65. StatService.Instance.doActiveReward(db, merchant, pos, GetUserId, ParentNav, TopUserId, ActPrize, ChangeType, ActType);
  66. db.Dispose();
  67. return;
  68. }
  69. else
  70. {
  71. RedisDbconn.Instance.AddList("ActiveRewardFailQueue", content);
  72. }
  73. }
  74. else
  75. {
  76. RedisDbconn.Instance.AddList("ActiveRewardFailQueue", content);
  77. }
  78. }
  79. db.Dispose();
  80. }
  81. }
  82. }