MerchantInfoController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. namespace MySystem.Areas.Api.Controllers.v1.Main2
  15. {
  16. [Area("Api")]
  17. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  18. public class MerchantInfoController : BaseController
  19. {
  20. public MerchantInfoController(IHttpContextAccessor accessor) : base(accessor)
  21. {
  22. }
  23. #region 商户激活-银联达标商户列表
  24. [Authorize]
  25. public JsonResult UnionPayQualifiedMerchants(string value)
  26. {
  27. value = PublicFunction.DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. Dictionary<string, object> Other = new Dictionary<string, object>();
  30. List<Dictionary<string, object>> dataList = UnionPayQualifiedMerchantsDo(value, out Other);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  32. }
  33. private List<Dictionary<string, object>> UnionPayQualifiedMerchantsDo(string value, out Dictionary<string, object> Other)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. string MerchantName = data["MerchantName"].ToString(); //商户名称
  37. string MctNo = data["MctNo"].ToString(); //商户号
  38. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  39. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  40. string condition = " and IsAct=1 and ExamineStatus=1 and Months=10";
  41. if (!string.IsNullOrEmpty(MerchantName))
  42. {
  43. condition += " and Name like '%" + MerchantName + "%'";
  44. }
  45. if (!string.IsNullOrEmpty(MctNo))
  46. {
  47. var merAddInfo = MerchantAddInfoService.Query(" and MchtNo=" + MctNo + "");
  48. condition += " and Id=" + merAddInfo.Id + "";
  49. }
  50. List<RelationData> relationData = new List<RelationData>();
  51. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  52. Other = new Dictionary<string, object>();
  53. int count = 0;
  54. List<Dictionary<string, object>> source = MerchantInfoService.List(relationData, condition, out count, pageNum, pageSize);
  55. foreach (Dictionary<string, object> subdata in source)
  56. {
  57. Dictionary<string, object> curData = new Dictionary<string, object>();
  58. var MerchantId = int.Parse(subdata["Id"].ToString());
  59. var merAddInfo = MerchantAddInfoService.Query(MerchantId);
  60. var Status = -1;
  61. var order = MerchantDepositOrderService.Query(" and Status>0 and MerchantId=" + MerchantId + "");
  62. if (order.Id > 0) Status = int.Parse(subdata["Status"].ToString());
  63. curData.Add("Id", MerchantId); //Id
  64. curData.Add("MerchantName", merAddInfo.CertMerchantName); //商户名称
  65. curData.Add("MctNo", merAddInfo.MchtNo); //商户号
  66. curData.Add("UpdateDate", order.UpdateDate.ToString() == "" ? "" : DateTime.Parse(order.UpdateDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  67. curData.Add("PayMode", order.Sort); //支付方式(1 支付宝 2 微信)
  68. curData.Add("Status", Status); //达标状态(-1 未参与 0 考核中 1 已通过 2 未通过 101 待领取 100 已领取 99 发放中)
  69. curData.Add("Months", subdata["Months"].ToString()); //达标月数
  70. dataList.Add(curData);
  71. }
  72. Other.Add("Count", count); //总数
  73. return dataList;
  74. }
  75. #endregion
  76. #region 商户管理-商户管理-银联重置登录密码
  77. [Authorize]
  78. public JsonResult UnionPayResetLoginPwd(string value)
  79. {
  80. value = PublicFunction.DesDecrypt(value);
  81. JsonData data = JsonMapper.ToObject(value);
  82. AppResultJson result = UnionPayResetLoginPwdDo(value);
  83. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  84. }
  85. private AppResultJson UnionPayResetLoginPwdDo(string value)
  86. {
  87. JsonData data = JsonMapper.ToObject(value);
  88. string MerchantId = data["MerchantId"].ToString(); //商户Id
  89. Dictionary<string, object> Obj = new Dictionary<string, object>();
  90. var Id = int.Parse(MerchantId);
  91. var query = main2db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  92. var loginMobile = main1db.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == query.Mobile) ?? new Models.Main1.MerchantLoginInfo();
  93. Dictionary<string, object> fields = new Dictionary<string, object>();
  94. if (query.Id > 0)
  95. {
  96. query.LoginPwd = function.MD532(query.Mobile.Substring(query.Mobile.Length - 6, 6)); //登录密码
  97. query.UpdateMan = AppConfig.LoginSession.sysAdminName + "_" + AppConfig.LoginSession.sysRealName;
  98. if (loginMobile.Id > 0)
  99. {
  100. loginMobile.LoginPwd = query.LoginPwd; //登录密码
  101. loginMobile.UpdateMan = AppConfig.LoginSession.sysAdminName + "_" + AppConfig.LoginSession.sysRealName;
  102. }
  103. }
  104. main2db.SaveChanges();
  105. main1db.SaveChanges();
  106. return new AppResultJson() { Status = "1", Info = "该商户的登录密码已重置为手机号后6位", Data = Obj };
  107. }
  108. #endregion
  109. #region 商户管理-商户管理-银联修改手机号
  110. [Authorize]
  111. public JsonResult UnionPayEditMobile(string value)
  112. {
  113. value = PublicFunction.DesDecrypt(value);
  114. JsonData data = JsonMapper.ToObject(value);
  115. AppResultJson result = UnionPayEditMobileDo(value);
  116. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  117. }
  118. private AppResultJson UnionPayEditMobileDo(string value)
  119. {
  120. JsonData data = JsonMapper.ToObject(value);
  121. string MerchantId = data["MerchantId"].ToString(); //商户Id
  122. string Mobile = data["Mobile"].ToString(); //新手机号
  123. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  124. Dictionary<string, object> Obj = new Dictionary<string, object>();
  125. if (Mobile.Length != 11 || !function.IsInt(Mobile) || Mobile.Substring(0, 1) != "1")
  126. {
  127. return new AppResultJson() { Status = "-1", Info = "手机号不正确" };
  128. }
  129. var mobilecheck = RedisDbconn.Instance.Get<string>("MobileCodeCheck:" + Mobile);
  130. if (mobilecheck == "")
  131. {
  132. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  133. }
  134. if (mobilecheck != MobileCode)
  135. {
  136. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  137. }
  138. RedisDbconn.Instance.Clear("MobileCodeCheck:" + Mobile);
  139. var check = Service.Main1.MerchantLoginInfoService.Query(" and LoginMobile=" + Mobile + "");
  140. if (check.Id > 0)
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "已存在相关登录手机号" };
  143. }
  144. var Id = int.Parse(MerchantId);
  145. var query = main2db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  146. var loginMobile = main1db.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == query.Mobile) ?? new Models.Main1.MerchantLoginInfo();
  147. Dictionary<string, object> fields = new Dictionary<string, object>();
  148. if (query.Id > 0)
  149. {
  150. query.Mobile = Mobile;
  151. query.UpdateMan = AppConfig.LoginSession.sysAdminName + "_" + AppConfig.LoginSession.sysRealName;
  152. query.LoginPwd = function.MD532(Mobile.Substring(Mobile.Length - 6, 6)); //登录密码
  153. if (loginMobile.Id > 0)
  154. {
  155. loginMobile.LoginMobile = Mobile;
  156. loginMobile.LoginPwd = query.LoginPwd; //登录密码
  157. loginMobile.UpdateMan = AppConfig.LoginSession.sysAdminName + "_" + AppConfig.LoginSession.sysRealName;
  158. }
  159. }
  160. main2db.SaveChanges();
  161. main1db.SaveChanges();
  162. return new AppResultJson() { Status = "1", Info = "修改成功,新密码默认为该手机号后6位", Data = Obj };
  163. }
  164. #endregion
  165. #region 商户管理-商户管理-银联商户激活订单补全
  166. [Authorize]
  167. public JsonResult UnionPayActOrderCompletion(string value)
  168. {
  169. value = PublicFunction.DesDecrypt(value);
  170. JsonData data = JsonMapper.ToObject(value);
  171. AppResultJson result = UnionPayActOrderCompletionDo(value);
  172. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  173. }
  174. private AppResultJson UnionPayActOrderCompletionDo(string value)
  175. {
  176. JsonData data = JsonMapper.ToObject(value);
  177. string MerchantId = data["MerchantId"].ToString(); //商户Id
  178. string OutTradeNo = data["OutTradeNo"].ToString(); //外部交易号(D或U开头)
  179. string TradeNo = data["TradeNo"].ToString(); //交易号(数字开头)
  180. Dictionary<string, object> Obj = new Dictionary<string, object>();
  181. if (string.IsNullOrEmpty(OutTradeNo) || string.IsNullOrEmpty(TradeNo))
  182. {
  183. return new AppResultJson() { Status = "-1", Info = "外部交易号或交易号为空", Data = Obj };
  184. }
  185. if (OutTradeNo.StartsWith("U"))
  186. {
  187. RedisDbconn.Instance.AddList("AlipayCallBack2", "{\"out_trade_no\":\"" + OutTradeNo + "\",\"transaction_id\":\"" + TradeNo + "\",\"total_fee\":\"" + 0 + "\",\"pay_mode\":\"1\",\"openid\":\"\",\"attach\":\"\"}");
  188. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  189. }
  190. else
  191. {
  192. return new AppResultJson() { Status = "-1", Info = "外部交易号有误", Data = Obj };
  193. }
  194. }
  195. #endregion
  196. #region 商户管理-商户管理-银联商户支付订单补全
  197. [Authorize]
  198. public JsonResult UnionPayOrderCompletion(string value)
  199. {
  200. value = PublicFunction.DesDecrypt(value);
  201. JsonData data = JsonMapper.ToObject(value);
  202. AppResultJson result = UnionPayOrderCompletionDo(value);
  203. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  204. }
  205. private AppResultJson UnionPayOrderCompletionDo(string value)
  206. {
  207. JsonData data = JsonMapper.ToObject(value);
  208. string MerchantId = data["MerchantId"].ToString(); //商户Id
  209. string OutTradeNo = data["OutTradeNo"].ToString(); //外部交易号(G开头)
  210. string TradeNo = data["TradeNo"].ToString(); //交易号(数字开头)
  211. Dictionary<string, object> Obj = new Dictionary<string, object>();
  212. if (string.IsNullOrEmpty(OutTradeNo) || string.IsNullOrEmpty(TradeNo))
  213. {
  214. return new AppResultJson() { Status = "-1", Info = "外部交易号或交易号为空", Data = Obj };
  215. }
  216. RedisDbconn.Instance.AddList("WeChatPayBackHd", "{\"outOrderNo\":\"" + TradeNo + "\",\"orderNo\":\"" + OutTradeNo + "\"}");
  217. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  218. }
  219. #endregion
  220. #region 商户管理-注销
  221. [Authorize]
  222. public JsonResult Logout(string value)
  223. {
  224. value = PublicFunction.DesDecrypt(value); ;
  225. JsonData data = JsonMapper.ToObject(value);
  226. AppResultJson result = LogoutDo(value);
  227. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  228. }
  229. private AppResultJson LogoutDo(string value)
  230. {
  231. JsonData data = JsonMapper.ToObject(value);
  232. Dictionary<string, object> Obj = new Dictionary<string, object>();
  233. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  234. function.WriteLog(DateTime.Now.ToString(), "注销商户日志");
  235. MerchantInfo info = main2db.MerchantInfo.FirstOrDefault(m => m.Id == Id);
  236. if(info != null)
  237. {
  238. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(info));
  239. main2db.MerchantInfo.Remove(info);
  240. }
  241. MerchantAddInfo addInfo = main2db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id);
  242. if(addInfo != null)
  243. {
  244. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(addInfo));
  245. main2db.MerchantAddInfo.Remove(addInfo);
  246. }
  247. main2db.SaveChanges();
  248. function.WriteLog("\n\n", "注销商户日志");
  249. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  250. }
  251. #endregion
  252. }
  253. }