HomeController.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Data;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Logging;
  9. using MySystem.Models;
  10. using System.Threading;
  11. using Library;
  12. using LitJson;
  13. namespace MySystem.Controllers
  14. {
  15. public class HomeController : Controller
  16. {
  17. private readonly ILogger<HomeController> _logger;
  18. public HomeController(ILogger<HomeController> logger)
  19. {
  20. _logger = logger;
  21. }
  22. public IActionResult Index()
  23. {
  24. return View();
  25. }
  26. public IActionResult Error()
  27. {
  28. string isapi = Request.Headers["Api"].ToString();
  29. if (isapi != "1")
  30. {
  31. if (Response.StatusCode == 500)
  32. {
  33. return Redirect("/public/errpage/pc/500.html");
  34. }
  35. else if (Response.StatusCode == 502)
  36. {
  37. return Redirect("/public/errpage/pc/502.html");
  38. }
  39. else if (Response.StatusCode == 404)
  40. {
  41. return Redirect("/public/errpage/pc/404.html");
  42. }
  43. }
  44. return View();
  45. }
  46. public string test(int id = 0)
  47. {
  48. string txt = "ok";
  49. // txt = WeChatFunction.Instance.QueryProfitShare("1646405429","4200001807202306098649105270","2023060910241258564572510");
  50. // ProfitHelper.Instance.ReturnStat(Id, 2);
  51. WebCMSEntities db = new WebCMSEntities();
  52. List<int> oids = new List<int>();
  53. if(id > 0)
  54. {
  55. oids.Add(id);
  56. }
  57. else
  58. {
  59. oids.Add(15);
  60. oids.Add(16);
  61. oids.Add(17);
  62. oids.Add(18);
  63. oids.Add(19);
  64. oids.Add(20);
  65. }
  66. foreach(int oid in oids)
  67. {
  68. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == oid);
  69. if(order != null)
  70. {
  71. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:2:List", order.Id.ToString());
  72. // RedisDbconn.Instance.AddList("ConsumerOrders:Divi:2:" + order.MerchantId, order);
  73. }
  74. }
  75. db.Dispose();
  76. return txt;
  77. }
  78. public string testAlipay()
  79. {
  80. // string content = AlipayFunction.Instance.QuerySignStatus("2023061317351531100060045");
  81. // List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
  82. // Parameters.Add(new RoyaltyParameters()
  83. // {
  84. // Account = "2088141704579033",
  85. // Amount = "0.01",
  86. // });
  87. // string content = AlipayFunction.Instance.Settle("2023061615441556447868073", "2023061622001451251436120885", Parameters);
  88. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), "2088141704579033");
  89. // string content = AlipayFunction.Instance.Refund("2023061622001451251436120885", "0.01", "门店分红");
  90. // string content = AlipayFunction.Instance.QuerySettle("2023071214274372011988068", "2023071222001457121457238496", "202307BB6d61386d17104395831e3ea6309f0X57");
  91. // MerchantConfirmService.Instance.StartDo(68, 2);
  92. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, "202307BB6d61386d17104395831e3ea6309f0X57");
  93. WebCMSEntities db = new WebCMSEntities();
  94. List<ConsumerOrders> orders = db.ConsumerOrders.Where(m => m.MerchantId == 70 && m.PayMode == 1 && m.Status > 0).OrderBy(m => m.Id).ToList();
  95. foreach(ConsumerOrders order in orders)
  96. {
  97. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
  98. MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
  99. if(order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
  100. {
  101. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  102. //添加分账接收方
  103. if(merchantAdd.Sort == 0)
  104. {
  105. string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, merchantAdd.AlipayAuthToken);
  106. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "支付宝添加分账方");
  107. merchantAdd.Sort = 1;
  108. db.SaveChanges();
  109. }
  110. //发起分账
  111. decimal fee = order.PayMoney * 0.01M;
  112. if(fee >= 0.01M)
  113. {
  114. string TradeNo = order.SeoTitle;
  115. string OrderNo = order.OrderNo;
  116. List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
  117. Parameters.Add(new RoyaltyParameters()
  118. {
  119. Account = AlipayFunction.Instance.Pid,
  120. Amount = fee.ToString("f2"),
  121. });
  122. AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
  123. //开始监听分账状态
  124. // Dictionary<string, object> req = new Dictionary<string, object>();
  125. // req.Add("TradeNo", TradeNo); //支付宝订单号
  126. // req.Add("OrderNo", OrderNo); //商户订单号
  127. // req.Add("AuthToken", merchantAdd.AlipayAuthToken);
  128. // RedisDbconn.Instance.AddList("AlipayShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  129. }
  130. else
  131. {
  132. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:1:List", order.Id.ToString());
  133. // RedisDbconn.Instance.AddRightList("ConsumerOrders:Divi:1:" + order.MerchantId, order);
  134. }
  135. }
  136. }
  137. db.Dispose();
  138. return "ok";
  139. }
  140. }
  141. }