/**
  * 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');
             });
         }
     }
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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');
     });
 }
Ejemplo n.º 4
0
 public function checkWinner($code)
 {
     $currentUser = Auth::user();
     $currentCode = Keycode::where('code', '=', $code)->first();
     $winner = Winner::where('user_id', '=', $currentUser->id)->first();
     if (!$winner) {
         Winner::create(['user_id' => $currentUser->id, 'keycode_id' => $currentCode->id]);
         return true;
     } else {
         return false;
     }
 }
 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'));
 }
Ejemplo n.º 6
0
 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');
     }
 }
Ejemplo n.º 7
0
 public function showWinners($id)
 {
     $winners = Winner::where('event_id', '=', $id)->get();
     return view('admin.award.winners', compact('winners'));
 }