/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $auctions = Auction::where('active', '=', true)->get();
     foreach ($auctions as $key => $auction) {
         if ($auction->end_date < Carbon::now() && $auction->active == true) {
             // auction end
             $auction->active = false;
             $auction->save();
             // highest bidder mail congrats
             $highestbid = Bid::where('auction_id', '=', $auction->id)->orderBy('price', 'desc')->first();
             $highestbiduser = User::where('id', '=', $highestbid->user_id)->first();
             $emailwon = $highestbiduser->login->email;
             Mail::raw('The auction ended, you bought the auction ' . $auction->title, function ($message) use($emailwon) {
                 $message->to($emailwon)->subject('The auction ended, you bought the auction ');
                 $message->from('*****@*****.**');
             });
             // other bidders damn it mail
             $count = Bid::where('auction_id', '=', $auction->id)->count();
             $skip = 1;
             $limit = $count - $skip;
             // the limit
             $otherbids = Bid::where('auction_id', '=', $auction->id)->orderBy('price', 'desc')->skip($skip)->take($limit)->get();
             foreach ($otherbids as $key => $bid) {
                 $user = User::where('id', '=', $bid->user_id)->first();
                 $emaillose = $user->login->email;
                 Mail::raw('The auction ended, you lost the auction ' . $auction->title, function ($message) use($emaillose) {
                     $message->to($emaillose)->subject('The auction ended, you lost the auction ');
                     $message->from('*****@*****.**');
                 });
             }
         }
     }
 }
Example #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Bid::create(['item' => 1, 'offer' => 2, 'owner' => 1, 'buyer' => 2, 'date_completed' => Carbon::now(), 'success' => true]);
     Bid::create(['item' => 2, 'offer' => 3, 'owner' => 2, 'buyer' => 1, 'date_completed' => Carbon::now(), 'success' => false]);
     Bid::create(['item' => 3, 'offer' => 1, 'owner' => 1, 'buyer' => 1, 'date_completed' => NULL, 'success' => false]);
     Bid::create(['item' => 2, 'offer' => 1, 'owner' => 2, 'buyer' => 1, 'date_completed' => NULL, 'success' => false]);
 }
Example #3
0
 public function buynow($id)
 {
     $auction = Auction::getAuctionWithBuyerForId($id);
     $buyer = Auth::user();
     $owner = $auction->owner;
     $bidders = Bid::getBiddersWithId($id);
     $auction->buyer_id = $buyer->id;
     $auction->save();
     // Email to owner
     Mail::raw('Your artwork ' . $auction->title . ' has been sold!', function ($message) use($owner) {
         $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
         $message->to($owner->email)->subject('Someone bough your artwork.');
     });
     // Email to buyer
     Mail::raw('Confirmation for the artwork you bought: ' . $auction->title . '!', function ($message) use($buyer) {
         $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
         $message->to($buyer->email)->subject('You bought an artwork.');
     });
     // Email to bidders
     foreach ($bidders as $bidder) {
         Mail::raw('Auction ended! Someone bought an artwork you bid on: ' . $auction->title . '!', function ($message) use($bidder) {
             $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
             $message->to($bidder->user->email)->subject('Someone bought an artwork you bid on.');
         });
     }
     // return $auction;
     return Redirect::route('home');
 }
Example #4
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         Mail::raw('Hi Dries!', function ($message) {
             $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
             $message->to('*****@*****.**')->subject('Test mail!');
         });
     })->daily();
     $schedule->call(function () {
         $expiringAuctions = Auction::getExpiringAuctions();
         foreach ($expiringAuctions as $auction) {
             $bidders = Bid::getBiddersWithId($auction->id);
             $highest = Bid::getHighestBidWithId($auction->id);
             $auction->buyer_id = $highest->id;
             $auction->save();
             foreach ($bidders as $bidWithBidder) {
                 $bidder = $bidWithBidder->user;
                 if ($bidder->id = $highest->id) {
                     Mail::raw('Auction ' . $auction->title . ' ended, you are the highest bidder!', function ($message) use($bidder) {
                         $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
                         $message->to($bidder->email)->subject('You are the highest bidder.');
                     });
                 } else {
                     Mail::raw('Auction ' . $auction->title . ' ended, you did not give the highest bid!', function ($message) use($bidder) {
                         $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
                         $message->to($bidder->email)->subject("Auction ended, you didn't get it.");
                     });
                 }
             }
         }
     })->daily();
 }
Example #5
0
 protected function mybids($id)
 {
     $mybids = Bid::where('bidder_id', $id)->get();
     foreach ($mybids as $bid) {
         $bid->auction = Auction::where('id', $bid->auction_id)->first();
     }
     return $mybids;
 }
Example #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(BidRequest $request)
 {
     $user = Auth::user();
     $bid = Bid::firstOrNew(array('user_id' => $user->id, 'auction_id' => $request->auction_id));
     $bid->price = $request->price;
     $bid->save();
     return Redirect::route('bids.index');
 }
 public function getHighestBid($id)
 {
     $bid = Bid::where('auction_id', '=', $id)->orderBy('price', 'desc')->take(1)->first();
     if ($bid) {
         return $bid->price + 1;
     }
     return $this->getLowestBid($id);
 }
Example #8
0
 public function hasAlreadyBid($user_id, $auction_id)
 {
     $bid = Bid::where(['user_id' => $user_id, 'auction_id' => $auction_id])->first();
     if ($bid) {
         return true;
     } else {
         return false;
     }
 }
Example #9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     $users = User::get()->lists('id')->all();
     $products = Product::get()->lists('id')->all();
     foreach (range(1, 30) as $index) {
         Bid::create(['amount' => $faker->randomNumber(), 'user_id' => $faker->randomElement($users), 'product_id' => $faker->randomElement($products)]);
     }
 }
Example #10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('bids')->delete();
     $auctions = Auction::get();
     foreach ($auctions as $auction) {
         $random_user = User::orderByRaw("RAND()")->first();
         if (rand(0, 5) == 0) {
             Bid::create(['user_id' => $random_user->id, 'auction_id' => $auction->id, 'price' => $auction->min_price + 999]);
         }
     }
 }
 public function myBids()
 {
     //get all your bids
     $bids = Bid::where('user_id', Auth::user()->id)->groupBy('art_id')->get();
     $auctions = collect([]);
     foreach ($bids as $bid) {
         $auction = $bid->art;
         $auctions->push($auction);
     }
     $data['auctions'] = $auctions;
     return View('User.my-bids')->with($data);
 }
Example #12
0
 public function myBids()
 {
     $mybids = Bid::where('user_id', Auth::user()->id)->orderby('art_id')->orderby('bid', 'desc')->get();
     $allBids = array();
     foreach ($mybids as $bid) {
         $art = Art::where('id', $bid->art_id)->where('sold', 0)->first();
         if ($art) {
             $bid['title'] = $art->title;
             $bid['ending'] = $art->ending;
             $allBids[] = $bid;
         }
     }
     $iBought = Art::where('sold_to', Auth::user()->id)->get();
     return View('profile.mybids', compact('allBids', 'iBought'));
 }
Example #13
0
 public function bids()
 {
     echo '<pre>';
     echo '<h1>All bids</h1>';
     $arr = Bid::all()->toArray();
     print_r($arr);
     echo '<h1>Completed bids</h1>';
     $bid = Bid::completed()->get()->toArray();
     print_r($bid);
     echo '<h1>Successfully completed bids</h1>';
     $bid = Bid::successful()->get()->toArray();
     print_r($bid);
     echo '<h1>First bid conversation</h1>';
     $bid = Bid::first()->conversation->toArray();
     print_r($bid);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $id)
 {
     $this->validate($request, ['amount' => 'required']);
     $user_id = Auth::User()->id;
     $auction_id = $id;
     if ($this->auction->highest_bid < $request['amount']) {
         $this->auction->updateHighestBid($request['amount'], $auction_id);
     }
     if (!$this->bid->hasAlreadyBid($user_id, $auction_id)) {
         Bid::create(['user_id' => $user_id, 'auction_id' => $auction_id, 'amount' => $request['amount']]);
     } else {
         $bid = Bid::where(['user_id' => $user_id, 'auction_id' => $auction_id])->first();
         $bid->amount = $request['amount'];
         $bid->save();
     }
     return redirect('/auctions/' . $id);
 }
Example #15
0
 protected function auctionDeleted($id)
 {
     $auction = Auction::find($id);
     $bids = Bid::where('auction_id', $id)->get();
     $watches = Watchlist::where('auction_id', $id)->get();
     $recipients = [];
     foreach ($bids as $bid) {
         if (!in_array($bid->bidder_id, $recipients)) {
             $recipients[] = $bid->bidder_id;
         }
     }
     foreach ($watches as $watch) {
         if (!in_array($watch->user_id, $recipients)) {
             $recipients[] = $watch->user_id;
         }
     }
     foreach ($recipients as $recipient) {
         $message = ['title' => 'Auction for ' . $auction->title . ' closed.', 'message' => 'We regret to inform you that the owner of ' . $auction->title . ' has closed the auction. This means that the work will not be sold and that no further bidding will be possible.', 'opened' => null, 'archived' => 0, 'user_id' => $recipient, 'sender_id' => 1];
         self::create($message);
     }
 }
Example #16
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         $today = Carbon::today();
         //alle auctions ophalen die eindigen
         $arts = Art::where('ending', "<", $today)->where('sold', 0)->get();
         // alle bidders afgaan
         foreach ($arts as $art) {
             $bidder = bid::where('bid', $art->highest())->where('art_id', $art->id)->select('user_id', 'bid')->first();
             if (!$bidder) {
                 $art->sold_for = 0;
                 $art->sold_to = 0;
                 $input = new notification();
                 $input->user_id = $art->user_id;
                 $input->notification = $bidder->title . " hasn't been sold before closing.";
                 $input->save();
             } else {
                 $art->sold_for = $bidder->bid;
                 $art->sold_to = $bidder->user_id;
                 $this->notification($art->id, $bidder->user_id);
                 //melding sturen naar alle bieders/geintresseerde die het niet verkregen
                 $input = new notification();
                 $input->user_id = $bidder->user_id;
                 $input->notification = $art->title . " is yours for " . $bidder->bid . " euro";
                 //
                 $input->save();
             }
             $art->sold = 1;
             Bid::where('art_id', $art->id)->delete();
             watchlist::where('art_id', $art->id)->delete();
             $art->save();
         }
         Mail::send('email.test', ['name' => 'jonas'], function ($message) {
             $message->to('*****@*****.**', 'test')->subject('welcome!');
         });
     })->dailyAt('00:01');
 }
Example #17
0
 public function auctionBought($id)
 {
     $bids = Bid::where('auction_id', '=', $id)->whereHas('auction', function ($q) {
         $q->where('active', '=', true);
     })->get();
     foreach ($bids as $bid) {
         $user = $bid->user;
         Mail::send('mails.buynow', ['user' => $user], function ($ms) use($user) {
             $ms->to($user['email'], $user['name'])->subject('Shame!');
         });
     }
     $auction = Auction::where('id', '=', $id)->first();
     $auction->active = false;
     $auction->sold = true;
     $auction->save();
 }
Example #18
0
 public function editBid()
 {
     if (\Request::ajax()) {
         $bid = Bid::where('project_id', '=', Input::get('project_id'))->where('user_id', '=', Input::get('user_id'));
         $new_bid_data = array("amount" => Input::get('offer'), "days" => Input::get('days'), "description" => Input::get('description'), "hours" => Input::get('hours'), "amount_per_hour" => Input::get('hoursmoney'));
         $bid->update($new_bid_data);
         echo json_encode(array("amount" => Input::get('offer'), "days" => Input::get('days'), "description" => Input::get('description'), "hours" => Input::get('hours'), "amount_per_hour" => Input::get('hoursmoney')));
     }
 }
Example #19
0
 public static function getHighestBidWithId($id = -1)
 {
     return Bid::with('user')->where('auction_id', $id)->orderBy('price')->first();
 }
Example #20
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Bid::destroy($id);
     Session::flash('flash_message', 'Bid successfully deleted!');
     return redirect('bid');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function bid(Request $request)
 {
     $this->validate($request, ['id' => 'required', 'bid' => 'required']);
     $data = $request->all();
     $bid = new App\Bid();
     $bid->user_id = Auth::user()->id;
     $bid->auction_id = $data['id'];
     $bid->price = $data['bid'];
     $bid->save();
     $locale = App::getLocale();
     $highestbid = App\Bid::where('auction_id', $bid->auction_id)->orderBy('price', 'DESC')->first();
     $auction = Auction::where('id', $bid->auction_id)->first();
     if ($highestbid->price > $auction->current_price) {
         $auction->current_price = $highestbid->price;
         $auction->save();
     }
     $bids = Auction::join('bids', 'bids.auction_id', '=', 'auctions.id')->where('bids.user_id', Auth::User()->id)->translatedIn($locale)->get();
     $newest = Auction::translatedIn($locale)->where('end_date', '>=', Carbon::now())->orderBy('created_at', 'DESC')->first();
     return view('my_bids.index', array('auctions' => $bids, 'newest' => $newest));
 }
Example #22
0
 protected function getHighestBid($auction_id)
 {
     $bid = Bid::where('auction_id', $auction_id)->orderBy('bid', 'DESC')->first();
     if ($bid != null) {
         return $bid->bid;
     }
 }
 public function postBid($property_id, Request $request)
 {
     $user = $request->user();
     //echo $request->bid_amount;
     //exit();
     $bid = new Bid();
     $bid->user_id = $user->id;
     $bid->property_id = $property_id;
     $bid->bid_amount = $request->bid_amount;
     $bid->save();
     return redirect('properties/bid/' . $property_id);
 }
Example #24
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     echo '<pre>';
     $bid = Bid::with('sold', 'bought', 'seller', 'buyer')->findOrFail($id)->toArray();
     print_r($bid);
 }
Example #25
0
 public function buyNow($art_id)
 {
     $art = Art::where('id', $art_id)->where('sold', 0)->firstOrFail();
     $art->sold = 1;
     $art->sold_for = $art->price;
     $art->sold_to = Auth::user()->id;
     $art->save();
     $this->notification($art->id, Auth::user()->id);
     Bid::where('art_id', $art_id)->delete();
     watchlist::where('art_id', $art_id)->delete();
     return redirect()->route('/')->withSuccess(trans('succes.bought'));
 }
 public function mybids()
 {
     $page = 'My Bids';
     $bid_watchlists = Bid::where('user_id', '=', Auth::user()->User->id)->get();
     return view('my_watchlist_bids', compact('bid_watchlists', 'page'));
 }
Example #27
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $bid = Bid::findOrFail($id);
     $bid->delete();
     return response()->json(Response::HTTP_NO_CONTENT);
 }
 public function detail($art_id)
 {
     $art = Auction::where('id', '=', $art_id)->first();
     if ($art->active == false || $art->end_date < Carbon::now()) {
         return Redirect::route('arts');
     } else {
         $auctions = Auction::where('artist', 'like', '%' . $art->artist . '%')->orWhere('year', '=', $art->year)->orWhere('title', 'like', '%' . $art->title . '%')->orderBy('end_date', 'asc')->get();
         $bids = Bid::where('auction_id', '=', $art_id)->count();
         return view('product_detail', compact('auctions', 'art', 'bids'));
     }
 }
 public function getProblem($id)
 {
     //        //
     //        $auction = Auction::find($id);
     //        ///get All Seller
     //        $sellers = $auction->bidders->unique();
     //        //Seller1 Bid
     //        $sellersBids = [];
     //        foreach ($sellers as $seller) {
     //            $bids = Bid::where(['auction_id' => $auction->id, 'seller_id' => $seller->id])->get();
     //            $bidsWithProduct = [];
     //            foreach ($bids as $bid) {
     //                $bidsWithProduct[$bid->id] = $bid;
     //                $bid->products;
     //            }
     //            $sellersBids[$seller->id] = $bidsWithProduct;
     //            //d
     //        }
     //        return response()->json(array($sellersBids));
     $auction = Auction::find($id);
     $products_in_auctions = $auction->products;
     $problem = array();
     ///bids
     $bids = Bid::where(['auction_id' => $auction->id])->get();
     foreach ($bids as $bid) {
         $bid_data = array();
         $bid_data['provider_id'] = $bid->seller_id . "";
         $product_in_bid = $bid->products;
         $bundle = "";
         $size = $product_in_bid->count();
         for ($x = 0; $x < $size; $x++) {
             if ($x == $size - 1) {
                 $bundle = $bundle . "A" . ($product_in_bid[$x]->id - 1);
             } else {
                 $bundle = $bundle . "A" . ($product_in_bid[$x]->id - 1) . "+";
             }
         }
         $bid_data['bundle'] = $bundle;
         $bid_data['price'] = $bid->price . "";
         $bid_data['bid_id'] = $bid->id . "";
         array_push($problem, $bid_data);
     }
     //[\"A0\",\"A1\",\"A2\",\"A3\",\"A4\"]
     $auction_bundle = "[";
     for ($x = 0; $x < $products_in_auctions->count(); $x++) {
         if ($x == $products_in_auctions->count() - 1) {
             $auction_bundle = $auction_bundle . "\"A" . ($products_in_auctions[$x]->id - 1) . "\"]";
         } else {
             $auction_bundle = $auction_bundle . "\"A" . ($products_in_auctions[$x]->id - 1) . "\",";
         }
     }
     $data = ['bundle' => $auction_bundle];
     array_push($problem, $data);
     return json_encode($problem);
 }
 public function scopeCount($id)
 {
     $bidCount = Bid::where('auction_id', $id)->get();
     return count($bidCount);
 }