ConsumerOrdersReturnDoService.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using MySystem.PxcModels;
  7. namespace MySystem
  8. {
  9. public class ConsumerOrdersReturnDoService
  10. {
  11. public readonly static ConsumerOrdersReturnDoService Instance = new ConsumerOrdersReturnDoService();
  12. private ConsumerOrdersReturnDoService()
  13. { }
  14. public void Start(JobMqMsg jobInfo)
  15. {
  16. string content = "";
  17. try
  18. {
  19. DoRefund();
  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 DoRefund()
  41. {
  42. bool op = true;
  43. while (op)
  44. {
  45. RefundItem item = RedisDbconn.Instance.RPop<RefundItem>("ConsumerOrdersStat");
  46. if (item != null)
  47. {
  48. bool success = false;
  49. WebCMSEntities db = new WebCMSEntities();
  50. if (item.PayMode == 1)
  51. {
  52. string resultString = new AlipayFunction().Refund(item.TradeNo, item.RefundMoney.ToString("f2"), "202202BB4fc8c2c03c914f2f87b6c678a77d7C03");
  53. JsonData jsonObj = JsonMapper.ToObject(resultString);
  54. if (jsonObj["alipay_trade_refund_response"]["code"].ToString() == "10000")
  55. {
  56. success = true;
  57. }
  58. }
  59. else if (item.PayMode == 2)
  60. {
  61. string AppId = "wxe2c051b3e46c0f6f";
  62. string MchId = "1611167423";
  63. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new MerchantAddInfo();
  64. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new MerchantInfo();
  65. string SubMchId = merchantAdd.SubMchid;
  66. string Description = merchant.Name;
  67. string RefundNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  68. Dictionary<string, string> dic = new WeChatFunction().Refund(AppId, MchId, SubMchId, item.RefundMoney, item.TotalMoney, item.TradeNo, RefundNo);
  69. if (dic.ContainsKey("status"))
  70. {
  71. if (dic["status"] == "SUCCESS")
  72. {
  73. success = true;
  74. }
  75. }
  76. }
  77. if (success)
  78. {
  79. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == item.ProfitId);
  80. if (order != null)
  81. {
  82. order.Status = 1;
  83. db.SaveChanges();
  84. }
  85. }
  86. db.Dispose();
  87. }
  88. else
  89. {
  90. op = false;
  91. }
  92. }
  93. }
  94. }
  95. }