<?php /** * Created by PhpStorm. * User: liyifei2012it * Date: 18/4/2 * Time: 11:23 */ namespace Api\Controller\Teacher; use Com\PackageValidate; use Common\Common\Constant; use Common\Common\Teacher; use Common\Service\ArticleService; class CourseListController extends \Api\Controller\AbstractController { /** * CourseList * @author liyifei * @desc 授课记录列表接口(讲师本人查看的授课记录页) * @param Int page:false:1 页码 * @param Int limit:false:20 每页记录数 * @param Int teacher_task_id 授课任务ID * @return array|bool 课程列表 array( 'page' => 1, // 页码 'limit' => 20, // 每页记录数 'total' => 200, // 记录总数 'list' => array( array( 'article_id' => 12, // 课程ID 'article_title' => '冰糖雪梨', // 课程标题 'article_type' => 1, // 课程类型(1=单课程,2=系列课程) 'cover_id' => 'b3ddbc502e307665f346cbd6e52cc10d', // 封面ID 'cover_url' => 'http://qy.vchangyi.org', // 封面图片URL 'study_total' => 10, // 已学习人数 'course_nature' => 3, // 课程性质(1=必修课;2=选修课;3=公共课) ), ), ) */ public function Index_post() { // 验证规则 $rules = [ 'page' => 'integer', 'limit' => 'integer', 'teacher_task_id' => 'integer|gt:0', ]; // 验证数据 $validate = new PackageValidate($rules, [], array_keys($rules)); $postData = $validate->postData; $teacherServ = &Teacher::instance(); $teacher = $teacherServ->getTeacherByConds(['uid' => $this->uid]); if (empty($teacher)) { E('_ERR_TEACHER_NOT_FOUND'); } if ($teacher['teacher_status'] == Constant::TEACHER_STATUS_DISABLE) { E('_ERR_TEACHER_NOT_FOUND'); } // 分页 $postData['page'] = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE; $postData['limit'] = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT; list($start, $perpage) = page_limit($postData['page'], $postData['limit']); // 排序 $orders = [ 'top_time' => 'DESC', 'update_time' => 'DESC' ]; // 课程列表 $articleServ = new ArticleService(); $conds = [ 'teacher_id' => $teacher['teacher_id'], ]; if (isset($postData['teacher_task_id'])) { $conds['teacher_task_id'] = $postData['teacher_task_id']; } $list = $articleServ->list_by_conds($conds, [$start, $perpage], $orders); // 课程总数 $total = $articleServ->count_by_conds($conds); $this->_result = [ 'page' => (int)$postData['page'], 'limit' => (int)$postData['limit'], 'total' => (int)$total, 'list' => $list, ]; } }