AlipayPayBackFeeService.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using MySystem.Models.Main;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. public class AlipayPayBackFeeService
  12. {
  13. public readonly static AlipayPayBackFeeService Instance = new AlipayPayBackFeeService();
  14. private AlipayPayBackFeeService()
  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. bool op = true;
  25. while (op)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("AlipayCallBack2");
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. try
  31. {
  32. sloveAlipayCallBack(content);
  33. }
  34. catch(Exception ex)
  35. {
  36. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "直联支付宝支付回调异常");
  37. }
  38. }
  39. else
  40. {
  41. Thread.Sleep(2000);
  42. }
  43. }
  44. }
  45. public void sloveAlipayCallBack(string content)
  46. {
  47. JsonData jsonObj = JsonMapper.ToObject(content);
  48. string OrderNo = jsonObj["out_trade_no"].ToString();
  49. string TradeNo = jsonObj["transaction_id"].ToString();
  50. decimal TotalFee = decimal.Parse(function.CheckNum(jsonObj["total_fee"].ToString()));
  51. WebCMSEntities db = new WebCMSEntities();
  52. MerchantDepositOrder order = db.MerchantDepositOrder.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 0);
  53. if(order != null)
  54. {
  55. order.Status = 1;
  56. order.UpdateDate = DateTime.Now;
  57. MerchantInfo mer = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId);
  58. if(mer != null)
  59. {
  60. mer.IsAct = 1;
  61. }
  62. db.SaveChanges();
  63. }
  64. db.Dispose();
  65. }
  66. }
  67. }