BalancePayBackService.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 BalancePayBackService
  12. {
  13. public readonly static BalancePayBackService Instance = new BalancePayBackService();
  14. private BalancePayBackService()
  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>("BalancePayQueue");
  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. AlipayPayBack2Service.Instance.DoOrder(db, OrderId);
  50. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 3 && m.PayStatus == 1);
  51. if(order != null)
  52. {
  53. UserAccount account = db.UserAccount.FirstOrDefault(m=>m.Id == order.UserId);
  54. if(account != null)
  55. {
  56. account.FreezeAmount -= order.TotalPrice;
  57. db.SaveChanges();
  58. }
  59. }
  60. db.Dispose();
  61. }
  62. }
  63. }