DeleteController.class.php 2.69 KB
<?php
/**
 * 删除答卷记录
 * User: Administrator
 * Date: 2017/8/21
 * Time: 14:36
 */

namespace Frontend\Controller\Temp;

use Common\Common\User;
use Common\Service\AnswerService;

class DeleteController extends AbstractController
{
    protected $_require_login = false;
    /** @var AnswerService  答卷接口 */
    protected $_answer_serv;

    public function before_action($action = '')
    {
        if (!parent::before_action($action)) {
            return false;
        }
        $this->_answer_serv = new AnswerService();
        return true;
    }

    /**
     *  查询答卷信息
     *  $ep_id  int 试卷ID 必须传
     *  $type  int 0 不及格   1 零分
     *  $ea_id int  按照答卷ID查询
     */
    public function Index()
    {
        $ep_id = I('get.ep_id');
        $type = I('get.type', 0);
        $ea_id = I('get.ea_id');
        $conds['ep_id'] = $ep_id;
        if (empty($ep_id)) {
            E('_EMPTY_EP_ID');
        }
        if ($type == 1) {
            // 零分
            $conds['my_score'] = 0;
        } else {
            // 不及格
            $conds['my_is_pass'] = AnswerService::UNPASS;
        }
        if ($ea_id) {
            $conds['ea_id'] = $ea_id;
        }
        // 查询试卷列表
        $list = $this->_answer_serv->list_by_conds($conds, []);
        $users = array_column($list, 'uid');
        $userServ = &User::instance();
        $users = $userServ->listAll(array('memUids' => $users));

        foreach ($list as $key => &$val) {
            foreach ($users as $k => $v) {
                if ($val['uid'] == $v['memUid']) {
                    $val['memUsername'] = $v['memUsername'];
                    $val['memMobile'] = $v['memMobile'];
                    $val['dpName'] = implode(',', array_column($v['dpName'], 'dpName'));
                }

            }
            unset($val['paper_info']);
        }
        print_r($list);
        exit;
    }

    /**
     *  重置删除考试答卷记录
     *  $ep_id  int 试卷ID 必须传
     *  $type  int  0 不及格 1 零分
     *  $ea_id int  按照答卷ID查询
     */
    public function ResetExam()
    {
        $ep_id = I('get.ep_id');
        $type = I('get.type', 0);
        $ea_id = I('get.ea_id');
        $conds['ep_id'] = $ep_id;
        if (empty($ep_id)) {
            E('_EMPTY_EP_ID');
        }
        if ($type == 1) {
            // 零分
            $conds['my_score'] = 0;
        } else {
            // 不及格
            $conds['my_is_pass'] = AnswerService::UNPASS;
        }
        if ($ea_id) {
            $conds['ea_id'] = $ea_id;
        }
        // 删掉答卷信息
        $this->_answer_serv->delete_answer($ep_id, $conds);

        return true;
    }
}