InfoController.class.php 2.59 KB
<?php
/**
 * 【考试中心-手机端】28-获取阅卷人查看测评试卷(已参与)详情接口
 * InfoController.class.php
 * @author: 蔡建华
 * @date: 2017-06-19
 */

namespace Api\Controller\Answer;

use Common\Service\PaperService;
use Common\Service\AnswerService;
use Common\Service\CategoryService;

class InfoController extends AbstractController
{

    public function Index_post()
    {
        // 接收post参数
        $params = I('post.');

        // 试卷id
        $ep_id = intval($params['ep_id']);
        // 答卷id
        $ea_id = intval($params['ea_id']);

        // 试卷ID和答卷ID不能同时为空且不能同时大于0
        if ((empty($ep_id) && empty($ea_id)) || (!empty($ep_id) && !empty($ea_id))) {

            E('_ERR_EA_EP_SOME');
        }

        // 答卷查询条件:(当前)用户id、答卷状态(待批阅、已批阅)
        $answer_conds = [
            'uid' => $this->uid,
            'answer_status>=?' => AnswerService::READ_WAITING // 批阅状态 0初始化 [1待批阅 2已批阅]
        ];

        // 试卷id不为空
        if ($ep_id) {
            // 追加答卷查询条件:试卷id
            $answer_conds['ep_id'] = $ep_id;
        } else {
            // 追加答卷查询条件:答卷id
            $answer_conds['ea_id'] = $ea_id;
        }

        // 实例化答卷service
        $answer_s = new AnswerService();
        // 根据试卷id或答卷id查询当前用户的待批阅、已批阅的答卷
        $answer = $answer_s->get_by_conds($answer_conds);
        // 没有符合条件的答卷,返回提示"答卷不存在"
        if (empty($answer)) {

            E('_ERR_COUNT_EMPTY_FOR_VOICE');
        }

        // 实例化试卷service
        $paper_s = new PaperService();
        // 有符合条件的答卷,获取该答卷的试卷id
        $ep_id = $answer['ep_id'];
        // 根据试卷id获取试卷数据
        $data = $paper_s->get($ep_id);

        // 试卷数据不存在,返回提示"试卷信息不存在"
        if (empty($data)) {

            E('_EMPTY_PAPER_DATA');
        }

        // 试卷数据存在,该试卷所属的试卷类别被禁用,返回提示"试卷分类已经被禁用"
        if (CategoryService::EC_CLOSE_STATES == $data['cate_status']) {

            E('_EMPTY_CATE_DATA');
        }

        // 格式化试卷信息
        $result = $paper_s->format_paper_detail($data,$this->uid);
        // 批阅状态(1:待批阅,2:已批阅)
        $result['answer_status'] = intval($answer['answer_status']);

        // 返回结果
        $this->_result = $result;
    }
}