MerchantDepositOrderController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.Main;
  11. using LitJson;
  12. using Library;
  13. using System.Data;
  14. using MySystem.Service.Main;
  15. using LKBAAlipayConfig;
  16. namespace MySystem.Areas.Api.Controllers.v1
  17. {
  18. [Area("Api")]
  19. [Route("/v1/qrcodeplatemain/[controller]/[action]")]
  20. public class MerchantDepositOrderController : BaseController
  21. {
  22. public MerchantDepositOrderController(IHttpContextAccessor accessor) : base(accessor)
  23. {
  24. }
  25. #region 商户激活-确认支付
  26. // [Authorize]
  27. public JsonResult Pay(string value)
  28. {
  29. value = DesDecrypt(value);
  30. JsonData data = JsonMapper.ToObject(value);
  31. AppResultJson result = PayDo(value);
  32. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  33. }
  34. private AppResultJson PayDo(string value)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1 支付宝)
  38. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  39. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //订单记录Id
  40. Dictionary<string, object> Obj = new Dictionary<string, object>();
  41. var query = MerchantDepositOrderService.Query(Id);
  42. if (query.Id > 0)
  43. {
  44. Dictionary<string, object> fields = new Dictionary<string, object>();
  45. fields.Add("Sort", PayMode); //支付方式(1 支付宝)
  46. MerchantDepositOrderService.Edit(fields, Id, false);
  47. string PayData = "";
  48. if (PayMode == 1)
  49. {
  50. string TotalPrice = query.ActPayPrice.ToString();
  51. function.WriteLog(query.OrderNo, "支付宝支付日志");
  52. function.WriteLog(TotalPrice.ToString(), "支付宝支付日志");
  53. function.WriteLog("商户激活—确认订单", "支付宝支付日志");
  54. string ProductName = "商户激活";
  55. PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, LKBAliPayInfo.AppId, LKBAliPayInfo.PrivateKey, SpHost + "/Api/Alipay/NoticePay2");
  56. function.WriteLog(PayData, "支付宝支付日志");
  57. }
  58. Obj.Add("PayData", PayData); //支付宝微信SDK所需数据
  59. }
  60. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  61. }
  62. #endregion
  63. #region 商户激活—确认订单
  64. // [Authorize]
  65. public JsonResult ConfirmOrder(string value)
  66. {
  67. value = DesDecrypt(value);
  68. JsonData data = JsonMapper.ToObject(value);
  69. AppResultJson result = ConfirmOrderDo(value);
  70. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  71. }
  72. private AppResultJson ConfirmOrderDo(string value)
  73. {
  74. function.WriteLog(value, "商户激活—确认订单");
  75. JsonData data = JsonMapper.ToObject(value);
  76. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  77. Dictionary<string, object> Obj = new Dictionary<string, object>();
  78. MerchantInfo merchant = MerchantInfoService.Query(MerchantId);
  79. string OrderNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  80. string check = RedisDbconn.Instance.Get<string>("ConfirmOrder:" + MerchantId + "_" + OrderNo);
  81. if (!string.IsNullOrEmpty(check))
  82. {
  83. return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
  84. }
  85. RedisDbconn.Instance.Set("ConfirmOrder:" + MerchantId + "_" + OrderNo, "1");
  86. RedisDbconn.Instance.SetExpire("ConfirmOrder:" + MerchantId + "_" + OrderNo, 10);
  87. var IsBuy = MerchantDepositOrderService.Query(" 1=1 and Status>0 and MerchantId=" + MerchantId + "");
  88. if (IsBuy.Id > 0) return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
  89. decimal ActPayPrice = 365; //服务费总额
  90. var Id = MerchantDepositOrderUtil.AddMerchantDepositOrder(OrderNo, merchant.UserId, MerchantId, ActPayPrice);
  91. var query = MerchantDepositOrderService.Query(Id);
  92. Obj.Add("Id", Id); //Id
  93. Obj.Add("CreateDate", query.CreateDate); //创建时间
  94. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  95. }
  96. #endregion
  97. #region 已激活商户-活动时间
  98. // [Authorize]
  99. public JsonResult Info(string value)
  100. {
  101. value = DesDecrypt(value);
  102. JsonData data = JsonMapper.ToObject(value);
  103. AppResultJson result = InfoDo(value);
  104. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  105. }
  106. private AppResultJson InfoDo(string value)
  107. {
  108. JsonData data = JsonMapper.ToObject(value);
  109. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  110. Dictionary<string, object> Obj = new Dictionary<string, object>();
  111. var CreateDate = "";
  112. var StartDate = "";
  113. var EndDate = "";
  114. var Status = -1;
  115. var query = MerchantDepositOrderService.Query(" 1=1 and Status>0 and MerchantId=" + MerchantId + "");
  116. if (query.Id > 0)
  117. {
  118. CreateDate = DateTime.Parse(query.UpdateDate.ToString()).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).Month + "月" + DateTime.Parse(query.UpdateDate.ToString()).Day + "日";
  119. StartDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Month + "月";
  120. EndDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Month + "月";
  121. Status = MerchantInfoService.Query(MerchantId).ExamineStatus;
  122. }
  123. Obj.Add("CreateDate", CreateDate); //参与时间
  124. Obj.Add("StartDate", StartDate); //考核开始时间
  125. Obj.Add("EndDate", EndDate); //考核结束时间
  126. Obj.Add("Status", Status); //考核状态(-1 未参与 0 考核中 1 已通过 2 未通过 101 待领取 100 已领取 99 发放中)
  127. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  128. }
  129. #endregion
  130. }
  131. }