CoursetypeController.class.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\AdminController;
  4. class CoursetypeController extends AdminController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. //课程类型列表
  9. public function index(){
  10. $page = I('get.p','1');
  11. session('page',$page);
  12. $res = M('CourseType')->select();
  13. foreach ($res as $r){
  14. $typeNum = M('Course')->where(array('course_type'=>$r['type_id']))->count();
  15. M('CourseType')->where(array('type_id'=>$r['type_id']))->save(array('type_num'=>$typeNum));
  16. }
  17. $count = M('CourseType')->where(array('is_delete'=>1))->count();
  18. //分页
  19. $Page = new \Think\Page($count);
  20. $show = $Page->show();
  21. $typeList = M('CourseType')->where(array('is_delete'=>1))->field()->order('type_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  22. $this->assign('page',$show);
  23. $this->assign('list',$typeList);
  24. $this->display();
  25. }
  26. //课程类型编辑
  27. public function edit(){
  28. $step = I('step','');
  29. $typeId = I('type_id','');
  30. if (empty($step)){
  31. $info = array();
  32. if (!empty($typeId)){
  33. $info = M('CourseType')->where(array('type_id'=>$typeId))->find();
  34. }
  35. $this->assign('info',$info);
  36. $this->display();
  37. }else if($step==2){
  38. $typeName = I('type_name','');
  39. if (mb_strlen($typeName,'UTF8')<2 || mb_strlen($typeName,'UTF8')>12){
  40. $this->error('课程类型名称2到12个汉字');
  41. }
  42. $res = M('CourseType')->where(array('type_name'=>$typeName,'is_delete'=>1))->find();
  43. if ($res!=NULL){
  44. $this->error('课程类型名称已经存在');
  45. }
  46. if ($typeId){
  47. M('CourseType')->where(array('type_id'=>$typeId))->save(array('type_name'=>$typeName));
  48. }else{
  49. M('CourseType')->add(array('type_name'=>$typeName,'operate_dt'=>time()));
  50. }
  51. $this->success('课程类型操作成功','/admin/coursetype/index');
  52. }
  53. }
  54. //删除
  55. public function del(){
  56. $typeId = I('type_id','');
  57. if (!$typeId){
  58. $this->error('课程类型ID错误');
  59. }
  60. //M('CourseType')->where(array('type_id'=>$typeId))->save(array('is_delete'=>2));
  61. M('CourseType')->where(array('type_id'=>$typeId))->delete();
  62. $this->success('课程类型操作成功','/admin/coursetype/index');
  63. }
  64. //分类下课程列表
  65. public function course(){
  66. $typeId = I('type_id','');
  67. if (!$typeId){
  68. $this->error('课程类型ID错误');
  69. }
  70. $condition = array('is_delete'=>1,'course_type'=>$typeId,'course_source'=>1);
  71. $count = M('Course')->where($condition)->count();
  72. //分页
  73. $Page = new \Think\Page($count);
  74. $show = $Page->show();
  75. $courseList = M('Course')->where($condition)->field()->order('course_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  76. $this->assign('page',$show);
  77. $this->assign('list',$courseList);
  78. $this->display('User/course');
  79. }
  80. }