123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using System.Web;
- using MySystem.MainModels;
- using LitJson;
- using Library;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("Api/v1/[controller]/[action]")]
- public class SchoolMakerStudyController : BaseController
- {
- public SchoolMakerStudyController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- }
- #region 商学院-创客学堂列表
- // [Authorize]
- public JsonResult List(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- // string Month = data["Month"].ToString(); //月份
- // string Title = data["Title"].ToString(); //标题
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<SchoolMakerStudy> query = maindb.SchoolMakerStudy.Where(m => m.Status > -1);
- // DateTime start = DateTime.Parse(Month.Substring(0, 4) + "-" + Month.Substring(4, 2) + "-01 00:00:00");
- // DateTime end = start.AddMonths(1);
- // if (!string.IsNullOrEmpty(data["Title"].ToString()))
- // {
- // query = query.Where(m => m.Title == Title);
- // }
- // if (!string.IsNullOrEmpty(data["Month"].ToString()))
- // {
- // query = query.Where(m => m.CreateDate >= start && m.CreateDate < end);
- // }
- int TotalCount = query.Count();
- query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- var mydata = query.ToList();
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Title", subdata.Title); //标题
- curData.Add("Detail", subdata.Detail); //介绍
- curData.Add("Lecturer", subdata.SeoTitle); //主讲人
- curData.Add("ListPic", StudyOrMeetDefaultPic(subdata.ListPic)); //列表图片
- curData.Add("Url", subdata.Url); //外链
- curData.Add("StudyPerson", subdata.QueryCount); //观看次数
- curData.Add("Id", subdata.Id); //Id
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 商学院-创客学堂一级菜单
- // [Authorize]
- public JsonResult FirstMenu(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = FirstMenuDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> FirstMenuDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- Models.WebCMSEntities db = new Models.WebCMSEntities();
- var query = db.Col.Where(m => m.Status > -1 && m.ColId.Contains("00500") && m.ColId.Length < 7);
- query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- var mydata = query.ToList();
- var time = DateTime.Now.AddDays(-3);
- foreach (var subdata in mydata)
- {
- var IsUpdate = 0;
- Dictionary<string, object> curData = new Dictionary<string, object>();
- var ChildCount = db.Col.Count(m => m.ParentId == subdata.Id);
- if (ChildCount > 0)
- {
- ChildCount = 1;
- }
- else
- {
- ChildCount = 0;
- }
- curData.Add("ColName", subdata.ColName); //标题
- curData.Add("ColPicPath", StudyOrMeetDefaultPic(subdata.ColPicPath)); //图片
- curData.Add("ColDetail", subdata.ColDetail); //简介
- curData.Add("Id", subdata.Id); //分类Id
- var check = maindb.SchoolMakerStudy.Any(m => m.Status > -1 && m.CreateDate >= time && m.SeoKeyword.StartsWith(subdata.ColId));
- if (check)
- {
- IsUpdate = 1;
- }
- curData.Add("IsUpdate", IsUpdate); //是否更新 1 是 0 否
- curData.Add("ChildCount", ChildCount); //是否有子级 1 是 0 否
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 商学院-创客学堂二级菜单
- // [Authorize]
- public JsonResult SecondMenu(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = SecondMenuDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> SecondMenuDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- int ColId = int.Parse(data["ColId"].ToString());//上级菜单Id
- int ChildCount = int.Parse(data["ChildCount"].ToString());//是否有子级
- int UserId = int.Parse(data["UserId"].ToString());//创客Id
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- Other = new Dictionary<string, object>();
- var time = DateTime.Now.AddDays(-3);
- var IsAuth = 0;
- Models.WebCMSEntities db = new Models.WebCMSEntities();
- if (ChildCount == 1)
- {
- var query = db.Col.Where(m => m.Status > -1 && m.ParentId == ColId);
- query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- var mydata = query.ToList();
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("ColName", subdata.ColName); //标题
- curData.Add("ColPicPath", subdata.ColPicPath); //图片
- curData.Add("ColDetail", subdata.ColDetail); //简介
- curData.Add("Id", subdata.Id); //分类Id
- dataList.Add(curData);
- }
- }
- else
- {
- var IsUpdate = 0;
- var IsFrst = 0;
- var query = db.Col.FirstOrDefault(m => m.Status > -1 && m.Id == ColId) ?? new Models.Col();
- var auth = query.ColId;
- var userInfo = maindb.UserCardRecord.FirstOrDefault(m => m.Id == UserId) ?? new UserCardRecord();
- if (query.Recommend == 0)
- {
- if (userInfo.Id > 0)
- {
- if (userInfo.SeoDescription.Contains("," + auth + ","))
- {
- IsAuth = 1;
- }
- }
- }
- else
- {
- IsAuth = 1;
- }
- var mydata = maindb.SchoolMakerStudy.Where(m => m.Status > -1 && m.SeoKeyword.Contains(query.ColId));
- mydata = mydata.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- mydata = mydata.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- mydata = mydata.Skip(skipNum).Take(PageSize);
- }
- foreach (var subdata in mydata.ToList())
- {
- IsUpdate += 1;
- var check = mydata.Any(m => m.Id == subdata.Id && m.CreateDate >= time);
- if (check)
- {
- IsFrst = 1;
- }
- if (IsUpdate == 1 && IsFrst == 1)
- {
- IsUpdate = 1;
- }
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Title", subdata.Title); //标题
- curData.Add("Detail", subdata.Detail); //介绍
- curData.Add("Lecturer", subdata.SeoTitle); //主讲人
- curData.Add("ListPic", StudyOrMeetDefaultPic(subdata.ListPic)); //列表图片
- curData.Add("Url", subdata.Url); //外链
- curData.Add("StudyPerson", subdata.QueryCount); //观看次数
- curData.Add("IsUpdate", IsUpdate == 1 ? 1 : 0); //是否最新 1 是 0 否
- curData.Add("Id", subdata.Id); //Id
- curData.Add("IsAuth", IsAuth); //是否开放 1 是 0 否
- dataList.Add(curData);
- }
- Other.Add("IsAuth", IsAuth);//1 是 0 否
- Other.Add("Info", "暂无观看权限");
- }
- // Other.Add("IsAuth", IsAuth);//1 是 0 否
- // Other.Add("Info", "暂无观看权限");
- return dataList;
- }
- #endregion
- #region 商学院-创客学堂二级菜单对应列表
- // [Authorize]
- public JsonResult StudyList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = StudyListDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> StudyListDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- int ColId = int.Parse(data["ColId"].ToString());//菜单Id
- int UserId = int.Parse(data["UserId"].ToString());//创客Id
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- var time = DateTime.Now.AddDays(-3);
- Models.WebCMSEntities db = new Models.WebCMSEntities();
- var query = db.Col.FirstOrDefault(m => m.Status > -1 && m.Id == ColId) ?? new Models.Col();
- var userInfo = maindb.UserCardRecord.FirstOrDefault(m => m.Id == UserId) ?? new UserCardRecord();
- var auth = query.ColId;
- var IsAuth = 0;
- if (query.Recommend == 0)
- {
- if (userInfo.Id > 0)
- {
- if (userInfo.SeoDescription.Contains(auth))
- {
- IsAuth = 1;
- }
- }
- }
- else
- {
- IsAuth = 1;
- }
- var mydata = maindb.SchoolMakerStudy.Where(m => m.Status > -1 && m.SeoKeyword.Contains(query.ColId));
- mydata = mydata.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- mydata = mydata.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- mydata = mydata.Skip(skipNum).Take(PageSize);
- }
- var IsUpdate = 0;
- var IsFrst = 0;
- foreach (var subdata in mydata.ToList())
- {
- IsUpdate += 1;
- var check = mydata.Any(m => m.Id == subdata.Id && m.CreateDate >= time);
- if (check)
- {
- IsFrst = 1;
- }
- if (IsUpdate == 1 && IsFrst == 1)
- {
- IsUpdate = 1;
- }
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Title", subdata.Title); //标题
- curData.Add("Detail", subdata.Detail); //介绍
- curData.Add("Lecturer", subdata.SeoTitle); //主讲人
- curData.Add("ListPic", StudyOrMeetDefaultPic(subdata.ListPic)); //列表图片
- curData.Add("Url", subdata.Url); //外链
- curData.Add("StudyPerson", subdata.QueryCount); //观看次数
- curData.Add("IsUpdate", IsUpdate == 1 ? 1 : 0); //是否最新 1 是 0 否
- curData.Add("Id", subdata.Id); //Id
- dataList.Add(curData);
- }
- Other = new Dictionary<string, object>();
- Other.Add("IsAuth", IsAuth);//1 是 0 否
- Other.Add("Info", "暂无观看权限");
- return dataList;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- for (int i = 0; i < signField.Length; i++)
- {
- dic.Add(signField[i], json[signField[i]].ToString());
- }
- string sign = json["sign"].ToString(); //客户端签名字符串
- return new Sign().sign(dic, sign);
- }
- #endregion
- }
- }
|