HomeController.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // 推荐王奖励666 // TODO:待完善
  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. List<RecommendPriceList> userdic = new List<RecommendPriceList>();
  51. WebCMSEntities db = new WebCMSEntities();
  52. //判断当月是否下单
  53. bool checkOrder = db.Orders.Any(m => m.PayDate >= start && m.PayDate < end && m.Status > 0 && m.TotalPrice == 66);
  54. if(checkOrder)
  55. {
  56. //统计当月下单名单
  57. 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();
  58. foreach(int uid in uids)
  59. {
  60. int ActCount = 0;
  61. List<Users> users = db.Users.Where(m => m.ParentUserId == uid && m.AuthFlag == 1 && m.AuthDate >= start).ToList();
  62. foreach(Users user in users)
  63. {
  64. int BeforeActCount = db.PosMachinesTwo.Count(m => m.BuyUserId == user.Id && m.ActivationState == 1 && m.ActivationTime < start);
  65. if(BeforeActCount == 0)
  66. {
  67. decimal tradeAmt = 0; //机具总交易额
  68. int actPosCount = 0; //激活机具数量
  69. //查询当前创客所属机具
  70. var posList = db.PosMachinesTwo.Select(m => new { m.ActivationState, m.ActivationTime, m.BuyUserId, m.BindMerchantId }).Where(m => m.BuyUserId == user.Id && m.ActivationState == 1 && m.ActivationTime >= start && m.ActivationTime < end).ToList();
  71. if(posList.Count > 0)
  72. {
  73. actPosCount = posList.Count;
  74. foreach(var pos in posList)
  75. {
  76. //查询机具交易额
  77. bool checkTrade = db.PosMerchantTradeSummay.Any(m => m.MerchantId == pos.BindMerchantId && m.TradeMonth == TradeMonth);
  78. if(checkTrade)
  79. {
  80. tradeAmt += db.PosMerchantTradeSummay.Where(m => m.MerchantId == pos.BindMerchantId && m.TradeMonth == TradeMonth).Sum(m => m.TradeAmount);
  81. }
  82. }
  83. decimal AvgTradeAmount = tradeAmt / actPosCount;
  84. if(AvgTradeAmount >= 30000 && actPosCount >= 3)
  85. {
  86. ActCount += 1;
  87. }
  88. }
  89. }
  90. }
  91. RecommendPriceList item = userdic.FirstOrDefault(m => m.UserId == uid);
  92. if(item != null)
  93. {
  94. item.ActCount += ActCount;
  95. }
  96. else
  97. {
  98. userdic.Add(new RecommendPriceList()
  99. {
  100. UserId = uid,
  101. ActCount = ActCount,
  102. });
  103. }
  104. }
  105. }
  106. string html = "<table>";
  107. foreach(RecommendPriceList item in userdic)
  108. {
  109. string status = "未达标";
  110. if(item.ActCount >= 6)
  111. {
  112. status = "已达标";
  113. }
  114. Users user = db.Users.FirstOrDefault(m => m.Id == item.UserId) ?? new Users();
  115. int subCount = db.Users.Count(m => m.ParentUserId == item.UserId && m.AuthFlag == 1 && m.AuthDate >= start);
  116. html += "<tr>";
  117. html += "<td>" + user.MakerCode + "</td>"; //创客编号
  118. html += "<td>" + user.RealName + "</td>"; //创客姓名
  119. html += "<td>" + subCount + "</td>"; //推荐总数
  120. html += "<td>" + item.ActCount + "</td>"; //成功推荐数
  121. html += "<td>" + status + "</td>"; //是否达标
  122. html += "</tr>";
  123. }
  124. html += "</table>";
  125. db.Dispose();
  126. return html;
  127. }
  128. // 创客达标返600
  129. public string shopOrder()
  130. {
  131. string html = "<table>";
  132. WebCMSEntities db = new WebCMSEntities();
  133. OtherMySqlConn.connstr = "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;";
  134. DataTable pos = OtherMySqlConn.dtable("select");
  135. // 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");
  136. 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");
  137. foreach(DataRow dr in dt.Rows)
  138. {
  139. int BuyUserId = int.Parse(dr["BuyUserId"].ToString());
  140. Users user = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  141. int ActCount = int.Parse(dr[1].ToString());
  142. decimal TradeAmount = 0;
  143. 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')");
  144. if(dtTrade.Rows.Count > 0)
  145. {
  146. TradeAmount = decimal.Parse(function.CheckNum(dtTrade.Rows[0][0].ToString()));
  147. }
  148. decimal AvgTradeAmount = TradeAmount / ActCount;
  149. string Result = "未达标";
  150. if(AvgTradeAmount >= 30000)
  151. {
  152. Result = "达标";
  153. }
  154. html += "<tr>";
  155. html += "<td>" + user.MakerCode + "</td>";
  156. html += "<td>" + user.RealName + "</td>";
  157. html += "<td>" + ActCount + "</td>";
  158. html += "<td>" + TradeAmount + "</td>";
  159. html += "<td>" + AvgTradeAmount.ToString("f2") + "</td>";
  160. html += "<td>" + Result + "</td>";
  161. html += "</tr>";
  162. }
  163. html += "</table>";
  164. db.Dispose();
  165. return html;
  166. }
  167. public string test()
  168. {
  169. SycnProfitServiceV2.Instance.DoSubsidyProfit(9, "202210");
  170. return "ok";
  171. }
  172. }
  173. }