ProfitShareService.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.Models.Main;
  5. using Library;
  6. using LitJson;
  7. using System.Text.RegularExpressions;
  8. using System.Threading;
  9. namespace MySystem
  10. {
  11. public class ProfitShareService
  12. {
  13. public readonly static ProfitShareService Instance = new ProfitShareService();
  14. private ProfitShareService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartListen);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartListen()
  23. {
  24. while (true)
  25. {
  26. string content = RedisDbconn.Instance.RPop<string>("ProfitShareHdQueue");
  27. if (!string.IsNullOrEmpty(content))
  28. {
  29. StartDo(content);
  30. }
  31. else
  32. {
  33. Thread.Sleep(2000);
  34. }
  35. }
  36. }
  37. public void StartDo(string content)
  38. {
  39. try
  40. {
  41. JsonData jsonObj = JsonMapper.ToObject(content);
  42. string ApplyNo = jsonObj["ApplyNo"].ToString(); //微信订单号
  43. string MchtNo = jsonObj["MchtNo"].ToString(); //商户订单号
  44. string OrderNo = jsonObj["OrderNo"].ToString(); //商户订单号
  45. JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(ApplyNo, MchtNo));
  46. string state = result["data"]["status"].ToString();
  47. if (result["data"]["status"].ToString() == "0")
  48. {
  49. WebCMSEntities db = new WebCMSEntities();
  50. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 2);
  51. if (order != null)
  52. {
  53. RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
  54. }
  55. db.Dispose();
  56. }
  57. else
  58. {
  59. RedisDbconn.Instance.AddList("ProfitShareHdQueue", content);
  60. }
  61. }
  62. catch (Exception ex)
  63. {
  64. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账队列异常");
  65. }
  66. }
  67. }
  68. }