Training.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\model\MajorLevel;
  5. use app\admin\model\Ztrees;
  6. use app\common\controller\Backend;
  7. use think\facade\Db;
  8. use think\facade\Request;
  9. use think\facade\View;
  10. class Training extends Backend
  11. {
  12. // todo 培养计划
  13. //专业管理
  14. public function index()
  15. {
  16. if (Request::isPost()){
  17. $page=input("page")?:1;
  18. $name=input("name", '', 'trim');
  19. $where["major_id"]=0;
  20. $list=Db::name("subject")->order("id desc")->where($where)
  21. ->where("name","like","%".$name."%")
  22. ->paginate(['list_rows' => $this->pageSize, 'page' => $page])->toArray();
  23. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  24. }
  25. return View::fetch();
  26. }
  27. // 添加
  28. public function add_major()
  29. {
  30. $name=input("name");
  31. $pid=input("pid")?:0;
  32. $update["name"]=$name;
  33. $update["major_id"]=$pid;
  34. $result=Db::name("subject")->insertGetId($update);
  35. if ($result){
  36. if ($pid==0){// 添加升级等级
  37. MajorLevel::add_level($result);
  38. }
  39. $update["id"]=$result;
  40. $update["pId"]=$pid;
  41. json_result(1,"添加成功",$update);
  42. }
  43. json_result(2,"添加失败");
  44. }
  45. // 修改
  46. public function update_major()
  47. {
  48. $id=input("id");
  49. $name=input("name");
  50. $where["id"]=$id;
  51. $update["name"]=$name;
  52. $result=Db::name("subject")->where($where)->update($update);
  53. if ($result){
  54. json_result(1,"修改成功");
  55. }
  56. json_result(2,"修改失败");
  57. }
  58. // 删除
  59. public function del()
  60. {
  61. $id=input("id");
  62. $where["id"]=$id;
  63. $where_us["major_id"]=$id;
  64. $cout=Db::name("subject")->where($where_us)->find();
  65. if ($cout){
  66. json_result(2,"请先删除下面的科目");
  67. }
  68. if ($cout["major_id"]==0){ // 删除专业等级表
  69. $del_where["subject_id"]=$id;
  70. Db::name("major_level")->where($del_where)->delete();
  71. }
  72. $result=Db::name("subject")->where($where)->delete();
  73. if ($result){
  74. json_result(1,"删除成功");
  75. }
  76. json_result(2,"删除失败11");
  77. }
  78. //课程科目管理
  79. public function course()
  80. {
  81. if (Request::isPost()){
  82. $page = input("page") ?: 1;
  83. $limit = input("limit") ?: 10;
  84. $name=input("name", '', 'trim');
  85. $where=[];
  86. if ($name){
  87. $where[]=["name","like","%".$name."%"];
  88. }
  89. $list=Db::name("subject")->order("major_id asc") ->where($where)->select()->toArray();
  90. // $list=Db::name("subject")->order("major_id asc") ->where($where)->paginate(['list_rows' => $limit, 'page' => $page])->toArray();
  91. // $list=$list["data"];
  92. foreach($list as $k=>$v){
  93. $list[$k]['lay_is_open']=false;
  94. $list[$k]["pId"]=$v["major_id"];
  95. $list[$k]["pid"]=$v["major_id"];
  96. }
  97. $ztree=Ztrees::sortListTier($list);
  98. return $result = ['code' => 0, 'msg' => "获取成功", 'data' => $ztree, 'count' => count($list)];
  99. }
  100. return View::fetch("text");
  101. }
  102. // 升级参数设置
  103. public function upgrade()
  104. {
  105. if (Request::isPost()){
  106. $page=input("page")?:1;
  107. $limit=input("limit")?:10;
  108. $name=input("name", '', 'trim');
  109. // $where["major_id"]=0;
  110. $list=Db::name("major_level")->alias("m")->order("m.id desc")
  111. ->leftJoin("subject su","m.subject_id=su.id")
  112. ->where("su.name","like","%".$name."%")
  113. ->field("m.*,su.name pro_name")
  114. ->paginate(['list_rows' => $limit, 'page' => $page])
  115. ->toArray();
  116. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  117. }
  118. return View::fetch();
  119. }
  120. // 修改
  121. public function update_upgrade()
  122. {
  123. $id=input("id");
  124. $min=input("min");
  125. $max=input("max");
  126. $where["id"]=$id;
  127. $update["min"]=$min;
  128. $update["max"]=$max;
  129. $result=Db::name("major_level")->where($where)->update($update);
  130. if ($result){
  131. json_result(1,"修改成功");
  132. }
  133. json_result(2,"修改失败");
  134. }
  135. }