AlipayPayBackService.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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(JobMqMsg jobInfo)
  15. {
  16. string content = "";
  17. try
  18. {
  19. dosomething();
  20. // string Msg = "success";
  21. // jobInfo.Status = Msg == "success" ? 1 : 0;
  22. // jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
  23. // RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
  24. }
  25. catch (Exception ex)
  26. {
  27. if (!string.IsNullOrEmpty(content))
  28. {
  29. Dictionary<string, string> data = new Dictionary<string, string>();
  30. data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  31. data.Add("ErrMsg", ex.ToString());
  32. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
  33. }
  34. else
  35. {
  36. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
  37. }
  38. }
  39. }
  40. private void dosomething()
  41. {
  42. bool op = true;
  43. while (op)
  44. {
  45. string content = RedisDbconn.Instance.RPop<string>("PayCallBack");
  46. if (!string.IsNullOrEmpty(content))
  47. {
  48. JsonData jsonObj = JsonMapper.ToObject(content);
  49. string OrderNo = jsonObj["out_trade_no"].ToString();
  50. string TradeNo = jsonObj["transaction_id"].ToString();
  51. decimal TotalFee = decimal.Parse(function.CheckNum(jsonObj["total_fee"].ToString()));
  52. WebCMSEntities db = new WebCMSEntities();
  53. ConsumerOrderForNo forNo = db.ConsumerOrderForNo.FirstOrDefault(m => m.OrderNo == OrderNo);
  54. if (forNo != null)
  55. {
  56. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == forNo.OrderIds && m.Status == 0);
  57. if (order != null)
  58. {
  59. order.Status = 1;
  60. order.UpdateDate = DateTime.Now;
  61. order.PayMoney = order.PayMoney;
  62. order.MaxDivi = order.MaxDivi;
  63. db.SaveChanges();
  64. RedisDbconn.Instance.AddList("ConsumerOrdersStat", order.Id);
  65. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:List", order.Id.ToString());
  66. RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:" + order.MerchantId, order);
  67. // ConsumerOrdersStatService.Instance.Stat(order);
  68. }
  69. }
  70. db.Dispose();
  71. }
  72. else
  73. {
  74. op = false;
  75. }
  76. }
  77. }
  78. }
  79. }