예제 #1
0
파일: ScoreAll.php 프로젝트: qious/Hnust
 public function scoreAll($scope, $course, $re = true)
 {
     if (empty($this->sid) || empty($course)) {
         throw new \Exception('参数有误', Config::RETURN_ERROR);
     }
     //获取学生信息
     $sql = 'SELECT `class`, `major`, `grade`, `school` FROM `student` WHERE `sid` = ? LIMIT 1';
     $result = Mysql::execute($sql, array($this->sid));
     $this->class = $result[0]['class'];
     $this->major = $result[0]['major'];
     $this->grade = $result[0]['grade'];
     $this->school = $result[0]['school'];
     //获取所有学生列表
     if ('class' === $scope) {
         $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`idcard`,\n                      IF(`b`.`score` IS NULL, '[]', `b`.`score`) `score`\n                    FROM `student` `a`\n                    LEFT JOIN `score` `b` ON `a`.`sid` = `b`.`sid`\n                    WHERE `a`.`class` = ?";
         $students = Mysql::execute($sql, array($this->class));
         $this->scoreName = $this->class;
     } else {
         $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`idcard`,\n                      IF(`b`.`score` IS NULL, '[]', `b`.`score`) `score`\n                    FROM `student` `a`\n                    LEFT JOIN `score` `b` ON `a`.`sid` = `b`.`sid`\n                    WHERE `a`.`major` = ? AND `a`.`grade` = ? AND `a`.`school` = ?";
         $students = Mysql::execute($sql, array($this->major, $this->grade, $this->school));
         $this->scoreName = $this->major;
     }
     $failures = array();
     foreach ($students as $student) {
         $score = json_decode($student['score'], true);
         foreach ($score as $termScore) {
             foreach ($termScore as $courseScore) {
                 if ($courseScore['course'] == $course) {
                     $this->credit = empty($this->credit) ? $courseScore['credit'] : $this->credit;
                     $data[] = array("sid" => $student['sid'], "name" => $student['name'], "score" => $courseScore['mark'], 'resit' => $courseScore['resit']);
                 }
             }
         }
         $temp = empty($data) ? array() : end($data);
         if ($temp['sid'] != $student['sid']) {
             $failures[] = array('sid' => $student['sid'], 'name' => $student['name'], 'idcard' => $student['idcard']);
         }
     }
     //多线程与多进程更新成绩
     if (\Hnust\input('re\\b', false)) {
         $failures = $students;
     }
     if (!empty($failures) && $re) {
         $url = Config::getConfig('local_base_url') . 'Update/score';
         Http::multi($url, $failures);
         return $this->scoreAll($scope, $course, false);
     } elseif (!empty($failures)) {
         foreach ($failures as $student) {
             $data[] = array('sid' => $student['sid'], 'name' => $student['name'], 'score' => '-1', 'resit' => false);
         }
     }
     return $data;
 }
예제 #2
0
파일: Update.php 프로젝트: qious/Hnust
 public function allScore()
 {
     //获取起始学号
     $this->getCache(__FUNCTION__);
     if (empty($this->sid)) {
         return $this->log('', '成绩更新', '学号为空,不更新成绩');
     }
     //全负荷运行
     Config::fullLoad();
     $baseUrl = Config::getConfig('local_base_url');
     for ($i = 0; $i < 20; $i++) {
         $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`idcard` FROM `student` `a`\n                    LEFT JOIN `score` `b` ON `a`.`sid` = `b`.`sid`\n                    WHERE (`b`.`sid` IS NULL OR (`b`.`time` + INTERVAL 3 DAY) < NOW())\n                    AND `a`.`sid` > ? LIMIT 20";
         $students = Mysql::execute($sql, array($this->sid));
         if (empty($students)) {
             return $this->log('', '成绩更新', '成绩更新完成');
         }
         $url = $baseUrl . 'update/score';
         Http::multi($url, $students);
         $this->sid = end($students)['sid'];
         $this->log($this->sid, '成绩更新', '成绩更新至' . $this->sid);
     }
     //递归
     $this->setCache(__FUNCTION__, $this->sid);
     $this->recursion(__FUNCTION__);
 }