Esempio n. 1
0
 public function score()
 {
     $sid = \Hnust\input('sid');
     $name = \Hnust\input('name');
     $idcard = \Hnust\input('idcard');
     $score = new \Hnust\Analyse\Score($sid, $name, $idcard);
     echo $score->getScore() && !$score->error ? 'success' : 'error';
 }
Esempio n. 2
0
 public function score()
 {
     $score = new \Hnust\Analyse\Score($this->sid);
     $this->data = $score->getScore();
     $this->info = array('sid' => $this->sid);
     if ($score->error) {
         $this->msg = $score->error;
     } elseif (empty($this->data)) {
         $this->msg = '未查询到相关成绩记录';
         $this->code = Config::RETURN_ERROR;
     }
 }
Esempio n. 3
0
 public function score()
 {
     //设置日志文件
     $this->logFileName = 'score';
     //判断是否考试时间
     if ('是' !== Config::getConfig('is_exam')) {
         return false;
         //判断当前是否工作时间
     } elseif (date('H') < 8 || date('H') > 21) {
         $this->record("=== 非正常工作时间,退出 ===");
         return false;
     }
     //全负荷运行
     Config::fullLoad();
     //成绩提醒缓存数据
     $cache = new Cache('remind_score');
     //获取开启成绩提醒的学生列表
     if (!($students = $cache->get('list'))) {
         $this->record('=== 学生列表为空,退出 ===');
         return false;
     }
     //判断新成绩
     $failures = array();
     foreach ($students as $student) {
         //获取新成绩
         try {
             $scoreClass = new \Hnust\Analyse\Score($student['sid'], $student['name'], $student['idcard']);
             $newScore = $scoreClass->getScore();
             if ($scoreClass->error) {
                 throw new \Exception('获取最新成绩失败', Config::RETURN_ERROR);
             }
         } catch (\Exception $e) {
             $failures[] = $student['name'];
             continue;
         }
         //获取旧成绩并缓存新成绩
         $oldScore = $cache->get($student['sid']);
         $cache->set($student['sid'], $newScore, 259200);
         if (empty($oldScore)) {
             $this->record("获取【{$student['name']}】的旧成绩失败");
             $failures[] = $student['name'];
             continue;
         }
         $remind = array();
         //这里如果两次考试课程名称、分数等都一致,会提醒失败
         foreach ($newScore as $term => $newTermScore) {
             $oldTermScore = isset($oldScore[$term]) ? $oldScore[$term] : array();
             $remind = array_merge($remind, array_filter($newTermScore, function ($courseScore) use($oldTermScore) {
                 for ($i = 0; $i < count($oldTermScore); $i++) {
                     if ($courseScore['course'] != $oldTermScore[$i]['course']) {
                         continue;
                     } else {
                         if ($courseScore['mark'] != $oldTermScore[$i]['mark']) {
                             continue;
                         } else {
                             if ($courseScore['resit'] != $oldTermScore[$i]['resit']) {
                                 continue;
                             } else {
                                 return false;
                             }
                         }
                     }
                 }
                 return true;
             }));
         }
         //无新成绩
         if (empty($remind)) {
             continue;
         }
         //构造消息
         $title = '新成绩提醒 -- Tick团队';
         $content = '';
         foreach ($remind as $item) {
             if (empty($item['mark']) || '不及格' == $item['mark'] || is_numeric($item['mark']) && $item['mark'] < 60) {
                 $content .= "{$item['course']}  <span style='color:red'>{$item['mark']}</span><br/>";
             } else {
                 $content .= "{$item['course']}  {$item['mark']}<br/>";
             }
         }
         $student['sms'] = array('name' => $student['name'], 'content' => trim(strip_tags($this->br2nl($content))), 'template' => 'SMS_6635017');
         $this->remind($student, $title, $content, '#/score', '1111');
     }
     $total = count($students);
     $success = $total - count($failures);
     $this->record("=== 成绩提醒执行完成 {$success}/{$total} ===");
 }
Esempio n. 4
0
 public function score()
 {
     $score = new \Hnust\Analyse\Score($this->sid);
     $data = $score->getScore();
     //查询失败
     if (empty($data)) {
         $this->msg = '未查询到相关成绩记录';
         $this->code = Config::RETURN_ERROR;
         return false;
     }
     //选取最大学期
     foreach ($data as $term => $termScore) {
         if ($term > $maxTerm) {
             $maxTerm = $term;
         }
     }
     //标题栏
     $this->data = array(array('title' => $maxTerm . ' 学期成绩'));
     //获取最近一个学期成绩
     foreach ($data[$maxTerm] as $courseScore) {
         $title .= "{$courseScore['course']}\t\t{$courseScore['mark']}";
         $title .= $courseScore['resit'] ? "*\n" : "\n";
     }
     $this->data[] = array('title' => trim($title));
     //获取错误信息
     if ($score->error) {
         $this->data[] = array('title' => trim($score->error));
     }
 }