public function checkCode(Request $request)
 {
     $code = $request->input('code');
     $currentPeriod = $this->period->checkPeriod();
     $user = Auth::User();
     $this->validate($request, ['code' => 'required|min:6|alpha_num|unique:keycodes,code,' . $code . ',id,used,1']);
     if ($this->user->checkIfParticipated($user)) {
         $this->user->hasParticipated($user);
         if ($this->validateCode->checkIfCodeIsValid($code)) {
             $result = $this->validateCode->checkIfCodeIsValid($code);
             if ($this->winner->checkWinner($code)) {
                 $this->validateCode->changeStateOfCode($result);
                 Mail::send('mails.winner', ['user' => $user], function ($ms) use($user) {
                     $ms->to($user->email, $user->name)->subject('U hebt gewonnen!');
                 });
                 $alreadyplayed = false;
                 $win = true;
                 return view('code/result', compact('win', 'alreadyplayed', 'currentPeriod'));
             }
         } else {
             $win = false;
             $alreadyplayed = false;
             return view('code/result', compact('win', 'alreadyplayed'));
         }
     } else {
         $win = false;
         $alreadyplayed = true;
         return view('code/result', compact('win', 'alreadyplayed'));
     }
 }
 public function index()
 {
     $winners = $this->winner->getWinnersOfPreviousPeriods();
     $currentPeriod = $this->period->checkPeriod();
     $periods = $this->period->all();
     return view('index', compact('winners', 'currentPeriod', 'periods'));
 }
 /** CODE VALIDATIE **/
 public function store(Request $request)
 {
     $winners = DB::table('winners')->get();
     if (Auth::check()) {
         /* Code opslagen voor controle bij admin */
         $code = new Code();
         $code->code = Input::get('code');
         $code->FK_user_id = Auth::user()->id;
         $code->save();
         $validCodes = DB::table('validCodes')->get();
         foreach ($validCodes as $validCode) {
             if (Hash::check(Input::get('code'), $validCode->validCode)) {
                 /*het is een valid code */
                 if ($validCode->FK_user_id == 0) {
                     /* het is een valid code die nog niet is ingevoerd */
                     /*                     $validCodeid = $validCode->id;
                                          $validCode = Validcode::find($validCodeid);*/
                     $lotteryImg = '';
                     // variabele meesturen om javascript te laten runnen
                     /* Kijken of het een winnende code is */
                     if ($validCode->winning1_losing0 == 0) {
                         $lotteryImg = 'lose';
                     }
                     if ($validCode->winning1_losing0 == 1) {
                         $lotteryImg = 'win';
                         $winner = new Winner();
                         $winner->winningMonth = Carbon::now()->month;
                         $winner->FK_user_id = Auth::user()->id;
                         $winner->name = Auth::user()->name;
                         $winner->city = Auth::user()->city;
                         $winner->save();
                     }
                     //Code updaten
                     $specificValidCode = Validcode::find($validCode->id);
                     $specificValidCode->FK_user_id = Auth::user()->id;
                     $specificValidCode->save();
                     $jumpSectionA = '';
                     // variabele meesturen om javascript te laten runnen
                     return view('index')->with('lotteryImg', $lotteryImg)->with('jumpSectionA', $jumpSectionA)->with('winners', $winners);
                 } else {
                     /* het is een validcode die al is gebruikt */
                     $jumpSectionA = '';
                     // variabele meesturen om javascript te laten runnen
                     $usedcodeMessage = 'Deze code is al reeds gebruikt !';
                     return view('index')->with('usedcodeMessage', $usedcodeMessage)->with('jumpSectionA', $jumpSectionA)->with('winners', $winners);
                 }
             }
         }
         /* Alle codes zijn gecheckt dus het is geen valid code */
         $wrongcodeMessage = 'Dit is geen juiste code!';
         $jumpSectionA = '';
         // variabele meesturen om javascript te laten runnen
         return view('index')->with('wrongcodeMessage', $wrongcodeMessage)->with('jumpSectionA', $jumpSectionA)->with('winners', $winners);
     } else {
         $message = 'Je moet inloggen of registreren om een code toe te voegen!';
         return view('index')->with('message', $message)->with('winners', $winners);
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get the time of now
     $time = Carbon::now()->toDateTimeString();
     $periods = Period::all();
     // Check if time is between start and end of a period
     foreach ($periods as $period) {
         if ($time >= $period->start && $time <= $period->end) {
             if (!$period->running) {
                 $period->running = 1;
                 $period->save();
             }
         } elseif ($period->running) {
             // Last period ends here + a mail of all the winners of that period is send to the admin
             $period->running = 0;
             $period->save();
             $winners = Winner::where('period', $period->id)->get();
             $data = ['title' => 'Winners of period ' . $period->id, 'content' => '', 'winners' => $winners];
             Mail::send('emails.winners', $data, function ($message) {
                 $message->to('*****@*****.**', 'Oscar');
                 $message->subject('Winners');
             });
         }
     }
 }
 public function getIndex()
 {
     $title = 'public';
     // get 8 most popular online rewards
     $rewards = Reward::orderBy('claimed', 'desc')->take(8)->get();
     // get last 5 winners
     $winners = Winner::orderBy('created_at', 'desc')->take(5)->get();
     // check if competition is running, has yet to start or has ended
     $time = Carbon::now()->toDateTimeString();
     $runningPeriod = Period::where('running', 1)->get();
     $firstPeriod = Period::orderBy('id', 'asc')->first();
     if (count($runningPeriod) == 1) {
         $competition['running'] = true;
         $competition['message'] = 'Enter your codes here to get your well-deserved points';
     } else {
         $competition['running'] = false;
         if ($time < $firstPeriod->start) {
             $competition['message'] = 'The competition has yet to start';
         } else {
             $competition['message'] = 'The competition has ended';
         }
     }
     // if logged in go to dashboard
     if (Auth::check()) {
         $user = Auth::user();
         $username = $user->name;
         $userPoints = $user->points;
         $title = 'Dashboard';
         $rewards = Reward::all();
         return view('dashboard.home', compact('competition', 'title', 'username', 'rewards', 'userPoints'));
     }
     return view('public.home', compact('competition', 'title', 'rewards', 'winners'));
 }
Beispiel #6
0
 public function start(Request $request)
 {
     if ($request->ajax()) {
         //get ip and store info
         $winner = Winner::where('user_id', '=', $request->ip())->first();
         if (!empty($winner)) {
             $result = ['msg' => '您已经抢过了,不能再抢了哦~', 'cdkey' => $winner->cdkey, 'status' => '2'];
         } else {
             $join = Join::create(['ip' => $request->ip()]);
             //get kucun
             if ($join->id) {
                 $award = Award::find($request->input('event_id'));
                 $result = ['msg' => '恭喜!您抢到了', 'cdkey' => $request->input('event_id'), 'status' => '1'];
                 if ($award->surplus <= 0) {
                     $result = ['msg' => '很遗憾,被抢光了!', 'status' => '0'];
                 } else {
                     //库存-1
                     $award->surplus = $award->surplus - 1;
                     $award->save();
                     //生成cdkey
                     $cdkey = $this->generateCdkey(5);
                     //
                     //保存中奖用户
                     $winner = Winner::create(['user_id' => $request->ip(), 'award_id' => $request->input('award_id'), 'cdkey' => $cdkey, 'event_id' => $request->input('event_id')]);
                     $result = ['msg' => '恭喜!您抢到了', 'cdkey' => $cdkey, 'status' => '1'];
                 }
             }
         }
     }
     return response()->json($result);
 }
Beispiel #7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $period = Competition::find(1)->current_period;
     $winners = Winner::where('period', $period)->get();
     $data = ['title' => 'Winners of period' . $period, 'content' => '', 'winners' => $winners];
     Mail::send('emails.welcome', $data, function ($message) {
         $message->to('*****@*****.**', 'Oscar');
         $message->subject('hello world');
     });
 }
Beispiel #8
0
 public function getWinnersOfPreviousPeriods()
 {
     $winners = Winner::all();
     $data = collect();
     foreach ($winners as $winner) {
         $user = Winner::find($winner->id)->user->name;
         $period = Winner::find($winner->id)->keycode->period_id;
         $data->push(['name' => $user, 'period' => $period]);
     }
     return $data->toArray();
 }
 public function users()
 {
     if (Auth::check()) {
         $users = User::all();
         $softDeletedUsers = User::onlyTrashed()->get();
         $winners = Winner::all();
         return view('admin/users', compact('users', 'softDeletedUsers', 'winners'));
     } else {
         return view('errors/404');
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // \Log::info('I was here @' . Carbon::now() );
     $thisDate = Date::where('endDate', '<', Carbon::now())->orderby('endDate', 'DESC')->first();
     $competitors = Competitor::where('created_at', '>', $thisDate->startDate)->where('created_at', '<', $thisDate->endDate)->where('is_deleted', '=', false)->get();
     if (!count($thisDate->winner) && count($competitors)) {
         // var_dump($competitors);
         $winner = $competitors->first();
         foreach ($competitors as $competitor) {
             var_dump($competitor->getTotalVotes());
             echo '</br>';
             if ($competitor->getTotalVotes() > $winner->getTotalVotes()) {
                 $winner = $competitor;
             }
         }
         $newWinner = new Winner();
         $newWinner->competitor_id = $winner->id;
         $newWinner->date_id = $thisDate->id;
         $newWinner->save();
     }
 }
 public function home()
 {
     $winners = Winner::all();
     // var_dump(empty($winners));
     if ($winners->first()) {
         echo 'test';
     } else {
         echo 'leeg';
     }
     foreach ($winners as $winner) {
         // var_dump($winner);
     }
     // var_dump($winners);
     $data = array('winners' => $winners);
     return View('welcome')->with($data);
 }
 public function test()
 {
     $thisDate = Date::where('endDate', '<', Carbon::now())->orderby('endDate', 'DESC')->first();
     $competitors = Competitor::where('created_at', '>', $thisDate->startDate)->where('created_at', '<', $thisDate->endDate)->get();
     if (!count($thisDate->winner) && count($competitors)) {
         // var_dump($competitors);
         $winner = $competitors->first();
         foreach ($competitors as $competitor) {
             var_dump($competitor->getTotalVotes());
             echo '</br>';
             if ($competitor->getTotalVotes() > $winner->getTotalVotes()) {
                 $winner = $competitor;
             }
         }
         $newWinner = new Winner();
         $newWinner->competitor_id = $winner->id;
         $newWinner->date_id = $thisDate->id;
         $newWinner->save();
     }
     // $thisDate = Date::where('endDate', '<', Carbon::now())->orderby('endDate', 'DESC')->first();
     // var_dump($thisDate);
     // echo '</br>';
     // if (count($thisDate->winner))
     // {
     //     echo 'er is reeds een winnaar';
     // } else
     // {
     //     echo 'er is nog geen winnaar';
     // }
 }
 public function run()
 {
     DB::table('winners')->delete();
     Winner::create(['name' => 'fred', 'value' => '100', 'period' => 1, 'user_id' => 1]);
 }
 public function getWinners()
 {
     $user = Auth::user();
     $username = $user->name;
     $userPoints = $user->points;
     $title = 'Dashboard winners';
     // get all periods to see how many exist
     $periods = Period::all();
     // get all winners of every period
     foreach ($periods as $period) {
         $winners[] = Winner::where('period', $period->id)->get();
     }
     return view('dashboard.winner.all', compact('title', 'username', 'userPoints', 'winners', 'periods'));
 }
 public function getWinners()
 {
     if (Auth::user()->admin) {
         $title = 'admin winners';
         $periods = Period::all();
         // get all the winners for every period
         foreach ($periods as $period) {
             $winners[] = Winner::where('period', $period->id)->get();
         }
         return view('admin.winners', compact('title', 'periods', 'winners'));
     } else {
         return redirect('dashboard');
     }
 }
Beispiel #16
0
 public function winnerCash($winner_id)
 {
     $winner = Winner::find($winner_id);
     $winner->is_cash = 1;
     $winner->save();
     if ($winner->id) {
         flash()->success('操作成功');
     } else {
         flash()->error('操作失败');
     }
     return redirect()->back();
 }