Beispiel #1
0
 public function develop()
 {
     $sql = "SELECT * FROM `app` ORDER BY `version` DESC, `time` DESC LIMIT 1";
     $result = Mysql::execute($sql);
     $this->data = $result[0];
     $this->data['url'] = $this->url($this->data['key']);
     return $this->data;
 }
Beispiel #2
0
 public function randJwc()
 {
     $sql = "SELECT COUNT(*) `count` FROM `student` `s`, `passwd` `p`\n                WHERE `s`.`sid` = `p`.`id` AND `p`.`part` = 'jwc'\n                AND `s`.`school` IN (SELECT `school` FROM `student` WHERE `sid` = ?)";
     $result = Mysql::execute($sql, array($this->id));
     $limit = 3;
     $start = mt_rand(0, $result[0]['count'] - $limit);
     $sql = "SELECT `s`.`sid`, `p`.`passwd` `jwc` FROM `student` `s`, `passwd` `p`\n                WHERE `s`.`sid` = `p`.`id` AND `p`.`part` =  'jwc'\n                AND `s`.`school` IN (SELECT `school` FROM `student` WHERE `sid` = ?)\n                LIMIT {$start}, {$limit}";
     return Mysql::execute($sql, array($this->id));
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 public function update()
 {
     $oldPasswd = \Hnust\input('oldPasswd');
     $newPasswd = \Hnust\input('newPasswd');
     $mail = \Hnust\input('mail');
     $phone = \Hnust\input('phone');
     //修改密码
     if (!empty($oldPasswd) && !empty($newPasswd)) {
         //验证旧密码
         $sql = 'SELECT * FROM `user` WHERE `uid` = ? AND `passwd` = ? LIMIT 1';
         $result = Mysql::execute($sql, array($this->uid, \Hnust\passwdEncrypt($this->uid, $oldPasswd)));
         //原密码错误
         if (empty($result)) {
             //错误次数加1
             $sql = 'UPDATE `user` SET `error` = (`error` + 1) WHERE `uid` = ? LIMIT 1';
             Mysql::execute($sql, array($this->uid));
             $this->code = Config::RETURN_ALERT;
             $this->msg = '原密码错误';
             return false;
         }
         //检查弱密码
         $sql = 'SELECT COUNT(*) `count` FROM `weak` WHERE `md5` = ? LIMIT 1';
         $result = Mysql::execute($sql, array($newPasswd));
         if ('0' != $result[0]['count']) {
             $this->code = Config::RETURN_ALERT;
             $this->msg = '您的密码过于简单';
             return false;
         }
         //修改密码
         $sql = 'UPDATE `user` SET `passwd` = ?, `error` = 0 WHERE `uid` = ?';
         Mysql::execute($sql, array(\Hnust\passwdEncrypt($this->uid, $newPasswd), $this->uid));
         //删除其他登陆设备
         $tokens = $this->authCache->smembers($this->uid);
         foreach ($tokens as $token) {
             if ($token === $this->token) {
                 continue;
             }
             $this->authCache->hdelete('token', $token);
             $this->authCache->sdelete($this->uid, $token);
         }
         $this->data = '修改成功,请牢记您的密码';
     }
     //修改其他数据
     $sql = "UPDATE `user` `u`,`student` `s`\n                SET `s`.`mail` = IF(? = '', `s`.`mail`, ?),\n                    `s`.`phone` = IF(length(?) <> 11, `s`.`phone`, ?)\n                WHERE `s`.`sid` = `u`.`uid` AND `u`.`uid` = ?";
     Mysql::execute($sql, array($mail, $mail, $phone, $phone, $this->uid));
     Wechat::updateUser($this->uid);
     $this->msg = '系统提示';
     $this->data = empty($this->data) ? '已保存您的修改' : $this->data;
     $this->code = Config::RETURN_CONFIRM;
     return true;
 }
Beispiel #5
0
 public static function recode($uid, $name, $module, $method, $key, $state)
 {
     $ip = Ip::value();
     $location = Ip::location($ip);
     $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $url = self::urlFormat($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     //写入数据库
     $sql = 'INSERT INTO `logs`(`uid`, `name`, `ip`, `location`, `module`, `method`, `key`, `ua`, `url`, `state`)
               VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
     $sqlArr = array($uid, $name, $ip, $location, $module, $method, $key, $ua, $url, $state);
     Mysql::execute($sql, $sqlArr);
     //推送实时日志
     self::realtime(array('uid' => $uid, 'name' => $name, 'ip' => $ip, 'location' => $location, 'module' => $module, 'method' => $method, 'key' => $key, 'ua' => $ua, 'url' => $url, 'state' => $state, 'time' => date('H:i:s', time())));
 }
Beispiel #6
0
 public function getScore()
 {
     $cache = new Cache('score');
     $cacheData = $cache->get($this->sid);
     if (time() - $cacheData['time'] <= \Hnust\Config::getConfig('score_cache_time')) {
         return $cacheData['data'];
     }
     try {
         $score = parent::getScore();
         //从成绩中获取个人信息
         $sid = $score['info']['sid'];
         $class = $score['info']['class'];
         $major = $score['info']['major'];
         $college = $score['info']['college'];
         $grade = $class[0] . $class[1] . "级";
         $time = $score['info']['time'];
         $score = $score['data'];
         //更新资料表
         $sql = 'UPDATE `student` SET `sid` = ?, `class` = ?, `major` = ?, `college` = ?, `grade` = ? WHERE `sid` = ?';
         Mysql::execute($sql, array($sid, $class, $major, $college, $grade, $this->sid));
         //更新成绩表
         $sql = "INSERT INTO `score`(`sid`, `score`, `time`) VALUES(?, ?, ?)\n                    ON DUPLICATE KEY UPDATE `score` = ?, `time` = ?";
         $jsonScore = json_encode($score, JSON_UNESCAPED_UNICODE);
         Mysql::execute($sql, array($sid, $jsonScore, $time, $jsonScore, $time));
         $cache->set($this->sid, array('time' => time(), 'data' => $score));
     } catch (\Exception $e) {
         if ($e->getCode() !== Config::RETURN_ERROR) {
             throw new \Exception($e->getMessage(), $e->getCode());
             //从数据库中获取成绩缓存
         } elseif (empty($cacheData)) {
             $sql = 'SELECT `score`, `time` FROM `score` WHERE `sid` = ?';
             $result = Mysql::execute($sql, array($this->sid));
             if (!empty($result)) {
                 $cacheData = array('time' => $result[0]['time'], 'data' => json_decode($result[0]['score'], true));
             }
         }
         //无缓存抛出异常
         if (empty($cacheData)) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
         $time = date('Y-m-d H:i:s', $cacheData['time']);
         $this->error = $e->getMessage() . "\n当前数据更新时间为:" . $time;
         $score = $cacheData['data'];
     }
     return $score;
 }
Beispiel #7
0
 public function auth()
 {
     //获取用户信息
     $sql = 'SELECT `u`.`uid`, `s`.`name`, `u`.`rank`
             FROM `user` `u`, `student` `s`
             WHERE `u`.`uid` = `s`.`sid` AND `u`.`apiToken` = ? LIMIT 1';
     $result = Mysql::execute($sql, array($this->token));
     //token不存在
     if (empty($result)) {
         return $this->checkAuth(Config::STATE_FORBIDDEN, Config::RETURN_ERROR, Config::getConfig('api_token_error_msg'));
     }
     //获取用户信息
     $this->uid = $result[0]['uid'];
     $this->name = $result[0]['name'];
     $this->rank = (int) $result[0]['rank'];
     //404错误
     if (empty($this->method) || is_null($this->access)) {
         http_response_code(404);
         return $this->checkAuth(Config::STATE_NOT_FOUND, Config::RETURN_ALERT, Config::getConfig('not_found_msg'));
     }
     //权限不足
     if ($this->rank < $this->access) {
         return $this->checkAuth(Config::STATE_FORBIDDEN, Config::RETURN_ERROR, Config::getConfig('api_forbid_access_msg'));
     }
     //权限不足或学号为空查自己
     if (empty($this->sid) || $this->sid === $this->uid) {
         $this->sid = $this->uid;
     } elseif ($this->rank < Config::RANK_OTHER) {
         return $this->checkAuth(Config::STATE_FORBIDDEN, Config::RETURN_ERROR, Config::getConfig('api_forbid_others_msg'));
     }
     //更新API调用次数
     $sql = 'UPDATE `user` SET
               `apiCount` = `apiCount` + 1,
               `lastTime` = NOW()
             WHERE `uid` = ?';
     Mysql::execute($sql, array($this->uid));
     //返回记录
     return $this->checkAuth(Config::STATE_API, Config::RETURN_NORMAL);
 }
Beispiel #8
0
 public function getRank($term, $scope, $by)
 {
     //获取学生信息
     $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'];
     //sql语句及sql数组
     if ('class' === $scope) {
         $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`class`, `a`.`major`,\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->title = $this->class . $term . ($by == 'term' ? '学期排名' : '学年排名');
         $this->rankName = $this->class;
     } else {
         $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`class`, `a`.`major`,\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->title = $this->major . $term . ($by == 'term' ? '学期排名' : '学年排名');
         $this->rankName = $this->major;
     }
     //选择要排名的学期及成绩
     $this->terms = array();
     $rankCourse = array();
     for ($i = 0; $i < count($students); $i++) {
         $score = @json_decode($students[$i]['score'], true);
         $rankScore = array();
         //统计学期和获取待排名成绩
         foreach ($score as $scoreTerm => $termScore) {
             //区分学期排名与学年排名
             $tempTerm = $by != 'term' ? substr($scoreTerm, 0, 9) : $scoreTerm;
             //统计学期
             for ($j = 0; $j < count($this->terms); $j++) {
                 if ($this->terms[$j] == $tempTerm) {
                     break;
                 }
             }
             if ($j == count($this->terms)) {
                 $this->terms[$j] = $tempTerm;
             }
             //去除补考
             for ($j = 0; $j < count($score[$scoreTerm]); $j++) {
                 if ($score[$scoreTerm][$j]['resit'] == true) {
                     array_splice($score[$scoreTerm], $j--, 1);
                 }
             }
             //获取待排名成绩
             if ($term == $tempTerm) {
                 $rankScore = array_merge($rankScore, $score[$scoreTerm]);
             }
         }
         //遍历待排名所有成绩
         for ($j = 0; $j < count($rankScore); $j++) {
             //统计科目
             for ($k = 0; $k < count($rankCourse); $k++) {
                 if ($rankScore[$j]['course'] == $rankCourse[$k]['course']) {
                     break;
                 }
             }
             if ($k == count($rankCourse) && !empty($rankScore[$j]['credit'])) {
                 $rankCourse[$k] = array('course' => $rankScore[$j]['course'], 'mode' => $rankScore[$j]['mode'], 'credit' => $rankScore[$j]['credit'], 'count' => 1);
             } elseif ($k != count($rankCourse)) {
                 $rankCourse[$k]['count']++;
             }
             //遍历其他成绩
             foreach ($score as $termScore) {
                 for ($k = 0; $k < count($termScore); $k++) {
                     //取科目最高分
                     if ($rankScore[$j]['course'] == $termScore[$k]['course'] && \Hnust\scoreCompare($rankScore[$j]['mark'], $termScore[$k]['mark'])) {
                         $rankScore[$j]['mark'] = $termScore[$k]['mark'];
                     }
                 }
             }
         }
         $students[$i]['rankScore'] = $rankScore;
     }
     //删除选修等科目
     for ($i = 0; $i < count($rankCourse); $i++) {
         if ($rankCourse[$i]['count'] < count($students) * 0.8) {
             array_splice($rankCourse, $i--, 1);
         }
     }
     //课程全部存入info数组
     $this->courses = array();
     for ($i = 0; $i < count($rankCourse); $i++) {
         $this->courses[$i] = $rankCourse[$i]['course'];
     }
     //计算
     for ($i = 0; $i < count($students); $i++) {
         $courseMark = array();
         $rankScore = $students[$i]['rankScore'];
         $countFail = $countMark = $countCredit = $totalCredit = $countGpa = $countPoint = 0;
         for ($j = 0; $j < count($rankCourse); $j++) {
             //获取单科分数
             $courseMark[$j] = 0;
             for ($k = 0; $k < count($rankScore); $k++) {
                 if ($rankCourse[$j]['course'] == $rankScore[$k]['course'] && \Hnust\scoreCompare($courseMark[$j], $rankScore[$k]['mark'])) {
                     $courseMark[$j] = $rankScore[$k]['mark'];
                 }
             }
             //将等级制转换为分数
             $tempMark = (double) str_replace(array('优', '良', '中', '及格', '不及格'), array(95.02, 84.02, 74.02, 60.02, 0), $courseMark[$j]);
             //分数转化为对应绩点
             $pointArray = array(90 => 4, 85 => 3.7, 82 => 3.3, 78 => 3.0, 75 => 2.7, 71 => 2.3, 66 => 2.0, 62 => 1.5, 60 => 1, 0 => 0);
             foreach ($pointArray as $mark => $point) {
                 if ($mark <= $tempMark) {
                     $tempPoint = $point;
                     break;
                 }
             }
             $countFail += $tempMark >= 60 ? 0 : 1;
             $countMark += $tempMark;
             $countCredit += $tempMark >= 60 ? $rankCourse[$j]['credit'] : 0;
             $totalCredit += $rankCourse[$j]['credit'];
             $countGpa += $tempMark * $rankCourse[$j]['credit'];
             $countPoint += $tempPoint * $rankCourse[$j]['credit'];
         }
         $avgMark = count($rankCourse) ? round($countMark / count($rankCourse), 2) : 0;
         $countMark = round($countMark, 2);
         $countCredit = round($countCredit, 2);
         $avgGpa = $totalCredit ? round($countGpa / $totalCredit, 2) : 0;
         $avgPoint = $totalCredit ? round($countPoint / $totalCredit, 2) : 0;
         $rank[] = array('name' => $students[$i]['name'], 'sid' => $students[$i]['sid'], 'course' => $courseMark, 'countFail' => $countFail, 'avgMark' => $avgMark, 'countMark' => $countMark, 'countCredit' => $countCredit, 'avgGpa' => $avgGpa, 'avgPoint' => $avgPoint);
     }
     //名次排序
     usort($rank, function ($a, $b) {
         $re = $a['avgGpa'] == $b['avgGpa'] ? $a['sid'] < $b['sid'] : $a['avgGpa'] > $b['avgGpa'];
         return $re ? -1 : 1;
     });
     for ($i = 0; $i < count($rank); $i++) {
         $rank[$i]['rank'] = $i + 1;
     }
     return $rank;
 }
Beispiel #9
0
 public function follow()
 {
     $info = Wechat::getUser($this->uid, false);
     if (!empty($info) && is_array($info)) {
         $wid = empty($info['weixinid']) ? '' : $info['weixinid'];
         $status = empty($info['status']) ? -1 : $info['status'];
         $sql = "INSERT INTO `weixin`(`uid`, `wid`, `status`) VALUES(?, ?, ?)\n                       ON DUPLICATE KEY UPDATE `wid` = IF(? = '', `wid`, ?), `status` = ?";
         $sqlArr = array($this->uid, $wid, $status, $wid, $wid, $status);
         Mysql::execute($sql, $sqlArr);
     }
 }
Beispiel #10
0
 public function passwd()
 {
     //全负荷执行
     Config::fullLoad();
     //添加学生学号到密码数据库
     $sql = 'INSERT INTO `weak`(`passwd`)
               (SELECT `sid` FROM `student` WHERE `sid` NOT IN
                 (SELECT `passwd` FROM `weak`))';
     Mysql::execute($sql);
     //添加教工号到数据库
     $sql = 'INSERT INTO `weak`(`passwd`)
               (SELECT `tid` FROM `teacher` WHERE `tid` NOT IN
                 (SELECT `passwd` FROM `weak`))';
     Mysql::execute($sql);
     //更新数据库
     while (true) {
         $sql = "SELECT `passwd` FROM `weak` WHERE `sha1` = '' OR `md5` = '' LIMIT 10000";
         $passwds = Mysql::execute($sql);
         if (empty($passwds)) {
             break;
         }
         $sql = 'UPDATE `weak` SET `sha1` = ?, `md5` = ? WHERE `passwd` = ? LIMIT 1';
         for ($i = 0; $i < count($passwds); $i++) {
             $passwd = $passwds[$i]['passwd'];
             $passwds[$i] = array(sha1($passwd), md5($passwd), $passwd);
         }
         if (Mysql::executeMultiple($sql, $passwds)) {
             Log::file('passwd', '成功更新' . count($passwds) . '条密码');
         } else {
             Log::file('passwd', '密码更新失败');
             break;
         }
     }
 }
Beispiel #11
0
 public function fetch($uid)
 {
     $sql = "SELECT `id`, `uid`, `type`, `title`, `content`, `success`, `received`, `time`, `upTime`\n                FROM `push` WHERE `uid` = ? AND `received` = 0 ORDER BY `id` ASC LIMIT 1";
     $data = Mysql::execute($sql, array($uid));
     return $data ? $data[0] : array();
 }
Beispiel #12
0
 public function search($key)
 {
     $sql = 'SELECT IF(`name` = ?, `course`, `name`) `name`, `course`, `all`, `fail`, `rate`
             FROM `failRate` WHERE (`course` = ? OR `name` = ?) AND `all` > 10';
     return Mysql::execute($sql, array($key, $key, $key));
 }
Beispiel #13
0
 public function user()
 {
     $sql = 'SELECT `u`.`uid`, `u`.`rank`, `u`.`apiToken`,
                    `s`.`name`, `s`.`class`, `s`.`major`, `s`.`college`,
                    `s`.`mail`, `s`.`phone`, `s`.`qq`
             FROM `user` `u`, `student` `s`
             WHERE `u`.`uid` = `s`.`sid` AND `u`.`uid` = ?';
     $result = Mysql::execute($sql, array($this->uid));
     $this->info = empty($result) ? array() : $result[0];
     $this->info['token'] = $this->token;
     //当前学期/周次
     $this->info['week'] = \Hnust\week();
     $this->info['term'] = Config::getConfig('current_term');
     //头像地址
     $this->info['avatar'] = Config::getConfig('local_base_url');
     if (empty($this->info['qq'])) {
         $this->info['avatar'] .= "avatar/qy/{$this->info['uid']}";
     } else {
         $this->info['avatar'] .= "avatar/qq/{$this->info['qq']}";
     }
     //用户所在群组
     $group = new \Hnust\Analyse\Group();
     $this->info['group'] = $group->belong($this->uid);
     //数组合并
     $this->info = array_merge($this->info, array('sid' => $this->sid, 'isAdmin' => $this->rank === Config::RANK_ADMIN));
     return $this->info;
 }
Beispiel #14
0
 public function network()
 {
     //设置日志文件
     $this->logFileName = 'network';
     //获取最新数据
     $net = file_get_contents('/proc/net/dev');
     $pattern = "/eth1:\\s*(\\d+)\\s+(\\d+)\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+(\\d+)\\s+(\\d+)/";
     preg_match($pattern, $net, $matches);
     $newRes = array('in' => array('bytes' => $matches[1], 'packets' => $matches[2]), 'out' => array('bytes' => $matches[3], 'packets' => $matches[4]), 'time' => time());
     //处理缓存数据
     $cache = new Cache('remind_network');
     $oldRes = $cache->get('res');
     $cache->set('res', $newRes);
     if (empty($oldRes)) {
         return;
     }
     //判断是否提醒
     $minutes = number_format(($newRes['time'] - $oldRes['time']) / 60, 2);
     $bytes = $newRes['out']['bytes'] - $oldRes['out']['bytes'];
     $currentSize = \Hnust\sizeFormat($bytes);
     $totalSize = \Hnust\sizeFormat($newRes['out']['bytes']);
     $remindValue = Config::getConfig('network_remind_value');
     $remindUser = Config::getConfig('network_remind_user');
     if ($bytes > $remindValue) {
         $sql = 'SELECT `sid`, `name`, `mail` FROM `student` WHERE `sid` = ?';
         $result = Mysql::execute($sql, array($remindUser));
         $student = $result[0];
         $title = '服务器流量异常提醒 -- Tick团队';
         $content = "尊敬的管理员您好,系统检测服务器出网流量在 {$minutes} 分钟内共消耗了 {$currentSize},累计使用 {$totalSize},请及时处理!";
         $this->remind($student, $title, $content, '', '0100');
     }
     $this->record("{$minutes} 分钟内共消耗出网流量 {$currentSize},累计使用 {$totalSize}");
 }
Beispiel #15
0
 public function getSchdule($sid, $term, $type = 0, $week = -1)
 {
     $cache = new Cache('schedule');
     $cacheData = $cache->get($sid);
     $cacheData = empty($cacheData) ? array() : $cacheData;
     if (time() - $cacheData[$term]['time'] <= \Hnust\Config::getConfig('schedule_cache_time')) {
         return $this->type($cacheData[$term]['data'], $type, $week);
     }
     try {
         $schedule = parent::getSchdule($sid, $term);
         //更新课表数据库
         if ($term === Config::getConfig('current_term')) {
             $sql = "INSERT INTO `schedule`(`sid`, `schedule`, `term`, `time`) VALUES(?, ?, ?, ?)\n                        ON DUPLICATE KEY UPDATE `schedule` = ?, `time` = ?";
             $jsonSchedule = json_encode($schedule, JSON_UNESCAPED_UNICODE);
             Mysql::execute($sql, array($sid, $jsonSchedule, $term, $time, $jsonSchedule, $time));
         }
         //设置缓存
         $cacheData[$term] = array('time' => time(), 'data' => $schedule);
         $cache->set($sid, $cacheData);
     } catch (\Exception $e) {
         if (empty($cacheData[$term]) || $e->getCode() !== Config::RETURN_ERROR) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
         $time = date('Y-m-d H:i:s', $cacheData[$term]['time']);
         $this->error = $e->getMessage() . "\n当前数据更新时间为:" . $time;
         $schedule = $cacheData[$term]['data'];
     }
     return $this->type($schedule, $type, $week);
 }
Beispiel #16
0
 public static function getConfig($method = '')
 {
     self::cacheInit();
     //读取缓存
     if (!self::DEBUG && empty(self::$config)) {
         self::$config = self::$cache->get('config');
     }
     //数据库中获取所有配置文件
     if (empty(self::$config) || !is_array(self::$config)) {
         self::$config = array();
         $sql = 'SELECT `method`, `value` FROM `ini`';
         $result = Mysql::execute($sql);
         if (false === $result) {
             throw new \Exception('服务器数据库异常', Config::RETURN_ERROR);
         }
         foreach ($result as $item) {
             self::$config[$item['method']] = $item['value'];
         }
         //缓存配置文件
         self::$cache->set('config', self::$config, Config::CONFIG_CACHE_TIME);
     }
     //返回想要的内容
     if (empty($method)) {
         return self::$config;
     } elseif (isset(self::$config[$method])) {
         return self::$config[$method];
     } else {
         return false;
     }
 }
Beispiel #17
0
 public function deleteMember($gid, $sid)
 {
     $sql = 'DELETE FROM `group_member` WHERE `gid` = ? AND `sid` = ?';
     return Mysql::execute($sql, array($gid, $sid));
 }
Beispiel #18
0
 public function log()
 {
     //清理日志文件
     $logSuffix = '.log';
     $logLength = 5000;
     $path = Config::BASE_PATH . Config::LOGS_PATH . '/';
     $handle = opendir($path);
     while ($handle && false !== ($file = readdir($handle))) {
         $suffix = strrchr(strtolower($file), $logSuffix);
         if ($suffix !== $logSuffix) {
             continue;
         }
         $content = file_get_contents($path . $file);
         $content = explode("\n", $content);
         $count = count($content);
         if ($count > $logLength) {
             $content = array_slice($content, $count - $logLength);
             $content = implode("\n", $content);
             file_put_contents($path . $file, $content);
         }
     }
     closedir($handle);
     //清除日志
     $sql = "DELETE FROM `logs`\n                WHERE `uid` IN ('1305010117', '1305010119', '1305020233')\n                OR (`ip` != ? AND `location` LIKE '%阿里%')\n                OR`time` < DATE_SUB(NOW(), INTERVAL 3 MONTH)";
     $num = Mysql::execute($sql, array(Config::getConfig('local_out_ip')));
     $sql = "DELETE FROM `logs` WHERE `uid` != ''\n                AND `uid` NOT IN (SELECT `uid` FROM `user`)";
     $num += Mysql::execute($sql);
     $log = "清除日志{$num}条";
     //更新日志
     $sql = "UPDATE `student` `s`, `logs` `l`\n                SET `l`.`key` = `s`.`name`\n                WHERE `l`.`key` = `s`.`sid`";
     $num = Mysql::execute($sql);
     $sql = "UPDATE `logs` SET `key` = ''\n                WHERE `key` in (`uid`, `name`, '湖南科技大学', '计算机科学与工程学院')";
     $num += Mysql::execute($sql);
     return $log . ",更新日志{$num}条";
 }
Beispiel #19
0
 public static function sendMsg($uid, $type, $data)
 {
     //判断用户是否关注微信
     $sql = 'SELECT `status` FROM `weixin` WHERE `uid` = ? LIMIT 1';
     $result = Mysql::execute($sql, array($uid));
     if (empty($result) || 1 != $result[0]['status']) {
         return false;
     }
     //调用接口发送消息
     self::init();
     $result = self::getHttp('sendMsg', array('to' => array('touser' => $uid), 'message' => array('msgtype' => $type, $type => $data)));
     return '0' == $result['errcode'];
 }
Beispiel #20
0
 public function getQueue()
 {
     $sql = 'SELECT `title`, `result`, `upTime` FROM `elective_queue` WHERE `sid` = ?';
     $sqlArr = array($this->sid);
     return Mysql::execute($sql, $sqlArr);
 }
Beispiel #21
0
 public function app()
 {
     $type = \Hnust\input('type');
     //发布App
     if ('put' === $type) {
         $version = \Hnust\input('version');
         $develop = \Hnust\input('develop');
         $intro = \Hnust\input('intro');
         $key = \Hnust\input('key');
         $size = \Hnust\input('size');
         $sql = "INSERT INTO `app` (`version`, `develop`, `intro`, `key`, `size`) VALUES (?, ?, ?, ?, ?);";
         $result = Mysql::execute($sql, array($version, $develop, $intro, $key, $size));
         if ($result) {
             $this->code = Config::RETURN_CONFIRM;
             $this->msg = '系统消息';
             $this->data = "{$version}版本发布成功";
         } else {
             $this->code = Config::RETURN_ERROR;
             $this->msg = "{$version}版本发布失败";
         }
         //获取APP统计记录
     } else {
         $this->data = $this->info = array();
         $sql = "SELECT `name`, `uid`, `ua`, `time`\n                    FROM (SELECT * FROM `logs` ORDER BY `time` DESC) `a`\n                    WHERE `ua` LIKE 'hnust%' AND `uid` != '' AND `name` != '游客'\n                    GROUP BY `uid` ORDER BY `time` DESC";
         $result = Mysql::execute($sql);
         foreach ($result as $item) {
             $clientInfo = explode('   ', $item['ua']);
             $this->data[] = array('name' => $item['name'], 'uid' => $item['uid'], 'time' => $item['time'], 'version' => $clientInfo[1], 'model' => $clientInfo[2], 'system' => $clientInfo[3], 'network' => $clientInfo[4] . ' / ' . $clientInfo[5], 'resolution' => $clientInfo[6]);
         }
         //获取七牛Token
         $qiniuInfo = Config::getConfig('qiniu_info');
         $qiniuInfo = json_decode($qiniuInfo, true);
         $auth = new \Qiniu\Auth($qiniuInfo['accessKey'], $qiniuInfo['secretKey']);
         $this->info['qiniu'] = $auth->uploadToken($qiniuInfo['bucket']);
     }
 }