GetStoreNoHelper.cs 4.4 KB

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