CheckWeChatSignService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 LitJson;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. namespace MySystem
  11. {
  12. public class CheckWeChatSignService
  13. {
  14. public readonly static CheckWeChatSignService Instance = new CheckWeChatSignService();
  15. private CheckWeChatSignService()
  16. { }
  17. public void Start()
  18. {
  19. Thread th = new Thread(StartListen);
  20. th.IsBackground = true;
  21. th.Start();
  22. }
  23. public void StartListen()
  24. {
  25. while (true)
  26. {
  27. DataTable dt = CustomerSqlConn.dtable("select Id,MchtNo from MerchantAddInfo where Id in (select Id from MerchantInfo where Sort=1 and `Status`=0 and QueryCount=0) and MchtNo!='' and MchtNo is not null", AppConfig.Base.SqlConnStr);
  28. foreach (DataRow dr in dt.Rows)
  29. {
  30. StartDo(new QueryMerchantStatus()
  31. {
  32. MerchantId = dr["Id"].ToString(),
  33. MerchantNo = dr["MchtNo"].ToString(),
  34. });
  35. Thread.Sleep(10000);
  36. }
  37. if(Library.ConfigurationManager.EnvironmentFlag == 2)
  38. {
  39. Thread.Sleep(300000);
  40. }
  41. else
  42. {
  43. Thread.Sleep(3600000);
  44. }
  45. }
  46. }
  47. public string StartDo(QueryMerchantStatus query)
  48. {
  49. try
  50. {
  51. var mId = int.Parse(query.MerchantId);
  52. WebCMSEntities db = new WebCMSEntities();
  53. MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == mId);
  54. var BrhCode = HaodaUnionParam.BrhCode;
  55. if (merchantadd.BrandId == 1) BrhCode = HaodaParam.BrhCode;
  56. //查询商户审核状态
  57. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(BrhCode, query.MerchantNo, merchantadd.BrandId, merchantadd.AgentName);
  58. returnInfo = returnInfo.Replace("null", "\"\"");
  59. JsonData dic = JsonMapper.ToObject(returnInfo);
  60. if(dic["resultCode"].ToString() == "1")
  61. {
  62. //审核成功(1- 待审核 2 -审核中 3 -审核被拒绝 4 -审核通过 6 -待复核)
  63. if (dic["data"]["code"].ToString() == "4")// && !string.IsNullOrEmpty(dic["data"]["storeNo"].ToString()) && !string.IsNullOrEmpty(dic["data"]["outMchtNo"].ToString()))
  64. {
  65. //查询商户是否存在
  66. if (merchantadd != null)
  67. {
  68. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == mId);
  69. merchantadd.StoreNo = dic["data"]["storeNo"].ToString();
  70. merchantadd.HdStatus = 1; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  71. merchantadd.OutMchtNo = dic["data"]["outMchtNo"].ToString();
  72. if (merchantadd.BrandId == 1)
  73. {
  74. merchantadd.Status = 2;
  75. merchantadd.QueryCount = 2;
  76. merchant.Status = 2;
  77. merchant.QueryCount = 2;
  78. merchantadd.HdPassDate = DateTime.Parse(dic["data"]["time"].ToString());
  79. MerchantAddInfo mainMer = db.MerchantAddInfo.FirstOrDefault(m => m.Id == merchantadd.ParentId);
  80. if(mainMer != null)
  81. {
  82. merchantadd.StoreNo = mainMer.StoreNo;
  83. }
  84. }
  85. else
  86. {
  87. if (merchant != null)
  88. {
  89. merchant.Status = 1;
  90. }
  91. //商户开通分账
  92. JsonData Info = JsonMapper.ToObject(HaoDaHelper.Instance.OpenDivideAccounts(merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
  93. //开通失败
  94. if (Info["resultCode"].ToString() == "0")
  95. {
  96. merchantadd.Status = -1;
  97. merchantadd.WeChatRemark = Info["errorDesc"].ToString();
  98. }
  99. //开通成功
  100. if (Info["resultCode"].ToString() == "1")
  101. {
  102. merchantadd.OpenAct = 1;//是否开通分账(1 是 0 否)
  103. merchantadd.HdStatus = 2; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  104. //分账接收方签约
  105. JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.DivideAccountsSign(AppConfig.Haoda.AcctNo, merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
  106. //失败
  107. if (Infos["resultCode"].ToString() == "0")
  108. {
  109. merchantadd.WeChatRemark = Infos["errorDesc"].ToString();
  110. }
  111. //成功
  112. else
  113. {
  114. merchantadd.HdStatus = 3; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  115. if (!string.IsNullOrEmpty(merchantadd.ToAcctNo))
  116. {
  117. if (!merchantadd.ToAcctNo.Contains("," + AppConfig.Haoda.AcctNo + ","))
  118. {
  119. merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
  120. }
  121. }
  122. else
  123. {
  124. merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
  125. }
  126. merchantadd.HdPassDate = DateTime.Now;
  127. }
  128. }
  129. //开户意愿申请
  130. RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", mId);
  131. RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", mId);
  132. }
  133. db.SaveChanges();
  134. //创客账号
  135. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  136. string pwd = merchantadd.MobilePhone.Substring(5);
  137. merchant.LoginPwd = function.MD532(pwd);
  138. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == merchantadd.MobilePhone);
  139. if (info == null)
  140. {
  141. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  142. {
  143. LoginMobile = merchantadd.MobilePhone,
  144. }).Entity;
  145. db1.SaveChanges();
  146. }
  147. info.LoginPwd = function.MD532(pwd);
  148. db1.SaveChanges();
  149. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == merchantadd.Id && m.Kind == 2);
  150. if (infolink == null)
  151. {
  152. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  153. {
  154. LoginId = info.Id,
  155. MerchantId = merchantadd.Id,
  156. Kind = 2,
  157. }).Entity;
  158. db1.SaveChanges();
  159. }
  160. db1.Dispose();
  161. if (merchantadd.BrandId == 1 && !string.IsNullOrEmpty(merchantadd.CybMakerCode))
  162. {
  163. SortedList<string, string> obj = new SortedList<string, string>();
  164. obj.Add("bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  165. obj.Add("merch_no", merchantadd.MchtNo);
  166. obj.Add("name", merchantadd.CertMerchantName);
  167. string IdCardNumber = merchantadd.IdCardNumber;
  168. if(!string.IsNullOrEmpty(IdCardNumber))
  169. {
  170. IdCardNumber = IdCardNumber.Substring(0, 6) + "**********" + IdCardNumber.Substring(IdCardNumber.Length - 4);
  171. }
  172. obj.Add("supplement_info", IdCardNumber);
  173. obj.Add("mobile", merchantadd.MobilePhone);
  174. obj.Add("maker_code", merchantadd.CybMakerCode);
  175. PushHelper.Instance.Do(obj);
  176. }
  177. }
  178. }
  179. //审核被拒绝
  180. else if (dic["data"]["code"].ToString() == "3")
  181. {
  182. if (merchantadd != null)
  183. {
  184. string WeChatRemark = dic["data"]["option"].ToString();
  185. if (WeChatRemark.Contains("租赁协议") && WeChatRemark.Contains("水电煤") && WeChatRemark.Contains("门头合影") && WeChatRemark.Contains("下载地址"))
  186. {
  187. WeChatRemark = "门头不一致需补充 “名称不一致说明函”";
  188. }
  189. if (WeChatRemark.Contains("盒伙人在门头合影"))
  190. {
  191. WeChatRemark = "门头不一致需补充 “名称不一致说明函”";
  192. }
  193. if (WeChatRemark.Contains("不支持跨商户进件"))
  194. {
  195. WeChatRemark = "该商户已注册,错误指令【404】";
  196. }
  197. merchantadd.WeChatRemark = WeChatRemark;
  198. merchantadd.Status = -1;
  199. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == mId);
  200. if (merchant != null)
  201. {
  202. merchant.Status = -1;
  203. }
  204. db.SaveChanges();
  205. }
  206. }
  207. else
  208. {
  209. return "wait";
  210. }
  211. }
  212. else
  213. {
  214. return "wait";
  215. }
  216. }
  217. catch (Exception ex)
  218. {
  219. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒商户进件状态查询异常");
  220. }
  221. return "";
  222. }
  223. }
  224. }