DetailController.class.php 2.84 KB
<?php
/**
 *【考试中心-后台】 获取考试答卷详情接口情
 * DetailController.class.php
 * @author: houyingcai
 * @email:  594609175@qq.com
 * @date :  2017-05-23 16:34:29
 * @version $Id$
 */

namespace Apicp\Controller\Answer;

use Common\Common\User;
use Common\Service\AnswerService;
use Common\Service\AnswerDetailService;
use Common\Service\PaperService;

class DetailController extends AbstractController
{
    /** @var  PaperService  实例化试卷对象 */
    protected $paper_service;
    /** @var  AnswerService  实例化答卷表对象 */
    protected $answer_service;
    /** @var  AnswerDetailService  实例化答卷详情表对象 */
    protected $answer_detail_service;

    public function before_action($action = '')
    {
        if (!parent::before_action($action)) {
            return false;
        }

        $this->paper_service = new PaperService();
        $this->answer_service = new AnswerService();
        $this->answer_detail_service = new AnswerDetailService();

        return true;
    }

    public function Index_post()
    {
        $params = I('post.');
        $ea_id = rintval($params['ea_id']);

        // 答卷ID不能为空
        if (empty($ea_id)) {

            E('_EMPTY_EA_ID');
        }

        // 获取答卷信息
        $answer = $this->answer_service->get($ea_id);
        // 答卷不存在
        if (empty($answer)) {

            E('_ERR_ANSWER_NOT_FOUND');
        }

        // 根据UID获取用户信息
        $user_service = &User::instance();

        // 获取答卷用户信息
        $user = $user_service->getByUid($answer['uid']);

        // 获取阅卷人信息
        if (empty($answer['marking_name'])) {

            $marking_user = $user_service->getByUid($answer['marking_uid']);
            $answer['marking_name'] = $marking_user['memUsername'];
        }
        
        // 获取答卷详情
        $answer_detail = $this->answer_detail_service->list_by_conds(['ea_id' => $answer['ea_id']]);

        // 获取试卷信息
        $paper = $this->paper_service->get($answer['ep_id']);

        // 格式化答卷详情
        $answer_list = $this->answer_detail_service->question_list_format(
            $answer_detail,
            $paper['marking_type'],
            AnswerService::ANSWER_PC_ANALYSIS
        );

        // 组装返回数据
        $data = array(
            'ep_name' => $paper['ep_name'],
            'my_score' => $answer['my_score'],
            'username' => $user['memUsername'],
            'marking_name' => $answer['marking_name'] ? $answer['marking_name'] : '系统阅卷',
            'answer_status' => intval($answer['answer_status']),
            'marking_time' => $answer['marking_time'],
            'marking_type' => intval($paper['marking_type']),
            'list' => $answer_list
        );

        $this->_result = $data;

        return true;
    }

}