ScoreCountController.class.php 1.66 KB
<?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] : [];
    }
}