HomeController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. using System.Security.Cryptography;
  12. using System.Text;
  13. using System.IO;
  14. namespace MySystem.Controllers
  15. {
  16. public class HomeController : Controller
  17. {
  18. private readonly ILogger<HomeController> _logger;
  19. public HomeController(ILogger<HomeController> logger)
  20. {
  21. _logger = logger;
  22. }
  23. public IActionResult Index()
  24. {
  25. return View();
  26. }
  27. public IActionResult Error()
  28. {
  29. string isapi = Request.Headers["Api"].ToString();
  30. if (isapi != "1")
  31. {
  32. if (Response.StatusCode == 500)
  33. {
  34. return Redirect("/public/errpage/pc/500.html");
  35. }
  36. else if (Response.StatusCode == 502)
  37. {
  38. return Redirect("/public/errpage/pc/502.html");
  39. }
  40. else if (Response.StatusCode == 404)
  41. {
  42. return Redirect("/public/errpage/pc/404.html");
  43. }
  44. }
  45. return View();
  46. }
  47. // 推荐王奖励666 // TODO:待完善
  48. public string InvitePrize666(string month)
  49. {
  50. DateTime start = DateTime.Parse(month + "-01 00:00:00");
  51. DateTime end = start.AddMonths(1);
  52. string TradeMonth = start.ToString("yyyyMM");
  53. List<RecommendPriceList> userdic = new List<RecommendPriceList>();
  54. WebCMSEntities db = new WebCMSEntities();
  55. //判断当月是否下单
  56. bool checkOrder = db.Orders.Any(m => m.PayDate >= start && m.PayDate < end && m.Status > 0 && m.TotalPrice == 66);
  57. if(checkOrder)
  58. {
  59. //统计当月下单名单
  60. 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();
  61. foreach(int uid in uids)
  62. {
  63. int ActCount = 0;
  64. List<Users> users = db.Users.Where(m => m.ParentUserId == uid && m.AuthFlag == 1 && m.AuthDate >= start).ToList();
  65. foreach(Users user in users)
  66. {
  67. int BeforeActCount = db.PosMachinesTwo.Count(m => m.BuyUserId == user.Id && m.ActivationState == 1 && m.ActivationTime < start);
  68. if(BeforeActCount == 0)
  69. {
  70. decimal tradeAmt = 0; //机具总交易额
  71. int actPosCount = 0; //激活机具数量
  72. //查询当前创客所属机具
  73. 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();
  74. if(posList.Count > 0)
  75. {
  76. actPosCount = posList.Count;
  77. foreach(var pos in posList)
  78. {
  79. //查询机具交易额
  80. bool checkTrade = db.PosMerchantTradeSummay.Any(m => m.MerchantId == pos.BindMerchantId && m.TradeMonth == TradeMonth);
  81. if(checkTrade)
  82. {
  83. tradeAmt += db.PosMerchantTradeSummay.Where(m => m.MerchantId == pos.BindMerchantId && m.TradeMonth == TradeMonth).Sum(m => m.TradeAmount);
  84. }
  85. }
  86. decimal AvgTradeAmount = tradeAmt / actPosCount;
  87. if(AvgTradeAmount >= 30000 && actPosCount >= 3)
  88. {
  89. ActCount += 1;
  90. }
  91. }
  92. }
  93. }
  94. RecommendPriceList item = userdic.FirstOrDefault(m => m.UserId == uid);
  95. if(item != null)
  96. {
  97. item.ActCount += ActCount;
  98. }
  99. else
  100. {
  101. userdic.Add(new RecommendPriceList()
  102. {
  103. UserId = uid,
  104. ActCount = ActCount,
  105. });
  106. }
  107. }
  108. }
  109. string html = "<table>";
  110. foreach(RecommendPriceList item in userdic)
  111. {
  112. string status = "未达标";
  113. if(item.ActCount >= 6)
  114. {
  115. status = "已达标";
  116. }
  117. Users user = db.Users.FirstOrDefault(m => m.Id == item.UserId) ?? new Users();
  118. int subCount = db.Users.Count(m => m.ParentUserId == item.UserId && m.AuthFlag == 1 && m.AuthDate >= start);
  119. html += "<tr>";
  120. html += "<td>" + user.MakerCode + "</td>"; //创客编号
  121. html += "<td>" + user.RealName + "</td>"; //创客姓名
  122. html += "<td>" + subCount + "</td>"; //推荐总数
  123. html += "<td>" + item.ActCount + "</td>"; //成功推荐数
  124. html += "<td>" + status + "</td>"; //是否达标
  125. html += "</tr>";
  126. }
  127. html += "</table>";
  128. db.Dispose();
  129. return html;
  130. }
  131. // 创客达标返600
  132. public string shopOrder()
  133. {
  134. string html = "<table>";
  135. WebCMSEntities db = new WebCMSEntities();
  136. OtherMySqlConn.connstr = "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;";
  137. DataTable pos = OtherMySqlConn.dtable("select");
  138. // 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");
  139. 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");
  140. foreach(DataRow dr in dt.Rows)
  141. {
  142. int BuyUserId = int.Parse(dr["BuyUserId"].ToString());
  143. Users user = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  144. int ActCount = int.Parse(dr[1].ToString());
  145. decimal TradeAmount = 0;
  146. 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')");
  147. if(dtTrade.Rows.Count > 0)
  148. {
  149. TradeAmount = decimal.Parse(function.CheckNum(dtTrade.Rows[0][0].ToString()));
  150. }
  151. decimal AvgTradeAmount = TradeAmount / ActCount;
  152. string Result = "未达标";
  153. if(AvgTradeAmount >= 30000)
  154. {
  155. Result = "达标";
  156. }
  157. html += "<tr>";
  158. html += "<td>" + user.MakerCode + "</td>";
  159. html += "<td>" + user.RealName + "</td>";
  160. html += "<td>" + ActCount + "</td>";
  161. html += "<td>" + TradeAmount + "</td>";
  162. html += "<td>" + AvgTradeAmount.ToString("f2") + "</td>";
  163. html += "<td>" + Result + "</td>";
  164. html += "</tr>";
  165. }
  166. html += "</table>";
  167. db.Dispose();
  168. return html;
  169. }
  170. public string test()
  171. {
  172. return DecryptString("tI2uU8zQp54=", "0535YANTAIJIANWANZHONG9912321232");
  173. }
  174. private SymmetricAlgorithm mCSP = new TripleDESCryptoServiceProvider();
  175. public string DecryptString(string Value, string sKey, string sIV = "12345678")
  176. {
  177. TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
  178. DES.Key = Convert.FromBase64String(sKey);
  179. DES.Mode = CipherMode.CBC;
  180. DES.Padding = System.Security.Cryptography.PaddingMode.None;
  181. DES.IV = ASCIIEncoding.ASCII.GetBytes(sIV);
  182. ICryptoTransform DESDecrypt = DES.CreateDecryptor();
  183. string result = "";
  184. try
  185. {
  186. byte[] Buffer = Convert.FromBase64String(Value);
  187. result = ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
  188. //MemoryStream msDecrypt = new MemoryStream(Buffer);
  189. //CryptoStream csDecrypt = new CryptoStream(msDecrypt,
  190. // DES.CreateDecryptor(DES.Key, DES.IV),
  191. // CryptoStreamMode.Read);
  192. //// Create buffer to hold the decrypted data.
  193. //byte[] fromEncrypt = new byte[Buffer.Length];
  194. //// Read the decrypted data out of the crypto stream
  195. //// and place it into the temporary buffer.
  196. //csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
  197. //result = System.Text.Encoding.Default.GetString(fromEncrypt);
  198. }
  199. catch (Exception e)
  200. {
  201. result = e.ToString();
  202. }
  203. return result;
  204. }
  205. }
  206. }