public function book() { //设置日志文件 $this->logFileName = 'book'; //图书借阅缓存 $cache = new Cache('remind_book'); if ($cache->get('lock')) { return false; } else { $cache->set('lock', true, 86000); } //全负荷运行 Config::fullLoad(); //剩余天数提醒 $remains = array(7, 3, 1, 0); //获取所有用户 $sql = 'SELECT `sid`, `name`, `phone`, `mail` FROM `student` WHERE `sid` IN (SELECT `uid` FROM `user`)'; $students = Mysql::execute($sql); foreach ($students as $student) { //判断是否需要获取借阅列表 if ($cache->get($student['sid'])) { continue; } try { $bookClass = new \Hnust\Analyse\Book($student['sid']); $loanList = $bookClass->getLoanList(); } catch (\Exception $e) { $this->record("获取【{$student['name']}】的借阅列表失败:" . $e->getMessage()); continue; } $minDiff = 20; foreach ($loanList as $item) { $minDiff = min($minDiff, $item['remain']); if (empty($item['remain']) || !in_array($item['remain'], $remains)) { continue; } try { $result = $bookClass->doRenew($item['barcode'], $item['department'], $item['library']); } catch (\Exception $e) { $result = $e->getMessage(); } $title = '图书借阅过期提醒 -- Tick团队'; $content = "亲爱的 {$student['name']} 同学,您借阅的《{$item['title']}》将于{$item['remain']}天内到期,我们已尝试为您进行续借操作,操作结果为:【{$result}】"; $student['sms'] = array('name' => $student['name'], 'book' => $item['title'], 'day' => (string) $item['remain'], 'result' => $result, 'template' => 'SMS_6730035'); $this->remind($student, $title, $content, '#/book', '1111'); } //计算多少天秒内不需要获取借阅列表 $cacheTime = ($minDiff - $remains[0] - 1) * 86400; if ($cacheTime > 0) { $cache->set($student['sid'], true, $cacheTime); } } $this->record("=== 图书提醒执行完成 ==="); }
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; } } }