ListController.class.php 2.35 KB
<?php
/**
 * 【考试中心-手机端】考试作答情况列表接口
 * ListController.class.php
 * @author: 蔡建华
 * @date: 2017-05-23
 */

namespace Api\Controller\Answer;

use Common\Service\AnswerDetailService;

class ListController extends AbstractController
{

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

        // 类型
        $type = intval($params['type']);
        // 答卷id
        $ea_id = intval($params['ea_id']);
        // 答卷id为空,返回提示"答卷ID不能为空"
        if (!$ea_id) {

            E('_EMPTY_EA_ID');
        }

        // 实例化答卷详情service
        $answer_detail_s = new AnswerDetailService();

        // 查询条件:答卷id
        $detail_conds['ea_id'] = $ea_id;
        // 根据答卷id查询总数
        $total = $answer_detail_s->count_by_conds($detail_conds);

        // 初始化未答题数
        $un_answer_num = 0;
        $data = [];
        // 答题数据不为空,获取答卷数据
        if ($total) {
            // 根据答卷id获取答卷详情列表数据
            $data_detail = $answer_detail_s->list_by_conds($detail_conds);
            // 答卷详情数据为空,返回提示"暂无信息"
            if (empty($data_detail)) {

                E('_ERR_DATA_NOT_EXIST');
            }

            // 未答题查询条件:答卷id,作答状态:未作答
            $un_detail_conds = [
                'ea_id' => $ea_id,
                'is_status' => AnswerDetailService::DO_PASS_STATE
            ];
            // 根据答卷id查询未答题的数量
            $un_answer_num = $answer_detail_s->count_by_conds($un_detail_conds);

            // 获取试题状态列表
            $data = $answer_detail_s->get_answer_detail($data_detail, $type);
        } else {
            // 返回提示"试卷信息不存在"
            E('_EMPTY_PAPER_DATA');
        }

        // 类型为错题解析,统计总数
        if (AnswerDetailService::ANSWER_TYPE_ERR_ANALYSIS == $type) {

            $total = count($data);
        }

        // 返回结果
        $this->_result = [
            'total' => intval($total),
            'unanswer_num' => intval($un_answer_num), // 未答题总数
            'answer_num' => $total - intval($un_answer_num), // 答题总数
            'list' => $data
        ];
    }
}