CourseListController.class.php
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?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,
];
}
}