PayHelper.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Threading;
  6. using System.IO;
  7. using MySystem.MainModels;
  8. using Library;
  9. using LitJson;
  10. namespace MySystem
  11. {
  12. public class PayHelper
  13. {
  14. public readonly static PayHelper Instance = new PayHelper();
  15. private PayHelper()
  16. { }
  17. private void threadStart()
  18. {
  19. string data = "";
  20. try
  21. {
  22. data = RedisDbconn.Instance.RPop<string>("PayCallBack");
  23. if (!string.IsNullOrEmpty(data))
  24. {
  25. ScanQueue(data);
  26. }
  27. }
  28. catch (Exception ex)
  29. {
  30. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + ex.ToString(), "支付回调队列异常");
  31. }
  32. }
  33. //要执行的方法
  34. private void ScanQueue(string data)
  35. {
  36. JsonData dateinfo = JsonMapper.ToObject(data);
  37. string OrderNo = dateinfo["out_trade_no"].ToString();
  38. string TradeNo = dateinfo["transaction_id"].ToString();
  39. decimal TotalFee = decimal.Parse(function.CheckNum(dateinfo["total_fee"].ToString()));
  40. int PayMode = int.Parse(function.CheckInt(dateinfo["pay_mode"].ToString()));
  41. OrderForNo orderForNo = OrderForNoDbconn.Instance.Get(OrderNo) ?? new OrderForNo();
  42. string OrderIds = orderForNo.OrderIds;
  43. if (!string.IsNullOrEmpty(OrderIds))
  44. {
  45. string[] orderIdList = OrderIds.Split(',');
  46. foreach (string orderIdStr in orderIdList)
  47. {
  48. int orderid = int.Parse(orderIdStr);
  49. Orders order = OrdersDbconn.Instance.Get(orderid);
  50. if (order != null)
  51. {
  52. if (order.Status == 0)
  53. {
  54. order.Status = 1;
  55. order.PayMode = PayMode;
  56. order.TradeNo = TradeNo;
  57. order.PayDate = DateTime.Now;
  58. List<int> proids = OrderProductDbconn.Instance.GetList(orderid);
  59. foreach (int proid in proids)
  60. {
  61. OrderProduct orderPro = OrderProductDbconn.Instance.Get(proid) ?? new OrderProduct();
  62. Products product = ProductsDbconn.Instance.Get(orderPro.ProductId);
  63. if (product != null)
  64. {
  65. product.MonthSale += orderPro.ProductCount;
  66. RedisDbconn.Instance.Set("Products:" + product.Id, product);
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }