ProfitCheckHelper.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using System.Threading;
  8. using Microsoft.Extensions.Hosting;
  9. using System.Threading.Tasks;
  10. using LitJson;
  11. namespace MySystem
  12. {
  13. public class ProfitCheckHelper
  14. {
  15. public readonly static ProfitCheckHelper Instance = new ProfitCheckHelper();
  16. private ProfitCheckHelper()
  17. {
  18. }
  19. #region 检查订单是否在队列里
  20. public void Start()
  21. {
  22. Thread th = new Thread(StartDo);
  23. th.IsBackground = true;
  24. th.Start();
  25. }
  26. public void StartDo()
  27. {
  28. while (true)
  29. {
  30. string orderidstring = RedisDbconn.Instance.RPop<string>("ConsumerProfitCheck");
  31. if (!string.IsNullOrEmpty(orderidstring))
  32. {
  33. DoSomeThing(orderidstring);
  34. Thread.Sleep(2000);
  35. }
  36. else
  37. {
  38. Thread.Sleep(60000);
  39. }
  40. }
  41. }
  42. public void DoSomeThing(string orderidstring)
  43. {
  44. try
  45. {
  46. int orderId = int.Parse(function.CheckInt(orderidstring));
  47. WebCMSEntities db = new WebCMSEntities();
  48. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == orderId);
  49. if(order != null)
  50. {
  51. var list = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId);
  52. if(!list.Any(m => m.Id == orderId) && !db.ConsumerProfit.Any(m => m.OrderId == orderId))
  53. {
  54. RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
  55. }
  56. }
  57. db.Dispose();
  58. }
  59. catch(Exception ex)
  60. {
  61. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "检查订单是否在队列里异常");
  62. }
  63. }
  64. #endregion
  65. }
  66. }