HaoDaFeeHelper.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Linq;
  6. using Microsoft.Extensions.Hosting;
  7. using MySystem;
  8. using MySystem.Models;
  9. using LitJson;
  10. using Library;
  11. using MySystem.Models.Main;
  12. public class HaoDaFeeHelper
  13. {
  14. public readonly static HaoDaFeeHelper Instance = new HaoDaFeeHelper();
  15. private HaoDaFeeHelper()
  16. {
  17. }
  18. public void Start()
  19. {
  20. Thread th = new Thread(StartDo);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. private void StartDo()
  25. {
  26. while (true)
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("HaoDaFeeQueue");
  29. if (!string.IsNullOrEmpty(content))
  30. {
  31. SetFee(int.Parse(content));
  32. }
  33. else
  34. {
  35. Thread.Sleep(10000);
  36. }
  37. }
  38. }
  39. public void SetFee(int Id)
  40. {
  41. try
  42. {
  43. WebCMSEntities db = new WebCMSEntities();
  44. MerchantAddInfo addinfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id);
  45. MerchantInfo info = db.MerchantInfo.FirstOrDefault(m => m.Id == Id);
  46. if(info != null && addinfo != null)
  47. {
  48. string FeeRate = addinfo.FeeRate;
  49. if(string.IsNullOrEmpty(FeeRate)) FeeRate = "0.38";
  50. string result = HaoDaHelper.Instance.SetFee(addinfo.MchtNo, FeeRate, addinfo.BrandId, addinfo.AgentName);
  51. JsonData jsonObj = JsonMapper.ToObject(result);
  52. result = result.Replace("null", "\"\"");
  53. int Status = 0;
  54. string Remark = "";
  55. string resultCode = jsonObj["resultCode"].ToString();
  56. if(resultCode != "1")
  57. {
  58. Remark = jsonObj["errorDesc"].ToString();
  59. }
  60. else
  61. {
  62. Status = 1;
  63. }
  64. db.MerchantFeeRecord.Add(new MerchantFeeRecord()
  65. {
  66. Status = Status,
  67. CreateDate = DateTime.Now,
  68. SettleFee = FeeRate,
  69. MerchantId = addinfo.Id,
  70. UserId = info.UserId,
  71. Remark = Remark,
  72. });
  73. db.SaveChanges();
  74. }
  75. db.Dispose();
  76. }
  77. catch (Exception ex)
  78. {
  79. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "修改商户费率异常");
  80. }
  81. }
  82. }