public function ajaxSubmitAction() { // 获取参数 $language = (int) Request::getPOST('language'); $code = Request::getPOST('code', '', true); $problemHash = Request::getPOST('problem-hash'); $userId = $this->loginUserInfo['id']; $globalId = array_search($problemHash, $this->contestInfo['problem_hash']); if (empty($globalId)) { $this->renderError('竞赛中无此题!'); } // 校验 if (strlen($code) < 50 || strlen($code) > 65535) { $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!'); } $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo) || $problemInfo['hidden']) { $this->renderError('题目不存在!'); } if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) { $this->renderError('编译器不支持!'); } if (OjSolutionInterface::submitAlready(array('user_id' => $userId))) { $this->renderError('提交频繁!'); } // 非法字符判断 if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) { if (false === iconv('UTF-8', 'GBK', $code)) { $this->renderError('代码中存在非法字符!'); } } OjSolutionInterface::save(array('global_id' => $globalId, 'user_id' => $userId, 'language' => $language, 'source' => $code, 'contest_id' => $this->contestInfo['id'])); $this->renderAjax(0); }
public static function getRankBoard($id) { $setInfo = self::getById($id); if (empty($setInfo)) { throw new InterfaceException('专题不存在!'); } $globalIds = json_decode($setInfo['problem_set'], true); if (empty($globalIds)) { return array(array(), array(), array()); } // 取出提交记录 $where = array(array('problem_global_id', 'IN', $globalIds), array('result', '>=', 4)); $order = array('id' => 'ASC'); $solutionList = OjSolutionInterface::getList(array('field' => 'id,user_id,problem_global_id,result', 'where' => $where, 'order' => $order)); // 计算$rankHash $rankHash = array(); $mat = array(); $firstBlood = array(); // 标记第一滴血 foreach ($solutionList as $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; $userId = $solutionInfo['user_id']; $result = $solutionInfo['result']; if (!isset($rankHash[$userId])) { $rankHash[$userId]['solved'] = 0; $rankHash[$userId]['all_fail_count'] = 0; } if (!isset($mat[$userId][$globalId])) { $mat[$userId][$globalId] = array(); $mat[$userId][$globalId]['fail_count'] = 0; } // 已经通过的,直接continue if (isset($mat[$userId][$globalId]['accepted'])) { continue; } // 如果这条solution是accepted if ($result == StatusVars::ACCEPTED) { $mat[$userId][$globalId]['accepted'] = 1; $rankHash[$userId]['solved']++; // 标记1血 if (!isset($firstBlood[$globalId])) { $mat[$userId][$globalId]['first_blood'] = 1; $firstBlood[$globalId] = 1; } continue; } else { $mat[$userId][$globalId]['fail_count']++; $rankHash[$userId]['all_fail_count']++; } } uasort($rankHash, array('OjProblemSetLogic', 'cmp')); // 获取用户信息 $userIds = array_unique(array_column($solutionList, 'user_id')); $userHash = UserCommonInterface::getById(array('id' => $userIds)); return array($rankHash, $mat, $userHash); }
public function defaultAction() { $contestId = Request::getGET('contest-id'); $contestInfo = OjContestInterface::getDetail(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } $problemHash = OjProblemInterface::getById(array('id' => $contestInfo['global_ids'])); $solutionList = OjSolutionInterface::getList(array('field' => 'problem_global_id', 'where' => array(array('contest_id', '=', $contestId)))); $submitGlobalIds = array_unique(array_column($solutionList, 'problem_global_id')); $this->renderFramework(array('contestInfo' => $contestInfo, 'problemHash' => $problemHash, 'globalIds' => $contestInfo['global_ids'], 'submitGlobalIds' => $submitGlobalIds), 'contest/set_problem.php'); }
public function defaultAction() { $pageSize = 100; // 获取参数 $page = Pager::get(); $remote = (int) Request::getGET('remote', 0); $keyword = Request::getGET('keyword'); $searchType = (int) Request::getGET('search-type', 1); // 构建where $where = array(); $where[] = array('remote', '=', $remote); $where[] = array('hidden', '=', 0); if (!empty($keyword)) { if ($searchType == 1) { $where[] = array('OR' => array(array('problem_code', '=', $keyword), array('title', 'LIKE', "%{$keyword}%"))); } else { if ($searchType == 2) { $where[] = array('OR' => array(array('problem_code', '=', $keyword), array('source', 'LIKE', "%{$keyword}%"))); } } } // 获取数据 $order = array('problem_code' => 'ASC'); $offset = ($page - 1) * $pageSize; $problemList = OjProblemInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset)); $allCount = OjProblemInterface::getCount($where); // 获取用户解决的题目 $userSolution = array(); if ($this->loginUserInfo) { $globalIds = array_column($problemList, 'id'); $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('contest_id', '=', 0), array('problem_global_id', 'IN', $globalIds)); $solutionList = OjSolutionInterface::getList(array('where' => $where)); foreach ($solutionList as $solutionId => $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) { $userSolution[$globalId] = $solutionInfo; } } } $userHash = array(); if ($allCount > 0) { $userIds = array_unique(array_column($problemList, 'user_id')); $userHash = UserCommonInterface::getById(array('id' => $userIds)); } // 缓存部分的html $html = array(); $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 10), 'widget/pager.php'); $tpl = $remote ? 'problem/list_remote.php' : 'problem/list.php'; // 输出 $this->renderFramework(array('html' => $html, 'problemList' => $problemList, 'userSolution' => $userSolution, 'userHash' => $userHash), $tpl); }
public function iframeShowAction() { $solutionId = (int) Request::getGET('solution-id'); $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId)); if (empty($solutionInfo) || false == OjSolutionHelper::hasLog($solutionInfo)) { $this->renderError(); } // 获取属主 $userId = $solutionInfo['user_id']; $userInfo = UserCommonInterface::getById(array('id' => $userId)); // 是否有权限查看,竞赛管理员,自己的solution if (!$this->isContestAdmin && $solutionInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('您没有权限查看!'); } $this->renderIframe(array('solutionInfo' => $solutionInfo), 'status/iframe/judge_log.php'); }
public function defaultAction() { $username = Request::getGET('username'); if (empty($username)) { $this->renderError(); } // 校验用户 $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); if (empty($userInfo)) { $this->renderError(); } // 获取solutionList $where = array(array('user_id', '=', $userInfo['id'])); $order = array('remote' => 'ASC', 'problem_code' => 'ASC'); $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => $order)); // 计算排名,先按题数,再按照提交次数 $where = array(array('OR' => array(array('solved_all', '>', $userInfo['solved_all']), array(array('solved_all', '=', $userInfo['solved_all']), array('submit_all', '>', $userInfo['submit_all'])), array(array('solved_all', '=', $userInfo['solved_all']), array('submit_all', '=', $userInfo['submit_all']), array('id', '<', $userInfo['id']))))); $prevCount = UserCommonInterface::getCount($where); $rank = intval($prevCount) + 1; // 计算解决的题目 $solvedProblemList = array(); $visited = array(); // 标记数组 foreach ($solutionList as $solutionInfo) { $remote = $solutionInfo['remote']; $problemCode = $solutionInfo['problem_code']; if (!isset($visited[$remote][$problemCode]) && $solutionInfo['result'] == StatusVars::ACCEPTED) { $problemInfo = array('remote' => $remote, 'problem_code' => $problemCode); $solvedProblemList[] = $problemInfo; $visited[$remote][$problemCode] = 1; } } // 计算未解决的题目 $unSolvedProblemList = array(); $visited2 = array(); foreach ($solutionList as $solutionInfo) { $remote = $solutionInfo['remote']; $problemCode = $solutionInfo['problem_code']; if (!isset($visited2[$remote][$problemCode]) && !isset($visited[$remote][$problemCode])) { $problemInfo = array('remote' => $remote, 'problem_code' => $problemCode); $unSolvedProblemList[] = $problemInfo; $visited2[$remote][$problemCode] = 1; } } // 输出 $this->renderFramework(array('rank' => $rank, 'userInfo' => $userInfo, 'solvedProblemList' => $solvedProblemList, 'unSolvedProblemList' => $unSolvedProblemList), 'user/my.php'); }
public function iframeShowAction() { $solutionId = (int) Request::getGET('solution-id'); $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId)); if (empty($solutionInfo) || false == OjSolutionHelper::hasLog($solutionInfo)) { $this->renderError(); } // 获取属主 $userId = $solutionInfo['user_id']; $userInfo = UserCommonInterface::getById(array('id' => $userId)); // solution level list($solutionInfo['level'], $solutionInfo['permission']) = OjSolutionHelper::solutionPermission($solutionInfo, $userInfo['share'], Arr::get('id', $this->loginUserInfo, 0), $this->isOjAdmin); if (!$solutionInfo['permission']) { $this->renderError('您没有权限查看!'); } $this->renderIframe(array('solutionInfo' => $solutionInfo), 'status/iframe/judge_log.php'); }
public function defaultAction() { $problemHash = OjContestInterface::getProblemHash(array('id' => $this->contestInfo['id'])); // 获取该用户比赛中提交的solutionList $where = array(array('contest_id', '=', $this->contestInfo['id']), array('user_id', '=', $this->loginUserInfo['id'])); $order = array('id' => 'ASC'); $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => $order)); // 构建hash,globalId => solutionInfo $userSolution = array(); foreach ($solutionList as $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) { $userSolution[$globalId] = $solutionInfo; } } $this->renderFramework(array('problemHash' => $problemHash, 'userSolution' => $userSolution), 'problem/list.php'); }
public function defaultAction() { $solutionId = (int) Request::getGET('solution-id'); // 获取solutionInfo $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId)); if (empty($solutionInfo)) { $this->renderError(); } // 获取属主 $userId = $solutionInfo['user_id']; $userInfo = UserCommonInterface::getById(array('id' => $userId)); if (empty($userInfo)) { $this->renderError(); } // 是否有权限查看,竞赛管理员,自己的solution if (!$this->isContestAdmin && $solutionInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('您没有权限查看!'); } $this->renderFramework(array('solutionInfo' => $solutionInfo), 'status/code.php'); }
public function defaultAction() { $solutionId = (int) Request::getGET('solution-id'); // 获取solutionInfo $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId)); if (empty($solutionInfo)) { $this->renderError(); } // 获取属主 $userId = $solutionInfo['user_id']; $userInfo = UserCommonInterface::getById(array('id' => $userId)); if (empty($userInfo)) { $this->renderError(); } // solution level list($solutionInfo['level'], $solutionInfo['permission']) = OjSolutionHelper::solutionPermission($solutionInfo, $userInfo['share'], Arr::get('id', $this->loginUserInfo, 0), $this->isOjAdmin); if (!$solutionInfo['permission']) { $this->renderError('您没有权限查看!'); } $this->renderFramework(array('solutionInfo' => $solutionInfo), 'status/code.php'); }
public function defaultAction() { $setId = (int) Request::getGET('set-id'); if (empty($setId)) { $this->renderError(); } $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError(); } if (!$this->isOjAdmin && $setInfo['hidden'] && $this->loginUserInfo['id'] != $setInfo['user_id']) { Cookie::delete('current_set'); $this->renderError('您没有权限查看!'); } // 设置当前的set Cookie::set('current_set', $setId); $problemJson = $setInfo['problem_set']; $globalIds = (array) json_decode($problemJson, true); // 按照$globalIds顺序 $problemList = OjProblemInterface::getById(array('id' => $globalIds)); // 获取用户解决的题目 $userSolution = array(); if ($this->loginUserInfo) { $where = array(array('problem_global_id', 'IN', $globalIds), array('user_id', '=', $this->loginUserInfo['id'])); $solutionList = OjSolutionInterface::getList(array('where' => $where)); foreach ($solutionList as $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) { $userSolution[$globalId] = $solutionInfo; } } } // userInfo $userInfo = UserCommonInterface::getById(array('id' => $setInfo['user_id'])); $this->renderFramework(array('setInfo' => $setInfo, 'problemList' => $problemList, 'userSolution' => $userSolution, 'userInfo' => $userInfo), 'set/set_problem.php'); }
/** * 同步数据到oj_solution * * @throws Exception */ public function sync() { $solutionInfo = OjSolutionInterface::getById(array('id' => $this->solutionId)); if (empty($solutionInfo)) { Logger::error('judge', "SOLUTION_ID:{$this->solutionId},Solution不存在!"); throw new Exception("SOLUTION_ID:{$this->solutionId},Solution不存在!"); } if ($solutionInfo['remote'] != StatusVars::REMOTE_POJ) { Logger::error('judge', "SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!"); throw new Exception("SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!"); } if (empty($solutionInfo['run_id'])) { Logger::error('judge', "RUN_ID为0!"); throw new Exception("SOLUTION_ID:{$this->solutionId},RUN_ID为0!"); } if ($solutionInfo['remote_uid'] != -1 && $solutionInfo['remote_uid'] != $this->uid) { Logger::error('judge', "SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!"); throw new Exception("SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!"); } // 尝试多次获取结果 $rowInfo = array(); $i = 1; while ($i <= 10) { $rowInfo = $this->getResult($solutionInfo['run_id']); if (false === $rowInfo || in_array($rowInfo['result'], StatusVars::$pojResultMap)) { break; } $i > 5 ? sleep(2) : usleep(500000); $i++; } // 获取获取结果超时 if (false === $rowInfo) { Logger::info('judge', "SOLUTION_ID:{$this->solutionId},获取结果失败2,写入TIME_OUT"); $data = array('id' => $this->solutionId, 'result' => StatusVars::TIME_OUT, 'time_cost' => 0, 'memory_cost' => 0); OjSolutionInterface::save($data); } else { Logger::info('judge', "SOLUTION_ID:{$this->solutionId},POJ远程judge成功!尝试次数:{$i}"); $trans = new Trans(DbConfig::$SERVER_TRANS); $trans->begin(); $data = array('trans' => $trans, 'id' => $this->solutionId, 'result' => $rowInfo['result'], 'time_cost' => $rowInfo['time_cost'], 'memory_cost' => $rowInfo['memory_cost']); OjSolutionInterface::save($data); // 保存Log $dataLog = array('trans' => $trans, 'solution_id' => $this->solutionId, 'ce' => Arr::get('ce', $rowInfo['judge_log'], ''), 're' => Arr::get('re', $rowInfo['judge_log'], '')); OjSolutionLogInterface::save($dataLog); $trans->commit(); } }
<?php /** * 从各大oj同步数据到oj_solution表 * * @notice 相同帐号在同一个时间提交代码,极有可能获取结果时混淆 */ require_once __DIR__ . '/../../../bootstrap.php'; require_once INCLUDE_PATH . '/remote_judge/HduJudger.class.php'; require_once INCLUDE_PATH . '/remote_judge/PojJudger.class.php'; require_once INCLUDE_PATH . '/remote_judge/ZojJudger.class.php'; // 获取命令行参数 $solutionId = $argv[1]; $solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId)); if (empty($solutionInfo)) { Logger::error('judge', "Solution不存在!solutionId={$solutionId}"); exit(1); } // 并发的客户端数量 const MAX_HDU_RUNNING = 2; const MAX_POJ_RUNNING = 2; const MAX_ZOJ_RUNNING = 2; try { if ($solutionInfo['remote'] == StatusVars::REMOTE_HDU) { if (empty($solutionInfo['run_id']) || $solutionInfo['remote_uid'] == -1) { $uid = $solutionId % MAX_HDU_RUNNING; $judge = new HduJudger($solutionId, $uid); $judge->run(); } else { $uid = $solutionInfo['remote_uid']; $judge = new HduJudger($solutionId, $uid);
public function ajaxRejudgeAction() { // 获取参数 $solutionId = (int) Request::getPOST('solution-id'); $solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId)); if (empty($solutionInfo)) { $this->renderError('Solution不存在!'); } // 竞赛管理员才可以重判,或者timeout if (!$this->isContestAdmin && $solutionInfo['result'] != StatusVars::TIME_OUT) { $this->renderError('你没有权限重判!'); } // 重判 OjSolutionInterface::rejudge(array('id' => $solutionId)); $this->renderAjax(0); }
public static function getRankBoard($id) { $contestInfo = self::getDetail($id); if (empty($contestInfo)) { throw new InterfaceException('专题不存在!'); } // 取出提交记录 $where = array(array('contest_id', '=', $id), array('result', '>=', 4), array('problem_global_id', 'IN', $contestInfo['global_ids'])); $order = array('id' => 'ASC'); $solutionList = OjSolutionInterface::getList(array('field' => 'id,user_id,problem_global_id,result,contest_submit_second', 'where' => $where, 'order' => $order, 'include_contest' => true)); // 计算$rankHash $rankHash = array(); $mat = array(); $firstBlood = array(); // 标记第一滴血 foreach ($solutionList as $solutionInfo) { $globalId = $solutionInfo['problem_global_id']; $userId = $solutionInfo['user_id']; $result = $solutionInfo['result']; if (!isset($rankHash[$userId])) { $rankHash[$userId]['solved'] = 0; $rankHash[$userId]['cost_second'] = 0; } if (!isset($mat[$userId][$globalId])) { $mat[$userId][$globalId] = array('accepted' => 0, 'first_blood' => 0, 'fail_count' => 0, 'pass_second' => 0); } // 已经通过的,直接continue if ($mat[$userId][$globalId]['accepted']) { continue; } // 如果这条solution是accepted if ($result == StatusVars::ACCEPTED) { // 记录到mat $mat[$userId][$globalId]['accepted'] = 1; $mat[$userId][$globalId]['pass_second'] = $solutionInfo['contest_submit_second']; if (!isset($firstBlood[$globalId])) { $mat[$userId][$globalId]['first_blood'] = 1; $firstBlood[$globalId] = 1; } // 记录到rankHash $rankHash[$userId]['solved']++; $rankHash[$userId]['cost_second'] += $mat[$userId][$globalId]['pass_second'] + $mat[$userId][$globalId]['fail_count'] * 20 * 60; continue; } else { $mat[$userId][$globalId]['fail_count']++; } } uasort($rankHash, array('OjContestLogic', 'cmp')); // 获取用户信息 $userIds = array_unique(array_column($solutionList, 'user_id')); $userHash = UserCommonInterface::getById(array('id' => $userIds)); return array($rankHash, $mat, $userHash); }
$solutionId = $argv[1]; if (empty($solutionId)) { Logger::error('judge', '缺少参数:$solutionId'); exit(1); } // 从评判队列中获取该条信息 $queueInfo = OjJudgeInterface::getRow(array('where' => array(array('solution_id', '=', $solutionId)))); if (empty($queueInfo)) { Logger::error('judge', "评判队列中不存在Solution!solutionId={$solutionId}"); exit(1); } $trans = new Trans(DbConfig::$SERVER_TRANS); $trans->begin(); // 保存result try { OjSolutionInterface::save(array('id' => $solutionId, 'time_cost' => $queueInfo['time_cost'], 'memory_cost' => $queueInfo['memory_cost'], 'judge_time' => $queueInfo['judge_time'], 'run_id' => $queueInfo['id'], 'result' => $queueInfo['result'], 'trans' => $trans)); } catch (Exception $e) { Logger::error('judge', "solutionId={$solutionId},保存solution失败," . $e->getMessage()); $trans->rollback(); throw $e; } // 保存log try { OjSolutionLogInterface::save(array('trans' => $trans, 'solution_id' => $solutionId, 'ce' => $queueInfo['ce'], 're' => $queueInfo['re'], 'detail' => $queueInfo['detail'])); } catch (Exception $e) { Logger::error('judge', "solutionId={$solutionId},保存log失败," . $e->getMessage()); $trans->rollback(); throw $e; } $trans->commit(); exit(0);
public function ajaxHelpAction() { // 获取参数 $solutionId = Request::getPOST('solution-id'); $solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId)); if (empty($solutionInfo)) { $this->renderError('solution不存在!'); } // 权限 if (!$this->isOjAdmin && $solutionInfo['user_id'] != Arr::get('id', $this->loginUserInfo, 0)) { $this->renderError('你没有权限操作!'); } $data = array('id' => $solutionId, 'share' => 1 - $solutionInfo['share']); OjSolutionInterface::save($data); $this->renderAjax(0); }
public static function save($data, $id = 0, $trans = null) { if (0 == $id) { $globalId = $data['global_id']; $language = $data['language']; $userId = $data['user_id']; $source = $data['source']; $contestId = Arr::get('contest_id', $data, 0); // 设置默认语言 Cookie::set('default_language', $language, time() + 365 * 86400); $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { throw new InterfaceException('题目不存在!'); } if (!array_key_exists($data['language'], StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) { throw new InterfaceException('编译器不支持!'); } // 连续提交判断 if (self::submitAlready($userId)) { throw new InterfaceException('提交频繁!'); } // 非法字符判断 if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) { if (false === iconv('UTF-8', 'GBK', $source)) { throw new InterfaceException('代码中存在非法字符!'); } } // 开始事务 $innerTrans = $trans; if (null == $trans) { $innerTrans = new Trans(DbConfig::$SERVER_TRANS); $innerTrans->begin(); } $solutionModel = new OjSolutionModel($innerTrans); $submitTime = time(); $data = array('problem_global_id' => $globalId, 'remote' => $problemInfo['remote'], 'problem_id' => $problemInfo['problem_id'], 'problem_code' => $problemInfo['problem_code'], 'user_id' => $userId, 'submit_time' => $submitTime, 'submit_ip' => Http::getClientIp(), 'language' => $language, 'result' => StatusVars::QUEUE, 'code_length' => strlen($source), 'remote_uid' => -1); $userInfo = UserCommonInterface::getById(array('id' => $userId)); if (0 == $contestId) { $solutionId = $solutionModel->insert($data); UserCommonInterface::save(array('trans' => $innerTrans, 'id' => $userId, 'submit_all' => $userInfo['submit_all'] + 1)); OjProblemInterface::save(array('trans' => $innerTrans, 'id' => $problemInfo['id'], 'submit' => $problemInfo['submit'])); } else { $contestInfo = OjContestInterface::getDetail(array('id' => $contestId)); if (empty($contestInfo)) { throw new InterfaceException('竞赛不存在!'); } if ($submitTime > $contestInfo['end_time']) { throw new InterfaceException('比赛已经结束!'); } if ($submitTime < $contestInfo['begin_time']) { throw new InterfaceException('比赛未开始!'); } // 获取当前的submit_order $lastRow = OjSolutionInterface::getRow(array('where' => array(array('contest_id', '=', $contestId)), 'order' => array('id' => 'DESC'))); $data['contest_id'] = $contestId; $data['contest_submit_order'] = empty($lastRow) ? 1 : intval($lastRow['contest_submit_order']) + 1; $data['contest_submit_second'] = $submitTime - $contestInfo['begin_time']; $data['contest_end_time'] = $contestInfo['end_time']; $solutionId = $solutionModel->insert($data); // 激活比赛 if (!$contestInfo['is_active']) { OjContestInterface::save(array('id' => $contestId, 'trans' => $innerTrans, 'is_active' => 1)); } } // 如果是HQU题库,加入队列 if ($problemInfo['remote'] == StatusVars::REMOTE_HQU) { OjJudgeInterface::save(array('trans' => $innerTrans, 'problem_id' => $problemInfo['problem_id'], 'language' => $language, 'source' => $source, 'user_id' => $userId, 'solution_id' => $solutionId)); } // 保存代码 OjSolutionCodeInterface::save(array('trans' => $innerTrans, 'solution_id' => $solutionId, 'source' => $source)); if (null == $trans && null != $innerTrans) { // 没有外部事务,并且存在内部事务 $innerTrans->commit(); } // 设置重复提交缓存 $memcached = MemcachedPool::getMemcached(MemcachedConfig::$SERVER_COMMON); $key = MemcachedKeys::OJ_SECOND_SUBMIT_ . $userId; $memcached->set($key, true, time() + 5); return $solutionId; } else { // 开始事务 $innerTrans = $trans; if (null == $trans && array_key_exists('result', $data)) { // 开启内部事务条件 $innerTrans = new Trans(DbConfig::$SERVER_TRANS); $innerTrans->begin(); } $model = new OjSolutionModel($innerTrans); if (array_key_exists('result', $data)) { self::updateResult($id, $data['result'], $innerTrans); unset($data['result']); } // 对某些字段特殊处理 $updateData = $data; $affects = $model->updateById($id, $updateData); if (null == $trans && null != $innerTrans) { // 没有外部事务,并且存在内部事务 $innerTrans->commit(); } return $affects; } }