ScoreInfoController.class.php
2.12 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
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2018-3-29
* Time: 15:06:45
*/
namespace Api\Controller\Course;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\Train;
use Common\Service\CourseArticleService;
use Common\Service\CourseScoreDetailService;
class ScoreInfoController extends \Api\Controller\AbstractController
{
/**
* ScoreInfo
* @author tangxingguo
* @desc 评分详情接口
* @param Int article_id:true 课程ID
* @return Array
array(
'score_info' => array(
'score_avg' => 1, // 整体评分
'content_score_avg' => 1, // 内容评分
'teacher_score_avg' => 1, // 讲师评分
'list' => array( // 项目列表
'item_id' => 1, // 评分项ID
'content' => 1, // 评分项
'item_score_avg' => 1, // 评分值
),
),
'my_score' => 1 // 我是否评分(1=未评;2=已评)
);
*/
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_by_conds(['article_id' => $articleId]);
if (empty($article)) {
E('_ERR_ARTICLE_DATA_NOT_FOUND');
}
// 用户是否已评分
$detailServ = new CourseScoreDetailService();
$count = $detailServ->count_by_conds(['article_id' => $articleId, 'uid' => $this->uid]);
$my_score = $count > 0 ? Constant::SCORE_STATUS_IS_TRUE : Constant::SCORE_STATUS_IS_FALSE;
$articleScore = &Train::instance()->getCourseScore([$articleId]);
$this->_result = [
'score_info' => $articleScore[$articleId],
'my_score' => $my_score
];
}
}