MerchantDepositOrderController.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. using LKBAAlipayConfig;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("/v1/qrcodeplatemain/[controller]/[action]")]
  18. public class MerchantDepositOrderController : BaseController
  19. {
  20. public MerchantDepositOrderController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. }
  23. #region 商户激活-确认支付
  24. [Authorize]
  25. public JsonResult Pay(string value)
  26. {
  27. value = DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. AppResultJson result = PayDo(value);
  30. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  31. }
  32. private AppResultJson PayDo(string value)
  33. {
  34. JsonData data = JsonMapper.ToObject(value);
  35. int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1 支付宝)
  36. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  37. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //订单记录Id
  38. Dictionary<string, object> Obj = new Dictionary<string, object>();
  39. var query = new MerchantDepositOrderService().QueryById(Id);
  40. if (query.Id > 0)
  41. {
  42. Dictionary<string, object> fields = new Dictionary<string, object>();
  43. fields.Add("Sort", PayMode); //支付方式(1 支付宝)
  44. MerchantDepositOrderService.Edit(fields, Id, false);
  45. string PayData = "";
  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, LKBAliPayInfo.AppId, LKBAliPayInfo.PrivateKey, SpHost + "/Api/Alipay/NoticePay2");
  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. var IsBuy = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
  86. if (IsBuy.Id > 0) return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
  87. decimal ActPayPrice = 365; //服务费总额
  88. var Id = MerchantDepositOrderUtil.AddMerchantDepositOrder(OrderNo, merchant.UserId, MerchantId, ActPayPrice);
  89. var query = new MerchantDepositOrderService().QueryById(Id);
  90. Obj.Add("Id", Id); //Id
  91. Obj.Add("CreateDate", query.CreateDate); //创建时间
  92. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  93. }
  94. #endregion
  95. #region 已激活商户-活动时间
  96. [Authorize]
  97. public JsonResult Info(string value)
  98. {
  99. value = DesDecrypt(value);
  100. JsonData data = JsonMapper.ToObject(value);
  101. AppResultJson result = InfoDo(value);
  102. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  103. }
  104. private AppResultJson InfoDo(string value)
  105. {
  106. JsonData data = JsonMapper.ToObject(value);
  107. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  108. Dictionary<string, object> Obj = new Dictionary<string, object>();
  109. var CreateDate = "";
  110. var StartDate = "";
  111. var EndDate = "";
  112. var Status = -1;
  113. var query = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
  114. if (query.Id > 0)
  115. {
  116. CreateDate = DateTime.Parse(query.UpdateDate.ToString()).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).Month + "月" + DateTime.Parse(query.UpdateDate.ToString()).Day + "日";
  117. StartDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Month + "月";
  118. EndDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Month + "月";
  119. Status = new MerchantInfoService().Query(MerchantId).ExamineStatus;
  120. }
  121. Obj.Add("CreateDate", CreateDate); //参与时间
  122. Obj.Add("StartDate", StartDate); //考核开始时间
  123. Obj.Add("EndDate", EndDate); //考核结束时间
  124. Obj.Add("Status", Status); //考核状态(-1 未参与 0 考核中 1 已通过 2 未通过 101 待领取 100 已领取 99 发放中)
  125. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  126. }
  127. #endregion
  128. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  129. /// <summary>
  130. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  131. /// </summary>
  132. /// <param name="value">请求的参数(json字符串)</param>
  133. /// <param name="signField">要签名的字段</param>
  134. /// <returns></returns>
  135. private string CheckSign(string value, string[] signField)
  136. {
  137. JsonData json = JsonMapper.ToObject(value);
  138. Dictionary<string, string> dic = new Dictionary<string, string>();
  139. for (int i = 0; i < signField.Length; i++)
  140. {
  141. dic.Add(signField[i], json[signField[i]].ToString());
  142. }
  143. string sign = json["sign"].ToString(); //客户端签名字符串
  144. return new Sign().sign(dic, sign);
  145. }
  146. #endregion
  147. }
  148. }