Ejemplo n.º 1
0
 public function electiveQueue()
 {
     //设置日志文件
     $this->logFileName = 'elective';
     if ('是' !== Config::getConfig('is_elective')) {
         return false;
     }
     //全负荷运行
     Config::fullLoad();
     $id = \Hnust\input('id/d', null);
     //获取未完成队列列表
     if (is_null($id)) {
         $sql = "SELECT `id` FROM `elective_queue`\n                    WHERE `result` = '' OR `result` IS NULL\n                    AND `upTime` < DATE_SUB(NOW(), INTERVAL 3 MINUTE) LIMIT 50";
         if ($result = Mysql::execute($sql)) {
             $baseUrl = Config::getConfig('local_base_url');
             foreach ($result as $item) {
                 try {
                     $http = new Http(array(CURLOPT_URL => $baseUrl . 'remind/electiveQueue?id=' . $item['id'], CURLOPT_TIMEOUT => 1));
                 } catch (\Exception $e) {
                     //pass
                 }
             }
             $this->record("=== 执行未处理的选课队列" . count($result) . '条');
         }
         return true;
     }
     //执行单个队列
     $sql = 'SELECT `s`.`sid`, `s`.`name`, `s`.`mail`, `e`.`title`, `e`.`url`
             FROM `elective_queue` `e`
             LEFT JOIN `student` `s` ON `e`.`sid` = `s`.`sid`
             WHERE `id` = ? LIMIT 1';
     if ($queue = Mysql::execute($sql, array($id))) {
         $queue = $queue[0];
         $elective = new \Hnust\Analyse\Elective($queue['sid']);
         for ($i = 0; $i < 3; $i++) {
             try {
                 $queue['result'] = $elective->doAction($queue['url']);
                 break;
             } catch (\Exception $e) {
                 //pass
             }
         }
         //执行成功
         if (!empty($queue['result'])) {
             //更新队列
             $sql = 'UPDATE `elective_queue` SET `result` = ? WHERE `id` = ? LIMIT 1';
             $sqlArr = array($queue['result'], $id);
             Mysql::execute($sql, $sqlArr);
             //推送
             $this->remind($queue, $queue['title'], $queue['result'], '#/elective', '1100');
         }
     }
 }
Ejemplo n.º 2
0
 public function elective()
 {
     $key = \Hnust\input('key');
     $title = \Hnust\input('title');
     $url = \Hnust\input('url');
     $type = \Hnust\input('type');
     $elective = new \Hnust\Analyse\Elective($this->sid, $this->passwd);
     if ('key' === $type) {
         $this->data = $elective->complet($key);
     } elseif ('search' === $type) {
         $result = $elective->search($key, $this->page);
         $this->data = $result['data'];
         $this->info = $result['info'];
         if (empty($this->data)) {
             $this->code = Config::RETURN_ERROR;
             $this->msg = '未找到相关课程记录';
         }
     } elseif ('addQueue' === $type) {
         $this->data = $elective->addQueue($title, $url);
         $this->msg = '已成功加入操作队列';
     } else {
         $this->data['selected'] = $elective->getSelected();
         $this->data['queue'] = $elective->getQueue();
     }
 }