AlipayPayBackService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.PxcModels;
  5. using Library;
  6. using LitJson;
  7. namespace MySystem
  8. {
  9. public class AlipayPayBackService
  10. {
  11. public readonly static AlipayPayBackService Instance = new AlipayPayBackService();
  12. private AlipayPayBackService()
  13. { }
  14. public void Start()
  15. {
  16. try
  17. {
  18. dosomething();
  19. }
  20. catch (Exception ex)
  21. {
  22. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "支付回调异常");
  23. }
  24. }
  25. private void dosomething()
  26. {
  27. bool op = true;
  28. while (op)
  29. {
  30. string content = RedisDbconn.Instance.RPop<string>("PayCallBack");
  31. if (!string.IsNullOrEmpty(content))
  32. {
  33. JsonData jsonObj = JsonMapper.ToObject(content);
  34. string OrderNo = jsonObj["out_trade_no"].ToString();
  35. string TradeNo = jsonObj["transaction_id"].ToString();
  36. decimal TotalFee = decimal.Parse(function.CheckNum(jsonObj["total_fee"].ToString()));
  37. WebCMSEntities db = new WebCMSEntities();
  38. ConsumerOrderForNo forNo = db.ConsumerOrderForNo.FirstOrDefault(m => m.OrderNo == OrderNo);
  39. if (forNo != null)
  40. {
  41. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == forNo.OrderIds && m.Status == 0);
  42. if (order != null)
  43. {
  44. order.Status = 1;
  45. order.UpdateDate = DateTime.Now;
  46. order.PayMoney = order.PayMoney;
  47. order.MaxDivi = order.MaxDivi;
  48. db.SaveChanges();
  49. RedisDbconn.Instance.AddList("ConsumerOrdersStat", order.Id);
  50. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:List", order.Id.ToString());
  51. RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:" + order.MerchantId, order);
  52. // ConsumerOrdersStatService.Instance.Stat(order);
  53. }
  54. }
  55. db.Dispose();
  56. }
  57. else
  58. {
  59. op = false;
  60. }
  61. }
  62. }
  63. }
  64. }