InfoController.class.php 3.81 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/27
 * Time: 11:41
 */
namespace Apicp\Controller\Course;

use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\Teacher;
use Common\Service\CourseArticleService;
use Common\Service\CourseItemService;

class InfoController extends \Apicp\Controller\AbstractController
{
    /**
     * Info
     * @author tangxingguo
     * @desc 课程详情
     * @param int article_id:true 课程ID
     * @return array 课程详情
                    array(
                        'article_id' => 123, // 课程ID
                        'article_title' => '好好学', // 课程标题
                        'ed_id' => 1, // 培训ID
                        'plan_id' => 2, // 培训安排ID
                        'cover_id' => 'b3ddbc502e307665f346cbd6e52cc10d', // 封面图片ID
                        'cover_url' => 'http://qy.vchangyi.org', // 封面图片地址
                        'start_time' => 12367890567, // 授课开始时间
                        'end_time' => 12367890567, // 授课结束时间
                        'credit' => 12, // 学分
                        'address' => '上海徐汇', // 授课地址
                        'content' => '介绍介绍课程', // 课程介绍
                        'is_notice' => 1, // 消息通知讲师(1=不开启,2=开启)
                        'tags' => '哈哈 啊啊', // 课程标签
                        'teacher_id' => 1, // 讲师ID
                        'teacher_name' => '李四', // 讲师姓名
                        'teacher_task_id' => 0, // 讲师授课任务ID(未设置任务时为0)
                        'task_name' => '第二季度任务', // 讲师授课任务名称
                        'class_hour' => 88.88, // 讲师授课课时
                        'is_reward' => 1, // 是否启用赞赏(1=不启用;2=启用)
                        'is_score' => 1, // 是否启用评分(1=不启用;2=启用)
                        'is_sign' => 1, // 是否启用签到(1=不启用;2=启用)
                        'score_item' => array( // 评分设置
                                array(
                                    'item_id' => 1, // 评分项ID
                                    'content' => '课程内容清晰合理、层次分明', // 评分内容
                                    'score_type' => 1, // 评分类型(1=课程内容;2=课程讲师)
                                    'score_order' => 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');
        }

        // 讲师姓名
        $teacherServ = &Teacher::instance();
        $teacher = $teacherServ->getTeacherInfo($article['teacher_id']);
        $article['teacher_name'] = isset($teacher['teacher_name']) ? $teacher['teacher_name'] : '';

        // 授课任务名称
        $task = $teacherServ->getTeackerTask($article['teacher_task_id']);
        $article['task_name'] = isset($task['task_name']) ? $task['task_name'] : '';

        // 评分设置项
        $itemServ = new CourseItemService();
        $article['score_item'] = $itemServ->list_by_conds(
            ['article_id' => $article['article_id']],
            null,
            ['score_order' => 'asc', 'created' => 'desc']
        );

        $this->_result = $article;
    }
}