MerchantAddInfoController.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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.Main2;
  11. using MySystem.Service.Main2;
  12. using LitJson;
  13. using Library;
  14. using MySystem.Service.KxsMain;
  15. namespace MySystem.Areas.Api.Controllers.v1.Main2
  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 UnionPayList(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 = UnionPayListDo(value, out Other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  33. }
  34. private List<Dictionary<string, object>> UnionPayListDo(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 HDStatus = data["HDStatus"].ToString(); //好哒状态(-1 审核失败 0 待审核 3 已通过)
  42. string WeChatStatus = data["WeChatStatus"].ToString(); //微信状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  43. string AliPayStatus = data["AliPayStatus"].ToString(); //支付宝状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  44. string AgentName = data["Channel"].ToString(); //所属创客编号
  45. int BrandId = 0; //品牌(0 银联 1 好哒)
  46. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  47. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  48. string condition = "";
  49. var merIds = MerchantInfoUtil.QuerySenedMerchantId();
  50. condition = " and Id in (" + merIds + ")";
  51. if (!string.IsNullOrEmpty(data["SubjectType"].ToString()))
  52. {
  53. if (data["SubjectType"].ToString() == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  54. if (data["SubjectType"].ToString() == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  55. if (data["SubjectType"].ToString() == "3") SubjectType = "SUBJECT_TYPE_SMALL"; //小微商户
  56. condition += " and SubjectType='" + SubjectType + "'";
  57. }
  58. if (!string.IsNullOrEmpty(data["CertMerchantName"].ToString()))
  59. {
  60. condition += " and CertMerchantName like '%" + CertMerchantName + "%'";
  61. }
  62. if (!string.IsNullOrEmpty(data["ServicePhone"].ToString()))
  63. {
  64. condition += " and ServicePhone='" + ServicePhone + "'";
  65. }
  66. if (!string.IsNullOrEmpty(data["MakerCode"].ToString()))
  67. {
  68. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  69. condition += " and Id in (" + Ids + ")";
  70. }
  71. if (!string.IsNullOrEmpty(data["HDStatus"].ToString()))
  72. {
  73. if (int.Parse(HDStatus) == 3)
  74. {
  75. condition += " and HdStatus in(1,2,3)";
  76. }
  77. else
  78. {
  79. condition += " and Status=" + HDStatus + "";
  80. }
  81. }
  82. if (!string.IsNullOrEmpty(data["WeChatStatus"].ToString()))
  83. {
  84. condition += " and Status=" + WeChatStatus + "";
  85. }
  86. if (!string.IsNullOrEmpty(data["AliPayStatus"].ToString()))
  87. {
  88. condition += " and QueryCount=" + AliPayStatus + "";
  89. }
  90. if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
  91. {
  92. BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //品牌(0 银联 1 好哒)
  93. condition += " and BrandId=" + BrandId + "";
  94. }
  95. if (!string.IsNullOrEmpty(data["Channel"].ToString()))
  96. {
  97. condition += " and AgentName='" + AgentName + "'";
  98. }
  99. List<RelationData> relationData = new List<RelationData>();
  100. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  101. Other = new Dictionary<string, object>();
  102. int count = 0;
  103. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  104. foreach (Dictionary<string, object> subdata in source)
  105. {
  106. Dictionary<string, object> curData = new Dictionary<string, object>();
  107. var hdStatus = int.Parse(subdata["HdStatus"].ToString());
  108. var status = int.Parse(subdata["Status"].ToString());
  109. var queryCount = int.Parse(subdata["QueryCount"].ToString());
  110. if (hdStatus != 3)
  111. {
  112. hdStatus = status;
  113. }
  114. //商户Id
  115. var MerchantId = int.Parse(subdata["Id"].ToString());
  116. //父商户Id
  117. var ParentId = int.Parse(subdata["ParentId"].ToString());
  118. //主体类型
  119. var subjectType = 0;
  120. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  121. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  122. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_SMALL") subjectType = 3; //小微商户
  123. curData.Add("Id", subdata["Id"].ToString()); //Id
  124. curData.Add("BrandId", subdata["BrandId"].ToString()); //品牌(0 银联 1 好哒)
  125. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体 3 小微)
  126. curData.Add("CertMerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  127. curData.Add("ServicePhone", subdata["ServicePhone"].ToString()); //客服电话
  128. curData.Add("BizStoreAddress", subdata["BizStoreAddress"].ToString()); //门店地址
  129. curData.Add("CreateDate", subdata["CreateDate"].ToString() == "" ? "" : DateTime.Parse(subdata["CreateDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //进件时间
  130. var userInfo = UsersService.Query(MerchantInfoService.Query(MerchantId).UserId);
  131. curData.Add("MakerCode", userInfo.MakerCode); //所属创客编号
  132. curData.Add("RealName", userInfo.RealName); //所属创客姓名
  133. curData.Add("HDStatus", hdStatus); //好哒状态(-1 审核失败 0 待审核 3 已通过)
  134. curData.Add("WeChatStatus", status); //微信状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  135. curData.Add("AliPayStatus", queryCount); //支付宝状态(-1 审核失败 0 待审核 1 待签约 2 已通过)
  136. curData.Add("ParentName", MerchantInfoService.Query(ParentId).Name);
  137. curData.Add("UpdateDate", subdata["UpdateDate"].ToString() == "" ? "" : DateTime.Parse(subdata["UpdateDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"));
  138. curData.Add("Channel", subdata["AgentName"].ToString()); //进件通道
  139. dataList.Add(curData);
  140. }
  141. Other.Add("Count", count); //总数
  142. return dataList;
  143. }
  144. #endregion
  145. #region 进件管理-获取商户门店号
  146. [Authorize]
  147. public JsonResult UnionPayGetStoreNo(string value)
  148. {
  149. value = PublicFunction.DesDecrypt(value);
  150. JsonData data = JsonMapper.ToObject(value);
  151. AppResultJson result = UnionPayGetStoreNoDo(value);
  152. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  153. }
  154. private AppResultJson UnionPayGetStoreNoDo(string value)
  155. {
  156. JsonData data = JsonMapper.ToObject(value);
  157. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString()));
  158. Dictionary<string, object> Obj = new Dictionary<string, object>();
  159. var merAddInfo = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantAddInfo();
  160. var merInfo = main2db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo();
  161. merAddInfo.Status = 0;
  162. merInfo.Status = 0;
  163. RedisDbconn.Instance.AddList("UnionPayGetStoreNoQueue", MerchantId.ToString());
  164. main2db.SaveChanges();
  165. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  166. }
  167. #endregion
  168. #region 进件管理-银联查看失败原因
  169. [Authorize]
  170. public JsonResult UnionPayQueryFailReason(string value)
  171. {
  172. value = PublicFunction.DesDecrypt(value);
  173. JsonData data = JsonMapper.ToObject(value);
  174. Dictionary<string, object> Obj = UnionPayQueryFailReasonDo(value);
  175. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  176. }
  177. private Dictionary<string, object> UnionPayQueryFailReasonDo(string value)
  178. {
  179. JsonData data = JsonMapper.ToObject(value);
  180. string MerchantId = data["MerchantId"].ToString(); //商户Id
  181. Dictionary<string, object> Obj = new Dictionary<string, object>();
  182. var query = MerchantAddInfoService.Query(int.Parse(MerchantId));
  183. Obj.Add("HdReason", query.WeChatRemark); //好哒原因
  184. Obj.Add("WeChatReason", query.WeChatRemark); //微信原因
  185. Obj.Add("AlipayReason", query.AlipayRemark); //支付宝原因
  186. return Obj;
  187. }
  188. #endregion
  189. #region 进件管理-银联进件详情
  190. [Authorize]
  191. public JsonResult UnionPayDetail(string value)
  192. {
  193. value = PublicFunction.DesDecrypt(value);
  194. JsonData data = JsonMapper.ToObject(value);
  195. Dictionary<string, object> Obj = UnionPayDetailDo(value);
  196. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  197. }
  198. private Dictionary<string, object> UnionPayDetailDo(string value)
  199. {
  200. JsonData data = JsonMapper.ToObject(value);
  201. string MerchantId = data["MerchantId"].ToString(); //商户Id
  202. Dictionary<string, object> Obj = new Dictionary<string, object>();
  203. Obj = MerchantAddInfoUtil.MerchantAddInfoDetail(int.Parse(MerchantId));
  204. return Obj;
  205. }
  206. #endregion
  207. #region 进件管理-银联提交进件
  208. [Authorize]
  209. public JsonResult UnionPaySubmit(string value)
  210. {
  211. value = PublicFunction.DesDecrypt(value);
  212. JsonData data = JsonMapper.ToObject(value);
  213. AppResultJson result = UnionPaySubmitDo(value);
  214. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  215. }
  216. private AppResultJson UnionPaySubmitDo(string value)
  217. {
  218. JsonData data = JsonMapper.ToObject(value);
  219. string MerchantId = data["MerchantId"].ToString(); //商户Id
  220. var info = MerchantAddInfoUtil.UnionPaySubmitDo(int.Parse(MerchantId));
  221. if (info == "success")
  222. {
  223. return new AppResultJson() { Status = "1", Info = "成功", Data = info };
  224. }
  225. else
  226. {
  227. return new AppResultJson() { Status = "-1", Info = "失败", Data = info };
  228. }
  229. }
  230. #endregion
  231. #region 商户管理-银联查询商户交易信息
  232. [Authorize]
  233. public JsonResult UnionPayQueryMerchantTradeInfo(string value)
  234. {
  235. value = PublicFunction.DesDecrypt(value);
  236. JsonData data = JsonMapper.ToObject(value);
  237. Dictionary<string, object> Other = new Dictionary<string, object>();
  238. List<Dictionary<string, object>> dataList = UnionPayQueryMerchantTradeInfoDo(value, out Other);
  239. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  240. }
  241. private List<Dictionary<string, object>> UnionPayQueryMerchantTradeInfoDo(string value, out Dictionary<string, object> Other)
  242. {
  243. JsonData data = JsonMapper.ToObject(value);
  244. string MerchantName = data["MerchantName"].ToString(); //商户名称
  245. string Mobile = data["Mobile"].ToString(); //手机号码
  246. string MakerCode = data["MakerCode"].ToString(); //所属创客
  247. string MatchNo = data["MatchNo"].ToString(); //商户号
  248. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体 3 小微)
  249. string IsAct = data["IsAct"].ToString(); //激活状态(0 未激活 1 已激活)
  250. string ActDate = data["ActDate"].ToString(); //激活时间
  251. int BrandId = 0; //品牌(0 银联 1 好哒)
  252. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  253. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  254. string condition = "";
  255. var merIds = MerchantInfoUtil.QueryAnyIsOkMerchantId();
  256. condition = " and Id in (" + merIds + ")";
  257. if (!string.IsNullOrEmpty(MerchantName))
  258. {
  259. condition += " and CertMerchantName like '%" + MerchantName + "%'";
  260. }
  261. if (!string.IsNullOrEmpty(Mobile))
  262. {
  263. condition += " and MobilePhone='" + Mobile + "'";
  264. }
  265. if (!string.IsNullOrEmpty(MakerCode))
  266. {
  267. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  268. condition += " and Id in (" + Ids + ")";
  269. }
  270. if (!string.IsNullOrEmpty(MatchNo))
  271. {
  272. condition += " and MchtNo='" + MatchNo + "'";
  273. }
  274. if (!string.IsNullOrEmpty(SubjectType))
  275. {
  276. if (SubjectType == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  277. if (SubjectType == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  278. if (SubjectType == "3") SubjectType = "SUBJECT_TYPE_SMALL"; //小微
  279. condition += " and SubjectType='" + SubjectType + "'";
  280. }
  281. if (!string.IsNullOrEmpty(IsAct))
  282. {
  283. var Ids = MerchantInfoUtil.QueryIsActMerchantId(int.Parse(IsAct));
  284. condition += " and Id in (" + Ids + ")";
  285. }
  286. if (!string.IsNullOrEmpty(data["ActDate"].ToString()))
  287. {
  288. string[] datelist = ActDate.Split(new string[] { " - " }, StringSplitOptions.None);
  289. string start = datelist[0];
  290. string end = datelist[1];
  291. var Ids = MerchantInfoUtil.QueryActDateMerchantId(start, end);
  292. condition += " and Id in (" + Ids + ")";
  293. }
  294. if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
  295. {
  296. BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //品牌(0 银联 1 好哒)
  297. condition += " and BrandId=" + BrandId + "";
  298. }
  299. List<RelationData> relationData = new List<RelationData>();
  300. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  301. Other = new Dictionary<string, object>();
  302. int count = 0;
  303. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  304. foreach (Dictionary<string, object> subdata in source)
  305. {
  306. Dictionary<string, object> curData = new Dictionary<string, object>();
  307. //商户Id
  308. var MerchantId = int.Parse(subdata["Id"].ToString());
  309. var merInfo = MerchantInfoService.Query(MerchantId);
  310. var userInfo = UsersService.Query(merInfo.UserId);
  311. curData.Add("MerchantId", subdata["Id"].ToString()); //商户Id
  312. curData.Add("BrandId", subdata["BrandId"].ToString()); //品牌(0 银联 1 好哒)
  313. curData.Add("IsAct", merInfo.IsAct); //激活状态(0 未激活 1 已激活)
  314. var actDate = "";
  315. var order = MerchantDepositOrderService.Query(" and Status>0 and MerchantId=" + MerchantId + "");
  316. if (order.Id > 0)
  317. {
  318. actDate = order.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  319. }
  320. curData.Add("ActDate", actDate); //激活时间
  321. curData.Add("MerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  322. curData.Add("Mobile", subdata["MobilePhone"].ToString()); //手机号码
  323. curData.Add("MakerCode", userInfo.MakerCode); //所属创客
  324. curData.Add("RealName", userInfo.RealName); //所属创客姓名
  325. var subjectType = 0;
  326. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  327. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  328. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_SMALL") subjectType = 3; //小微
  329. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体 3 小微)
  330. curData.Add("MatchNo", subdata["MchtNo"].ToString()); //商户号
  331. var amountInfo = MerchantAmountSummayService.Sum("TradeCount,TotalActual,TradeAmount", " and MerchantId=" + MerchantId + "");
  332. curData.Add("OrderCount", decimal.Parse(amountInfo["TradeCount"].ToString())); //订单总数
  333. curData.Add("InComeAmount", decimal.Parse(amountInfo["TotalActual"].ToString()).ToString("f2")); //实收总金额
  334. curData.Add("TradeAmount", decimal.Parse(amountInfo["TradeAmount"].ToString()).ToString("f2")); //营业总金额
  335. dataList.Add(curData);
  336. }
  337. Other.Add("Count", count); //总数
  338. return dataList;
  339. }
  340. #endregion
  341. #region 节点操作-银联提交微信开户意愿
  342. [Authorize]
  343. public JsonResult UnionWeChatMerchantOpenAccount(string value)
  344. {
  345. value = PublicFunction.DesDecrypt(value);
  346. JsonData data = JsonMapper.ToObject(value);
  347. AppResultJson result = UnionWeChatMerchantOpenAccountDo(value);
  348. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  349. }
  350. private AppResultJson UnionWeChatMerchantOpenAccountDo(string value)
  351. {
  352. JsonData data = JsonMapper.ToObject(value);
  353. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  354. Dictionary<string, object> Obj = new Dictionary<string, object>();
  355. var merAddInfo = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
  356. if (merAddInfo.HdStatus != 3)
  357. {
  358. return new AppResultJson() { Status = "-1", Info = "商户未添加分账接收方账户", Data = Obj };
  359. }
  360. var merInfo = main2db.MerchantInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantInfo();
  361. merAddInfo.Status = 0;
  362. merAddInfo.ApplymentId = null;
  363. merAddInfo.WeChatSignUrl = null;
  364. merInfo.Status = 0;
  365. main2db.SaveChanges();
  366. RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", id.ToString());
  367. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  368. }
  369. #endregion
  370. #region 节点操作-银联提交支付宝开户意愿
  371. [Authorize]
  372. public JsonResult UnionAlipayMerchantOpenAccount(string value)
  373. {
  374. value = PublicFunction.DesDecrypt(value);
  375. JsonData data = JsonMapper.ToObject(value);
  376. AppResultJson result = UnionAlipayMerchantOpenAccountDo(value);
  377. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  378. }
  379. private AppResultJson UnionAlipayMerchantOpenAccountDo(string value)
  380. {
  381. JsonData data = JsonMapper.ToObject(value);
  382. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  383. Dictionary<string, object> Obj = new Dictionary<string, object>();
  384. var merAddInfo = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
  385. if (merAddInfo.HdStatus != 3)
  386. {
  387. return new AppResultJson() { Status = "-1", Info = "商户未添加分账接收方账户", Data = Obj };
  388. }
  389. var merInfo = main2db.MerchantInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantInfo();
  390. merAddInfo.QueryCount = 0;
  391. merAddInfo.SeoTitle = null;
  392. merAddInfo.AlipaySignUrl = null;
  393. merInfo.QueryCount = 0;
  394. main2db.SaveChanges();
  395. RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", id.ToString());
  396. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  397. }
  398. #endregion
  399. #region 节点操作-银联提交进件
  400. [Authorize]
  401. public JsonResult UnionMerchantAdd(string value)
  402. {
  403. value = PublicFunction.DesDecrypt(value);
  404. JsonData data = JsonMapper.ToObject(value);
  405. AppResultJson result = UnionMerchantAddDo(value);
  406. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  407. }
  408. private AppResultJson UnionMerchantAddDo(string value)
  409. {
  410. JsonData data = JsonMapper.ToObject(value);
  411. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  412. Dictionary<string, object> Obj = new Dictionary<string, object>();
  413. var merAddInfo = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
  414. var merInfo = main2db.MerchantInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantInfo();
  415. merAddInfo.Status = 0;
  416. merAddInfo.QueryCount = 0;
  417. merInfo.Status = 0;
  418. merInfo.QueryCount = 0;
  419. RedisDbconn.Instance.AddList("MerchantConfirmHdQueue", "{\"MerchantId\":\"" + id + "\"}");
  420. main2db.SaveChanges();
  421. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  422. }
  423. #endregion
  424. #region 节点操作-银联绑定微信appid
  425. [Authorize]
  426. public JsonResult UnionMerchantBindWeChatAppId(string value)
  427. {
  428. value = PublicFunction.DesDecrypt(value);
  429. JsonData data = JsonMapper.ToObject(value);
  430. AppResultJson result = UnionMerchantBindWeChatAppIdDo(value);
  431. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  432. }
  433. private AppResultJson UnionMerchantBindWeChatAppIdDo(string value)
  434. {
  435. JsonData data = JsonMapper.ToObject(value);
  436. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  437. var merAddInfo = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
  438. merAddInfo.HdBindWeChat = 0;
  439. main2db.SaveChanges();
  440. return new AppResultJson() { Status = "1", Info = "" };
  441. }
  442. #endregion
  443. #region 节点操作-银联获取好哒认证结果
  444. [Authorize]
  445. public JsonResult UnionMerchantGetAuth(string value)
  446. {
  447. value = PublicFunction.DesDecrypt(value);
  448. JsonData data = JsonMapper.ToObject(value);
  449. Dictionary<string, object> Obj = UnionMerchantGetAuthDo(value);
  450. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  451. }
  452. private Dictionary<string, object> UnionMerchantGetAuthDo(string value)
  453. {
  454. JsonData data = JsonMapper.ToObject(value);
  455. Dictionary<string, object> Obj = new Dictionary<string, object>();
  456. MerchantAddInfo query = new MerchantAddInfo();
  457. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  458. query = MerchantAddInfoService.Query(id);
  459. Obj.Add("WeChatMerchantId", query.WeChatMerchantId); //微信商户号
  460. Obj.Add("AliMerchantId", query.AliMerchantId); //支付宝商户号
  461. Obj.Add("WeChatStatus", ""); //微信认证状态
  462. Obj.Add("AlipayStatus", ""); //支付宝认证状态
  463. return Obj;
  464. }
  465. #endregion
  466. #region 节点操作-银联获取审核状态
  467. [Authorize]
  468. public JsonResult UnionMerchantQueryStatus(string value)
  469. {
  470. value = PublicFunction.DesDecrypt(value);
  471. JsonData data = JsonMapper.ToObject(value);
  472. Dictionary<string, object> Obj = UnionMerchantQueryStatusDo(value);
  473. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  474. }
  475. private Dictionary<string, object> UnionMerchantQueryStatusDo(string value)
  476. {
  477. JsonData data = JsonMapper.ToObject(value);
  478. Dictionary<string, object> Obj = new Dictionary<string, object>();
  479. MerchantAddInfo query = new MerchantAddInfo();
  480. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  481. query = MerchantAddInfoService.Query(id);
  482. Obj.Add("AlipaySignUrl", query.AlipaySignUrl); //支付宝签约地址
  483. Obj.Add("WeChatSignUrl", query.WeChatSignUrl); //微信签约地址
  484. Obj.Add("MchtNo", query.MchtNo); //好哒商户号
  485. Obj.Add("OutMchtNo", query.OutMchtNo); //慧掌柜商户号
  486. Obj.Add("StoreNo", query.StoreNo); //门店号
  487. Obj.Add("ToAcctNo", query.ToAcctNo); //分账接收方
  488. Obj.Add("HdPassDate", query.HdPassDate == null ? "" : query.HdPassDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //好哒审核通过时间
  489. Obj.Add("HdBindWeChat", query.HdBindWeChat); //好哒绑定微信状态
  490. string HdRemark = "";
  491. string WeChatRemark = "";
  492. string AlipayRemark = "";
  493. int HdStatus = 0;
  494. int WeChatStatus = 0;
  495. int AlipayStatus = 0;
  496. if (query.HdStatus == 0 && query.Status == -1)
  497. {
  498. HdStatus = -1;
  499. HdRemark = query.WeChatRemark;
  500. }
  501. if (query.HdStatus == 3)
  502. {
  503. WeChatStatus = query.Status;
  504. AlipayStatus = query.QueryCount;
  505. WeChatRemark = query.WeChatRemark;
  506. AlipayRemark = query.AlipayRemark;
  507. }
  508. Obj.Add("HdStatus", HdStatus); //好哒进件状态
  509. Obj.Add("HdRemark", HdRemark); //好哒备注
  510. Obj.Add("WeChatRemark", WeChatRemark); //微信备注
  511. Obj.Add("AlipayRemark", AlipayRemark); //支付宝备注
  512. Obj.Add("WeChatStatus", WeChatStatus); //微信审核状态
  513. Obj.Add("AlipayStatus", AlipayStatus); //微信审核状态
  514. return Obj;
  515. }
  516. #endregion
  517. #region 节点操作-好哒同步审核结果
  518. [Authorize]
  519. public JsonResult SycnMerchantQueryStatus(string value)
  520. {
  521. value = PublicFunction.DesDecrypt(value);
  522. JsonData data = JsonMapper.ToObject(value);
  523. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  524. Dictionary<string, object> Obj = new Dictionary<string, object>();
  525. MerchantAddInfo add = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id);
  526. if(add != null)
  527. {
  528. if(add.BrandId != 1)
  529. {
  530. return Json(new AppResultJson() { Status = "-1", Info = "不是好哒商户", Data = Obj });
  531. }
  532. if(!string.IsNullOrEmpty(add.OutMchtNo))
  533. {
  534. add.Status = 2;
  535. add.QueryCount = 2;
  536. add.HdStatus = 1;
  537. add.HdPassDate = DateTime.Now;
  538. }
  539. else
  540. {
  541. add.Status = 0;
  542. add.QueryCount = 0;
  543. }
  544. MerchantInfo mer = main2db.MerchantInfo.FirstOrDefault(m => m.Id == id);
  545. if(mer != null)
  546. {
  547. if(!string.IsNullOrEmpty(add.OutMchtNo))
  548. {
  549. mer.Status = 2;
  550. mer.QueryCount = 2;
  551. }
  552. else
  553. {
  554. mer.Status = 0;
  555. mer.QueryCount = 0;
  556. }
  557. }
  558. main2db.SaveChanges();
  559. return Json(new AppResultJson() { Status = "1", Info = "已同步", Data = Obj });
  560. }
  561. return Json(new AppResultJson() { Status = "-1", Info = "同步失败", Data = Obj });
  562. }
  563. #endregion
  564. #region 节点操作-删除商户
  565. [Authorize]
  566. public JsonResult DeleteMerchant(string value)
  567. {
  568. value = PublicFunction.DesDecrypt(value);
  569. JsonData data = JsonMapper.ToObject(value);
  570. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  571. Dictionary<string, object> Obj = new Dictionary<string, object>();
  572. MerchantAddInfo add = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id);
  573. if(add != null)
  574. {
  575. if(add.Status == 2 || add.QueryCount == 2)
  576. {
  577. return Json(new AppResultJson() { Status = "-1", Info = "已签约的商户不能删除", Data = Obj });
  578. }
  579. main2db.MerchantAddInfo.Remove(add);
  580. }
  581. MerchantInfo mer = main2db.MerchantInfo.FirstOrDefault(m => m.Id == id);
  582. if(mer != null)
  583. {
  584. main2db.MerchantInfo.Remove(mer);
  585. }
  586. main2db.SaveChanges();
  587. return Json(new AppResultJson() { Status = "1", Info = "已删除", Data = Obj });
  588. }
  589. #endregion
  590. #region 进件管理-银联修改商户名称
  591. [Authorize]
  592. public JsonResult UnionPayEditMerchantName(string value)
  593. {
  594. value = PublicFunction.DesDecrypt(value);
  595. JsonData data = JsonMapper.ToObject(value);
  596. AppResultJson result = UnionPayEditMerchantNameDo(value);
  597. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  598. }
  599. private AppResultJson UnionPayEditMerchantNameDo(string value)
  600. {
  601. JsonData data = JsonMapper.ToObject(value);
  602. string MerchantId = data["MerchantId"].ToString(); //商户Id
  603. string MerchantName = data["MerchantName"].ToString(); //新商户名称
  604. string MerchantShortName = data["MerchantShortName"].ToString(); //新商户简称
  605. Dictionary<string, object> Obj = new Dictionary<string, object>();
  606. var Id = int.Parse(MerchantId);
  607. var query = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  608. var merInfo = main2db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  609. if (query.Id > 0)
  610. {
  611. if (!string.IsNullOrEmpty(MerchantName))
  612. {
  613. query.CertMerchantName = MerchantName;
  614. merInfo.Name = MerchantName;
  615. }
  616. if (!string.IsNullOrEmpty(MerchantShortName))
  617. {
  618. query.MerchantShortname = MerchantShortName;
  619. }
  620. }
  621. main2db.SaveChanges();
  622. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  623. }
  624. #endregion
  625. #region 商户管理-银联查询商户交易信息导出
  626. [Authorize]
  627. public JsonResult ExportUnionPayQueryMerchantTradeInfo(string value)
  628. {
  629. value = PublicFunction.DesDecrypt(value);
  630. JsonData data = JsonMapper.ToObject(value);
  631. AppResultJson result = ExportUnionPayQueryMerchantTradeInfoDo(value);
  632. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  633. }
  634. private AppResultJson ExportUnionPayQueryMerchantTradeInfoDo(string value)
  635. {
  636. JsonData data = JsonMapper.ToObject(value);
  637. string MerchantName = data["MerchantName"].ToString(); //商户名称
  638. string Mobile = data["Mobile"].ToString(); //手机号码
  639. string MakerCode = data["MakerCode"].ToString(); //所属创客
  640. string MatchNo = data["MatchNo"].ToString(); //商户号
  641. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体 3 小微)
  642. string IsAct = data["IsAct"].ToString(); //激活状态(0 未激活 1 已激活)
  643. string ActDate = data["ActDate"].ToString(); //激活时间
  644. string condition = "";
  645. var merIds = MerchantInfoUtil.QueryAnyIsOkMerchantId();
  646. condition = " and Id in (" + merIds + ")";
  647. if (!string.IsNullOrEmpty(MerchantName))
  648. {
  649. condition += " and CertMerchantName like '%" + MerchantName + "%'";
  650. }
  651. if (!string.IsNullOrEmpty(Mobile))
  652. {
  653. condition += " and MobilePhone='" + Mobile + "'";
  654. }
  655. if (!string.IsNullOrEmpty(MakerCode))
  656. {
  657. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  658. condition += " and Id in (" + Ids + ")";
  659. }
  660. if (!string.IsNullOrEmpty(MatchNo))
  661. {
  662. condition += " and MchtNo='" + MatchNo + "'";
  663. }
  664. if (!string.IsNullOrEmpty(SubjectType))
  665. {
  666. if (SubjectType == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  667. if (SubjectType == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  668. if (SubjectType == "3") SubjectType = "SUBJECT_TYPE_SMALL"; //小微
  669. condition += " and SubjectType='" + SubjectType + "'";
  670. }
  671. if (!string.IsNullOrEmpty(IsAct))
  672. {
  673. var Ids = MerchantInfoUtil.QueryIsActMerchantId(int.Parse(IsAct));
  674. condition += " and Id in (" + Ids + ")";
  675. }
  676. if (!string.IsNullOrEmpty(data["ActDate"].ToString()))
  677. {
  678. string[] datelist = ActDate.Split(new string[] { " - " }, StringSplitOptions.None);
  679. string start = datelist[0];
  680. string end = datelist[1];
  681. var Ids = MerchantInfoUtil.QueryActDateMerchantId(start, end);
  682. condition += " and Id in (" + Ids + ")";
  683. }
  684. Dictionary<string, object> Obj = new Dictionary<string, object>();
  685. var Sql = "SELECT a.Id '商户Id',(CASE WHEN b.IsAct=0 THEN '未激活' WHEN b.IsAct=1 THEN '已激活' ELSE '' end) '激活状态',c.UpdateDate '激活时间',a.CertMerchantName '商户名称',a.MobilePhone '手机号码',b.UserId '所属创客Id',(CASE WHEN a.SubjectType='SUBJECT_TYPE_ENTERPRISE' THEN '企业公司' WHEN a.SubjectType='SUBJECT_TYPE_INDIVIDUAL' THEN '个体工商户' WHEN a.SubjectType='SUBJECT_TYPE_SMALL' THEN '小微' ELSE '' end) '主体类型',a.MchtNo '商户号',(SELECT SUM(TradeCount) TradeCount FROM QrCodePlateMainServer2.MerchantAmountSummay WHERE 1=1 AND MerchantId=a.Id) '订单总数',(SELECT SUM(TotalActual) TotalActual FROM QrCodePlateMainServer2.MerchantAmountSummay WHERE 1=1 AND MerchantId=a.Id)' 实收总金额',(SELECT SUM(TradeAmount) TradeAmount FROM QrCodePlateMainServer2.MerchantAmountSummay WHERE 1=1 AND MerchantId=a.Id) '营业总金额' FROM(SELECT Id,CertMerchantName,MobilePhone,MchtNo,SubjectType FROM QrCodePlateMainServer2.MerchantAddInfo WHERE 1=1 " + condition + " AND (Status=2 or QueryCount=2)) a LEFT JOIN (SELECT Id,IsAct,UserId FROM QrCodePlateMainServer2.MerchantInfo WHERE 1=1 AND Status=2 or QueryCount=2) b ON a.Id=b.Id LEFT JOIN (SELECT MerchantId,UpdateDate FROM QrCodePlateMainServer2.MerchantDepositOrder WHERE `Status`>0)c ON a.Id=c.MerchantId ORDER BY a.Id";
  686. var FileName = "商户管理-银联查询商户交易信息" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  687. string SendData = "{\"Operater\":\"" + AppConfig.LoginSession.sysId + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  688. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  689. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  690. }
  691. #endregion
  692. #region 银联结算管理-银联结算记录
  693. [Authorize]
  694. public JsonResult UnionPaySettlementRecordList(string value)
  695. {
  696. value = PublicFunction.DesDecrypt(value);
  697. JsonData data = JsonMapper.ToObject(value);
  698. Dictionary<string, object> Other = new Dictionary<string, object>();
  699. List<Dictionary<string, object>> dataList = UnionPaySettlementRecordListDo(value, out Other);
  700. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  701. }
  702. private List<Dictionary<string, object>> UnionPaySettlementRecordListDo(string value, out Dictionary<string, object> Other)
  703. {
  704. JsonData data = JsonMapper.ToObject(value);
  705. string MerchantName = data["MerchantName"].ToString(); //商户名称
  706. string MerchantNo = data["MerchantNo"].ToString(); //商户号
  707. string SettlementDate = data["SettlementDate"].ToString(); //结算时间(必填)
  708. string SettleStatus = data["SettleStatus"].ToString(); //出款状态(0 入账成功 1 入账失败 2 结算超时 3 入账受理成功 4 已提交结算请求)
  709. string pageSize = data["page_size"].ToString();
  710. string pageNum = data["page_num"].ToString();
  711. var MerchantId = 0;
  712. string StartDate = "";
  713. string EndDate = "";
  714. if (!string.IsNullOrEmpty(data["MerchantName"].ToString()))
  715. {
  716. var merAddInfo = MerchantAddInfoService.Query(" and CertMerchantName='" + MerchantName + "'");
  717. MerchantId = merAddInfo.Id;
  718. }
  719. if (!string.IsNullOrEmpty(data["MerchantNo"].ToString()))
  720. {
  721. var merAddInfo = MerchantAddInfoService.Query(" and MchtNo='" + MerchantNo + "'");
  722. MerchantId = merAddInfo.Id;
  723. }
  724. if (!string.IsNullOrEmpty(data["SettlementDate"].ToString()))
  725. {
  726. string[] datelist = SettlementDate.Split(new string[] { " - " }, StringSplitOptions.None);
  727. StartDate = datelist[0];
  728. EndDate = datelist[1];
  729. }
  730. Other = new Dictionary<string, object>();
  731. var dataList = MySelfUtil.CardInComeRecordList(MerchantId, StartDate, EndDate, SettleStatus, pageSize, pageNum, out Other);
  732. Other = Other;
  733. return dataList;
  734. }
  735. #endregion
  736. #region 重置交易额-银联重置商户交易额
  737. [Authorize]
  738. public JsonResult UnionPayResetMerchantAmount(string value)
  739. {
  740. value = PublicFunction.DesDecrypt(value);
  741. JsonData data = JsonMapper.ToObject(value);
  742. AppResultJson result = UnionPayResetMerchantAmountDo(value);
  743. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  744. }
  745. private AppResultJson UnionPayResetMerchantAmountDo(string value)
  746. {
  747. JsonData data = JsonMapper.ToObject(value);
  748. string MerchantId = data["MerchantId"].ToString(); //商户Id
  749. string TradeDate = data["TradeDate"].ToString(); //交易时间
  750. if (string.IsNullOrEmpty(data["MerchantId"].ToString()) || string.IsNullOrEmpty(data["TradeDate"].ToString()))
  751. {
  752. return new AppResultJson() { Status = "-1", Info = "商户Id和交易时间不能为空" };
  753. }
  754. string[] datelist = TradeDate.Split(new string[] { " - " }, StringSplitOptions.None);
  755. string start = DateTime.Parse(datelist[0]).ToString("yyyyMMdd");
  756. string end = DateTime.Parse(datelist[1]).ToString("yyyyMMdd");
  757. string info = "{\"MerchantId\":\"" + MerchantId + "\",\"StartDate\":\"" + start + "\",\"EndDate\": \"" + end + "\"}";
  758. RedisDbconn.Instance.AddList("ResetMerchantStatDataQueue2", info);
  759. Dictionary<string, object> Obj = new Dictionary<string, object>();
  760. return new AppResultJson() { Status = "1", Info = "成功", Data = Obj };
  761. }
  762. #endregion
  763. #region 商户管理-修改商户进件通道
  764. [Authorize]
  765. public JsonResult SetMerchantChannel(string value)
  766. {
  767. value = PublicFunction.DesDecrypt(value);
  768. JsonData data = JsonMapper.ToObject(value);
  769. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  770. string channel = data["channel"].ToString();
  771. Dictionary<string, object> Obj = new Dictionary<string, object>();
  772. MerchantAddInfo add = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == id);
  773. if(add != null)
  774. {
  775. add.AgentName = channel;
  776. main2db.SaveChanges();
  777. }
  778. return Json(new AppResultJson() { Status = "1", Info = "已修改", Data = Obj });
  779. }
  780. #endregion
  781. #region 商户管理-商户进件通道列表
  782. [Authorize]
  783. public JsonResult MerchantChannelList(string value)
  784. {
  785. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  786. Dictionary<string, object> item = new Dictionary<string, object>();
  787. item.Add("Id", "1");
  788. item.Add("Name", "蒲晓敏,T1715836(盒伙人)");
  789. list.Add(item);
  790. item = new Dictionary<string, object>();
  791. item.Add("Id", "2");
  792. item.Add("Name", "蒲晓敏,T1805778(盒伙人)");
  793. list.Add(item);
  794. item = new Dictionary<string, object>();
  795. item.Add("Id", "3");
  796. item.Add("Name", "蒲晓敏,Y5710589(迅易通)");
  797. list.Add(item);
  798. item = new Dictionary<string, object>();
  799. item.Add("Id", "4");
  800. item.Add("Name", "蒲晓敏,Y7009274(迅易通)");
  801. list.Add(item);
  802. item = new Dictionary<string, object>();
  803. item.Add("Id", "5");
  804. item.Add("Name", "蒲晓敏,Y5718505(迅易通)");
  805. list.Add(item);
  806. return Json(new AppResultJson() { Status = "1", Info = "", Data = list });
  807. }
  808. #endregion
  809. }
  810. }