215 lines
8.8 KiB
C#
215 lines
8.8 KiB
C#
|
|
using CYQ.Data.Cache;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using Song.ServiceInterfaces;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Configuration;
|
|||
|
|
using System.Dynamic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Runtime.Remoting.Contexts;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Taurus.Core;
|
|||
|
|
using Taurus.Mvc;
|
|||
|
|
using Taurus.Mvc.Attr;
|
|||
|
|
using WeiSha.Common;
|
|||
|
|
|
|||
|
|
namespace PeiXun.Controllers.BasicInfo
|
|||
|
|
{
|
|||
|
|
public class CoursesAPIController : Controller
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
[Token]
|
|||
|
|
[HttpGet]
|
|||
|
|
public void CourseList()
|
|||
|
|
{
|
|||
|
|
int index = Query<int>("index"); index = index == 0 ? 1 : index;
|
|||
|
|
int size = Query<int>("size"); size = size == 0 ? 1 : size;
|
|||
|
|
int sbjid = Query<int>("sbjid"); sbjid = sbjid == 0 ? -1 : sbjid; //专业id
|
|||
|
|
string search = Query<string>("search");
|
|||
|
|
string order = Query<string>("order"); //排序,flux流量最大优先,def推荐、流量,tax排序号,new最新,rec推荐
|
|||
|
|
|
|||
|
|
Song.Entities.Organization org = Business.Do<IOrganization>().OrganCurrent();
|
|||
|
|
int sum = 0;
|
|||
|
|
List<Song.Entities.Course> cour = Business.Do<ICourse>().CoursePager(org.Org_ID, sbjid, -1, true, search, order, size, index, out sum);
|
|||
|
|
|
|||
|
|
dynamic obj = new ExpandoObject();
|
|||
|
|
obj.sum = sum;
|
|||
|
|
obj.index = index; obj.size = size;
|
|||
|
|
obj.sbjid = sbjid;
|
|||
|
|
|
|||
|
|
for (int i = 0; i < cour.Count; i++)
|
|||
|
|
{
|
|||
|
|
Song.Entities.Course c = cour[i];
|
|||
|
|
c.Cou_LogoSmall = Upload.Get["Course"].Virtual + c.Cou_LogoSmall;
|
|||
|
|
c.Cou_Logo = Upload.Get["Course"].Virtual + c.Cou_Logo;
|
|||
|
|
//是否免费,或是限时免费
|
|||
|
|
if (c.Cou_IsLimitFree)
|
|||
|
|
{
|
|||
|
|
DateTime freeEnd = c.Cou_FreeEnd.AddDays(1).Date;
|
|||
|
|
if (!(c.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now))
|
|||
|
|
c.Cou_IsLimitFree = false;
|
|||
|
|
}
|
|||
|
|
c.Cou_Intro = c.Cou_Target = c.Cou_Content = "";
|
|||
|
|
c.Cou_Name = c.Cou_Name.Replace("\"", """);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
obj.data = cour;
|
|||
|
|
Write(JsonConvert.SerializeObject(obj));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Token]
|
|||
|
|
[HttpGet]
|
|||
|
|
public void SelfCourse()
|
|||
|
|
{
|
|||
|
|
string action = Query<string>("action");
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(action)) action = "buycou";
|
|||
|
|
|
|||
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|||
|
|
DistributedCache cache = DistributedCache.Instance;
|
|||
|
|
Song.Entities.Accounts emp = cache.Get<Song.Entities.Accounts>(token);
|
|||
|
|
//学员登录id
|
|||
|
|
int stid = emp.Ac_ID;
|
|||
|
|
|
|||
|
|
dynamic obj = new ExpandoObject();
|
|||
|
|
obj.code = 1;
|
|||
|
|
obj.msg = "success";
|
|||
|
|
|
|||
|
|
switch (action)
|
|||
|
|
{
|
|||
|
|
case "buycou":
|
|||
|
|
List<Song.Entities.Course> buyCou = Business.Do<ICourse>().CourseForStudent(stid, null, 1, false, -1);
|
|||
|
|
HandleCourseInfo(buyCou, action, stid);
|
|||
|
|
obj.data = buyCou;
|
|||
|
|
break;
|
|||
|
|
case "overcou":
|
|||
|
|
List<Song.Entities.Course> overCou = Business.Do<ICourse>().CourseForStudent(stid, null, 2, false, -1);
|
|||
|
|
HandleCourseInfo(overCou, action, stid);
|
|||
|
|
obj.data = overCou;
|
|||
|
|
break;
|
|||
|
|
case "trycou":
|
|||
|
|
List<Song.Entities.Course> trycou = Business.Do<ICourse>().CourseForStudent(stid, null, -1, true, -1);
|
|||
|
|
HandleCourseInfo(trycou, action, stid);
|
|||
|
|
obj.data = trycou;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
Write(JsonConvert.SerializeObject(obj));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[Token]
|
|||
|
|
[HttpGet]
|
|||
|
|
public void CourseInfo()
|
|||
|
|
{
|
|||
|
|
int couid = Query<int>("couid");
|
|||
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|||
|
|
DistributedCache cache = DistributedCache.Instance;
|
|||
|
|
Song.Entities.Accounts emp = cache.Get<Song.Entities.Accounts>(token);
|
|||
|
|
int accid = emp.Ac_ID;
|
|||
|
|
|
|||
|
|
Song.Entities.Course course = Business.Do<ICourse>().CourseSingle(couid);
|
|||
|
|
if (course == null) return;
|
|||
|
|
|
|||
|
|
//是否免费,或是限时免费
|
|||
|
|
if (course.Cou_IsLimitFree)
|
|||
|
|
{
|
|||
|
|
DateTime freeEnd = course.Cou_FreeEnd.AddDays(1).Date;
|
|||
|
|
if (!(course.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now))
|
|||
|
|
course.Cou_IsLimitFree = false;
|
|||
|
|
}
|
|||
|
|
//课程资源路径
|
|||
|
|
course.coupath = Upload.Get["Course"].Virtual;
|
|||
|
|
//学习该课程的总人数,包括已经过期的
|
|||
|
|
int studyCount = Business.Do<ICourse>().CourseStudentSum(course.Cou_ID, null);
|
|||
|
|
course.studyCount = studyCount;
|
|||
|
|
//是否学习当前课程
|
|||
|
|
//是否购买当前课程
|
|||
|
|
bool isBuy = false;
|
|||
|
|
//是否购买
|
|||
|
|
isBuy = Business.Do<ICourse>().StudyIsCourse(accid, course.Cou_ID);
|
|||
|
|
//没有购买,但处于限时免费中
|
|||
|
|
if (!isBuy && course.Cou_IsLimitFree)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
course.isBuy = isBuy;
|
|||
|
|
//是否可以学习,如果是免费或已经选修便可以学习,否则当前课程允许试用且当前章节是免费的,也可以学习
|
|||
|
|
bool canStudy = isBuy || course.Cou_IsFree || course.Cou_IsLimitFree || course.Cou_IsTry;
|
|||
|
|
course.canStudy = canStudy;
|
|||
|
|
//树形章节输出
|
|||
|
|
Song.Entities.Outline[] outlines = Business.Do<IOutline>().OutlineAll(course.Cou_ID, true);
|
|||
|
|
if (outlines.Length > 0)
|
|||
|
|
course.olTree = Business.Do<IOutline>().OutlineTree(outlines);
|
|||
|
|
//课程公告
|
|||
|
|
List<Song.Entities.Guide> guides = Business.Do<IGuide>().GuideCount(0, course.Cou_ID, 0, 0).ToList();
|
|||
|
|
course.guides = guides;
|
|||
|
|
|
|||
|
|
dynamic obj = new ExpandoObject();
|
|||
|
|
obj.code = 1;
|
|||
|
|
obj.msg = "success";
|
|||
|
|
|
|||
|
|
obj.data = course;
|
|||
|
|
Write(JsonConvert.SerializeObject(obj));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据课程ID获取课程信息
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="id"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
//[Cache(Expires = 60)]
|
|||
|
|
//public Song.Entities.Course ForID(int id)
|
|||
|
|
//{
|
|||
|
|
// Song.Entities.Course cur = Business.Do<ICourse>().CourseSingle(id);
|
|||
|
|
// return _tran(cur);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 生成json
|
|||
|
|
/// </summary>
|
|||
|
|
protected void HandleCourseInfo(List<Song.Entities.Course> courses, string action, int stid)
|
|||
|
|
{
|
|||
|
|
//string tm = "{\"sum\":" + courses.Count + ",\"action\":\"" + action + "\",\"object\":[";
|
|||
|
|
for (int i = 0; i < courses.Count; i++)
|
|||
|
|
{
|
|||
|
|
Song.Entities.Course c = courses[i];
|
|||
|
|
c.Cou_LogoSmall = Upload.Get["Course"].Virtual + c.Cou_LogoSmall;
|
|||
|
|
c.Cou_Logo = Upload.Get["Course"].Virtual + c.Cou_Logo;
|
|||
|
|
//是否免费,或是限时免费
|
|||
|
|
if (c.Cou_IsLimitFree)
|
|||
|
|
{
|
|||
|
|
DateTime freeEnd = c.Cou_FreeEnd.AddDays(1).Date;
|
|||
|
|
if (!(c.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now))
|
|||
|
|
c.Cou_IsLimitFree = false;
|
|||
|
|
}
|
|||
|
|
c.Cou_Intro = c.Cou_Target = c.Cou_Content = "";
|
|||
|
|
c.Cou_Name = c.Cou_Name.Replace("\"", """);
|
|||
|
|
|
|||
|
|
c.olcount = Business.Do<IOutline>().OutlineOfCount(c.Cou_ID, -1, true); //当前课程里的章节数
|
|||
|
|
c.quscount = Business.Do<IQuestions>().QuesOfCount(c.Org_ID, c.Sbj_ID, c.Cou_ID, -1, 0, true);//当前课程的试题
|
|||
|
|
//增加输出项
|
|||
|
|
//Dictionary<string, object> addParas = new Dictionary<string, object>();
|
|||
|
|
//addParas.Add("olcount", Business.Do<IOutline>().OutlineOfCount(c.Cou_ID, -1, true)); //当前课程里的章节数
|
|||
|
|
//addParas.Add("quscount", Business.Do<IQuestions>().QuesOfCount(c.Org_ID, c.Sbj_ID, c.Cou_ID, -1, 0, true)); //当前课程的试题
|
|||
|
|
//获取课程的购买信息
|
|||
|
|
Song.Entities.Student_Course sc = Business.Do<ICourse>().StudentCourse(stid, c.Cou_ID);
|
|||
|
|
if (sc != null)
|
|||
|
|
{
|
|||
|
|
//addParas.Add("starttime", sc.Stc_StartTime);
|
|||
|
|
//addParas.Add("endtime", sc.Stc_EndTime);
|
|||
|
|
c.starttime = sc.Stc_StartTime.ToString();
|
|||
|
|
c.endtime = sc.Stc_EndTime.ToString();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//tm += "" + c.ToJson(null, null, addParas);
|
|||
|
|
//if (i < courses.Count - 1) tm += ",";
|
|||
|
|
}
|
|||
|
|
//return tm;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|