StudyMapController.class.php 2.37 KB
<?php
/**
 * Created by PhpStorm.
 * User: pw
 * Date: 18/5/29
 * Time: 16:10
 */
namespace Frontend\Controller\Index;

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

class StudyMapController extends AbstractController
{
    /**
     * 考试类型:测评
     */
    const EVALUATION = 0;

    /**
     * 考试类型:模拟
     */
    const SIMULATION = 1;

    /**
     * 从学习地图应用的学习内容跳转至手机端考试详情页
     */
    public function Index()
    {
        $map_id = I('get.map_id', 0, 'intval');
        $path_id = I('get.path_id', 0, 'intval');
        $app_data_id = I('get.app_data_id', 0, 'intval');

        // 跳转至前端详情页,详情页请求详情接口时会报出此错误
        $paperServ = new PaperService();
        $exam = $paperServ->get($app_data_id);
        if (empty($exam)) {
            redirectFront('/app/page/exam/exam-start', ['ep_id' => $app_data_id]);
        }

        // 前端所需参数
        $param = [
            'map_id' => $map_id,
            'path_id' => $path_id,
            'ep_id' => $app_data_id
        ];

        // 如果是模拟考试,参加过并且已交卷
        if (self::SIMULATION == $exam['paper_type']) {
            $answerServ = new AnswerService();
            $conds = [
                'ep_id' => $app_data_id,
                'uid' => !empty($this->_login->user) ? $this->_login->user['memUid'] : ''
            ];
            $test_answer = $answerServ->list_by_conds($conds);
            if (!empty($test_answer) && !empty($test_answer[0]['my_end_time'])) {
                // 跳转页面
                redirectFront('/app/page/exam/exam-test-record', $param);
            }
        } elseif (self::EVALUATION == $exam['paper_type']) {
            $answerServ = new AnswerService();
            $conds = [
                'ep_id' => $app_data_id,
                'uid' => !empty($this->_login->user) ? $this->_login->user['memUid'] : ''
            ];
            $test_answer = $answerServ->list_by_conds($conds);
            if (!empty($test_answer) && !empty($test_answer[0]['my_end_time'])) {
                // 跳转页面
                $param['ea_id'] = $test_answer[0]['ea_id'];
                redirectFront('/app/page/exam/exam-result', $param);
            }
        }

        // 跳转页面
        redirectFront('/app/page/exam/exam-start', $param);
    }
}