TradeFilterService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 TradeFilterService
  12. {
  13. public readonly static TradeFilterService Instance = new TradeFilterService();
  14. private TradeFilterService()
  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>("TradeFilterQueue");
  27. if (!string.IsNullOrEmpty(data))
  28. {
  29. try
  30. {
  31. JsonData jsonOj = JsonMapper.ToObject(data);
  32. int Kind = int.Parse(function.CheckInt(jsonOj["Kind"].ToString()));
  33. int OrderId = int.Parse(function.CheckInt(jsonOj["OrderId"].ToString()));
  34. int PrizeUserId = int.Parse(function.CheckInt(jsonOj["PrizeUserId"].ToString()));
  35. decimal Amount = decimal.Parse(function.CheckNum(jsonOj["Amount"].ToString()));
  36. WebCMSEntities db = new WebCMSEntities();
  37. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  38. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  39. db.TradeFilterRecord.Add(new TradeFilterRecord()
  40. {
  41. CreateDate = DateTime.Now,
  42. IntercetpAmount = Amount,
  43. OrderDate = order.PayDate,
  44. OrderNo = order.OrderNo,
  45. OrderId = order.Id,
  46. PrizeUserId = PrizeUserId,
  47. OrderUserId = order.UserId,
  48. Kind = Kind,
  49. });
  50. db.Dispose();
  51. }
  52. catch (Exception ex)
  53. {
  54. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "训练营拦截奖励异常");
  55. }
  56. }
  57. else
  58. {
  59. Thread.Sleep(500);
  60. }
  61. }
  62. }
  63. }
  64. }