HaoDaFeeHelper.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. int Status = 0;
  53. string Remark = "";
  54. string resultCode = jsonObj["resultCode"].ToString();
  55. if(resultCode != "0")
  56. {
  57. Remark = jsonObj["errorDesc"].ToString();
  58. }
  59. else
  60. {
  61. Status = 1;
  62. }
  63. db.MerchantFeeRecord.Add(new MerchantFeeRecord()
  64. {
  65. Status = Status,
  66. CreateDate = DateTime.Now,
  67. SettleFee = FeeRate,
  68. MerchantId = addinfo.Id,
  69. UserId = info.UserId,
  70. Remark = Remark,
  71. });
  72. db.SaveChanges();
  73. }
  74. db.Dispose();
  75. }
  76. catch (Exception ex)
  77. {
  78. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "修改商户费率异常");
  79. }
  80. }
  81. }