Exemple #1
0
 public function run()
 {
     DB::table('borrow')->truncate();
     for ($i = 0; $i < 10; $i++) {
         $book = new Borrow();
         $book->book_id = rand(1, 10);
         $book->username = str_random(10);
         $book->userno = rand(10000, 99999);
         $book->phone = rand(13100000000, 15100000000);
         $book->return_at = \Carbon\Carbon::now();
         $book->status = rand(0, 1);
         $book->save();
     }
 }
Exemple #2
0
 public function borrow2()
 {
     //$user = user::where('email', '=', Input::get('bemail'))->firstOrFail();
     $returnData = "";
     $name = Input::get("name");
     $email = Input::get("email");
     if (Request::ajax()) {
         $userCount = User::where('email', '=', Input::get('email'))->count();
         $bookCount = Book::where('barcode', '=', Input::get('barcode'))->count();
         if ($userCount == 1) {
             $returnData = $returnData . " user existed ";
             $user = User::where('email', '=', Input::get('email'))->find(1);
         }
         if ($userCount == 0) {
             $name = Input::get("name");
             $email = Input::get("email");
             $user = user::create(array('email' => $email, 'name' => $name));
             $returnData = $returnData . " user is created ";
         }
         if ($bookCount == 1) {
             $returnData = $returnData . " book existed ";
             $book = Book::where('barcode', '=', Input::get('barcode'))->find(1);
         }
         if ($bookCount == 0) {
             $title = Input::get('title');
             $author = Input::get('author');
             $barcode = Input::get('barcode');
             $book = book::create(array('title' => $title, 'author' => $author, 'barcode' => $barcode));
             $returnData = $returnData . " book is created ";
         }
         $borrow = Borrow::create(array('user_id' => $user->id, 'book_id' => $book->id));
         $returnData = $returnData . " borrowing is successful user id =" . $user->id . " book id =" . $book->id;
     }
     return $returnData;
 }
 public function overTime(Request $request)
 {
     $num = 10;
     $username = $request->session()->get("username");
     $borrows = Borrow::where("date-should-return", "<", DB::raw("curdate()"))->paginate($num);
     return view("/admin/OverTime", ['username' => $username, "borrows" => $borrows]);
 }
 public function history(Request $request)
 {
     $num = 10;
     $username = $request->session()->get("username");
     $user = User::where('username', '=', $username)->first();
     if ($user == null) {
         return redirect('/reader/home');
     }
     $borrows = Borrow::where('reader-id', '=', $user['reader-id'])->orderBy('id')->paginate($num);
     return view('/reader/history', ['username' => $username, 'borrows' => $borrows]);
 }
Exemple #5
0
 public function back($id)
 {
     $data = array('errNum' => 0, 'errMsg' => '', 'errDate' => '');
     $borrow = Borrow::find($id);
     $borrow->status = 1;
     $book = Book::find($borrow->book_id);
     $book->book_res = $book->book_res + 1;
     $book->save();
     if ($borrow->update()) {
         $data['errMsg'] = "归还成功";
         return json_encode($data);
     } else {
         $data['errMsg'] = "归还失败";
         return json_encode($data);
     }
 }
 public function bookLossAction(Request $request)
 {
     $reader_id = $request->input("reader-id");
     $isbn = $request->input("isbn");
     $book = Book::where("isbn", '=', $isbn)->first();
     if ($book == null) {
         return redirect('/admin/bookLoss')->with("msg", "读者证编号有误,请检查!");
     }
     if ($book['quantity-out'] + $book['quantity-loss'] + 1 > $book['quantity-in']) {
         return redirect('/admin/bookLoss')->with("msg", "图书信息有误,请检查!");
     }
     $borrow = Borrow::where("reader-id", '=', $reader_id)->where("book-id", '=', $book['book-id'])->where("returned", '=', 0)->first();
     if ($borrow == null) {
         return redirect('/admin/bookLoss')->with("msg", "信息有误,请检查!");
     }
     $book['quantity-out'] = $book['quantity-out'] - 1;
     $book['quantity-Loss'] += 1;
     $book->save();
     $borrow['loss'] = true;
     $borrow->save();
     return redirect('/admin/bookLoss')->with("msg", "图书挂失成功!");
 }