ScoreCountController.class.php
1.66 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
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2017/4/27
* Time: 10:59
*/
namespace Apicp\Controller\Course;
use Com\PackageValidate;
use Common\Common\Train;
use Common\Service\CourseArticleService;
class ScoreCountController extends \Apicp\Controller\AbstractController
{
/**
* ScoreCount
* @author tangxingguo
* @desc 评分统计接口
* @param Int article_id:true 课程ID
* @return Array
array(
'score_avg' => 1, // 整体评分
'content_score_avg' => 1, // 内容评分
'teacher_score_avg' => 1, // 讲师评分
'list' => array( // 项目ID
'item_id' => 1, // 评分项ID
'score_type' => 1, // 评分类型(1=课程内容;2=课程讲师)
'content' => 1, // 评分项
'item_score_avg' => 1, // 评分值
),
);
*/
public function Index_post()
{
$rules = [
'article_id' => 'require|integer',
];
// 验证请求数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$articleId = $validate->postData['article_id'];
// 取课程
$articleServ = new CourseArticleService();
$article = $articleServ->get($articleId);
if (empty($article)) {
E('_ERR_ARTICLE_DATA_NOT_FOUND');
}
$train = &Train::instance();
$articleScore = $train->getCourseScore([$articleId]);
$this->_result = isset($articleScore[$articleId]) ? $articleScore[$articleId] : [];
}
}