GetStoreNoHelper.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using System.Threading;
  8. using Microsoft.Extensions.Hosting;
  9. using System.Threading.Tasks;
  10. using LitJson;
  11. /// <summary>
  12. /// 获取商户门店号、微信支付宝商户号
  13. /// </summary>
  14. namespace MySystem
  15. {
  16. public class GetStoreNoHelper
  17. {
  18. public readonly static GetStoreNoHelper Instance = new GetStoreNoHelper();
  19. private GetStoreNoHelper()
  20. {
  21. }
  22. #region
  23. public void Start()
  24. {
  25. Thread th = new Thread(StartDo);
  26. th.IsBackground = true;
  27. th.Start();
  28. }
  29. public void StartDo()
  30. {
  31. while (true)
  32. {
  33. string MerchantId = RedisDbconn.Instance.RPop<string>("UnionPayGetStoreNoQueue");
  34. if (!string.IsNullOrEmpty(MerchantId))
  35. {
  36. DoSomeThing(MerchantId);
  37. Thread.Sleep(2000);
  38. }
  39. else
  40. {
  41. Thread.Sleep(60000);
  42. }
  43. }
  44. }
  45. public void DoSomeThing(string MerchantId)
  46. {
  47. try
  48. {
  49. int Id = int.Parse(function.CheckInt(MerchantId));
  50. WebCMSEntities db = new WebCMSEntities();
  51. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  52. MerchantInfo merInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  53. if (string.IsNullOrEmpty(AddInfo.StoreNo) && string.IsNullOrEmpty(AddInfo.OutMchtNo))
  54. {
  55. var BrhCode = HaodaUnionParam.BrhCode;
  56. if (AddInfo.BrandId == 1)
  57. {
  58. if (AddInfo.BrandId == 1)
  59. {
  60. if(string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>("AgentBrhCode:" + AddInfo.AgentName)))
  61. {
  62. BrhCode = HaodaParam.BrhCode;
  63. }
  64. else
  65. {
  66. BrhCode = RedisDbconn.Instance.Get<string>("AgentBrhCode:" + AddInfo.AgentName);
  67. }
  68. }
  69. }
  70. //查询商户审核状态
  71. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(BrhCode, AddInfo.MchtNo, AddInfo.BrandId);
  72. var check = false;
  73. JsonData jsonObj = JsonMapper.ToObject(returnInfo);
  74. if (jsonObj["resultCode"].ToString() == "1")
  75. {
  76. var StoreNo = jsonObj["data"]["storeNo"].ToString();
  77. var OutMchtNo = jsonObj["data"]["outMchtNo"].ToString();
  78. if (!string.IsNullOrEmpty(StoreNo) && !string.IsNullOrEmpty(OutMchtNo))
  79. {
  80. AddInfo.StoreNo = StoreNo;
  81. AddInfo.OutMchtNo = OutMchtNo;
  82. db.SaveChanges();
  83. }
  84. //查询实名认证状态
  85. var result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo, AddInfo.BrandId);
  86. JsonData jsonData = JsonMapper.ToObject(result);
  87. if (jsonData["resultCode"].ToString() == "1")
  88. {
  89. var AliMerchantId = jsonObj["aliMerchantId"].ToString();
  90. var WeChatMerchantId = jsonObj["wechatMerchantId"].ToString();
  91. if (!string.IsNullOrEmpty(AliMerchantId) && !string.IsNullOrEmpty(WeChatMerchantId))
  92. {
  93. AddInfo.AliMerchantId = AliMerchantId;
  94. AddInfo.WeChatMerchantId = WeChatMerchantId;
  95. db.SaveChanges();
  96. }
  97. check = true;
  98. }
  99. }
  100. if (check)
  101. {
  102. AddInfo.Status = 0;
  103. merInfo.Status = 0;
  104. db.SaveChanges();
  105. }
  106. else
  107. {
  108. RedisDbconn.Instance.AddList("UnionPayGetStoreNoQueue", MerchantId.ToString());
  109. }
  110. }
  111. db.Dispose();
  112. }
  113. catch (Exception ex)
  114. {
  115. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取商户门店号队列异常");
  116. }
  117. }
  118. #endregion
  119. }
  120. }