SchoolMakerStudyController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 SchoolMakerStudyController : BaseController
  19. {
  20. public SchoolMakerStudyController(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. List<Dictionary<string, object>> dataList = ListDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  32. }
  33. public List<Dictionary<string, object>> ListDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. // string Month = data["Month"].ToString(); //月份
  37. // string Title = data["Title"].ToString(); //标题
  38. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  39. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  40. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  41. IQueryable<SchoolMakerStudy> query = maindb.SchoolMakerStudy.Where(m => m.Status > -1);
  42. // DateTime start = DateTime.Parse(Month.Substring(0, 4) + "-" + Month.Substring(4, 2) + "-01 00:00:00");
  43. // DateTime end = start.AddMonths(1);
  44. // if (!string.IsNullOrEmpty(data["Title"].ToString()))
  45. // {
  46. // query = query.Where(m => m.Title == Title);
  47. // }
  48. // if (!string.IsNullOrEmpty(data["Month"].ToString()))
  49. // {
  50. // query = query.Where(m => m.CreateDate >= start && m.CreateDate < end);
  51. // }
  52. int TotalCount = query.Count();
  53. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  54. if (PageNum == 1)
  55. {
  56. query = query.Take(PageSize);
  57. }
  58. else
  59. {
  60. int skipNum = PageSize * (PageNum - 1);
  61. query = query.Skip(skipNum).Take(PageSize);
  62. }
  63. var mydata = query.ToList();
  64. foreach (var subdata in mydata)
  65. {
  66. Dictionary<string, object> curData = new Dictionary<string, object>();
  67. curData.Add("Title", subdata.Title); //标题
  68. curData.Add("Detail", subdata.Detail); //介绍
  69. curData.Add("Lecturer", subdata.SeoTitle); //主讲人
  70. curData.Add("ListPic", StudyOrMeetDefaultPic(subdata.ListPic)); //列表图片
  71. curData.Add("Url", subdata.Url); //外链
  72. curData.Add("StudyPerson", subdata.QueryCount); //观看次数
  73. curData.Add("Id", subdata.Id); //Id
  74. dataList.Add(curData);
  75. }
  76. return dataList;
  77. }
  78. #endregion
  79. #region 商学院-创客学堂一级菜单
  80. // [Authorize]
  81. public JsonResult FirstMenu(string value)
  82. {
  83. value = DesDecrypt(value);
  84. JsonData data = JsonMapper.ToObject(value);
  85. List<Dictionary<string, object>> dataList = FirstMenuDo(value);
  86. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  87. }
  88. public List<Dictionary<string, object>> FirstMenuDo(string value)
  89. {
  90. JsonData data = JsonMapper.ToObject(value);
  91. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  92. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  93. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  94. Models.WebCMSEntities db = new Models.WebCMSEntities();
  95. var query = db.Col.Where(m => m.Status > -1 && m.ColId.Contains("00500") && m.ColId.Length < 7);
  96. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  97. if (PageNum == 1)
  98. {
  99. query = query.Take(PageSize);
  100. }
  101. else
  102. {
  103. int skipNum = PageSize * (PageNum - 1);
  104. query = query.Skip(skipNum).Take(PageSize);
  105. }
  106. var mydata = query.ToList();
  107. var time = DateTime.Now.AddDays(-3);
  108. foreach (var subdata in mydata)
  109. {
  110. var IsUpdate = 0;
  111. Dictionary<string, object> curData = new Dictionary<string, object>();
  112. var ChildCount = db.Col.Count(m => m.ParentId == subdata.Id);
  113. if (ChildCount > 0)
  114. {
  115. ChildCount = 1;
  116. }
  117. else
  118. {
  119. ChildCount = 0;
  120. }
  121. curData.Add("ColName", subdata.ColName); //标题
  122. curData.Add("ColPicPath", StudyOrMeetDefaultPic(subdata.ColPicPath)); //图片
  123. curData.Add("ColDetail", subdata.ColDetail); //简介
  124. curData.Add("Id", subdata.Id); //分类Id
  125. var check = maindb.SchoolMakerStudy.Any(m => m.Status > -1 && m.CreateDate >= time && m.SeoKeyword.StartsWith(subdata.ColId));
  126. if (check)
  127. {
  128. IsUpdate = 1;
  129. }
  130. curData.Add("IsUpdate", IsUpdate); //是否更新 1 是 0 否
  131. curData.Add("ChildCount", ChildCount); //是否有子级 1 是 0 否
  132. dataList.Add(curData);
  133. }
  134. return dataList;
  135. }
  136. #endregion
  137. #region 商学院-创客学堂二级菜单
  138. // [Authorize]
  139. public JsonResult SecondMenu(string value)
  140. {
  141. value = DesDecrypt(value);
  142. JsonData data = JsonMapper.ToObject(value);
  143. Dictionary<string, object> Other = new Dictionary<string, object>();
  144. List<Dictionary<string, object>> dataList = SecondMenuDo(value, out Other);
  145. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  146. }
  147. public List<Dictionary<string, object>> SecondMenuDo(string value, out Dictionary<string, object> Other)
  148. {
  149. JsonData data = JsonMapper.ToObject(value);
  150. int ColId = int.Parse(data["ColId"].ToString());//上级菜单Id
  151. int ChildCount = int.Parse(data["ChildCount"].ToString());//是否有子级
  152. int UserId = int.Parse(data["UserId"].ToString());//创客Id
  153. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  154. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  155. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  156. Other = new Dictionary<string, object>();
  157. var time = DateTime.Now.AddDays(-3);
  158. var IsAuth = 0;
  159. Models.WebCMSEntities db = new Models.WebCMSEntities();
  160. if (ChildCount == 1)
  161. {
  162. var query = db.Col.Where(m => m.Status > -1 && m.ParentId == ColId);
  163. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  164. if (PageNum == 1)
  165. {
  166. query = query.Take(PageSize);
  167. }
  168. else
  169. {
  170. int skipNum = PageSize * (PageNum - 1);
  171. query = query.Skip(skipNum).Take(PageSize);
  172. }
  173. var mydata = query.ToList();
  174. foreach (var subdata in mydata)
  175. {
  176. Dictionary<string, object> curData = new Dictionary<string, object>();
  177. curData.Add("ColName", subdata.ColName); //标题
  178. curData.Add("ColPicPath", subdata.ColPicPath); //图片
  179. curData.Add("ColDetail", subdata.ColDetail); //简介
  180. curData.Add("Id", subdata.Id); //分类Id
  181. dataList.Add(curData);
  182. }
  183. }
  184. else
  185. {
  186. var IsUpdate = 0;
  187. var IsFrst = 0;
  188. var query = db.Col.FirstOrDefault(m => m.Status > -1 && m.Id == ColId) ?? new Models.Col();
  189. var auth = query.ColId;
  190. var userInfo = maindb.UserCardRecord.FirstOrDefault(m => m.Id == UserId) ?? new UserCardRecord();
  191. if (query.Recommend == 0)
  192. {
  193. if (userInfo.Id > 0)
  194. {
  195. if (userInfo.SeoDescription.Contains("," + auth + ","))
  196. {
  197. IsAuth = 1;
  198. }
  199. }
  200. }
  201. else
  202. {
  203. IsAuth = 1;
  204. }
  205. var mydata = maindb.SchoolMakerStudy.Where(m => m.Status > -1 && m.SeoKeyword.Contains(query.ColId));
  206. mydata = mydata.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  207. if (PageNum == 1)
  208. {
  209. mydata = mydata.Take(PageSize);
  210. }
  211. else
  212. {
  213. int skipNum = PageSize * (PageNum - 1);
  214. mydata = mydata.Skip(skipNum).Take(PageSize);
  215. }
  216. foreach (var subdata in mydata.ToList())
  217. {
  218. IsUpdate += 1;
  219. var check = mydata.Any(m => m.Id == subdata.Id && m.CreateDate >= time);
  220. if (check)
  221. {
  222. IsFrst = 1;
  223. }
  224. if (IsUpdate == 1 && IsFrst == 1)
  225. {
  226. IsUpdate = 1;
  227. }
  228. Dictionary<string, object> curData = new Dictionary<string, object>();
  229. curData.Add("Title", subdata.Title); //标题
  230. curData.Add("Detail", subdata.Detail); //介绍
  231. curData.Add("Lecturer", subdata.SeoTitle); //主讲人
  232. curData.Add("ListPic", StudyOrMeetDefaultPic(subdata.ListPic)); //列表图片
  233. curData.Add("Url", subdata.Url); //外链
  234. curData.Add("StudyPerson", subdata.QueryCount); //观看次数
  235. curData.Add("IsUpdate", IsUpdate == 1 ? 1 : 0); //是否最新 1 是 0 否
  236. curData.Add("Id", subdata.Id); //Id
  237. curData.Add("IsAuth", IsAuth); //是否开放 1 是 0 否
  238. dataList.Add(curData);
  239. }
  240. Other.Add("IsAuth", IsAuth);//1 是 0 否
  241. Other.Add("Info", "暂无观看权限");
  242. }
  243. // Other.Add("IsAuth", IsAuth);//1 是 0 否
  244. // Other.Add("Info", "暂无观看权限");
  245. return dataList;
  246. }
  247. #endregion
  248. #region 商学院-创客学堂二级菜单对应列表
  249. // [Authorize]
  250. public JsonResult StudyList(string value)
  251. {
  252. value = DesDecrypt(value);
  253. JsonData data = JsonMapper.ToObject(value);
  254. Dictionary<string, object> Other = new Dictionary<string, object>();
  255. List<Dictionary<string, object>> dataList = StudyListDo(value, out Other);
  256. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  257. }
  258. public List<Dictionary<string, object>> StudyListDo(string value, out Dictionary<string, object> Other)
  259. {
  260. JsonData data = JsonMapper.ToObject(value);
  261. int ColId = int.Parse(data["ColId"].ToString());//菜单Id
  262. int UserId = int.Parse(data["UserId"].ToString());//创客Id
  263. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  264. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  265. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  266. var time = DateTime.Now.AddDays(-3);
  267. Models.WebCMSEntities db = new Models.WebCMSEntities();
  268. var query = db.Col.FirstOrDefault(m => m.Status > -1 && m.Id == ColId) ?? new Models.Col();
  269. var userInfo = maindb.UserCardRecord.FirstOrDefault(m => m.Id == UserId) ?? new UserCardRecord();
  270. var auth = query.ColId;
  271. var IsAuth = 0;
  272. if (query.Recommend == 0)
  273. {
  274. if (userInfo.Id > 0)
  275. {
  276. if (userInfo.SeoDescription.Contains(auth))
  277. {
  278. IsAuth = 1;
  279. }
  280. }
  281. }
  282. else
  283. {
  284. IsAuth = 1;
  285. }
  286. var mydata = maindb.SchoolMakerStudy.Where(m => m.Status > -1 && m.SeoKeyword.Contains(query.ColId));
  287. mydata = mydata.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  288. if (PageNum == 1)
  289. {
  290. mydata = mydata.Take(PageSize);
  291. }
  292. else
  293. {
  294. int skipNum = PageSize * (PageNum - 1);
  295. mydata = mydata.Skip(skipNum).Take(PageSize);
  296. }
  297. var IsUpdate = 0;
  298. var IsFrst = 0;
  299. foreach (var subdata in mydata.ToList())
  300. {
  301. IsUpdate += 1;
  302. var check = mydata.Any(m => m.Id == subdata.Id && m.CreateDate >= time);
  303. if (check)
  304. {
  305. IsFrst = 1;
  306. }
  307. if (IsUpdate == 1 && IsFrst == 1)
  308. {
  309. IsUpdate = 1;
  310. }
  311. Dictionary<string, object> curData = new Dictionary<string, object>();
  312. curData.Add("Title", subdata.Title); //标题
  313. curData.Add("Detail", subdata.Detail); //介绍
  314. curData.Add("Lecturer", subdata.SeoTitle); //主讲人
  315. curData.Add("ListPic", StudyOrMeetDefaultPic(subdata.ListPic)); //列表图片
  316. curData.Add("Url", subdata.Url); //外链
  317. curData.Add("StudyPerson", subdata.QueryCount); //观看次数
  318. curData.Add("IsUpdate", IsUpdate == 1 ? 1 : 0); //是否最新 1 是 0 否
  319. curData.Add("Id", subdata.Id); //Id
  320. dataList.Add(curData);
  321. }
  322. Other = new Dictionary<string, object>();
  323. Other.Add("IsAuth", IsAuth);//1 是 0 否
  324. Other.Add("Info", "暂无观看权限");
  325. return dataList;
  326. }
  327. #endregion
  328. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  329. /// <summary>
  330. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  331. /// </summary>
  332. /// <param name="value">请求的参数(json字符串)</param>
  333. /// <param name="signField">要签名的字段</param>
  334. /// <returns></returns>
  335. private string CheckSign(string value, string[] signField)
  336. {
  337. JsonData json = JsonMapper.ToObject(value);
  338. Dictionary<string, string> dic = new Dictionary<string, string>();
  339. for (int i = 0; i < signField.Length; i++)
  340. {
  341. dic.Add(signField[i], json[signField[i]].ToString());
  342. }
  343. string sign = json["sign"].ToString(); //客户端签名字符串
  344. return new Sign().sign(dic, sign);
  345. }
  346. #endregion
  347. }
  348. }