ActivityProgressBarController.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using Microsoft.AspNetCore.Authorization;
  10. using System.Web;
  11. using MySystem.MainModels;
  12. using LitJson;
  13. using Library;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/[controller]/[action]")]
  18. public class ActivityProgressBarController : BaseController
  19. {
  20. public ActivityProgressBarController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  23. }
  24. #region 创客-翻倍活动
  25. [Authorize]
  26. public JsonResult List(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> Obj = ListDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  32. }
  33. public Dictionary<string, object> ListDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  37. Dictionary<string, object> Obj = new Dictionary<string, object>();
  38. var lastmonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  39. var thismonth = DateTime.Now.ToString("yyyyMM");
  40. DateTime start = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
  41. DateTime end = DateTime.Now.AddDays(16 - DateTime.Now.Day).Date;
  42. // DateTime end = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);//本月月底
  43. int IsBuy = 0;//是否参与(0-否 1-是)
  44. Orders od = maindb.Orders.FirstOrDefault(m => m.UserId == UserId && m.TotalPrice == 88 && m.Status > 0 && m.CreateDate >= start && m.CreateDate <= end);
  45. if (od != null)
  46. {
  47. IsBuy = 1;
  48. string UserIdString = "," + UserId + ",";
  49. List<Users> users = maindb.Users.Where(m => m.ParentNav.Contains(UserIdString) || m.Id == UserId).ToList();
  50. List<int> uids = new List<int>();
  51. List<int> uids2 = new List<int>();
  52. foreach (var user in users)
  53. {
  54. uids.Add(user.Id);
  55. }
  56. var orders = maindb.Orders.Select(m => new { m.Id, m.UserId, m.TotalPrice, m.Status, m.CreateDate }).Where(m => m.TotalPrice == 88 && m.Status > 0 && uids.Contains(m.UserId) && m.CreateDate >= start && m.CreateDate <= end).ToList();
  57. foreach (var order in orders)
  58. {
  59. uids2.Add(order.UserId);
  60. }
  61. users = users.Where(m => uids2.Contains(m.Id)).ToList();
  62. List<ProgressUserList> list = new List<ProgressUserList>();
  63. foreach (Users user in users)
  64. {
  65. int IsOk = 0;//是否达标(0-否 1-是)
  66. decimal lastMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == lastmonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt + m.ProfitNonDirectTradeAmt);
  67. decimal thisMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == thismonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt + m.ProfitNonDirectTradeAmt);
  68. if (thisMonthAmt >= lastMonthAmt * 2)
  69. {
  70. IsOk = 1;
  71. }
  72. ProgressUserList item = new ProgressUserList()
  73. {
  74. LastMonth = lastMonthAmt,
  75. ThisMonth = thisMonthAmt,
  76. UserId = user.Id,
  77. IsOk = IsOk,
  78. ParentNav = user.ParentNav
  79. };
  80. list.Add(item);
  81. }
  82. list = list.OrderBy(m => m.ParentNav).ToList();
  83. int index = 0;
  84. decimal selfTrade = 0; // 自己的本月交易额
  85. decimal lastTrade = 0; // 自己的上月交易额
  86. decimal totalTrade = 0; // 自己的本月目标交易额
  87. string selfNav = ""; // 自己的ParentNav
  88. List<string> ParentNavs = new List<string>();
  89. if (list.Count > 0)
  90. {
  91. foreach (ProgressUserList sub in list)
  92. {
  93. index += 1;
  94. if (index == 1)
  95. {
  96. selfTrade = sub.ThisMonth;
  97. lastTrade = sub.LastMonth;
  98. totalTrade = lastTrade * 2;
  99. selfNav = sub.ParentNav + "," + sub.UserId + ",";
  100. }
  101. else
  102. {
  103. bool op = true; //是否满足条件
  104. string ParentNav = sub.ParentNav + "," + sub.UserId + ",";
  105. foreach (string subNav in ParentNavs)
  106. {
  107. if (ParentNavs.Contains(ParentNav) && ParentNav != subNav)
  108. {
  109. op = false;
  110. }
  111. }
  112. if (op)
  113. {
  114. if (sub.IsOk == 1)
  115. {
  116. selfTrade -= sub.ThisMonth;
  117. totalTrade -= sub.ThisMonth;
  118. }
  119. }
  120. ParentNavs.Add(ParentNav);
  121. }
  122. }
  123. }
  124. if (lastTrade * 2 < 2000000 || selfTrade == 0 || totalTrade < 2000000)
  125. {
  126. totalTrade = 2000000;
  127. }
  128. Obj.Add("IsBuy", IsBuy);
  129. Obj.Add("SelfTrade", selfTrade);
  130. Obj.Add("LastTrade", lastTrade);
  131. Obj.Add("TotalTrade", totalTrade);
  132. return Obj;
  133. }
  134. else
  135. {
  136. Obj.Add("IsBuy", IsBuy);
  137. return Obj;
  138. }
  139. }
  140. #endregion
  141. }
  142. }