MerchantAddInfoController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.Models.Main1;
  11. using MySystem.Service.Main1;
  12. using LitJson;
  13. using Library;
  14. using MySystem.Service.KxsMain;
  15. namespace MySystem.Areas.Api.Controllers.v1.Main1
  16. {
  17. [Area("Api")]
  18. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  19. public class MerchantAddInfoController : BaseController
  20. {
  21. public MerchantAddInfoController(IHttpContextAccessor accessor) : base(accessor)
  22. {
  23. }
  24. #region 进件管理-直连商户列表
  25. [Authorize]
  26. public JsonResult DirectList(string value)
  27. {
  28. value = PublicFunction.DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> Other = new Dictionary<string, object>();
  31. List<Dictionary<string, object>> dataList = DirectListDo(value, out Other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  33. }
  34. private List<Dictionary<string, object>> DirectListDo(string value, out Dictionary<string, object> Other)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体)
  38. string CertMerchantName = data["CertMerchantName"].ToString(); //商户名称
  39. string ServicePhone = data["ServicePhone"].ToString(); //客服电话
  40. string MakerCode = data["MakerCode"].ToString(); //所属创客编号
  41. string WeChatStatus = data["WeChatStatus"].ToString(); //微信状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  42. string AliPayStatus = data["AliPayStatus"].ToString(); //支付宝状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  43. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  44. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  45. string condition = "";
  46. var merIds = MerchantInfoUtil.QuerySenedMerchantId();
  47. condition = " and Id in (" + merIds + ")";
  48. if (!string.IsNullOrEmpty(data["SubjectType"].ToString()))
  49. {
  50. if (data["SubjectType"].ToString() == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  51. if (data["SubjectType"].ToString() == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  52. condition += " and SubjectType='" + SubjectType + "'";
  53. }
  54. if (!string.IsNullOrEmpty(data["CertMerchantName"].ToString()))
  55. {
  56. condition += " and CertMerchantName like '%" + CertMerchantName + "%'";
  57. }
  58. if (!string.IsNullOrEmpty(data["ServicePhone"].ToString()))
  59. {
  60. condition += " and ServicePhone='" + ServicePhone + "'";
  61. }
  62. if (!string.IsNullOrEmpty(data["MakerCode"].ToString()))
  63. {
  64. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  65. condition += " and Id in (" + Ids + ")";
  66. }
  67. if (!string.IsNullOrEmpty(data["WeChatStatus"].ToString()))
  68. {
  69. condition += " and Status=" + WeChatStatus + "";
  70. }
  71. if (!string.IsNullOrEmpty(data["AliPayStatus"].ToString()))
  72. {
  73. condition += " and QueryCount=" + AliPayStatus + "";
  74. }
  75. List<RelationData> relationData = new List<RelationData>();
  76. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  77. Other = new Dictionary<string, object>();
  78. int count = 0;
  79. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  80. foreach (Dictionary<string, object> subdata in source)
  81. {
  82. Dictionary<string, object> curData = new Dictionary<string, object>();
  83. var status = int.Parse(subdata["Status"].ToString());
  84. var queryCount = int.Parse(subdata["QueryCount"].ToString());
  85. //商户Id
  86. var MerchantId = int.Parse(subdata["Id"].ToString());
  87. //主体类型
  88. var subjectType = 0;
  89. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  90. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  91. curData.Add("Id", subdata["Id"].ToString()); //Id
  92. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体)
  93. curData.Add("CertMerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  94. curData.Add("ServicePhone", subdata["ServicePhone"].ToString()); //客服电话
  95. curData.Add("BizStoreAddress", subdata["BizStoreAddress"].ToString()); //门店地址
  96. curData.Add("CreateDate", subdata["CreateDate"].ToString() == "" ? "" : DateTime.Parse(subdata["CreateDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //进件时间
  97. var userInfo = UsersService.Query(MerchantInfoService.Query(MerchantId).UserId);
  98. curData.Add("MakerCode", userInfo.MakerCode); //所属创客编号
  99. curData.Add("RealName", userInfo.RealName); //所属创客姓名
  100. curData.Add("WeChatStatus", status); //微信状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  101. curData.Add("AliPayStatus", queryCount); //支付宝状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  102. dataList.Add(curData);
  103. }
  104. Other.Add("Count", count); //总数
  105. return dataList;
  106. }
  107. #endregion
  108. #region 进件管理-直连查看失败原因
  109. [Authorize]
  110. public JsonResult DirectQueryFailReason(string value)
  111. {
  112. value = PublicFunction.DesDecrypt(value);
  113. JsonData data = JsonMapper.ToObject(value);
  114. Dictionary<string, object> Obj = DirectQueryFailReasonDo(value);
  115. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  116. }
  117. private Dictionary<string, object> DirectQueryFailReasonDo(string value)
  118. {
  119. JsonData data = JsonMapper.ToObject(value);
  120. string MerchantId = data["MerchantId"].ToString(); //商户Id
  121. Dictionary<string, object> Obj = new Dictionary<string, object>();
  122. var query = MerchantAddInfoService.Query(int.Parse(MerchantId));
  123. Obj.Add("HdReason", query.WeChatRemark); //好哒原因
  124. Obj.Add("WeChatReason", query.WeChatRemark); //微信原因
  125. Obj.Add("AlipayReason", query.AlipayRemark); //支付宝原因
  126. return Obj;
  127. }
  128. #endregion
  129. #region 进件管理-直连进件详情
  130. [Authorize]
  131. public JsonResult DirectDetail(string value)
  132. {
  133. value = PublicFunction.DesDecrypt(value);
  134. JsonData data = JsonMapper.ToObject(value);
  135. Dictionary<string, object> Obj = DirectDetailDo(value);
  136. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  137. }
  138. private Dictionary<string, object> DirectDetailDo(string value)
  139. {
  140. JsonData data = JsonMapper.ToObject(value);
  141. string MerchantId = data["MerchantId"].ToString(); //商户Id
  142. Dictionary<string, object> Obj = new Dictionary<string, object>();
  143. Obj = MerchantAddInfoUtil.MerchantAddInfoDetail(int.Parse(MerchantId));
  144. return Obj;
  145. }
  146. #endregion
  147. #region 进件管理-直连提交进件
  148. [Authorize]
  149. public JsonResult DirectSubmit(string value)
  150. {
  151. value = PublicFunction.DesDecrypt(value);
  152. JsonData data = JsonMapper.ToObject(value);
  153. AppResultJson result = DirectSubmitDo(value);
  154. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  155. }
  156. private AppResultJson DirectSubmitDo(string value)
  157. {
  158. JsonData data = JsonMapper.ToObject(value);
  159. string MerchantId = data["MerchantId"].ToString(); //商户Id
  160. var info = MerchantAddInfoUtil.DirectSubmitDo(int.Parse(MerchantId));
  161. if (info == "success")
  162. {
  163. return new AppResultJson() { Status = "1", Info = "成功", Data = info };
  164. }
  165. else
  166. {
  167. return new AppResultJson() { Status = "-1", Info = "失败", Data = info };
  168. }
  169. }
  170. #endregion
  171. #region 商户管理-直连查询商户交易信息
  172. [Authorize]
  173. public JsonResult DirectQueryMerchantTradeInfo(string value)
  174. {
  175. value = PublicFunction.DesDecrypt(value); ;
  176. JsonData data = JsonMapper.ToObject(value);
  177. Dictionary<string, object> Other = new Dictionary<string, object>();
  178. List<Dictionary<string, object>> dataList = DirectQueryMerchantTradeInfoDo(value, out Other);
  179. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  180. }
  181. private List<Dictionary<string, object>> DirectQueryMerchantTradeInfoDo(string value, out Dictionary<string, object> Other)
  182. {
  183. JsonData data = JsonMapper.ToObject(value);
  184. string MerchantName = data["MerchantName"].ToString(); //商户名称
  185. string Mobile = data["Mobile"].ToString(); //手机号码
  186. string MakerCode = data["MakerCode"].ToString(); //所属创客
  187. string AliPID = data["AliPID"].ToString(); //支付宝PID
  188. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  189. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体)
  190. string IsAct = data["IsAct"].ToString(); //激活状态(0 未激活 1 已激活)
  191. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  192. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  193. string condition = "";
  194. var merIds = MerchantInfoUtil.QueryAnyIsOkMerchantId();
  195. condition = " and Id in (" + merIds + ")";
  196. if (!string.IsNullOrEmpty(MerchantName))
  197. {
  198. condition += " and CertMerchantName like '%" + MerchantName + "%'";
  199. }
  200. if (!string.IsNullOrEmpty(Mobile))
  201. {
  202. condition += " and MobilePhone='" + Mobile + "'";
  203. }
  204. if (!string.IsNullOrEmpty(MakerCode))
  205. {
  206. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  207. condition += " and Id in (" + Ids + ")";
  208. }
  209. if (!string.IsNullOrEmpty(AliPID))
  210. {
  211. condition += " and AlipayPid='" + AliPID + "'";
  212. }
  213. if (!string.IsNullOrEmpty(WeChatNo))
  214. {
  215. condition += " and SubMchid='" + WeChatNo + "'";
  216. }
  217. if (!string.IsNullOrEmpty(SubjectType))
  218. {
  219. if (SubjectType == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  220. if (SubjectType == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  221. condition += " and SubjectType='" + SubjectType + "'";
  222. }
  223. if (!string.IsNullOrEmpty(IsAct))
  224. {
  225. var Ids = MerchantInfoUtil.QueryIsActMerchantId(int.Parse(IsAct));
  226. condition += " and Id in (" + Ids + ")";
  227. }
  228. List<RelationData> relationData = new List<RelationData>();
  229. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  230. Other = new Dictionary<string, object>();
  231. int count = 0;
  232. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  233. foreach (Dictionary<string, object> subdata in source)
  234. {
  235. Dictionary<string, object> curData = new Dictionary<string, object>();
  236. //商户Id
  237. var MerchantId = int.Parse(subdata["Id"].ToString());
  238. var merInfo = MerchantInfoService.Query(MerchantId);
  239. var userInfo = UsersService.Query(merInfo.UserId);
  240. curData.Add("MerchantId", subdata["Id"].ToString()); //商户Id
  241. curData.Add("IsAct", merInfo.IsAct); //激活状态(0 未激活 1 已激活)
  242. curData.Add("MerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  243. curData.Add("Mobile", subdata["MobilePhone"].ToString()); //手机号码
  244. curData.Add("MakerCode", userInfo.MakerCode); //所属创客
  245. curData.Add("RealName", userInfo.RealName); //所属创客姓名
  246. var subjectType = 0;
  247. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  248. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  249. curData.Add("AliPID", subdata["AlipayPid"].ToString()); //支付宝PID
  250. curData.Add("AliPayToken", subdata["AlipayAuthToken"].ToString()); //支付宝token
  251. curData.Add("WeChatNo", subdata["SubMchid"].ToString()); //微信商户号
  252. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体 3 小微)
  253. var amountInfo = MerchantAmountSummayService.Sum("TradeCount,TotalActual,TradeAmount", " and MerchantId=" + MerchantId + "");
  254. curData.Add("OrderCount", decimal.Parse(amountInfo["TradeCount"].ToString())); //订单总数
  255. curData.Add("InComeAmount", decimal.Parse(amountInfo["TotalActual"].ToString()).ToString("f2")); //实收总金额
  256. curData.Add("TradeAmount", decimal.Parse(amountInfo["TradeAmount"].ToString()).ToString("f2")); //营业总金额
  257. dataList.Add(curData);
  258. }
  259. Other.Add("Count", count); //总数
  260. return dataList;
  261. #endregion
  262. }
  263. #region 商户管理-直连添加支付宝PID和微信商户号
  264. [Authorize]
  265. public JsonResult DirectAddPIDOrWeChatNo(string value)
  266. {
  267. value = PublicFunction.DesDecrypt(value);
  268. JsonData data = JsonMapper.ToObject(value);
  269. AppResultJson result = DirectAddPIDOrWeChatNoDo(value);
  270. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  271. }
  272. private AppResultJson DirectAddPIDOrWeChatNoDo(string value)
  273. {
  274. JsonData data = JsonMapper.ToObject(value);
  275. string MerchantId = data["MerchantId"].ToString(); //商户Id
  276. string AliPPID = data["AliPPID"].ToString(); //支付宝PID
  277. string AliPayToken = data["AliPayToken"].ToString(); //支付宝token
  278. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  279. Dictionary<string, object> Obj = new Dictionary<string, object>();
  280. // var query = MerchantAddInfoService.Query(int.Parse(MerchantId));
  281. var Id = int.Parse(MerchantId);
  282. var query = main1db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  283. Dictionary<string, object> fields = new Dictionary<string, object>();
  284. if (query.Id > 0)
  285. {
  286. if (string.IsNullOrEmpty(query.AlipayPid))
  287. {
  288. fields.Add("AlipayPid", AliPPID); //支付宝PID
  289. query.AlipayPid = AliPPID;
  290. }
  291. if (!string.IsNullOrEmpty(AliPayToken))
  292. {
  293. fields.Add("AlipayAuthToken", AliPayToken); //支付宝token
  294. query.AlipayAuthToken = AliPayToken;
  295. }
  296. if (string.IsNullOrEmpty(query.SubMchid))
  297. {
  298. fields.Add("SubMchid", WeChatNo); //微信商户号
  299. query.SubMchid = WeChatNo;
  300. }
  301. }
  302. main1db.SaveChanges();
  303. // AppResultJson resultJson = MerchantAddInfoService.Edit(fields, int.Parse(MerchantId), false);
  304. return new AppResultJson() { Status = "1", Info = "添加成功", Data = Obj };
  305. }
  306. #endregion
  307. #region 节点操作-直联提交微信商户进件
  308. [Authorize]
  309. public JsonResult DirectWeChatMerchantAdd(string value)
  310. {
  311. value = PublicFunction.DesDecrypt(value);
  312. JsonData data = JsonMapper.ToObject(value);
  313. AppResultJson result = DirectWeChatMerchantAddDo(value);
  314. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  315. }
  316. private AppResultJson DirectWeChatMerchantAddDo(string value)
  317. {
  318. JsonData data = JsonMapper.ToObject(value);
  319. Dictionary<string, object> Obj = new Dictionary<string, object>();
  320. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  321. RedisDbconn.Instance.AddList("MerchantConfirmQueue", "{\"MerchantId\":\"" + id + "\",\"Kind\":\"2\"}");
  322. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  323. }
  324. #endregion
  325. #region 节点操作-直联提交支付宝商户进件
  326. [Authorize]
  327. public JsonResult DirectAlipayMerchantAdd(string value)
  328. {
  329. value = PublicFunction.DesDecrypt(value); ;
  330. JsonData data = JsonMapper.ToObject(value);
  331. AppResultJson result = DirectAlipayMerchantAddDo(value);
  332. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  333. }
  334. private AppResultJson DirectAlipayMerchantAddDo(string value)
  335. {
  336. JsonData data = JsonMapper.ToObject(value);
  337. Dictionary<string, object> Obj = new Dictionary<string, object>();
  338. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  339. RedisDbconn.Instance.AddList("MerchantConfirmQueue", "{\"MerchantId\":\"" + id + "\",\"Kind\":\"1\"}");
  340. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  341. }
  342. #endregion
  343. #region 节点操作-直联查询微信商户审核状态
  344. [Authorize]
  345. public JsonResult DirectWeChatMerchantQueryAudit(string value)
  346. {
  347. value = PublicFunction.DesDecrypt(value); ;
  348. JsonData data = JsonMapper.ToObject(value);
  349. Dictionary<string, object> Obj = DirectWeChatMerchantQueryAuditDo(value);
  350. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  351. }
  352. private Dictionary<string, object> DirectWeChatMerchantQueryAuditDo(string value)
  353. {
  354. JsonData data = JsonMapper.ToObject(value);
  355. Dictionary<string, object> Obj = new Dictionary<string, object>();
  356. MerchantAddInfo query = new MerchantAddInfo();
  357. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  358. query = MerchantAddInfoService.Query(id);
  359. Obj.Add("WeChatSignUrl", query.WeChatSignUrl); //微信签约地址
  360. Obj.Add("WeChatRemark", query.WeChatRemark); //微信备注
  361. Obj.Add("WeChatMerchantId", query.WeChatMerchantId); //微信商户号
  362. Obj.Add("Status", query.Status); //微信审核状态
  363. if(query.Status < 1)
  364. {
  365. RedisDbconn.Instance.AddList("WeChatSignQueue", new MerchantSign()
  366. {
  367. BusinessCode = query.BusinessCode,
  368. MerchantAddInfoId = id,
  369. Status = ""
  370. });
  371. }
  372. return Obj;
  373. }
  374. #endregion
  375. #region 节点操作-直联查询支付宝商户审核状态
  376. [Authorize]
  377. public JsonResult DirectAlipayMerchantQueryAudit(string value)
  378. {
  379. value = PublicFunction.DesDecrypt(value); ;
  380. JsonData data = JsonMapper.ToObject(value);
  381. Dictionary<string, object> Obj = DirectAlipayMerchantQueryAuditDo(value);
  382. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  383. }
  384. private Dictionary<string, object> DirectAlipayMerchantQueryAuditDo(string value)
  385. {
  386. JsonData data = JsonMapper.ToObject(value);
  387. Dictionary<string, object> Obj = new Dictionary<string, object>();
  388. MerchantAddInfo query = new MerchantAddInfo();
  389. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  390. query = MerchantAddInfoService.Query(id);
  391. Obj.Add("AlipayPid", query.AlipayPid); //支付宝唯一标识
  392. Obj.Add("AlipayAuthToken", query.AlipayAuthToken); //支付宝商家令牌
  393. Obj.Add("AlipaySignUrl", query.AlipaySignUrl); //支付宝签约地址
  394. Obj.Add("AlipayRemark", query.AlipayRemark); //支付宝备注
  395. Obj.Add("Status", query.QueryCount); //支付宝审核状态
  396. if(query.Status < 1)
  397. {
  398. RedisDbconn.Instance.AddList("AlipaySignQueue", new MerchantSign()
  399. {
  400. BusinessCode = query.SeoTitle,
  401. MerchantAddInfoId = id,
  402. Status = ""
  403. });
  404. }
  405. return Obj;
  406. }
  407. #endregion
  408. }
  409. }