HomeController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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(string p)
  171. {
  172. BsModels.WebCMSEntities db = new BsModels.WebCMSEntities();
  173. var sysadmins = db.SysAdmin.ToList();
  174. foreach(var sysadmin in sysadmins)
  175. {
  176. BsModels.SysAdmin edit = db.SysAdmin.FirstOrDefault(m => m.Id == sysadmin.Id);
  177. if(edit != null)
  178. {
  179. string pwd = function.get_Random(8);
  180. edit.Password = function.MD5_32(pwd);
  181. db.SaveChanges();
  182. function.WriteLog(edit.AdminName + ":" + pwd, "pwd");
  183. }
  184. }
  185. db.Dispose();
  186. return "ok";
  187. }
  188. private SymmetricAlgorithm mCSP = new TripleDESCryptoServiceProvider();
  189. public string DecryptString(string Value, string sKey, string sIV = "12345678")
  190. {
  191. TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
  192. DES.Key = Convert.FromBase64String(sKey);
  193. DES.Mode = CipherMode.CBC;
  194. DES.Padding = System.Security.Cryptography.PaddingMode.None;
  195. DES.IV = ASCIIEncoding.ASCII.GetBytes(sIV);
  196. ICryptoTransform DESDecrypt = DES.CreateDecryptor();
  197. string result = "";
  198. try
  199. {
  200. byte[] Buffer = Convert.FromBase64String(Value);
  201. result = ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
  202. //MemoryStream msDecrypt = new MemoryStream(Buffer);
  203. //CryptoStream csDecrypt = new CryptoStream(msDecrypt,
  204. // DES.CreateDecryptor(DES.Key, DES.IV),
  205. // CryptoStreamMode.Read);
  206. //// Create buffer to hold the decrypted data.
  207. //byte[] fromEncrypt = new byte[Buffer.Length];
  208. //// Read the decrypted data out of the crypto stream
  209. //// and place it into the temporary buffer.
  210. //csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
  211. //result = System.Text.Encoding.Default.GetString(fromEncrypt);
  212. }
  213. catch (Exception e)
  214. {
  215. result = e.ToString();
  216. }
  217. return result;
  218. }
  219. public string cash()
  220. {
  221. WebCMSEntities db = new WebCMSEntities();
  222. List<int> ids = new List<int>();
  223. ids.Add(179761);
  224. ids.Add(180213);
  225. ids.Add(180651);
  226. ids.Add(180810);
  227. ids.Add(181026);
  228. ids.Add(181187);
  229. ids.Add(181300);
  230. ids.Add(181376);
  231. ids.Add(181428);
  232. ids.Add(181468);
  233. ids.Add(181601);
  234. ids.Add(181814);
  235. foreach(int Id in ids)
  236. {
  237. UserCashRecord edit = db.UserCashRecord.FirstOrDefault(m => m.Id == Id && m.Status == 0);
  238. if (edit != null)
  239. {
  240. edit.Status = 2;
  241. edit.Remark = "出款银行故障,请重试";
  242. edit.UpdateMan = "系统";
  243. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == edit.UserId);
  244. if (account != null)
  245. {
  246. decimal TradeAmount = edit.TradeAmount;
  247. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  248. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  249. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  250. account.BalanceAmount += TradeAmount;
  251. // if (account.FreezeAmount >= TradeAmount)
  252. // {
  253. account.FreezeAmount -= TradeAmount;
  254. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  255. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  256. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  257. db.UserAccountRecord.Add(new UserAccountRecord()
  258. {
  259. CreateDate = DateTime.Now,
  260. UpdateDate = DateTime.Now,
  261. UserId = edit.UserId, //创客
  262. ChangeType = 6, //变动类型
  263. ProductType = 99, //产品类型
  264. ChangeAmount = TradeAmount, //变更金额
  265. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  266. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  267. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  268. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  269. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  270. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  271. });
  272. db.SaveChanges();
  273. // }
  274. // else
  275. // {
  276. // function.WriteLog(Id.ToString(), "冻结金额不足");
  277. // }
  278. }
  279. }
  280. }
  281. db.Dispose();
  282. return "ok";
  283. }
  284. }
  285. }