MerchantAddInfoController.cs 17 KB

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