TrainController.class.php 3.64 KB
<?php
/**
 * 线下培训入口
 * User: yingcai
 * Date: 2017/9/6
 * Time: 下午5:19
 */

namespace Frontend\Controller\Index;

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

class TrainController extends \Common\Controller\Frontend\AbstractController
{
    /**
     * 不是必须登录
     * @var string $_require_login
     */
    protected $_require_login = false;

    public function Index()
    {
        $plan_id = I('plan_id', 0, 'rintval');
        $ed_id = I('ed_id', 0, 'rintval');
        $app_data_id = I('app_data_id', 0, 'rintval');

        // 初始化缓存信息
        $paper_info = [];

        // 实例化缓存
        $cache =& Cache::instance();

        try {

            // 获取当前试卷缓存信息
            $paper_info = $cache->get('Common.Exam_wx_' . $app_data_id);

        } catch (\Think\Exception $e) {
            \Think\Log::record($e);

        } catch (\Exception $e) {
            \Think\Log::record($e);

        }

        // 如果缓存不存在
        if (empty($paper_info)) {

            // 试卷表初始化
            $paper_service = new PaperService();

            // 获取试卷详情
            $paper_info = $paper_service->get($app_data_id);

            // 如果没有缓存新增缓存
            $cache->set('Common.Exam_wx_' . $app_data_id, $paper_info, 7200);

        }

        // 如果已参与跳转已参与详情  未参与跳转未参与详情
        $service = new AnswerService();

        $conds = array('ep_id' => $app_data_id, 'uid' => $this->uid, 'my_time > ?' => 0, 'obj_id' => $plan_id);
        // 详情
        $info = $service->get_by_conds($conds);

        // 获取试卷状态
        $ep_status = AnswerService::STATUS_ING;

        // 未作答
        if (empty($info)) {

            redirectFront('/app/page/exam/exam-start', array(
                '_identifier' => APP_IDENTIFIER,
                'ep_id' => $app_data_id,
                'ed_id' => $ed_id,
                'plan_id' => $plan_id,
                'ep_status' => $ep_status
            ));

        }

        // 测评试卷
        if (PaperService::EVALUATION_PAPER_TYPE == $paper_info['paper_type']) {

            // 如果是手动阅卷且没有阅卷
            if (PaperService::MANUAL_MARKING_TYPE == $paper_info['marking_type']
                &&
                $info['answer_status'] < PaperService::READ_OVER
            ) {

                // 已作答测评详情
                redirectFront('app/page/exam/exam-scoring',
                    array(
                        '_identifier' => APP_IDENTIFIER,
                        'ep_id' => $app_data_id,
                        'ed_id' => $ed_id,
                        'plan_id' => $plan_id
                    ));

            }

            // 已作答测评详情
            redirectFront('app/page/exam/exam-result',
                array(
                    '_identifier' => APP_IDENTIFIER,
                    'ea_id' => $info['ea_id'],
                    'pageType' => 'going',
                    'ep_status' => $ep_status,
                    'ep_id' => $app_data_id,
                    'ed_id' => $ed_id,
                    'plan_id' => $plan_id
                ));
        }

        // 模拟
        if (PaperService::SIMULATION_PAPER_TYPE == $paper_info['paper_type']) {

            // 已作答模拟
            redirectFront('/app/page/exam/exam-test-record', array(
                '_identifier' => APP_IDENTIFIER,
                'ep_id' => $app_data_id,
                'ep_status' => $ep_status,
                'ed_id' => $ed_id,
                'plan_id' => $plan_id
            ));
        }
    }

}