select(); foreach ($res as $r){ $typeNum = M('Course')->where(array('course_type'=>$r['type_id']))->count(); M('CourseType')->where(array('type_id'=>$r['type_id']))->save(array('type_num'=>$typeNum)); } $count = M('CourseType')->where(array('is_delete'=>1))->count(); //分页 $Page = new \Think\Page($count); $show = $Page->show(); $typeList = M('CourseType')->where(array('is_delete'=>1))->field()->order('type_id desc')->limit($Page->firstRow.','.$Page->listRows)->select(); $this->assign('page',$show); $this->assign('list',$typeList); $this->display(); } //课程类型编辑 public function edit(){ $step = I('step',''); $typeId = I('type_id',''); if (empty($step)){ $info = array(); if (!empty($typeId)){ $info = M('CourseType')->where(array('type_id'=>$typeId))->find(); } $this->assign('info',$info); $this->display(); }else if($step==2){ $typeName = I('type_name',''); if (mb_strlen($typeName,'UTF8')<2 || mb_strlen($typeName,'UTF8')>12){ $this->error('课程类型名称2到12个汉字'); } $res = M('CourseType')->where(array('type_name'=>$typeName,'is_delete'=>1))->find(); if ($res!=NULL){ $this->error('课程类型名称已经存在'); } if ($typeId){ M('CourseType')->where(array('type_id'=>$typeId))->save(array('type_name'=>$typeName)); }else{ M('CourseType')->add(array('type_name'=>$typeName,'operate_dt'=>time())); } $this->success('课程类型操作成功','/admin/coursetype/index'); } } //删除 public function del(){ $typeId = I('type_id',''); if (!$typeId){ $this->error('课程类型ID错误'); } //M('CourseType')->where(array('type_id'=>$typeId))->save(array('is_delete'=>2)); M('CourseType')->where(array('type_id'=>$typeId))->delete(); $this->success('课程类型操作成功','/admin/coursetype/index'); } //分类下课程列表 public function course(){ $typeId = I('type_id',''); if (!$typeId){ $this->error('课程类型ID错误'); } $condition = array('is_delete'=>1,'course_type'=>$typeId,'course_source'=>1); $count = M('Course')->where($condition)->count(); //分页 $Page = new \Think\Page($count); $show = $Page->show(); $courseList = M('Course')->where($condition)->field()->order('course_id desc')->limit($Page->firstRow.','.$Page->listRows)->select(); $this->assign('page',$show); $this->assign('list',$courseList); $this->display('User/course'); } }