MerchantAddInfoController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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 DirectUpdateSignUrl(string value)
  174. {
  175. value = PublicFunction.DesDecrypt(value);
  176. JsonData data = JsonMapper.ToObject(value);
  177. AppResultJson result = DirectUpdateSignUrlDo(value);
  178. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  179. }
  180. private AppResultJson DirectUpdateSignUrlDo(string value)
  181. {
  182. JsonData data = JsonMapper.ToObject(value);
  183. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString()));
  184. string Kind = data["Kind"].ToString(); //类型(1 支付宝 2 微信 )
  185. Dictionary<string, object> Obj = new Dictionary<string, object>();
  186. RedisDbconn.Instance.AddList("UpdateSignUrlQueue", "{\"MerchantId\":\"" + MerchantId + "\",\"Kind\":\"" + Kind + "\"}");
  187. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  188. }
  189. #endregion
  190. #region 商户管理-直连查询商户交易信息
  191. [Authorize]
  192. public JsonResult DirectQueryMerchantTradeInfo(string value)
  193. {
  194. value = PublicFunction.DesDecrypt(value);
  195. JsonData data = JsonMapper.ToObject(value);
  196. Dictionary<string, object> Other = new Dictionary<string, object>();
  197. List<Dictionary<string, object>> dataList = DirectQueryMerchantTradeInfoDo(value, out Other);
  198. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  199. }
  200. private List<Dictionary<string, object>> DirectQueryMerchantTradeInfoDo(string value, out Dictionary<string, object> Other)
  201. {
  202. JsonData data = JsonMapper.ToObject(value);
  203. string MerchantName = data["MerchantName"].ToString(); //商户名称
  204. string Mobile = data["Mobile"].ToString(); //手机号码
  205. string MakerCode = data["MakerCode"].ToString(); //所属创客
  206. string AliPID = data["AliPID"].ToString(); //支付宝PID
  207. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  208. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体)
  209. string IsAct = data["IsAct"].ToString(); //激活状态(0 未激活 1 已激活)
  210. string ActDate = data["ActDate"].ToString(); //激活时间
  211. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  212. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  213. string condition = "";
  214. var merIds = MerchantInfoUtil.QueryAnyIsOkMerchantId();
  215. condition = " and Id in (" + merIds + ")";
  216. if (!string.IsNullOrEmpty(MerchantName))
  217. {
  218. condition += " and CertMerchantName like '%" + MerchantName + "%'";
  219. }
  220. if (!string.IsNullOrEmpty(Mobile))
  221. {
  222. condition += " and MobilePhone='" + Mobile + "'";
  223. }
  224. if (!string.IsNullOrEmpty(MakerCode))
  225. {
  226. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  227. condition += " and Id in (" + Ids + ")";
  228. }
  229. if (!string.IsNullOrEmpty(AliPID))
  230. {
  231. condition += " and AlipayPid='" + AliPID + "'";
  232. }
  233. if (!string.IsNullOrEmpty(WeChatNo))
  234. {
  235. condition += " and SubMchid='" + WeChatNo + "'";
  236. }
  237. if (!string.IsNullOrEmpty(SubjectType))
  238. {
  239. if (SubjectType == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  240. if (SubjectType == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  241. condition += " and SubjectType='" + SubjectType + "'";
  242. }
  243. if (!string.IsNullOrEmpty(IsAct))
  244. {
  245. var Ids = MerchantInfoUtil.QueryIsActMerchantId(int.Parse(IsAct));
  246. condition += " and Id in (" + Ids + ")";
  247. }
  248. if (!string.IsNullOrEmpty(data["ActDate"].ToString()))
  249. {
  250. string[] datelist = ActDate.Split(new string[] { " - " }, StringSplitOptions.None);
  251. string start = datelist[0];
  252. string end = datelist[1];
  253. var Ids = MerchantInfoUtil.QueryActDateMerchantId(start, end);
  254. condition += " and Id in (" + Ids + ")";
  255. }
  256. List<RelationData> relationData = new List<RelationData>();
  257. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  258. Other = new Dictionary<string, object>();
  259. int count = 0;
  260. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  261. foreach (Dictionary<string, object> subdata in source)
  262. {
  263. Dictionary<string, object> curData = new Dictionary<string, object>();
  264. //商户Id
  265. var MerchantId = int.Parse(subdata["Id"].ToString());
  266. var merInfo = MerchantInfoService.Query(MerchantId);
  267. var userInfo = UsersService.Query(merInfo.UserId);
  268. curData.Add("MerchantId", subdata["Id"].ToString()); //商户Id
  269. curData.Add("IsAct", merInfo.IsAct); //激活状态(0 未激活 1 已激活)
  270. var actDate = "";
  271. var order = MerchantDepositOrderService.Query(" and Status>0 and MerchantId=" + MerchantId + "");
  272. if (order.Id > 0)
  273. {
  274. actDate = order.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  275. }
  276. curData.Add("ActDate", actDate); //激活时间
  277. curData.Add("MerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  278. curData.Add("Mobile", subdata["MobilePhone"].ToString()); //手机号码
  279. curData.Add("MakerCode", userInfo.MakerCode); //所属创客
  280. curData.Add("RealName", userInfo.RealName); //所属创客姓名
  281. var subjectType = 0;
  282. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  283. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  284. curData.Add("AliPID", subdata["AlipayPid"].ToString()); //支付宝PID
  285. curData.Add("AliPayToken", subdata["AlipayAuthToken"].ToString()); //支付宝token
  286. curData.Add("WeChatNo", subdata["SubMchid"].ToString()); //微信商户号
  287. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体 3 小微)
  288. var amountInfo = MerchantAmountSummayService.Sum("TradeCount,TotalActual,TradeAmount", " and MerchantId=" + MerchantId + "");
  289. curData.Add("OrderCount", decimal.Parse(amountInfo["TradeCount"].ToString())); //订单总数
  290. curData.Add("InComeAmount", decimal.Parse(amountInfo["TotalActual"].ToString()).ToString("f2")); //实收总金额
  291. curData.Add("TradeAmount", decimal.Parse(amountInfo["TradeAmount"].ToString()).ToString("f2")); //营业总金额
  292. dataList.Add(curData);
  293. }
  294. Other.Add("Count", count); //总数
  295. return dataList;
  296. #endregion
  297. }
  298. #region 商户管理-直连修改商户微信或支付宝签约状态为成功
  299. [Authorize]
  300. public JsonResult DirectEditAlipayOrWeChatStatus(string value)
  301. {
  302. value = PublicFunction.DesDecrypt(value);
  303. JsonData data = JsonMapper.ToObject(value);
  304. AppResultJson result = DirectEditAlipayOrWeChatStatusDo(value);
  305. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  306. }
  307. private AppResultJson DirectEditAlipayOrWeChatStatusDo(string value)
  308. {
  309. JsonData data = JsonMapper.ToObject(value);
  310. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  311. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString())); //类型(0 所有 1 支付宝 2 微信)
  312. Dictionary<string, object> Obj = new Dictionary<string, object>();
  313. var query = main1db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantAddInfo();
  314. var querys = main1db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo();
  315. Dictionary<string, object> fields = new Dictionary<string, object>();
  316. if (Kind == 0)
  317. {
  318. query.QueryCount = 2;
  319. query.Status = 2;
  320. querys.QueryCount = 2;
  321. querys.Status = 2;
  322. }
  323. if (Kind == 1)
  324. {
  325. query.QueryCount = 2;
  326. querys.QueryCount = 2;
  327. }
  328. if (Kind == 2)
  329. {
  330. query.Status = 2;
  331. querys.Status = 2;
  332. }
  333. main1db.SaveChanges();
  334. return new AppResultJson() { Status = "1", Info = "修改成功", Data = Obj };
  335. }
  336. #endregion
  337. #region 商户管理-直连添加支付宝PID和微信商户号
  338. [Authorize]
  339. public JsonResult DirectAddPIDOrWeChatNo(string value)
  340. {
  341. value = PublicFunction.DesDecrypt(value);
  342. JsonData data = JsonMapper.ToObject(value);
  343. AppResultJson result = DirectAddPIDOrWeChatNoDo(value);
  344. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  345. }
  346. private AppResultJson DirectAddPIDOrWeChatNoDo(string value)
  347. {
  348. JsonData data = JsonMapper.ToObject(value);
  349. string MerchantId = data["MerchantId"].ToString(); //商户Id
  350. string AliPPID = data["AliPPID"].ToString(); //支付宝PID
  351. string AliPayToken = data["AliPayToken"].ToString(); //支付宝token
  352. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  353. Dictionary<string, object> Obj = new Dictionary<string, object>();
  354. // var query = MerchantAddInfoService.Query(int.Parse(MerchantId));
  355. var Id = int.Parse(MerchantId);
  356. var query = main1db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  357. Dictionary<string, object> fields = new Dictionary<string, object>();
  358. if (query.Id > 0)
  359. {
  360. if (string.IsNullOrEmpty(query.AlipayPid))
  361. {
  362. // fields.Add("AlipayPid", AliPPID); //支付宝PID
  363. query.AlipayPid = AliPPID;
  364. }
  365. if (!string.IsNullOrEmpty(AliPayToken))
  366. {
  367. // fields.Add("AlipayAuthToken", AliPayToken); //支付宝token
  368. query.AlipayAuthToken = AliPayToken;
  369. }
  370. if (string.IsNullOrEmpty(query.SubMchid))
  371. {
  372. // fields.Add("SubMchid", WeChatNo); //微信商户号
  373. query.SubMchid = WeChatNo;
  374. }
  375. }
  376. main1db.SaveChanges();
  377. // AppResultJson resultJson = MerchantAddInfoService.Edit(fields, int.Parse(MerchantId), false);
  378. return new AppResultJson() { Status = "1", Info = "添加成功", Data = Obj };
  379. }
  380. #endregion
  381. #region 节点操作-直联提交微信商户进件
  382. [Authorize]
  383. public JsonResult DirectWeChatMerchantAdd(string value)
  384. {
  385. value = PublicFunction.DesDecrypt(value);
  386. JsonData data = JsonMapper.ToObject(value);
  387. AppResultJson result = DirectWeChatMerchantAddDo(value);
  388. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  389. }
  390. private AppResultJson DirectWeChatMerchantAddDo(string value)
  391. {
  392. JsonData data = JsonMapper.ToObject(value);
  393. Dictionary<string, object> Obj = new Dictionary<string, object>();
  394. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  395. var merAddInfo = main1db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
  396. var merInfo = main1db.MerchantInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantInfo();
  397. merAddInfo.Status = 0;
  398. merInfo.Status = 0;
  399. RedisDbconn.Instance.AddList("MerchantConfirmQueue", "{\"MerchantId\":\"" + id + "\",\"Kind\":\"2\"}");
  400. main1db.SaveChanges();
  401. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  402. }
  403. #endregion
  404. #region 节点操作-直联提交支付宝商户进件
  405. [Authorize]
  406. public JsonResult DirectAlipayMerchantAdd(string value)
  407. {
  408. value = PublicFunction.DesDecrypt(value);
  409. JsonData data = JsonMapper.ToObject(value);
  410. AppResultJson result = DirectAlipayMerchantAddDo(value);
  411. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  412. }
  413. private AppResultJson DirectAlipayMerchantAddDo(string value)
  414. {
  415. JsonData data = JsonMapper.ToObject(value);
  416. Dictionary<string, object> Obj = new Dictionary<string, object>();
  417. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  418. var merAddInfo = main1db.MerchantAddInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantAddInfo();
  419. var merInfo = main1db.MerchantInfo.FirstOrDefault(m => m.Id == id) ?? new MerchantInfo();
  420. merAddInfo.QueryCount = 0;
  421. merInfo.QueryCount = 0;
  422. RedisDbconn.Instance.AddList("MerchantConfirmQueue", "{\"MerchantId\":\"" + id + "\",\"Kind\":\"1\"}");
  423. main1db.SaveChanges();
  424. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  425. }
  426. #endregion
  427. #region 节点操作-直联查询微信商户审核状态
  428. [Authorize]
  429. public JsonResult DirectWeChatMerchantQueryAudit(string value)
  430. {
  431. value = PublicFunction.DesDecrypt(value);
  432. JsonData data = JsonMapper.ToObject(value);
  433. Dictionary<string, object> Obj = DirectWeChatMerchantQueryAuditDo(value);
  434. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  435. }
  436. private Dictionary<string, object> DirectWeChatMerchantQueryAuditDo(string value)
  437. {
  438. JsonData data = JsonMapper.ToObject(value);
  439. Dictionary<string, object> Obj = new Dictionary<string, object>();
  440. MerchantAddInfo query = new MerchantAddInfo();
  441. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  442. query = MerchantAddInfoService.Query(id);
  443. Obj.Add("WeChatSignUrl", query.WeChatSignUrl); //微信签约地址
  444. Obj.Add("WeChatRemark", query.WeChatRemark); //微信备注
  445. Obj.Add("WeChatMerchantId", query.WeChatMerchantId); //微信商户号
  446. Obj.Add("Status", query.Status); //微信审核状态
  447. if (query.Status < 2)
  448. {
  449. RedisDbconn.Instance.AddList("WeChatSignQueue", new MerchantSign()
  450. {
  451. BusinessCode = query.BusinessCode,
  452. MerchantAddInfoId = id,
  453. Status = ""
  454. });
  455. }
  456. return Obj;
  457. }
  458. #endregion
  459. #region 节点操作-直联查询支付宝商户审核状态
  460. [Authorize]
  461. public JsonResult DirectAlipayMerchantQueryAudit(string value)
  462. {
  463. value = PublicFunction.DesDecrypt(value);
  464. JsonData data = JsonMapper.ToObject(value);
  465. Dictionary<string, object> Obj = DirectAlipayMerchantQueryAuditDo(value);
  466. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  467. }
  468. private Dictionary<string, object> DirectAlipayMerchantQueryAuditDo(string value)
  469. {
  470. JsonData data = JsonMapper.ToObject(value);
  471. Dictionary<string, object> Obj = new Dictionary<string, object>();
  472. MerchantAddInfo query = new MerchantAddInfo();
  473. int id = int.Parse(function.CheckInt(data["id"].ToString()));
  474. query = MerchantAddInfoService.Query(id);
  475. Obj.Add("AlipayPid", query.AlipayPid); //支付宝唯一标识
  476. Obj.Add("AlipayAuthToken", query.AlipayAuthToken); //支付宝商家令牌
  477. Obj.Add("AlipaySignUrl", query.AlipaySignUrl); //支付宝签约地址
  478. Obj.Add("AlipayRemark", query.AlipayRemark); //支付宝备注
  479. Obj.Add("Status", query.QueryCount); //支付宝审核状态
  480. if (query.Status < 2)
  481. {
  482. RedisDbconn.Instance.AddList("AlipaySignQueue", new MerchantSign()
  483. {
  484. BusinessCode = query.SeoTitle,
  485. MerchantAddInfoId = id,
  486. Status = ""
  487. });
  488. }
  489. return Obj;
  490. }
  491. #endregion
  492. #region 商户管理-直连查询商户交易信息导出
  493. [Authorize]
  494. public JsonResult ExportDirectQueryMerchantTradeInfo(string value)
  495. {
  496. value = PublicFunction.DesDecrypt(value);
  497. JsonData data = JsonMapper.ToObject(value);
  498. AppResultJson result = ExportDirectQueryMerchantTradeInfoDo(value);
  499. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  500. }
  501. private AppResultJson ExportDirectQueryMerchantTradeInfoDo(string value)
  502. {
  503. JsonData data = JsonMapper.ToObject(value);
  504. string MerchantName = data["MerchantName"].ToString(); //商户名称
  505. string Mobile = data["Mobile"].ToString(); //手机号码
  506. string MakerCode = data["MakerCode"].ToString(); //所属创客
  507. string AliPID = data["AliPID"].ToString(); //支付宝PID
  508. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  509. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体)
  510. string IsAct = data["IsAct"].ToString(); //激活状态(0 未激活 1 已激活)
  511. string ActDate = data["ActDate"].ToString(); //激活时间
  512. string condition = "";
  513. var merIds = MerchantInfoUtil.QueryAnyIsOkMerchantId();
  514. condition = " and Id in (" + merIds + ")";
  515. if (!string.IsNullOrEmpty(MerchantName))
  516. {
  517. condition += " and CertMerchantName like '%" + MerchantName + "%'";
  518. }
  519. if (!string.IsNullOrEmpty(Mobile))
  520. {
  521. condition += " and MobilePhone='" + Mobile + "'";
  522. }
  523. if (!string.IsNullOrEmpty(MakerCode))
  524. {
  525. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  526. condition += " and Id in (" + Ids + ")";
  527. }
  528. if (!string.IsNullOrEmpty(AliPID))
  529. {
  530. condition += " and AlipayPid='" + AliPID + "'";
  531. }
  532. if (!string.IsNullOrEmpty(WeChatNo))
  533. {
  534. condition += " and SubMchid='" + WeChatNo + "'";
  535. }
  536. if (!string.IsNullOrEmpty(SubjectType))
  537. {
  538. if (SubjectType == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  539. if (SubjectType == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  540. condition += " and SubjectType='" + SubjectType + "'";
  541. }
  542. if (!string.IsNullOrEmpty(IsAct))
  543. {
  544. var Ids = MerchantInfoUtil.QueryIsActMerchantId(int.Parse(IsAct));
  545. condition += " and Id in (" + Ids + ")";
  546. }
  547. if (!string.IsNullOrEmpty(data["ActDate"].ToString()))
  548. {
  549. string[] datelist = ActDate.Split(new string[] { " - " }, StringSplitOptions.None);
  550. string start = datelist[0];
  551. string end = datelist[1];
  552. var Ids = MerchantInfoUtil.QueryActDateMerchantId(start, end);
  553. condition += " and Id in (" + Ids + ")";
  554. }
  555. Dictionary<string, object> Obj = new Dictionary<string, object>();
  556. 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',a.AlipayPid '支付宝PID',a.AlipayAuthToken '支付宝token',a.SubMchid '微信商户号',(CASE WHEN a.SubjectType='SUBJECT_TYPE_ENTERPRISE' THEN '企业公司' WHEN a.SubjectType='SUBJECT_TYPE_INDIVIDUAL' THEN '个体工商户' ELSE '' end) SubjectType,(SELECT SUM(TradeCount) TradeCount FROM MerchantAmountSummay WHERE 1=1 AND MerchantId=a.Id) '订单总数',(SELECT SUM(TotalActual) TotalActual FROM MerchantAmountSummay WHERE 1=1 AND MerchantId=a.Id)' 实收总金额',(SELECT SUM(TradeAmount) TradeAmount FROM MerchantAmountSummay WHERE 1=1 AND MerchantId=a.Id) '营业总金额' FROM(SELECT Id,CertMerchantName,MobilePhone,SubjectType,AlipayPid,AlipayAuthToken,SubMchid FROM MerchantAddInfo WHERE 1=1 " + condition + " AND (Status=2 or QueryCount=2)) a LEFT JOIN (SELECT Id,IsAct,UserId FROM MerchantInfo WHERE 1=1 AND Status=2 or QueryCount=2) b ON a.Id=b.Id LEFT JOIN (SELECT MerchantId,UpdateDate FROM MerchantDepositOrder WHERE `Status`>0)c ON a.Id=c.MerchantId ORDER BY a.Id";
  557. var FileName = "商户管理-直连查询商户交易信息" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  558. string SendData = "{\"Operater\":\"" + AppConfig.LoginSession.sysId + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  559. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  560. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  561. }
  562. #endregion
  563. #region 重置交易额-直连重置商户交易额
  564. [Authorize]
  565. public JsonResult DirectResetMerchantAmount(string value)
  566. {
  567. value = PublicFunction.DesDecrypt(value);
  568. JsonData data = JsonMapper.ToObject(value);
  569. AppResultJson result = DirectResetMerchantAmountDo(value);
  570. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  571. }
  572. private AppResultJson DirectResetMerchantAmountDo(string value)
  573. {
  574. JsonData data = JsonMapper.ToObject(value);
  575. string MerchantId = data["MerchantId"].ToString(); //商户Id
  576. string TradeDate = data["TradeDate"].ToString(); //交易时间
  577. if (string.IsNullOrEmpty(data["MerchantId"].ToString()) || string.IsNullOrEmpty(data["TradeDate"].ToString()))
  578. {
  579. return new AppResultJson() { Status = "-1", Info = "商户Id和交易时间不能为空" };
  580. }
  581. string[] datelist = TradeDate.Split(new string[] { " - " }, StringSplitOptions.None);
  582. string start = DateTime.Parse(datelist[0]).ToString("yyyyMMdd");
  583. string end = DateTime.Parse(datelist[1]).ToString("yyyyMMdd");
  584. string info = "{\"MerchantId\":\"" + MerchantId + "\",\"StartDate\":\"" + start + "\",\"EndDate\": \"" + end + "\"}";
  585. RedisDbconn.Instance.AddList("ResetMerchantStatDataQueue", info);
  586. Dictionary<string, object> Obj = new Dictionary<string, object>();
  587. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  588. }
  589. #endregion
  590. }
  591. }