MerchantDepositOrderController.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #region 商户激活-确认支付
  23. // [Authorize]
  24. public JsonResult Pay(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. AppResultJson result = PayDo(value);
  29. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  30. }
  31. public AppResultJson PayDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1 支付宝)
  35. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  36. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //订单记录Id
  37. Dictionary<string, object> Obj = new Dictionary<string, object>();
  38. var query = new MerchantDepositOrderService().QueryById(Id);
  39. if (query.Id > 0)
  40. {
  41. Dictionary<string, object> fields = new Dictionary<string, object>();
  42. fields.Add("Sort", PayMode); //支付方式(1 支付宝)
  43. MerchantDepositOrderService.Edit(fields, Id, false);
  44. string PayData = "";
  45. KxsMainModels.PublicAccountSet set = new AlipayFunctionForKxs(_accessor.HttpContext).SetData(MerchantId);
  46. if (PayMode == 1)
  47. {
  48. string TotalPrice = query.ActPayPrice.ToString();
  49. function.WriteLog(query.OrderNo, "支付宝支付日志");
  50. function.WriteLog(TotalPrice.ToString(), "支付宝支付日志");
  51. function.WriteLog("商户激活—确认订单", "支付宝支付日志");
  52. string ProductName = "商户激活—确认订单";
  53. PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, set.AlipayAppId, set.AlipayPrivateKey, SpHost + "/Api/Alipay/NoticePay");
  54. function.WriteLog(PayData, "支付宝支付日志");
  55. }
  56. Obj.Add("PayData", PayData); //支付宝微信SDK所需数据
  57. }
  58. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  59. }
  60. #endregion
  61. #region 商户激活-确认订单
  62. // [Authorize]
  63. public JsonResult ConfirmOrder(string value)
  64. {
  65. value = DesDecrypt(value);
  66. JsonData data = JsonMapper.ToObject(value);
  67. AppResultJson result = ConfirmOrderDo(value);
  68. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  69. }
  70. private AppResultJson ConfirmOrderDo(string value)
  71. {
  72. function.WriteLog(value, "商户激活—确认订单");
  73. JsonData data = JsonMapper.ToObject(value);
  74. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  75. Dictionary<string, object> Obj = new Dictionary<string, object>();
  76. MerchantInfo merchant = new MerchantInfoService().Query(MerchantId);
  77. string OrderNo = "D" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  78. string check = RedisDbconn.Instance.Get<string>("ConfirmOrder:" + MerchantId + "_" + OrderNo);
  79. if (!string.IsNullOrEmpty(check))
  80. {
  81. return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
  82. }
  83. RedisDbconn.Instance.Set("ConfirmOrder:" + MerchantId + "_" + OrderNo, "1");
  84. RedisDbconn.Instance.SetExpire("ConfirmOrder:" + MerchantId + "_" + OrderNo, 10);
  85. decimal ActPayPrice = 365; //服务费总额
  86. var Id = MerchantDepositOrderUtil.AddMerchantDepositOrder(OrderNo, merchant.UserId, MerchantId, ActPayPrice);
  87. var query = new MerchantDepositOrderService().QueryById(Id);
  88. Obj.Add("Id", Id); //Id
  89. Obj.Add("CreateDate", query.CreateDate); //创建时间
  90. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  91. }
  92. #endregion
  93. #region 已激活商户-活动时间
  94. // [Authorize]
  95. public JsonResult Info(string value)
  96. {
  97. value = DesDecrypt(value);
  98. JsonData data = JsonMapper.ToObject(value);
  99. Dictionary<string, object> Obj = InfoDo(value);
  100. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  101. }
  102. public Dictionary<string, object> InfoDo(string value)
  103. {
  104. JsonData data = JsonMapper.ToObject(value);
  105. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  106. Dictionary<string, object> Obj = new Dictionary<string, object>();
  107. var CreateDate = "";
  108. var StartDate = "";
  109. var EndDate = "";
  110. var query = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
  111. if (query.Id > 0)
  112. {
  113. CreateDate = DateTime.Parse(query.UpdateDate.ToString()).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).Month + "月" + DateTime.Parse(query.UpdateDate.ToString()).Day + "日";
  114. StartDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Month + "月";
  115. EndDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Month + "月";
  116. }
  117. Obj.Add("CreateDate", CreateDate); //参与时间
  118. Obj.Add("StartDate", StartDate); //考核开始时间
  119. Obj.Add("EndDate", EndDate); //考核结束时间
  120. return Obj;
  121. }
  122. #endregion
  123. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  124. /// <summary>
  125. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  126. /// </summary>
  127. /// <param name="value">请求的参数(json字符串)</param>
  128. /// <param name="signField">要签名的字段</param>
  129. /// <returns></returns>
  130. private string CheckSign(string value, string[] signField)
  131. {
  132. JsonData json = JsonMapper.ToObject(value);
  133. Dictionary<string, string> dic = new Dictionary<string, string>();
  134. for (int i = 0; i < signField.Length; i++)
  135. {
  136. dic.Add(signField[i], json[signField[i]].ToString());
  137. }
  138. string sign = json["sign"].ToString(); //客户端签名字符串
  139. return new Sign().sign(dic, sign);
  140. }
  141. #endregion
  142. }
  143. }