HomeController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Library;
  11. namespace MySystem.Controllers
  12. {
  13. public class HomeController : Controller
  14. {
  15. private readonly ILogger<HomeController> _logger;
  16. public HomeController(ILogger<HomeController> logger)
  17. {
  18. _logger = logger;
  19. }
  20. public IActionResult Index()
  21. {
  22. return View();
  23. }
  24. public IActionResult Error()
  25. {
  26. string isapi = Request.Headers["Api"].ToString();
  27. if (isapi != "1")
  28. {
  29. if (Response.StatusCode == 500)
  30. {
  31. return Redirect("/public/errpage/pc/500.html");
  32. }
  33. else if (Response.StatusCode == 502)
  34. {
  35. return Redirect("/public/errpage/pc/502.html");
  36. }
  37. else if (Response.StatusCode == 404)
  38. {
  39. return Redirect("/public/errpage/pc/404.html");
  40. }
  41. }
  42. return View();
  43. }
  44. // 推荐王奖励
  45. public string InvitePrize666(string month)
  46. {
  47. DateTime start = DateTime.Parse(month + "-01 00:00:00");
  48. DateTime end = start.AddMonths(1);
  49. string TradeMonth = start.ToString("yyyyMM");
  50. WebCMSEntities db = new WebCMSEntities();
  51. //判断当月是否下单
  52. bool checkOrder = db.Orders.Any(m => m.PayDate >= start && m.PayDate < end && m.Status > 0 && m.TotalPrice == 66);
  53. if(checkOrder)
  54. {
  55. //统计当月下单名单
  56. List<int> uids = db.Orders.Where(m => m.PayDate >= start && m.PayDate < end && m.Status > 0 && m.TotalPrice == 66).ToList().Select(m => m.UserId).Distinct().ToList();
  57. foreach(int uid in uids)
  58. {
  59. decimal tradeAmt = 0; //机具总交易额
  60. int actPosCount = 0; //激活机具数量
  61. //查询当前创客所属机具
  62. var posList = db.PosMachinesTwo.Select(m => new { m.ActivationState, m.ActivationTime, m.BuyUserId, m.BindMerchantId }).Where(m => m.BuyUserId == uid && m.ActivationState == 1 && m.ActivationTime >= start && m.ActivationTime < end).ToList();
  63. if(posList.Count > 0)
  64. {
  65. actPosCount = posList.Count;
  66. foreach(var pos in posList)
  67. {
  68. //查询机具交易额
  69. bool checkTrade = db.PosMerchantTradeSummay.Any(m => m.MerchantId == pos.BindMerchantId && m.TradeMonth == TradeMonth);
  70. if(checkTrade)
  71. {
  72. tradeAmt = db.PosMerchantTradeSummay.Where(m => m.MerchantId == pos.BindMerchantId && m.TradeMonth == TradeMonth).Sum(m => m.TradeAmount);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. db.Dispose();
  79. return "";
  80. }
  81. // 创客达标返600
  82. public string shopOrder()
  83. {
  84. string html = "<table>";
  85. WebCMSEntities db = new WebCMSEntities();
  86. OtherMySqlConn.connstr = "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;";
  87. DataTable pos = OtherMySqlConn.dtable("select");
  88. // DataTable dt = OtherMySqlConn.dtable("select BuyUserId,count(Id) from PosMachinesTwo where BuyUserId in (select DISTINCT UserId from Orders where TotalPrice=600 and `Status`>0 and CreateDate<'2022-07-01 00:00:00') and ActivationState=1 and ActivationTime<'2022-07-01 00:00:00' group by BuyUserId HAVING count(Id)>=20");
  89. DataTable dt = OtherMySqlConn.dtable("select BuyUserId,count(Id) from PosMachinesTwo where ActivationState=1 and ActivationTime<'2022-07-01 00:00:00' and BuyUserId in (69542,124745) group by BuyUserId HAVING count(Id)>=20");
  90. foreach(DataRow dr in dt.Rows)
  91. {
  92. int BuyUserId = int.Parse(dr["BuyUserId"].ToString());
  93. Users user = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  94. int ActCount = int.Parse(dr[1].ToString());
  95. decimal TradeAmount = 0;
  96. DataTable dtTrade = OtherMySqlConn.dtable("select sum(TradeAmount) from PosMerchantTradeSummay where TradeMonth='202206' and MerchantId in (select DISTINCT BindMerchantId from PosMachinesTwo where BuyUserId=" + BuyUserId + " and ActivationState=1 and ActivationTime<'2022-07-01 00:00:00')");
  97. if(dtTrade.Rows.Count > 0)
  98. {
  99. TradeAmount = decimal.Parse(function.CheckNum(dtTrade.Rows[0][0].ToString()));
  100. }
  101. decimal AvgTradeAmount = TradeAmount / ActCount;
  102. string Result = "未达标";
  103. if(AvgTradeAmount >= 30000)
  104. {
  105. Result = "达标";
  106. }
  107. html += "<tr>";
  108. html += "<td>" + user.MakerCode + "</td>";
  109. html += "<td>" + user.RealName + "</td>";
  110. html += "<td>" + ActCount + "</td>";
  111. html += "<td>" + TradeAmount + "</td>";
  112. html += "<td>" + AvgTradeAmount.ToString("f2") + "</td>";
  113. html += "<td>" + Result + "</td>";
  114. html += "</tr>";
  115. }
  116. html += "</table>";
  117. db.Dispose();
  118. return html;
  119. }
  120. }
  121. }