Beispiel #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();
     }
 }
Beispiel #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $data = array('errNum' => 0, 'errMsg' => '', 'errDate' => '');
     $borrow = new Borrow();
     $borrow->book_id = $request->book_id;
     $borrow->username = $request->username;
     $borrow->userno = $request->userno ? $request->userno : "";
     $borrow->phone = $request->phone ? $request->phone : "";
     $borrow->return_at = $request->return_at;
     $borrow->status = 0;
     //减去一本库存
     $book = Book::find($request->book_id);
     $book->book_res = $book->book_res - 1;
     $book->save();
     if ($borrow->save()) {
         $data['errMsg'] = "添加成功";
         return json_encode($data);
     } else {
         $data['errMsg'] = "添加失败";
         return json_encode($data);
     }
 }
 public function bookBorrowAction(Request $request)
 {
     $date = date("Y-m-d");
     $reader_id = $request->input("reader-id");
     $isbn = $request->input("isbn");
     $reader = Reader::find($reader_id);
     //对输入信息进行检查
     if ($reader == null) {
         return redirect('/admin/bookBorrow')->with("msg", "读者证编号有误,请检查!");
     }
     if ($reader['loss'] == true) {
         //挂失处理
         return redirect('/admin/bookBorrow')->with("msg", "该借书证已挂失,请先解挂后再借书!");
     }
     $book = Book::where("isbn", '=', $isbn)->first();
     if ($book == null) {
         return redirect('/admin/bookBorrow')->with("msg", "图书ISBN有误,请检查!");
     }
     if ($book['quantity-in'] - $book['quantity-out'] - $book['quantity-loss'] < 1) {
         return redirect('/admin/bookBorrow')->with("msg", "图书数量不足,请检查ISBN!");
     }
     $level = Level::find($reader['level']);
     $borrowedBookNum = Borrow::where("reader-id", '=', $reader_id)->where("returned", '=', false)->where('loss', '<>', true)->get()->count();
     if ($borrowedBookNum >= $level['numbers']) {
         //借书数量限制
         return redirect('/admin/bookBorrow')->with("msg", "该用户借书数量超过限制,请先归还部分图书!");
     }
     $book['quantity-out'] += 1;
     $book->save();
     $borrow = new Borrow();
     $shouldReturnDate = date("Y-m-d", strtotime("+" . $level['days'] . " days"));
     $borrow['reader-id'] = $reader_id;
     $borrow['book-id'] = $book['book-id'];
     $borrow['date-borrow'] = $date;
     $borrow['date-should-return'] = $shouldReturnDate;
     $borrow->save();
     return redirect('/admin/bookBorrow')->with("msg", "借阅成功!");
 }