CheckWeChatSignService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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)
  56. {
  57. if(string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>("AgentBrhCode:" + merchantadd.AgentName)))
  58. {
  59. BrhCode = HaodaParam.BrhCode;
  60. }
  61. else
  62. {
  63. BrhCode = RedisDbconn.Instance.Get<string>("AgentBrhCode:" + merchantadd.AgentName);
  64. }
  65. }
  66. //查询商户审核状态
  67. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(BrhCode, query.MerchantNo, merchantadd.BrandId, merchantadd.AgentName);
  68. returnInfo = returnInfo.Replace("null", "\"\"");
  69. JsonData dic = JsonMapper.ToObject(returnInfo);
  70. if(dic["resultCode"].ToString() == "1")
  71. {
  72. //审核成功(1- 待审核 2 -审核中 3 -审核被拒绝 4 -审核通过 6 -待复核)
  73. if (dic["data"]["code"].ToString() == "4")// && !string.IsNullOrEmpty(dic["data"]["storeNo"].ToString()) && !string.IsNullOrEmpty(dic["data"]["outMchtNo"].ToString()))
  74. {
  75. //查询商户是否存在
  76. if (merchantadd != null)
  77. {
  78. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == mId);
  79. merchantadd.StoreNo = dic["data"]["storeNo"].ToString();
  80. merchantadd.HdStatus = 1; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  81. merchantadd.OutMchtNo = dic["data"]["outMchtNo"].ToString();
  82. if (merchantadd.BrandId == 1)
  83. {
  84. merchantadd.Status = 2;
  85. merchantadd.QueryCount = 2;
  86. merchant.Status = 2;
  87. merchant.QueryCount = 2;
  88. merchantadd.HdPassDate = DateTime.Parse(dic["data"]["time"].ToString());
  89. MerchantAddInfo mainMer = db.MerchantAddInfo.FirstOrDefault(m => m.Id == merchantadd.ParentId);
  90. if(mainMer != null)
  91. {
  92. merchantadd.StoreNo = mainMer.StoreNo;
  93. }
  94. PosPushDataNewHelper.Bind(merchantadd, merchant);
  95. }
  96. else
  97. {
  98. if (merchant != null)
  99. {
  100. merchant.Status = 1;
  101. }
  102. //商户开通分账
  103. JsonData Info = JsonMapper.ToObject(HaoDaHelper.Instance.OpenDivideAccounts(merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
  104. //开通失败
  105. if (Info["resultCode"].ToString() == "0")
  106. {
  107. merchantadd.Status = -1;
  108. merchantadd.WeChatRemark = Info["errorDesc"].ToString();
  109. }
  110. //开通成功
  111. if (Info["resultCode"].ToString() == "1")
  112. {
  113. merchantadd.OpenAct = 1;//是否开通分账(1 是 0 否)
  114. merchantadd.HdStatus = 2; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  115. //分账接收方签约
  116. JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.DivideAccountsSign(AppConfig.Haoda.AcctNo, merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
  117. //失败
  118. if (Infos["resultCode"].ToString() == "0")
  119. {
  120. merchantadd.WeChatRemark = Infos["errorDesc"].ToString();
  121. }
  122. //成功
  123. else
  124. {
  125. merchantadd.HdStatus = 3; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  126. if (!string.IsNullOrEmpty(merchantadd.ToAcctNo))
  127. {
  128. if (!merchantadd.ToAcctNo.Contains("," + AppConfig.Haoda.AcctNo + ","))
  129. {
  130. merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
  131. }
  132. }
  133. else
  134. {
  135. merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
  136. }
  137. merchantadd.HdPassDate = DateTime.Now;
  138. }
  139. }
  140. //开户意愿申请
  141. RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", mId);
  142. RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", mId);
  143. }
  144. db.SaveChanges();
  145. //创客账号
  146. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  147. string pwd = merchantadd.MobilePhone.Substring(5);
  148. merchant.LoginPwd = function.MD532(pwd);
  149. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == merchantadd.MobilePhone);
  150. if (info == null)
  151. {
  152. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  153. {
  154. LoginMobile = merchantadd.MobilePhone,
  155. }).Entity;
  156. db1.SaveChanges();
  157. }
  158. info.LoginPwd = function.MD532(pwd);
  159. db1.SaveChanges();
  160. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == merchantadd.Id && m.Kind == 2);
  161. if (infolink == null)
  162. {
  163. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  164. {
  165. LoginId = info.Id,
  166. MerchantId = merchantadd.Id,
  167. Kind = 2,
  168. }).Entity;
  169. db1.SaveChanges();
  170. }
  171. db1.Dispose();
  172. if (merchantadd.BrandId == 1 && !string.IsNullOrEmpty(merchantadd.CybMakerCode))
  173. {
  174. SortedList<string, string> obj = new SortedList<string, string>();
  175. obj.Add("bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  176. obj.Add("merch_no", merchantadd.MchtNo);
  177. obj.Add("name", merchantadd.CertMerchantName);
  178. string IdCardNumber = merchantadd.IdCardNumber;
  179. if(!string.IsNullOrEmpty(IdCardNumber))
  180. {
  181. IdCardNumber = IdCardNumber.Substring(0, 6) + "**********" + IdCardNumber.Substring(IdCardNumber.Length - 4);
  182. }
  183. obj.Add("supplement_info", IdCardNumber);
  184. obj.Add("mobile", merchantadd.MobilePhone);
  185. obj.Add("maker_code", merchantadd.CybMakerCode);
  186. PushHelper.Instance.Do(obj);
  187. }
  188. }
  189. }
  190. //审核被拒绝
  191. else if (dic["data"]["code"].ToString() == "3")
  192. {
  193. if (merchantadd != null)
  194. {
  195. string WeChatRemark = dic["data"]["option"].ToString();
  196. if (WeChatRemark.Contains("租赁协议") && WeChatRemark.Contains("水电煤") && WeChatRemark.Contains("门头合影") && WeChatRemark.Contains("下载地址"))
  197. {
  198. WeChatRemark = "门头不一致需补充 “名称不一致说明函”";
  199. }
  200. if (WeChatRemark.Contains("盒伙人在门头合影"))
  201. {
  202. WeChatRemark = "门头不一致需补充 “名称不一致说明函”";
  203. }
  204. if (WeChatRemark.Contains("不支持跨商户进件"))
  205. {
  206. WeChatRemark = "该商户已注册,错误指令【404】";
  207. }
  208. merchantadd.WeChatRemark = WeChatRemark;
  209. merchantadd.Status = -1;
  210. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == mId);
  211. if (merchant != null)
  212. {
  213. merchant.Status = -1;
  214. }
  215. db.SaveChanges();
  216. }
  217. }
  218. else
  219. {
  220. return "wait";
  221. }
  222. }
  223. else
  224. {
  225. return "wait";
  226. }
  227. }
  228. catch (Exception ex)
  229. {
  230. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒商户进件状态查询异常");
  231. }
  232. return "";
  233. }
  234. }
  235. }