MerchantInfoController.cs 13 KB

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