MerchantAddInfoController.cs 33 KB

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