MerchantInfoController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. if (loginMobile.Id > 0)
  98. {
  99. loginMobile.LoginPwd = query.LoginPwd; //登录密码
  100. }
  101. }
  102. main2db.SaveChanges();
  103. main1db.SaveChanges();
  104. return new AppResultJson() { Status = "1", Info = "该商户的登录密码已重置为手机号后6位", Data = Obj };
  105. }
  106. #endregion
  107. #region 商户管理-商户管理-银联修改手机号
  108. [Authorize]
  109. public JsonResult UnionPayEditMobile(string value)
  110. {
  111. value = PublicFunction.DesDecrypt(value);
  112. JsonData data = JsonMapper.ToObject(value);
  113. AppResultJson result = UnionPayEditMobileDo(value);
  114. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  115. }
  116. private AppResultJson UnionPayEditMobileDo(string value)
  117. {
  118. JsonData data = JsonMapper.ToObject(value);
  119. string MerchantId = data["MerchantId"].ToString(); //商户Id
  120. string Mobile = data["Mobile"].ToString(); //新手机号
  121. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  122. Dictionary<string, object> Obj = new Dictionary<string, object>();
  123. if (Mobile.Length != 11 || !function.IsInt(Mobile) || Mobile.Substring(0, 1) != "1")
  124. {
  125. return new AppResultJson() { Status = "-1", Info = "手机号不正确" };
  126. }
  127. var mobilecheck = RedisDbconn.Instance.Get<string>("MobileCodeCheck:" + Mobile);
  128. if (mobilecheck == "")
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  131. }
  132. if (mobilecheck != MobileCode)
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  135. }
  136. RedisDbconn.Instance.Clear("MobileCodeCheck:" + Mobile);
  137. var check = Service.Main1.MerchantLoginInfoService.Query(" and LoginMobile=" + Mobile + "");
  138. if (check.Id > 0)
  139. {
  140. return new AppResultJson() { Status = "-1", Info = "已存在相关登录手机号" };
  141. }
  142. var Id = int.Parse(MerchantId);
  143. var query = main2db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  144. var loginMobile = main1db.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == query.Mobile) ?? new Models.Main1.MerchantLoginInfo();
  145. Dictionary<string, object> fields = new Dictionary<string, object>();
  146. if (query.Id > 0)
  147. {
  148. query.Mobile = Mobile;
  149. query.LoginPwd = function.MD532(Mobile.Substring(Mobile.Length - 6, 6)); //登录密码
  150. if (loginMobile.Id > 0)
  151. {
  152. loginMobile.LoginMobile = Mobile;
  153. loginMobile.LoginPwd = query.LoginPwd; //登录密码
  154. }
  155. }
  156. main2db.SaveChanges();
  157. main1db.SaveChanges();
  158. return new AppResultJson() { Status = "1", Info = "修改成功,新密码默认为该手机号后6位", Data = Obj };
  159. }
  160. #endregion
  161. #region 商户管理-商户管理-银联商户激活订单补全
  162. [Authorize]
  163. public JsonResult UnionPayActOrderCompletion(string value)
  164. {
  165. value = PublicFunction.DesDecrypt(value);
  166. JsonData data = JsonMapper.ToObject(value);
  167. AppResultJson result = UnionPayActOrderCompletionDo(value);
  168. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  169. }
  170. private AppResultJson UnionPayActOrderCompletionDo(string value)
  171. {
  172. JsonData data = JsonMapper.ToObject(value);
  173. string MerchantId = data["MerchantId"].ToString(); //商户Id
  174. string OutTradeNo = data["OutTradeNo"].ToString(); //外部交易号(D或U开头)
  175. string TradeNo = data["TradeNo"].ToString(); //交易号(数字开头)
  176. Dictionary<string, object> Obj = new Dictionary<string, object>();
  177. if (string.IsNullOrEmpty(OutTradeNo) || string.IsNullOrEmpty(TradeNo))
  178. {
  179. return new AppResultJson() { Status = "-1", Info = "外部交易号或交易号为空", Data = Obj };
  180. }
  181. if (OutTradeNo.StartsWith("U"))
  182. {
  183. RedisDbconn.Instance.AddList("AlipayCallBack2", "{\"out_trade_no\":\"" + OutTradeNo + "\",\"transaction_id\":\"" + TradeNo + "\",\"total_fee\":\"" + 0 + "\",\"pay_mode\":\"1\",\"openid\":\"\",\"attach\":\"\"}");
  184. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  185. }
  186. else
  187. {
  188. return new AppResultJson() { Status = "-1", Info = "外部交易号有误", Data = Obj };
  189. }
  190. }
  191. #endregion
  192. #region 商户管理-商户管理-银联商户支付订单补全
  193. [Authorize]
  194. public JsonResult UnionPayOrderCompletion(string value)
  195. {
  196. value = PublicFunction.DesDecrypt(value);
  197. JsonData data = JsonMapper.ToObject(value);
  198. AppResultJson result = UnionPayOrderCompletionDo(value);
  199. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  200. }
  201. private AppResultJson UnionPayOrderCompletionDo(string value)
  202. {
  203. JsonData data = JsonMapper.ToObject(value);
  204. string MerchantId = data["MerchantId"].ToString(); //商户Id
  205. string OutTradeNo = data["OutTradeNo"].ToString(); //外部交易号(G开头)
  206. string TradeNo = data["TradeNo"].ToString(); //交易号(数字开头)
  207. Dictionary<string, object> Obj = new Dictionary<string, object>();
  208. if (string.IsNullOrEmpty(OutTradeNo) || string.IsNullOrEmpty(TradeNo))
  209. {
  210. return new AppResultJson() { Status = "-1", Info = "外部交易号或交易号为空", Data = Obj };
  211. }
  212. RedisDbconn.Instance.AddList("WeChatPayBackHd", "{\"outOrderNo\":\"" + TradeNo + "\",\"orderNo\":\"" + OutTradeNo + "\"}");
  213. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  214. }
  215. #endregion
  216. }
  217. }