MerchantConfirmService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using MySystem.PxcModels;
  6. using Library;
  7. using LitJson;
  8. namespace MySystem
  9. {
  10. public class MerchantConfirmService
  11. {
  12. public readonly static MerchantConfirmService Instance = new MerchantConfirmService();
  13. private MerchantConfirmService()
  14. { }
  15. public void Start(string MerchantIdString, int Kind = 0)
  16. {
  17. try
  18. {
  19. int MerchantId = int.Parse(function.CheckInt(MerchantIdString));
  20. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  21. PxcModels.MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  22. PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  23. if (AddInfo != null && merchant != null)
  24. {
  25. string BusinessCode = AddInfo.BusinessCode;
  26. if (string.IsNullOrEmpty(BusinessCode))
  27. {
  28. BusinessCode = "KXS" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
  29. AddInfo.BusinessCode = BusinessCode;
  30. }
  31. merchant.LoginPwd = function.MD532(AddInfo.MobilePhone.Substring(5));
  32. PxcModels.MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
  33. if (query == null)
  34. {
  35. query = new PxcModels.MerchantParamSet();
  36. query.IsAll = 1;
  37. db.MerchantParamSet.Add(query);
  38. db.SaveChanges();
  39. RedisDbconn.Instance.Set("MerchantParamSet:" + MerchantId, query);
  40. }
  41. PxcModels.MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
  42. if (merchantForMobile == null)
  43. {
  44. merchantForMobile = db.MerchantForMobile.Add(new PxcModels.MerchantForMobile()
  45. {
  46. Mobile = AddInfo.MobilePhone,
  47. }).Entity;
  48. db.SaveChanges();
  49. }
  50. merchantForMobile.MerchantId = MerchantId;
  51. db.SaveChanges();
  52. List<MerchantInfo> merchants = RedisDbconn.Instance.GetList<MerchantInfo>("MerchantList:" + merchant.UserId, 1, 10000000);
  53. //微信
  54. if (Kind == 0 || Kind == 2)
  55. {
  56. string result = new WeChatFunction().MerchantCreate(AddInfo, merchant);
  57. if (result.Contains("\"applyment_id\":"))
  58. {
  59. JsonData jsonObj = JsonMapper.ToObject(result);
  60. AddInfo.ApplymentId = jsonObj["applyment_id"].ToString();
  61. AddInfo.Status = 0;
  62. db.SaveChanges();
  63. List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("MerchantSignList", 1, 10000000);
  64. bool op = signs.Any(m => m.BusinessCode == BusinessCode);
  65. if (!op)
  66. {
  67. RedisDbconn.Instance.AddList("WeChatSignList", new MerchantSign()
  68. {
  69. BusinessCode = BusinessCode,
  70. MerchantAddInfoId = MerchantId,
  71. Status = ""
  72. });
  73. }
  74. signs.Clear();
  75. if (merchants.Any(m => m.Id == merchant.Id) == false)
  76. {
  77. RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
  78. }
  79. else
  80. {
  81. PxcModels.MerchantAddInfo merchantAddInfo = RedisDbconn.Instance.Get<PxcModels.MerchantAddInfo>("MerchantAddInfo:" + MerchantId);
  82. if (merchantAddInfo != null)
  83. {
  84. merchantAddInfo.ApplymentId = AddInfo.ApplymentId;
  85. merchantAddInfo.Status = AddInfo.Status;
  86. RedisDbconn.Instance.Set("MerchantAddInfo:" + MerchantId, merchantAddInfo);
  87. }
  88. }
  89. }
  90. else if (result.Contains("\"message\":"))
  91. {
  92. JsonData jsonObj = JsonMapper.ToObject(result);
  93. AddInfo.Status = -1;
  94. merchant.Status = -1;
  95. string Season = function.CheckNull(AddInfo.SeoDescription);
  96. if (string.IsNullOrEmpty(Season))
  97. {
  98. Season = "WeChat:" + jsonObj["message"].ToString() + ";";
  99. }
  100. else
  101. {
  102. Season = Regex.Replace(Season, "WeChat:.*?;", "");
  103. Season += "WeChat:" + jsonObj["message"].ToString() + ";";
  104. }
  105. AddInfo.SeoDescription = Season;
  106. db.SaveChanges();
  107. if (merchants.Any(m => m.Id == merchant.Id) == false)
  108. {
  109. RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
  110. }
  111. else
  112. {
  113. PxcModels.MerchantAddInfo merchantAddInfo = RedisDbconn.Instance.Get<PxcModels.MerchantAddInfo>("MerchantAddInfo:" + MerchantId);
  114. if (merchantAddInfo != null)
  115. {
  116. merchantAddInfo.SeoDescription = AddInfo.SeoDescription;
  117. merchantAddInfo.Status = AddInfo.Status;
  118. RedisDbconn.Instance.Set("MerchantAddInfo:" + MerchantId, merchantAddInfo);
  119. }
  120. }
  121. List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("WeChatSignList", 1, 10000000);
  122. MerchantSign sign = signs.FirstOrDefault(m => m.BusinessCode == BusinessCode);
  123. if (sign != null)
  124. {
  125. signs.Remove(sign);
  126. RedisDbconn.Instance.Clear("WeChatSignList");
  127. RedisDbconn.Instance.AddList("WeChatSignList", signs.ToArray());
  128. }
  129. }
  130. }
  131. //支付宝
  132. if (Kind == 0 || Kind == 1)
  133. {
  134. bool checkAlipay = true;
  135. string content = new AlipayFunction().GetBatchNo(AddInfo.CreateMan, AddInfo.IdCardName, AddInfo.MobilePhone, AddInfo.ContactEmail);
  136. JsonData json = JsonMapper.ToObject(content);
  137. if (json["alipay_open_agent_create_response"]["code"].ToString() == "10000")
  138. {
  139. string batch_no = json["alipay_open_agent_create_response"]["batch_no"].ToString();
  140. string Qualifications = AddInfo.Qualifications;
  141. if (!string.IsNullOrEmpty(Qualifications))
  142. {
  143. Qualifications = function.getPath("/bsserver_com" + Qualifications);
  144. }
  145. content = new AlipayFunction().CommonSign(batch_no, AddInfo.UpdateMan, AddInfo.LicenseNumber, function.getPath("/bsserver_com" + AddInfo.LicenseCopy), Qualifications);
  146. json = JsonMapper.ToObject(content);
  147. if (json["alipay_open_agent_common_sign_response"]["code"].ToString() == "10000")
  148. {
  149. content = new AlipayFunction().CommonSignConfirm(batch_no);
  150. json = JsonMapper.ToObject(content);
  151. if (json["alipay_open_agent_commonsign_confirm_response"]["code"].ToString() == "10000")
  152. {
  153. AddInfo.QueryCount = 0;
  154. AddInfo.SeoTitle = batch_no;
  155. db.SaveChanges();
  156. List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("MerchantSignList", 1, 10000000);
  157. bool op = signs.Any(m => m.BusinessCode == batch_no);
  158. if (!op)
  159. {
  160. RedisDbconn.Instance.AddList("AlipaySignList", new MerchantSign()
  161. {
  162. BusinessCode = batch_no,
  163. MerchantAddInfoId = MerchantId,
  164. Status = ""
  165. });
  166. }
  167. signs.Clear();
  168. if (merchants.Any(m => m.Id == merchant.Id) == false)
  169. {
  170. RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
  171. }
  172. }
  173. else
  174. {
  175. checkAlipay = false;
  176. }
  177. }
  178. else
  179. {
  180. checkAlipay = false;
  181. }
  182. }
  183. else
  184. {
  185. checkAlipay = false;
  186. }
  187. if (!checkAlipay)
  188. {
  189. JsonData jsonObj = JsonMapper.ToObject(content);
  190. AddInfo.QueryCount = -1;
  191. merchant.Status = -1;
  192. string Season = function.CheckNull(AddInfo.SeoDescription);
  193. if (string.IsNullOrEmpty(Season))
  194. {
  195. Season = "Alipay:" + jsonObj["alipay_open_agent_create_response"]["sub_msg"].ToString() + ";";
  196. }
  197. else
  198. {
  199. Season = Regex.Replace(Season, "Alipay:.*?;", "");
  200. Season = "Alipay:" + jsonObj["alipay_open_agent_create_response"]["sub_msg"].ToString() + ";" + Season;
  201. }
  202. AddInfo.SeoDescription = Season;
  203. db.SaveChanges();
  204. if (merchants.Any(m => m.Id == merchant.Id) == false)
  205. {
  206. RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
  207. }
  208. else
  209. {
  210. PxcModels.MerchantAddInfo merchantAddInfo = RedisDbconn.Instance.Get<PxcModels.MerchantAddInfo>("MerchantAddInfo:" + MerchantId);
  211. if (merchantAddInfo != null)
  212. {
  213. merchantAddInfo.SeoDescription = AddInfo.SeoDescription;
  214. merchantAddInfo.QueryCount = AddInfo.QueryCount;
  215. RedisDbconn.Instance.Set("MerchantAddInfo:" + MerchantId, merchantAddInfo);
  216. }
  217. }
  218. List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("AlipaySignList", 1, 10000000);
  219. MerchantSign sign = signs.FirstOrDefault(m => m.BusinessCode == BusinessCode);
  220. if (sign != null)
  221. {
  222. signs.Remove(sign);
  223. RedisDbconn.Instance.Clear("AlipaySignList");
  224. RedisDbconn.Instance.AddList("AlipaySignList", signs.ToArray());
  225. }
  226. }
  227. }
  228. }
  229. db.Dispose();
  230. }
  231. catch (Exception ex)
  232. {
  233. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
  234. }
  235. }
  236. }
  237. }