Curriculum.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. //declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\model\Video;
  5. use app\common\controller\Backend;
  6. use think\facade\Db;
  7. use think\facade\Request;
  8. use think\facade\Session;
  9. use think\facade\View;
  10. use Ramsey\Uuid\Uuid;
  11. class Curriculum extends Backend
  12. {
  13. // todo 课程管理
  14. // 上传的课程
  15. public function index()
  16. {
  17. // Uuid::uuid1();
  18. }
  19. // 我发布的课程
  20. public function my()
  21. {
  22. if (Request::isPost()) {
  23. $page = input("page") ?: 1;
  24. $name = input("name", '', 'trim');
  25. // $admin = is_admin();
  26. $where = [];
  27. // if ($admin) {
  28. // $where["c.subject_id"] = $admin;
  29. // }
  30. if ($name) {
  31. $where["c.grade|s.name|su.name"] = $name;
  32. }
  33. if ( $this->quanxian==1){
  34. $where["c.creater_id"]=$this->adminid;
  35. }
  36. if ($this->project){
  37. $where["c.major_id"]=$this->project;
  38. }
  39. $list = Db::name("course")
  40. ->alias("c")
  41. ->order("c.id desc")
  42. ->leftJoin("subject s", "c.major_id=s.id")
  43. ->leftJoin("subject su", "c.subject_id=su.id")
  44. ->where($where)
  45. ->field("c.*,s.name major,su.name subject")
  46. ->paginate(['list_rows' => $this->pageSize, 'page' => $page])
  47. ->each(function ($item) {
  48. if ($item["create_time"]) {
  49. $item["create_time"] = date('Y-m-d H:i:s', $item["create_time"]);
  50. }
  51. return $item;
  52. })
  53. ->toArray();
  54. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  55. }
  56. return View::fetch();
  57. }
  58. // 删除课程
  59. public function del_course()
  60. {
  61. $id = input("id");
  62. $course = Db::name("course")->where(["id" => $id])->delete();
  63. if ($course) {
  64. json_result(1, "操作成功");
  65. }
  66. json_result(2, "操作失败");
  67. }
  68. // 添加或者修改课程
  69. public function add()
  70. {
  71. if (Request::isPost()) {
  72. $id = input("id");
  73. $add["major_id"] = input("major_id") ?: json_result(2, "请选择专业");
  74. $add["subject_id"] = input("subject_id") ?: json_result(2, "请选科目");
  75. // $add["founder"]=
  76. $add["person"] = input("person") ?: json_result(2, "请填写加入学习计划人数");
  77. $add["image"] = input("image") ?: json_result(2, "请选封面");
  78. $add["teachers"] = input("teachers") ?: json_result(2, "请选任课教师");
  79. $add["content"] = input("content") ?: json_result(2, "请选科目简介");
  80. $add["grade"] = input("grade") ?: json_result(2, "请选年级");
  81. // $add["name"] = input("name") ?: json_result(2, "请选课程名");
  82. $add["class_id"] = input("class_id") ?: json_result(2, "请选课程");
  83. $add["update_time"] = time();
  84. $name=Db::name("subject")->where(["id"=>$add["subject_id"]])->find();
  85. $add["name"] =$name["name"];
  86. if ($id) {
  87. Db::name("course")->where(["id" => $id])->update($add);
  88. } else {
  89. $add["create_time"] = time();
  90. $admin=Session::get("admin");
  91. $add["founder"] = $admin["username"];
  92. $add["creater_id"]=$this->adminid;
  93. Db::name("course")->insert($add);
  94. }
  95. json_result(1, "操作成功");
  96. }
  97. $id = input("id");
  98. if ($id) {
  99. $examination = Db::name("course")->where(["id" => $id])->find();
  100. $examination["teachers"]=explode(",",$examination["teachers"]);
  101. } else {
  102. $examination = [];
  103. }
  104. $data["examination"] = $examination;
  105. $whers["major_id"] = ["!=", 0];
  106. $data["major"] = Db::name("subject")->where($whers)->select();
  107. $data["laboratory"] = Db::name("laboratory")->where("status", "=", "0")->field("id,name,person")->select();
  108. $data["user"] = Db::name("user")->where("type", "=", "2")->field("id,name")->select();
  109. // dump($data);
  110. View::assign("info", $data);
  111. return View::fetch();
  112. }
  113. // 科目
  114. public function subject_kemu()
  115. {
  116. $id = input("id");
  117. if ($id) {
  118. $where["major_id"] = $id;
  119. $major = Db::name("subject")->where($where)->field("id,name")->select();
  120. if ($major) {
  121. json_result(1, "", $major);
  122. } else {
  123. json_result(2, "未添加科目");
  124. }
  125. } else {
  126. json_result(2);
  127. }
  128. }
  129. //课程材料表
  130. public function materiallist()
  131. {
  132. if (Request::isPost()) {
  133. // dump($course_id);die();
  134. $course_id = input("course_id");
  135. $page = input("page") ?: 1;
  136. $limit = input("limit") ?: 10;
  137. $where["course_id"] = $course_id;
  138. $list = Db::name("course_material")->where($where)->paginate(["list_rows" => $limit, "page" => $page])->each(function ($item){
  139. $item["create_time"]=date("Y-m-d H:i:s",(int)$item["create_time"]);
  140. return $item;
  141. })->toArray();
  142. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  143. }
  144. $course_id = input("course_id");
  145. View::assign("course_id", $course_id);
  146. return View::fetch();
  147. }
  148. public function getini()
  149. {
  150. // ini_set("upload_max_filesize","1000M");//即允许上传文件大小的最大值
  151. // ini_set("post_max_size","1001M");//指通过表单POST给PHP的所能接收的最大值
  152. // ini_set("memory_limit","9M");//;每个PHP页面所吃掉的最大内存
  153. $upload_max_filesize= ini_get("upload_max_filesize");
  154. $post_max_size= ini_get("post_max_size");
  155. $memory_limit= ini_get("memory_limit");
  156. d($upload_max_filesize);
  157. d($post_max_size);
  158. d($memory_limit);
  159. }
  160. // 上传资料
  161. public function addmaterial()
  162. {
  163. if (Request::isPost()) {
  164. $course_id = input("course_id");
  165. $id = input("id");
  166. $add["name"] = input("name") ?: json_result(2, "请设置材料名称");
  167. $add["url"] = input("url") ?: json_result(2, "请上传材料");
  168. $add["update_time"] = time();
  169. $filesize=0;
  170. $filetype="";
  171. if (is_file(Pah.$add["url"])){
  172. $filesizes=filesize(Pah.$add["url"]);
  173. $filesize = round($filesizes/1024/1024,2);
  174. $filetype=pathinfo(Pah.$add["url"])["extension"];
  175. }
  176. $add["size"]=$filesize;
  177. $add["type"]=$filetype;
  178. if ($id) {
  179. Db::name("course_material")->where(["id" => $id])->update($add);
  180. } else {
  181. $add["create_time"] = time();
  182. $add["course_id"] = $course_id;
  183. Db::name("course_material")->insert($add);
  184. }
  185. json_result(1, "操作成功");
  186. }
  187. $id = input("id");
  188. $course_id = input("course_id");
  189. $data = Db::name("course_material")->where(["id" => $id])->find();
  190. View::assign("info", $data);
  191. View::assign("course_id", $course_id);
  192. return View::fetch();
  193. }
  194. // 删除课程材料
  195. public function del_material()
  196. {
  197. $id = input("id");
  198. Db::name("course_material")->where(["id" => $id])->delete();
  199. json_result(1, "删除成功");
  200. }
  201. //课程视频表
  202. public function videolist()
  203. {
  204. if (Request::isPost()) {
  205. $course_id = input("course_id");
  206. $page = input("page") ?: 1;
  207. $limit = input("limit") ?: 10;
  208. $where["course_id"] = $course_id;
  209. $list = Db::name("course_video")->order("order desc")->where($where)->paginate(["list_rows" => $limit, "page" => $page])->each(function ($item){
  210. $item["create_time"]=date("Y-m-d H:i:s",(int)$item["create_time"]);
  211. return $item;
  212. })->toArray();
  213. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  214. }
  215. $course_id = input("course_id");
  216. View::assign("course_id", $course_id);
  217. return View::fetch();
  218. }
  219. // 上传视频
  220. public function addvideo()
  221. {
  222. if (Request::isPost()) {
  223. $course_id = input("course_id");
  224. $id = input("id");
  225. $add["name"] = input("name") ?: json_result(2, "请设置视频名称");
  226. $add["url"] = input("url") ?: json_result(2, "请上传视频");
  227. $add["order"] = input("order") ?: json_result(2, "第几节课程");
  228. $add["backimge"] = input("image") ?: json_result(2, "视频封面");
  229. $add["update_time"] = time();
  230. if (!is_numeric($add["order"])||strpos($add["order"],".")!==false){
  231. json_result(2,"课程章节 只能是 整数");
  232. }
  233. if ($add["url"]){
  234. $filesize=0;
  235. $filetype="";
  236. $videotime=0;
  237. if (is_file(Pah.$add["url"])){
  238. $filesizes=filesize(Pah.$add["url"]);
  239. $filesize = round($filesizes/1024/1024,2);
  240. $filetype=pathinfo(Pah.$add["url"])["extension"];
  241. }
  242. if (!$add["backimge"]){
  243. $video=Video::ffmpeg_getTime(Pah.$add["url"]);
  244. $add["backimge"]=$video["img"];
  245. $add["time"]=$video["seconds"];
  246. // dump($video);
  247. }else{
  248. $video=Video::video_time(Pah.$add["url"]);
  249. $add["time"]=$video;
  250. // dump($video);
  251. }
  252. $add["size"]=$filesize;
  253. $add["type"]=$filetype;
  254. $add["time_long"]=$tim= gmdate("H:i:s", $add["time"]);;
  255. }
  256. // dump($add);return ;
  257. if ($id) {
  258. Db::name("course_video")->where(["id" => $id])->update($add);
  259. } else {
  260. $add["create_time"] = time();
  261. $add["course_id"] = $course_id;
  262. Db::name("course_video")->insert($add);
  263. }
  264. json_result(1, "操作成功");
  265. }
  266. $id = input("id");
  267. $data = Db::name("course_video")->where(["id" => $id])->find();
  268. View::assign("info", $data);
  269. $course_id = input("course_id");
  270. View::assign("course_id", $course_id);
  271. return View::fetch();
  272. }
  273. // 删除视频
  274. public function del_video()
  275. {
  276. $id = input("id");
  277. Db::name("course_video")->where(["id" => $id])->delete();
  278. json_result(1, "删除成功");
  279. }
  280. }