MerchantDepositOrderController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 MySystem.MainModels;
  10. using LitJson;
  11. using Library;
  12. using MySystem.Service.Main;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("/v1/qrcodeplatemain/[controller]/[action]")]
  17. public class MerchantDepositOrderController : BaseController
  18. {
  19. public MerchantDepositOrderController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. //AppId
  23. private string AppId = "2021004123675441";
  24. //私钥
  25. private string PrivateKey = "MIIEogIBAAKCAQEAn6vdQjedN72fPHtU1a1zSBvoYoyn9fIrjJhnJg4tGAVPk20I4AMiiKpgWn9cDAEgLddceYfR0IRWw+ojZZqVjJsLG8D715H4xJ6AnllWyeNJd43CdTctTnXRAl25Cw2SuG1kanAA/BO186J2LyN/z7l70LkxOFUJVHXhTx0sKxAS7ZBA43ewjl7ycp108eNNbR63gLjy4VDP63pOnI4MuTNeXh3ET/eunREs8gGuvdXOfY9r2Dyj9lOiOPn1xyrZPpT+WGXrPxLyWnSAz1EkLx7d2aRPFFC1rwJQbcsdBnmN35d6hbofOOe9kPN23Z34d0X6ohD0VbiUUdpzU4f9ZwIDAQABAoIBAFK+U3i/LT/3ig9jskDRE86od7KqRVgU2TCQwdNcwU2TYvt5I4JC3aCI+kmrel3WL4DR++AW3En8aqI4MYOzqhAlQIpvZZL+2DW8Fdb5YRpaK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CYW6agkDhb8LdLZMlEsTcEpkOLoSmQ=";
  26. // 公钥
  27. private string PublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn6vdQjedN72fPHtU1a1zSBvoYoyn9fIrjJhnJg4tGAVPk20I4AMiiKpgWn9cDAEgLddceYfR0IRWw+ojZZqVjJsLG8D715H4xJ6AnllWyeNJd43CdTctTnXRAl25Cw2SuG1kanAA/BO186J2LyN/z7l70LkxOFUJVHXhTx0sKxAS7ZBA43ewjl7ycp108eNNbR63gLjy4VDP63pOnI4MuTNeXh3ET/eunREs8gGuvdXOfY9r2Dyj9lOiOPn1xyrZPpT+WGXrPxLyWnSAz1EkLx7d2aRPFFC1rwJQbcsdBnmN35d6hbofOOe9kPN23Z34d0X6ohD0VbiUUdpzU4f9ZwIDAQAB";
  28. // 支付宝公钥
  29. private string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnw14hKejqS+si/XZpNQpFAVOVXJIThj5Qn7H14n/vsb7uRLug1+Jcve8ehTkaN3s5ibrrELCnz0dvshi3cOz9svDSbLG5OdC1biAvZzpDkvVPswOd9f9jO8Jvqk3QTXTI3MSN9gOpKomI0te3qs5kkOQx6kRozzKjU/G//o/PbJCxpBxf/QNRV3XmCwJLZMBE7ukYqi1WO9Jra8jdczFKwrd/nhiKBKdupAtVVeKlylGD2i2YLkGAH1cLsPUN9DtzrXNblGXm2HK3l9SnMDjqnakiVdEQJTNYNpEiHaOJsVmPQL38nM6miz5wNd4gTchKzXPtoZWqto+eIvYaEA/KwIDAQAB";
  30. #region 商户激活-确认支付
  31. // [Authorize]
  32. public JsonResult Pay(string value)
  33. {
  34. value = DesDecrypt(value);
  35. JsonData data = JsonMapper.ToObject(value);
  36. AppResultJson result = PayDo(value);
  37. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  38. }
  39. public AppResultJson PayDo(string value)
  40. {
  41. JsonData data = JsonMapper.ToObject(value);
  42. int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1 支付宝)
  43. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  44. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //订单记录Id
  45. Dictionary<string, object> Obj = new Dictionary<string, object>();
  46. var query = new MerchantDepositOrderService().QueryById(Id);
  47. if (query.Id > 0)
  48. {
  49. Dictionary<string, object> fields = new Dictionary<string, object>();
  50. fields.Add("Sort", PayMode); //支付方式(1 支付宝)
  51. MerchantDepositOrderService.Edit(fields, Id, false);
  52. string PayData = "";
  53. KxsMainModels.PublicAccountSet set = new AlipayFunctionForKxs(_accessor.HttpContext).SetData(MerchantId);
  54. if (PayMode == 1)
  55. {
  56. string TotalPrice = query.ActPayPrice.ToString();
  57. function.WriteLog(query.OrderNo, "支付宝支付日志");
  58. function.WriteLog(TotalPrice.ToString(), "支付宝支付日志");
  59. function.WriteLog("商户激活—确认订单", "支付宝支付日志");
  60. string ProductName = "商户激活";
  61. PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, set.AlipayAppId, set.AlipayPrivateKey, SpHost + "/Api/Alipay/NoticePay");
  62. // PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, AppId, PrivateKey, SpHost + "/Api/Alipay/NoticePay2");
  63. function.WriteLog(PayData, "支付宝支付日志");
  64. }
  65. Obj.Add("PayData", PayData); //支付宝微信SDK所需数据
  66. }
  67. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  68. }
  69. #endregion
  70. #region 商户激活-确认订单
  71. // [Authorize]
  72. public JsonResult ConfirmOrder(string value)
  73. {
  74. value = DesDecrypt(value);
  75. JsonData data = JsonMapper.ToObject(value);
  76. AppResultJson result = ConfirmOrderDo(value);
  77. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  78. }
  79. private AppResultJson ConfirmOrderDo(string value)
  80. {
  81. function.WriteLog(value, "商户激活—确认订单");
  82. JsonData data = JsonMapper.ToObject(value);
  83. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  84. Dictionary<string, object> Obj = new Dictionary<string, object>();
  85. MerchantInfo merchant = new MerchantInfoService().Query(MerchantId);
  86. string OrderNo = "D" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  87. string check = RedisDbconn.Instance.Get<string>("ConfirmOrder:" + MerchantId + "_" + OrderNo);
  88. if (!string.IsNullOrEmpty(check))
  89. {
  90. return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
  91. }
  92. RedisDbconn.Instance.Set("ConfirmOrder:" + MerchantId + "_" + OrderNo, "1");
  93. RedisDbconn.Instance.SetExpire("ConfirmOrder:" + MerchantId + "_" + OrderNo, 10);
  94. var IsBuy = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
  95. if (IsBuy.Id > 0) return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
  96. decimal ActPayPrice = 365; //服务费总额
  97. var Id = MerchantDepositOrderUtil.AddMerchantDepositOrder(OrderNo, merchant.UserId, MerchantId, ActPayPrice);
  98. var query = new MerchantDepositOrderService().QueryById(Id);
  99. Obj.Add("Id", Id); //Id
  100. Obj.Add("CreateDate", query.CreateDate); //创建时间
  101. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  102. }
  103. #endregion
  104. #region 已激活商户-活动时间
  105. // [Authorize]
  106. public JsonResult Info(string value)
  107. {
  108. value = DesDecrypt(value);
  109. JsonData data = JsonMapper.ToObject(value);
  110. AppResultJson result = InfoDo(value);
  111. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  112. }
  113. public AppResultJson InfoDo(string value)
  114. {
  115. JsonData data = JsonMapper.ToObject(value);
  116. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  117. Dictionary<string, object> Obj = new Dictionary<string, object>();
  118. var CreateDate = "";
  119. var StartDate = "";
  120. var EndDate = "";
  121. var Status = -1;
  122. var query = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
  123. if (query.Id > 0)
  124. {
  125. CreateDate = DateTime.Parse(query.UpdateDate.ToString()).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).Month + "月" + DateTime.Parse(query.UpdateDate.ToString()).Day + "日";
  126. StartDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Month + "月";
  127. EndDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Month + "月";
  128. Status = new MerchantInfoService().Query(MerchantId).ExamineStatus;
  129. }
  130. Obj.Add("CreateDate", CreateDate); //参与时间
  131. Obj.Add("StartDate", StartDate); //考核开始时间
  132. Obj.Add("EndDate", EndDate); //考核结束时间
  133. Obj.Add("Status", Status); //考核状态(-1 未参与 0 考核中 1 已通过 2 未通过 101 待领取 100 已领取 99 发放中)
  134. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  135. }
  136. #endregion
  137. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  138. /// <summary>
  139. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  140. /// </summary>
  141. /// <param name="value">请求的参数(json字符串)</param>
  142. /// <param name="signField">要签名的字段</param>
  143. /// <returns></returns>
  144. private string CheckSign(string value, string[] signField)
  145. {
  146. JsonData json = JsonMapper.ToObject(value);
  147. Dictionary<string, string> dic = new Dictionary<string, string>();
  148. for (int i = 0; i < signField.Length; i++)
  149. {
  150. dic.Add(signField[i], json[signField[i]].ToString());
  151. }
  152. string sign = json["sign"].ToString(); //客户端签名字符串
  153. return new Sign().sign(dic, sign);
  154. }
  155. #endregion
  156. }
  157. }