Пример #1
0
 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("=== 图书提醒执行完成 ===");
 }
Пример #2
0
 public function book()
 {
     $type = \Hnust\input('type');
     $book = new \Hnust\Analyse\Book($this->sid, $this->passwd);
     if ('renew' === $type) {
         $barcode = \Hnust\input('barcode');
         $department = \Hnust\input('department');
         $library = \Hnust\input('library');
         $this->code = Config::RETURN_ALERT;
         $this->data = $this->msg = $book->doRenew($barcode, $department, $library);
     } elseif ('search' === $type) {
         $this->data = $book->getBookList($this->key, $this->page);
         if (empty($this->data)) {
             $this->code = Config::RETURN_ERROR;
             $this->msg = 1 === $this->page ? '未找到相关书籍' : '没有更多了...';
         }
     } elseif ('info' === $type) {
         $id = \Hnust\input('id');
         $this->data = $book->getBookInfo($id);
     } else {
         $this->data = $book->getLoanList();
         if (0 === count($this->data)) {
             $this->code = Config::RETURN_ERROR;
             $this->msg = '未找到相关借书记录';
         }
     }
 }