MerchantConfirmService.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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>("MerchantConfirmHdQueue");
  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. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒商户进件异常");
  38. }
  39. }
  40. else
  41. {
  42. Thread.Sleep(2000);
  43. }
  44. }
  45. }
  46. public void StartDo(int MerchantId)
  47. {
  48. WebCMSEntities db = new WebCMSEntities();
  49. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  50. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  51. if (AddInfo.HdStatus >= 1)
  52. {
  53. //开户意愿申请
  54. if (AddInfo.Status == -1 && merchant.Status == -1)
  55. {
  56. AddInfo.WeChatSignUrl = "";
  57. AddInfo.WeChatRemark = "";
  58. AddInfo.Status = 0;
  59. RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", AddInfo.Id);
  60. }
  61. if (AddInfo.QueryCount == -1 && merchant.QueryCount == -1)
  62. {
  63. AddInfo.AlipaySignUrl = "";
  64. AddInfo.AlipayRemark = "";
  65. AddInfo.QueryCount = 0;
  66. RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", AddInfo.Id);
  67. }
  68. db.SaveChanges();
  69. }
  70. else
  71. {
  72. if (AddInfo != null && merchant != null)
  73. {
  74. string BusinessCode = AddInfo.BusinessCode;
  75. if (string.IsNullOrEmpty(BusinessCode))
  76. {
  77. BusinessCode = "LKB" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
  78. AddInfo.BusinessCode = BusinessCode;
  79. }
  80. MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
  81. if (query == null)
  82. {
  83. query = new MerchantParamSet();
  84. query.IsAll = 1;
  85. db.MerchantParamSet.Add(query);
  86. db.SaveChanges();
  87. }
  88. MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
  89. if (merchantForMobile == null)
  90. {
  91. merchantForMobile = db.MerchantForMobile.Add(new MerchantForMobile()
  92. {
  93. Mobile = AddInfo.MobilePhone,
  94. }).Entity;
  95. db.SaveChanges();
  96. }
  97. merchantForMobile.MerchantId = MerchantId;
  98. db.SaveChanges();
  99. if (AddInfo.Status <= 0)
  100. {
  101. //好哒新建商户
  102. string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo), AddInfo.BrandId);
  103. JsonData jsonObj = JsonMapper.ToObject(result);
  104. //创建成功
  105. if (jsonObj["resultCode"].ToString() == "1")
  106. {
  107. AddInfo.WeChatRemark = "";
  108. if (string.IsNullOrEmpty(AddInfo.MchtNo))
  109. {
  110. AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  111. }
  112. AddInfo.Status = 0;
  113. AddInfo.HdStatus = 0; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  114. merchant.Status = 0;
  115. db.SaveChanges();
  116. // QueryMerchantStatus queryMerchantStatus = new QueryMerchantStatus();
  117. // queryMerchantStatus.MerchantId = MerchantId.ToString();
  118. // queryMerchantStatus.MerchantNo = AddInfo.MchtNo;
  119. // RedisDbconn.Instance.AddList("WeChatSignHdQueue", queryMerchantStatus);
  120. }
  121. //创建失败
  122. else
  123. {
  124. AddInfo.Status = -1;
  125. merchant.Status = -1;
  126. string errorDesc = jsonObj["errorDesc"].ToString();
  127. if (errorDesc.Contains("租赁协议") && errorDesc.Contains("水电煤") && errorDesc.Contains("门头合影") && errorDesc.Contains("下载地址"))
  128. {
  129. errorDesc = "门头不一致,需上传名称不一致说明函";
  130. }
  131. AddInfo.WeChatRemark = errorDesc;
  132. // if (string.IsNullOrEmpty(AddInfo.MchtNo))
  133. // {
  134. // if (jsonObj.ToJson().Contains("mchtNo"))
  135. // {
  136. // AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  137. // }
  138. // }
  139. db.SaveChanges();
  140. }
  141. }
  142. }
  143. }
  144. db.Dispose();
  145. }
  146. }
  147. }