GetStoreNoHelper.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. //查询商户审核状态
  56. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(HaoDaHelper.BrhCode, AddInfo.MchtNo);
  57. var check = false;
  58. JsonData jsonObj = JsonMapper.ToObject(returnInfo);
  59. if (jsonObj["resultCode"].ToString() == "1")
  60. {
  61. var StoreNo = jsonObj["data"]["storeNo"].ToString();
  62. var OutMchtNo = jsonObj["data"]["outMchtNo"].ToString();
  63. if (!string.IsNullOrEmpty(StoreNo) && !string.IsNullOrEmpty(OutMchtNo))
  64. {
  65. AddInfo.StoreNo = StoreNo;
  66. AddInfo.OutMchtNo = OutMchtNo;
  67. db.SaveChanges();
  68. }
  69. //查询实名认证状态
  70. var result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo);
  71. JsonData jsonData = JsonMapper.ToObject(result);
  72. if (jsonData["resultCode"].ToString() == "1")
  73. {
  74. var AliMerchantId = jsonObj["aliMerchantId"].ToString();
  75. var WeChatMerchantId = jsonObj["wechatMerchantId"].ToString();
  76. if (!string.IsNullOrEmpty(AliMerchantId) && !string.IsNullOrEmpty(WeChatMerchantId))
  77. {
  78. AddInfo.AliMerchantId = AliMerchantId;
  79. AddInfo.WeChatMerchantId = WeChatMerchantId;
  80. db.SaveChanges();
  81. }
  82. check = true;
  83. }
  84. }
  85. if (check)
  86. {
  87. AddInfo.Status = 0;
  88. merInfo.Status = 0;
  89. db.SaveChanges();
  90. }
  91. else
  92. {
  93. RedisDbconn.Instance.AddList("UnionPayGetStoreNoQueue", MerchantId.ToString());
  94. }
  95. }
  96. db.Dispose();
  97. }
  98. catch (Exception ex)
  99. {
  100. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取商户门店号队列异常");
  101. }
  102. }
  103. #endregion
  104. }
  105. }