ReservePayBackService.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using MySystem.PxcModels;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. public class ReservePayBackService
  12. {
  13. public readonly static ReservePayBackService Instance = new ReservePayBackService();
  14. private ReservePayBackService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void dosomething()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("ReservePayQueue");
  29. if (!string.IsNullOrEmpty(content))
  30. {
  31. sloveAlipayCallBack(content);
  32. }
  33. else
  34. {
  35. Thread.Sleep(2000);
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商城订单余额支付异常");
  41. Thread.Sleep(2000);
  42. }
  43. }
  44. }
  45. public void sloveAlipayCallBack(string content)
  46. {
  47. int OrderId = int.Parse(function.CheckInt(content));
  48. WebCMSEntities db = new WebCMSEntities();
  49. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 4 && m.PayStatus == 0);
  50. if (order != null)
  51. {
  52. decimal TotalPrice = order.TotalPrice;
  53. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
  54. if (account != null)
  55. {
  56. if(account.LeaderReserve >= TotalPrice)
  57. {
  58. AlipayPayBack2Service.Instance.DoOrderV2(db, OrderId);
  59. }
  60. }
  61. }
  62. db.Dispose();
  63. }
  64. }
  65. }