Beispiel #1
0
 /**
  * 搜索记录包含借阅信息
  *
  * @param string  personId 记录的成员id
  * @param int     status 记录的状态
  * @param int     page 搜索结果的页数
  * @param int     size 搜索结果每页的数量
  * @return  array 搜索结果,如果发生错误,则返回false
  */
 public static function searchRecordsWithBookName($personId, $status = -1, $page = 1, $size = 10)
 {
     try {
         $dataBaseHandler = getDataBaseHander();
         $sql = "select record.*,book.name as bookName from record left join book on record.book_id = book.id " . "where person_id ={$personId} ";
         if ($status != -1) {
             $sql = $sql . " and record.status = {$status}";
         } else {
             $sql = $sql . " and record.status != -1 ";
         }
         if ($size != -1) {
             $sql = $sql . " order by borrow_time desc limit " . ($page - 1) * $size . ",{$size} ;";
         }
         $stmt = $dataBaseHandler->prepare($sql);
         $stmt->execute();
         for ($i = 0; $row = $stmt->fetch(); $i++) {
             $tempRecord = new Record();
             $tempRecord->recordId = $row['id'];
             $tempRecord->bookId = $row['book_id'];
             $tempRecord->personId = $row['person_id'];
             $tempRecord->status = $row['status'];
             $tempRecord->borrowTime = $row['borrow_time'];
             $tempRecord->remandTime = $row['remand_time'];
             $tempRecord->bookName = $row['bookName'];
             $resultRecord['records'][$i] = $tempRecord;
         }
         $count = $stmt->rowCount();
         $stmt->closeCursor();
         $pageSum = intval($count / $size);
         $resultRecord['pageSum'] = $count % $size != 0 ? $pageSum + 1 : $pageSum;
         $resultRecord['currentPage'] = $page;
         return $resultRecord;
     } catch (PDOExecption $e) {
         print "搜索记录失败: " . $e->getMessage() . "</br>";
         return false;
     } catch (Exception $e) {
         print "搜索记录失败: " . $e->getMessage() . "</br>";
         return false;
     }
 }
Beispiel #2
0
 /**
  * 获得成员
  *
  * @param string  personId 要获得的成员id
  * @return Person 获得的成员,如果出现错误则返回false
  */
 public static function getPersonWithBorrowCount($personId)
 {
     try {
         $dataBaseHandler = getDataBaseHander();
         $sql = "select a.*," . " (select count(*) from record left join book on record.book_id = book.id " . "where record.person_id = a.id and record.status = 1) as count," . "(select count(*) from record left join book on record.book_id = book.id " . "where record.person_id = a.id) as allCount from person as a where id = ?;";
         $stmt = $dataBaseHandler->prepare($sql);
         $stmt->bindParam(1, $personId);
         $stmt->execute();
         if ($row = $stmt->fetch()) {
             $tempPerson = new Person();
             $tempPerson->personId = $row['id'];
             $tempPerson->name = $row['name'];
             $tempPerson->sunccoNo = $row['suncco_no'];
             $tempPerson->type = $row['type'];
             $tempPerson->borrowBookCount = $row['count'];
             $tempPerson->allBorrowBookCount = $row['allCount'];
             return $tempPerson;
         } else {
             throw new Exception("获得成员失败:没有找到");
         }
     } catch (PDOExecption $e) {
         print "获得成员失败: " . $e->getMessage() . "</br>";
         return false;
     } catch (Exception $e) {
         print "获得成员失败: " . $e->getMessage() . "</br>";
         return false;
     }
 }
Beispiel #3
0
 /**
  * 续借
  *
  * @param string  bookId 书籍Id
  * @param string  personId 成员id
  * @return  bool 还书结果
  */
 public static function renewBook($bookId, $personId)
 {
     try {
         $dataBaseHandler = getDataBaseHander();
         $remanRecordSql = "update record set status = 0,remand_time ='" . date("Y-m-d h:i:s") . "' where book_id = '{$bookId}' and person_id = '{$personId}' and status = 1";
         $borrowRecordSql = "insert into record (book_id,person_id,borrow_time) values ('" . $bookId . "','" . $personId . "','" . date("Y-m-d") . "');";
         try {
             $dataBaseHandler->beginTransaction();
             $dataBaseHandler->exec($remanRecordSql);
             $dataBaseHandler->exec($borrowRecordSql);
             $dataBaseHandler->commit();
         } catch (PDOExecption $e) {
             $dataBaseHandler->rollBack();
             throw $e;
         }
         return true;
     } catch (PDOExecption $e) {
         print "续借失败: " . $e->getMessage() . "</br>";
         return false;
     }
 }