MerchantAddInfoController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 Status = data["Status"].ToString(); //商户状态(0 审核中 1 已通过 -1 审核失败 20 微信待签约 21 微信已签约 10 支付宝待签约 11 支付宝已签约)
  42. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  43. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  44. string condition = "";
  45. var merIds = MerchantInfoUtil.QuerySenedMerchantId();
  46. condition = " and Id in (" + merIds + ")";
  47. if (!string.IsNullOrEmpty(data["SubjectType"].ToString()))
  48. {
  49. if (data["SubjectType"].ToString() == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  50. if (data["SubjectType"].ToString() == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  51. condition += " and SubjectType='" + SubjectType + "'";
  52. }
  53. if (!string.IsNullOrEmpty(data["CertMerchantName"].ToString()))
  54. {
  55. condition += " and CertMerchantName='" + CertMerchantName + "'";
  56. }
  57. if (!string.IsNullOrEmpty(data["ServicePhone"].ToString()))
  58. {
  59. condition += " and ServicePhone='" + ServicePhone + "'";
  60. }
  61. if (!string.IsNullOrEmpty(data["MakerCode"].ToString()))
  62. {
  63. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  64. condition += " and Id in (" + Ids + ")";
  65. }
  66. if (!string.IsNullOrEmpty(data["Status"].ToString()))
  67. {
  68. if (Status == "0") condition += " and Status=0 and QueryCount=0"; //待审核
  69. if (Status == "-1") condition += " and (Status=-1 or QueryCount=-1)"; //审核失败
  70. if (Status == "1") condition += " and (Status=1 or QueryCount=1)"; //待签约
  71. if (Status == "2") condition += " and Status=2 and QueryCount=2"; //已通过
  72. }
  73. List<RelationData> relationData = new List<RelationData>();
  74. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  75. Other = new Dictionary<string, object>();
  76. int count = 0;
  77. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  78. foreach (Dictionary<string, object> subdata in source)
  79. {
  80. Dictionary<string, object> curData = new Dictionary<string, object>();
  81. var status = int.Parse(subdata["Status"].ToString());
  82. var queryCount = int.Parse(subdata["QueryCount"].ToString());
  83. //商户Id
  84. var MerchantId = int.Parse(subdata["Id"].ToString());
  85. //主体类型
  86. var subjectType = 0;
  87. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  88. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  89. curData.Add("Id", subdata["Id"].ToString()); //Id
  90. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体)
  91. curData.Add("CertMerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  92. curData.Add("ServicePhone", subdata["ServicePhone"].ToString()); //客服电话
  93. curData.Add("BizStoreAddress", subdata["BizStoreAddress"].ToString()); //门店地址
  94. curData.Add("CreateDate", subdata["CreateDate"].ToString() == null ? "" : DateTime.Parse(subdata["CreateDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //进件时间
  95. var userInfo = UsersService.Query(MerchantInfoService.Query(MerchantId).UserId);
  96. curData.Add("MakerCode", userInfo.MakerCode); //所属创客编号
  97. curData.Add("RealName", userInfo.RealName); //所属创客姓名
  98. //商户状态
  99. var MerStatus = 0;
  100. if (status == 0 && queryCount == 0) MerStatus = 0; //待审核
  101. if (status == -1 || queryCount == -1) MerStatus = -1; //审核失败
  102. if (status == 1 || queryCount == 1) MerStatus = 1; //待签约
  103. if (status == 2 && queryCount == 2) MerStatus = 1; //已通过
  104. curData.Add("Status", MerStatus); //商户状态
  105. //审核平台
  106. var AuditInfo = 1;
  107. if (status == -1 && queryCount >= 1) AuditInfo = 2;
  108. if (status >= 1 && queryCount == -1) AuditInfo = 1;
  109. curData.Add("AuditInfo", AuditInfo); //审核平台(1 支付宝 2 微信)
  110. dataList.Add(curData);
  111. }
  112. Other.Add("Count", count); //总数
  113. return dataList;
  114. }
  115. #endregion
  116. #region 进件管理-直连查看失败原因
  117. [Authorize]
  118. public JsonResult DirectQueryFailReason(string value)
  119. {
  120. value = PublicFunction.DesDecrypt(value);
  121. JsonData data = JsonMapper.ToObject(value);
  122. Dictionary<string, object> Obj = DirectQueryFailReasonDo(value);
  123. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  124. }
  125. private Dictionary<string, object> DirectQueryFailReasonDo(string value)
  126. {
  127. JsonData data = JsonMapper.ToObject(value);
  128. string MerchantId = data["MerchantId"].ToString(); //商户Id
  129. Dictionary<string, object> Obj = new Dictionary<string, object>();
  130. MerchantAddInfo query = new MerchantAddInfo();
  131. query = MerchantAddInfoService.Query(int.Parse(MerchantId));
  132. var info = "";
  133. if (query.Status == -1)
  134. {
  135. info += "微信:" + query.WeChatRemark + "\n";
  136. }
  137. if (query.QueryCount == -1)
  138. {
  139. info += "支付宝:" + query.AlipayRemark + "\n";
  140. }
  141. Obj.Add("Info", info); //失败原因
  142. return Obj;
  143. }
  144. #endregion
  145. #region 进件管理-直连进件详情
  146. [Authorize]
  147. public JsonResult DirectDetail(string value)
  148. {
  149. value = PublicFunction.DesDecrypt(value);
  150. JsonData data = JsonMapper.ToObject(value);
  151. Dictionary<string, object> Obj = DirectDetailDo(value);
  152. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  153. }
  154. private Dictionary<string, object> DirectDetailDo(string value)
  155. {
  156. JsonData data = JsonMapper.ToObject(value);
  157. string MerchantId = data["MerchantId"].ToString(); //商户Id
  158. Dictionary<string, object> Obj = new Dictionary<string, object>();
  159. Obj = MerchantAddInfoUtil.MerchantAddInfoDetail(int.Parse(MerchantId));
  160. return Obj;
  161. }
  162. #endregion
  163. #region 进件管理-直连提交进件
  164. [Authorize]
  165. public JsonResult DirectSubmit(string value)
  166. {
  167. value = PublicFunction.DesDecrypt(value);
  168. JsonData data = JsonMapper.ToObject(value);
  169. AppResultJson result = DirectSubmitDo(value);
  170. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  171. }
  172. private AppResultJson DirectSubmitDo(string value)
  173. {
  174. JsonData data = JsonMapper.ToObject(value);
  175. string MerchantId = data["MerchantId"].ToString(); //商户Id
  176. var info = MerchantAddInfoUtil.DirectSubmitDo(int.Parse(MerchantId));
  177. if (info == "success")
  178. {
  179. return new AppResultJson() { Status = "1", Info = "成功", Data = info };
  180. }
  181. else
  182. {
  183. return new AppResultJson() { Status = "-1", Info = "失败", Data = info };
  184. }
  185. }
  186. #endregion
  187. #region 商户管理-直连查询商户交易信息
  188. [Authorize]
  189. public JsonResult DirectQueryMerchantTradeInfo(string value)
  190. {
  191. value = PublicFunction.DesDecrypt(value); ;
  192. JsonData data = JsonMapper.ToObject(value);
  193. Dictionary<string, object> Other = new Dictionary<string, object>();
  194. List<Dictionary<string, object>> dataList = DirectQueryMerchantTradeInfoDo(value, out Other);
  195. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  196. }
  197. private List<Dictionary<string, object>> DirectQueryMerchantTradeInfoDo(string value, out Dictionary<string, object> Other)
  198. {
  199. JsonData data = JsonMapper.ToObject(value);
  200. string MerchantName = data["MerchantName"].ToString(); //商户名称
  201. string Mobile = data["Mobile"].ToString(); //手机号码
  202. string MakerCode = data["MakerCode"].ToString(); //所属创客
  203. string MatchNo = data["MatchNo"].ToString(); //商户号
  204. string AliPID = data["AliPID"].ToString(); //支付宝PID
  205. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  206. string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体)
  207. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  208. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  209. string condition = "";
  210. var merIds = MerchantInfoUtil.QuerySenedMerchantId();
  211. condition = " and Id in (" + merIds + ")";
  212. if (!string.IsNullOrEmpty(MerchantName))
  213. {
  214. condition += " and CertMerchantName='" + MerchantName + "'";
  215. }
  216. if (!string.IsNullOrEmpty(Mobile))
  217. {
  218. condition += " and MobilePhone='" + Mobile + "'";
  219. }
  220. if (!string.IsNullOrEmpty(MakerCode))
  221. {
  222. var Ids = MerchantInfoUtil.QueryMerchantIdByMakerCode(MakerCode);
  223. condition += " and Id in (" + Ids + ")";
  224. }
  225. if (!string.IsNullOrEmpty(AliPID))
  226. {
  227. condition += " and AlipayPid='" + AliPID + "'";
  228. }
  229. if (!string.IsNullOrEmpty(WeChatNo))
  230. {
  231. condition += " and SubMchid='" + WeChatNo + "'";
  232. }
  233. if (!string.IsNullOrEmpty(SubjectType))
  234. {
  235. if (SubjectType == "1") SubjectType = "SUBJECT_TYPE_ENTERPRISE"; //企业公司
  236. if (SubjectType == "2") SubjectType = "SUBJECT_TYPE_INDIVIDUAL"; //个体工商户
  237. condition += " and SubjectType='" + SubjectType + "'";
  238. }
  239. List<RelationData> relationData = new List<RelationData>();
  240. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  241. Other = new Dictionary<string, object>();
  242. int count = 0;
  243. List<Dictionary<string, object>> source = MerchantAddInfoService.List(relationData, condition, out count, pageNum, pageSize);
  244. foreach (Dictionary<string, object> subdata in source)
  245. {
  246. Dictionary<string, object> curData = new Dictionary<string, object>();
  247. //商户Id
  248. var MerchantId = int.Parse(subdata["Id"].ToString());
  249. curData.Add("MerchantId", subdata["Id"].ToString()); //商户Id
  250. curData.Add("MerchantName", subdata["CertMerchantName"].ToString()); //商户名称
  251. curData.Add("Mobile", subdata["MobilePhone"].ToString()); //手机号码
  252. curData.Add("MakerCode", UsersService.Query(MerchantInfoService.Query(MerchantId).UserId).MakerCode); //所属创客
  253. var subjectType = 0;
  254. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_ENTERPRISE") subjectType = 1; //企业公司
  255. if (subdata["SubjectType"].ToString() == "SUBJECT_TYPE_INDIVIDUAL") subjectType = 2; //个体工商户
  256. curData.Add("AliPID", subdata["AlipayPid"].ToString()); //支付宝PID
  257. curData.Add("WeChatNo", subdata["SubMchid"].ToString()); //微信商户号
  258. curData.Add("SubjectType", subjectType); //主体类型(1 企业 2 个体 3 小微)
  259. curData.Add("MatchNo", subdata["MchtNo"].ToString()); //商户号
  260. curData.Add("OrderCount", ConsumerOrdersService.Count(" and Status>0 and MerchantId=" + MerchantId + "")); //订单总数
  261. curData.Add("InComeAmount", ConsumerOrdersService.Sum(" and Status>0 and MerchantId=" + MerchantId + "", "MerchantActualAmount")); //实收总金额
  262. curData.Add("TradeAmount", ConsumerOrdersService.Sum(" and Status>0 and MerchantId=" + MerchantId + "", "PayMoney")); //营业总金额
  263. dataList.Add(curData);
  264. }
  265. Other.Add("Count", count); //总数
  266. return dataList;
  267. #endregion
  268. }
  269. #region 商户管理-直连添加支付宝PID和微信商户号
  270. [Authorize]
  271. public JsonResult DirectAddPIDOrWeChatNo(string value)
  272. {
  273. value = PublicFunction.DesDecrypt(value);
  274. JsonData data = JsonMapper.ToObject(value);
  275. AppResultJson result = DirectAddPIDOrWeChatNoDo(value);
  276. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  277. }
  278. private AppResultJson DirectAddPIDOrWeChatNoDo(string value)
  279. {
  280. JsonData data = JsonMapper.ToObject(value);
  281. string MerchantId = data["MerchantId"].ToString(); //商户Id
  282. string AliPPID = data["AliPPID"].ToString(); //支付宝PID
  283. string WeChatNo = data["WeChatNo"].ToString(); //微信商户号
  284. Dictionary<string, object> Obj = new Dictionary<string, object>();
  285. var query = MerchantAddInfoService.Query(int.Parse(MerchantId));
  286. Dictionary<string, object> fields = new Dictionary<string, object>();
  287. if (query.Id > 0)
  288. {
  289. if (!string.IsNullOrEmpty(query.AlipayPid))
  290. {
  291. fields.Add("AlipayPid", AliPPID); //支付宝PID
  292. }
  293. if (!string.IsNullOrEmpty(query.SubMchid))
  294. {
  295. fields.Add("SubMchid", WeChatNo); //微信商户号
  296. }
  297. }
  298. AppResultJson resultJson = MerchantAddInfoService.Edit(fields, int.Parse(MerchantId));
  299. return new AppResultJson() { Status = "1", Info = "添加成功", Data = Obj };
  300. }
  301. #endregion
  302. }
  303. }