PrizeController.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. using System.IO;
  14. using System.Text;
  15. namespace MySystem.Areas.Api.Controllers.v1
  16. {
  17. [Area("Api")]
  18. [Route("Api/[controller]/[action]")]
  19. public class PrizeController : BaseController
  20. {
  21. public PrizeController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  22. {
  23. }
  24. #region 获取奖励日志
  25. [Route("/v1/pri/PriLog/getPriLogDetail")]
  26. public Dictionary<string, object> Set(string value)
  27. {
  28. Utils.WriteLog(DateTime.Now.ToString() + "\n" + value, "获取奖励日志");
  29. JsonData data = JsonMapper.ToObject(value);
  30. string DataNo = data["data_no"].ToString();
  31. string PrizeKind = "0"; //data["prize_kind"].ToString();
  32. string content = function.PostWebRequest("https://logic-executor.kexiaoshuang.com/noauth/pri/logdetail", "value={\"data_no\":\"" + DataNo + "\",\"prize_kind\":\"" + PrizeKind + "\"}");
  33. content = content.Replace(": null", ": \"\"");
  34. Dictionary<string, object> result = new Dictionary<string, object>();
  35. JsonData json = JsonMapper.ToObject(content);
  36. result.Add("data", json["data"].ToJson());
  37. result.Add("status", json["status"].ToString());
  38. result.Add("msg", "成功");
  39. return result;
  40. }
  41. public string AesDecrypt(string str, string key)
  42. {
  43. if (string.IsNullOrEmpty(str)) return null;
  44. byte[] toEncryptArray = Convert.FromBase64String(str);
  45. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  46. {
  47. Key = Encoding.UTF8.GetBytes(key),
  48. Mode = System.Security.Cryptography.CipherMode.ECB,
  49. Padding = System.Security.Cryptography.PaddingMode.PKCS7,
  50. };
  51. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
  52. byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  53. return Encoding.UTF8.GetString(resultArray);
  54. }
  55. #endregion
  56. #region 创客-翻倍活动
  57. // [Authorize]
  58. [Route("/api/v1/ActivityProgressBar/List")]
  59. public JsonResult List(string value)
  60. {
  61. value = DesDecrypt(value);
  62. JsonData data = JsonMapper.ToObject(value);
  63. Dictionary<string, object> Obj = ListDo(value);
  64. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  65. }
  66. public Dictionary<string, object> ListDo(string value)
  67. {
  68. JsonData data = JsonMapper.ToObject(value);
  69. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  70. Dictionary<string, object> Obj = new Dictionary<string, object>();
  71. var lastmonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  72. var thismonth = DateTime.Now.ToString("yyyyMM");
  73. DateTime start = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
  74. DateTime end = DateTime.Now.AddDays(16 - DateTime.Now.Day).Date;
  75. // DateTime end = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);//本月月底
  76. int IsBuy = 0;//是否参与(0-否 1-是)
  77. Orders od = maindb.Orders.FirstOrDefault(m => m.UserId == UserId && m.TotalPrice == 88 && m.Status > 0 && m.CreateDate >= start && m.CreateDate <= end);
  78. if (od != null)
  79. {
  80. IsBuy = 1;
  81. string UserIdString = "," + UserId + ",";
  82. List<Users> users = maindb.Users.Where(m => m.ParentNav.Contains(UserIdString) || m.Id == UserId).ToList();
  83. List<int> uids = new List<int>();
  84. List<int> uids2 = new List<int>();
  85. foreach (var user in users)
  86. {
  87. uids.Add(user.Id);
  88. }
  89. 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();
  90. foreach (var order in orders)
  91. {
  92. uids2.Add(order.UserId);
  93. }
  94. users = users.Where(m => uids2.Contains(m.Id)).ToList();
  95. List<ProgressUserList> list = new List<ProgressUserList>();
  96. foreach (Users user in users)
  97. {
  98. int IsOk = 0;//是否达标(0-否 1-是)
  99. decimal lastMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == lastmonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  100. decimal thisMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == thismonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  101. if (thisMonthAmt >= lastMonthAmt * 2)
  102. {
  103. IsOk = 1;
  104. }
  105. ProgressUserList item = new ProgressUserList()
  106. {
  107. LastMonth = lastMonthAmt,
  108. ThisMonth = thisMonthAmt,
  109. UserId = user.Id,
  110. IsOk = IsOk,
  111. ParentNav = user.ParentNav
  112. };
  113. list.Add(item);
  114. }
  115. list = list.OrderBy(m => m.ParentNav).ToList();
  116. int index = 0;
  117. decimal selfTrade = 0; // 自己的本月交易额
  118. decimal lastTrade = 0; // 自己的上月交易额
  119. decimal totalTrade = 0; // 自己的本月目标交易额
  120. string selfNav = ""; // 自己的ParentNav
  121. List<string> ParentNavs = new List<string>();
  122. if (list.Count > 0)
  123. {
  124. foreach (ProgressUserList sub in list)
  125. {
  126. index += 1;
  127. if (index == 1)
  128. {
  129. selfTrade = sub.ThisMonth;
  130. lastTrade = sub.LastMonth;
  131. totalTrade = lastTrade * 2;
  132. selfNav = sub.ParentNav + "," + sub.UserId + ",";
  133. }
  134. else
  135. {
  136. bool op = true; //是否满足条件
  137. string ParentNav = sub.ParentNav + "," + sub.UserId + ",";
  138. foreach (string subNav in ParentNavs)
  139. {
  140. if (ParentNavs.Contains(ParentNav) && ParentNav != subNav)
  141. {
  142. op = false;
  143. }
  144. }
  145. if (op)
  146. {
  147. if (sub.IsOk == 1)
  148. {
  149. selfTrade -= sub.ThisMonth;
  150. totalTrade -= sub.ThisMonth;
  151. }
  152. }
  153. ParentNavs.Add(ParentNav);
  154. }
  155. }
  156. }
  157. if (lastTrade * 2 < 2000000 || selfTrade == 0 || totalTrade < 2000000)
  158. {
  159. totalTrade = 2000000;
  160. }
  161. Obj.Add("IsBuy", IsBuy);
  162. Obj.Add("SelfTrade", selfTrade);
  163. Obj.Add("LastTrade", lastTrade);
  164. Obj.Add("TotalTrade", totalTrade);
  165. return Obj;
  166. }
  167. else
  168. {
  169. Obj.Add("IsBuy", IsBuy);
  170. return Obj;
  171. }
  172. }
  173. #endregion
  174. }
  175. }