예제 #1
0
 public function store(Request $request)
 {
     $booksToRenew = Input::get('checkbox');
     $tmp_timestamp = strtotime('today');
     foreach ($booksToRenew as $id) {
         $record = DB::table('lends')->select('id', 'due_date', 'continued')->where('book_id', $id)->get();
         $record_id = $record[0]->id;
         $due_date = $record[0]->due_date;
         $has_renewed = $record[0]->continued;
         // 是在到期3天内续借
         $cond1 = $due_date - $tmp_timestamp <= 3 * 24 * 60 * 60;
         // 3天
         // 没有续借过
         $cond2 = !$has_renewed;
         // 没有被人预约
         $reserve = DB::table('reserves')->select('id')->where('book_id', $id)->get();
         $cond3 = empty($reserve);
         //            var_dump($cond1);
         //            var_dump($cond2);
         //            var_dump($cond3);
         if ($cond1 and $cond2 and $cond3) {
             $lend = Lend::find($record_id);
             $lend->lend_date = $tmp_timestamp;
             $lend->due_date = strtotime('+30 days', $tmp_timestamp);
             $lend->continued = 1;
             $lend->save();
         }
     }
     return Redirect::to('/user/home')->with('message_success', '续借完成!');
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('lends')->delete();
     DB::table('users')->delete();
     User::create(['id' => '1', 'name' => '郑文凯', 'email' => '*****@*****.**', 'password' => Hash::make('123'), 'is_admin' => 1, 'reserve_num' => 1]);
     User::create(['id' => '2', 'name' => '陈翔宇', 'email' => '*****@*****.**', 'password' => Hash::make('1'), 'is_admin' => 0, 'reserve_num' => 10]);
     DB::table('books')->delete();
     Book::create(['id' => '1', 'book_name' => '书名', 'author' => '作者', 'ISBN' => '123456', 'press_name' => '出版社', 'press_date' => '123456', 'url' => '链接', 'in_use' => '0']);
     Lend::create(['user_id' => '2', 'book_id' => '1', 'lend_date' => '1234', 'due_date' => '2345', 'return_date' => '3456', 'continued' => '1', 'is_returned' => '0']);
 }
예제 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['user_id' => 'required', 'book_id' => 'required']);
     $lend = new Lend();
     $lend->user_id = Input::get('user_id');
     $lend->book_id = Input::get('book_id');
     $lend_date = strtotime('today');
     $due_date = strtotime('+30 days', $lend_date);
     $lend->lend_date = $lend_date;
     $lend->due_date = $due_date;
     $lend->return_date = 0;
     $lend->continued = 0;
     $lend->is_returned = 0;
     if ($lend->save()) {
         return Redirect::to('admin/lends');
     } else {
         return Redirect::back()->withInput()->withErrors('fail to save!');
     }
     //
 }
예제 #4
0
 public function store(Request $request)
 {
     $this->validate($request, ['user_id' => 'required', 'book_id' => 'required']);
     $user_id = Input::get('user_id');
     $book_id = Input::get('book_id');
     $delete_succeed = Lend::where('user_id', '=', "{$user_id}")->where('book_id', '=', "{$book_id}")->delete();
     if ($delete_succeed) {
         return Redirect::to('admin/return');
     } else {
         return Redirect::back()->withErrors('删除失败!');
     }
 }