/** * 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('*****@*****.**'); }); } } } }
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; }
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); }
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; } }
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); }
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')); }
/** * 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); }
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); } }
/** * 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'); }
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 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 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'))); } }
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')); }
protected function getHighestBid($auction_id) { $bid = Bid::where('auction_id', $auction_id)->orderBy('bid', 'DESC')->first(); if ($bid != null) { return $bid->bid; } }
public static function getBiddersWithId($id = -1) { return Bid::where('auction_id', $id)->with('user')->get(); }
/** * 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)); }
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); }
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(); }