ActivityRecommendKingController.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 ActivityRecommendKingController : BaseController
  19. {
  20. public ActivityRecommendKingController(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> Other = new Dictionary<string, object>();
  31. List<Dictionary<string, object>> Obj = ListDo(value, out Other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj, Other = Other });
  33. }
  34. public List<Dictionary<string, object>> ListDo(string value, out Dictionary<string, object> Other)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. List<Dictionary<string, object>> Obj = new List<Dictionary<string, object>>();
  38. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  39. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  40. int SkipNum = PageSize * (PageNum - 1);
  41. var days = (int)DateTime.Now.DayOfWeek - 1;
  42. DateTime start = DateTime.Parse(DateTime.Now.AddDays(-days).ToString("yyyy-MM-dd") + " 00:00:00");
  43. DateTime end = start.AddDays(6);
  44. string startDate = start.ToString("yyyyMMdd");
  45. string endDate = end.ToString("yyyyMMdd");
  46. string StartId = function.ReadInstance("/ActivityRecommendKing/StartId" + startDate + ".txt");
  47. if(string.IsNullOrEmpty(StartId))
  48. {
  49. DataTable getid = OtherMySqlConn.dtable("SELECT min(Id) FROM UserTradeMonthSummary where SeoKeyword >= '" + startDate + "' and SeoKeyword <= '" + endDate + "'");
  50. if(getid.Rows.Count > 0)
  51. {
  52. StartId = getid.Rows[0][0].ToString();
  53. function.WritePage("/ActivityRecommendKing/", "StartId" + startDate + ".txt", StartId);
  54. }
  55. }
  56. DataTable dt = OtherMySqlConn.dtable("SELECT UserId,sum(ActiveBuddyMerStatus) Sum FROM UserTradeMonthSummary where Id>=" + StartId + " and SeoKeyword >= '" + startDate + "' and SeoKeyword <= '" + endDate + "'and SeoTitle='self' GROUP BY UserId ORDER BY Sum DESC LIMIT " + SkipNum + "," + PageSize + "");
  57. foreach (DataRow item in dt.Rows)
  58. {
  59. Dictionary<string, object> obj = new Dictionary<string, object>();
  60. var query = maindb.Users.FirstOrDefault(m => m.Id == (int)item["UserId"]);
  61. obj.Add("HeadPhoto", DefaultPic(query.HeadPhoto));
  62. obj.Add("RealName", PublicFunction.SetSensitiveName(query.RealName));
  63. obj.Add("MakerCode", query.MakerCode);
  64. obj.Add("OpenCount", int.Parse(item["Sum"].ToString()));
  65. Obj.Add(obj);
  66. }
  67. Other = new Dictionary<string, object>();
  68. Other.Add("StratTime", start.ToString("yyyy-MM-dd"));
  69. Other.Add("EndTime", end.ToString("yyyy-MM-dd"));
  70. return Obj;
  71. }
  72. #endregion
  73. }
  74. }