MerchantConfirmService.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using LitJson;
  8. using System.Threading;
  9. namespace MySystem
  10. {
  11. public class MerchantConfirmService
  12. {
  13. public readonly static MerchantConfirmService Instance = new MerchantConfirmService();
  14. private MerchantConfirmService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartListen);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartListen()
  23. {
  24. // while (true)
  25. // {
  26. // string content = RedisDbconn.Instance.RPop<string>("MerchantConfirmQueue");
  27. // if (!string.IsNullOrEmpty(content))
  28. // {
  29. // try
  30. // {
  31. // JsonData jsonObj = JsonMapper.ToObject(content);
  32. // int MerchantId = int.Parse(jsonObj["MerchantId"].ToString());
  33. // StartDo(MerchantId);
  34. // }
  35. // catch (Exception ex)
  36. // {
  37. // function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒商户进件异常");
  38. // }
  39. // }
  40. // else
  41. // {
  42. // Thread.Sleep(2000);
  43. // }
  44. // }
  45. // StartDo(1);//开通分账和添加分账接收方
  46. while (true)
  47. {
  48. StartDo(571);
  49. // StartDo(580);
  50. // StartDo(581);//小微
  51. Thread.Sleep(20000);
  52. }
  53. // StartDo(581);//小微
  54. }
  55. public void StartDo(int MerchantId)
  56. {
  57. WebCMSEntities db = new WebCMSEntities();
  58. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  59. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  60. if (AddInfo != null && merchant != null)
  61. {
  62. string BusinessCode = AddInfo.BusinessCode;
  63. if (string.IsNullOrEmpty(BusinessCode))
  64. {
  65. BusinessCode = "LKB" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
  66. AddInfo.BusinessCode = BusinessCode;
  67. }
  68. merchant.LoginPwd = function.MD532(AddInfo.MobilePhone.Substring(5));
  69. MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
  70. if (query == null)
  71. {
  72. query = new MerchantParamSet();
  73. query.IsAll = 1;
  74. db.MerchantParamSet.Add(query);
  75. db.SaveChanges();
  76. }
  77. MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
  78. if (merchantForMobile == null)
  79. {
  80. merchantForMobile = db.MerchantForMobile.Add(new MerchantForMobile()
  81. {
  82. Mobile = AddInfo.MobilePhone,
  83. }).Entity;
  84. db.SaveChanges();
  85. }
  86. merchantForMobile.MerchantId = MerchantId;
  87. db.SaveChanges();
  88. if (AddInfo.Status <= 0)
  89. {
  90. //好哒新建商户
  91. string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
  92. JsonData jsonObj = JsonMapper.ToObject(result);
  93. //创建成功
  94. if (jsonObj["resultCode"].ToString() == "1")
  95. {
  96. AddInfo.WeChatRemark = "";
  97. AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  98. AddInfo.Status = 0;
  99. merchant.Status = 0;
  100. db.SaveChanges();
  101. QueryMerchantStatus queryMerchantStatus = new QueryMerchantStatus();
  102. queryMerchantStatus.MerchantId = MerchantId.ToString();
  103. queryMerchantStatus.MerchantNo = AddInfo.MchtNo;
  104. RedisDbconn.Instance.AddList("WeChatSignQueue", queryMerchantStatus);
  105. }
  106. //创建失败
  107. else
  108. {
  109. AddInfo.Status = -1;
  110. merchant.Status = -1;
  111. AddInfo.WeChatRemark = jsonObj["errorDesc"].ToString();
  112. db.SaveChanges();
  113. }
  114. }
  115. }
  116. db.Dispose();
  117. }
  118. }
  119. }