public function dashboard() { $steam_accounts = SteamAccount::with('rank')->get(); $digits = Digit::get(); $ranks = Rank::get(); return view('mod.index', compact('steam_accounts', 'digits', 'ranks')); }
public function destroy($id, User $user) { $rank = Rank::find($id); $log = new Log(); $log->user_id = $user->id; $log->log = "删除等级" . print_r($rank->toArray(), true); $log->save(); Rank::destroy($id); return redirect()->action('RankController@index'); }
/** * Store a new volunteer. * Responds to requests to POST /volunteers * * @param \App\Http\Requests\CreateVolunteerRequest $request * @return Response */ public function store(CreateVolunteerRequest $request) { $randomString = Str::random(); $volunteer = Volunteer::create(['name' => $request->get('name'), 'email' => $request->get('email'), 'password' => $randomString, 'gender' => $request->get('gender'), 'date_of_birth' => $request->get('date_of_birth'), 'contact_no' => $request->get('contact_no'), 'occupation' => $request->get('occupation'), 'has_car' => $request->get('car'), 'area_of_preference_1' => $request->get('area_of_preference_1'), 'area_of_preference_2' => $request->get('area_of_preference_2'), 'is_approved' => 'approved', 'rank_id' => Rank::lowest()->first()->rank_id]); $email = $volunteer->email; Mail::send('emails.welcome_volunteer', compact('volunteer', 'randomString'), function ($message) use($email) { $message->subject('Your CareGuide Volunteer account has been registered.'); $message->bcc($email); }); return redirect('volunteers')->with('success', 'Volunteers is added successfully!'); }
/** * Execute the console command. * * @return mixed */ public function handle() { $liendivision = $this->argument('liendivision'); $id = $this->argument('id'); $classements = xml_result_equ('classement', $liendivision); $i = 1; foreach ($classements as $classement) { $rank = Rank::where('team_id', $id)->where('equipe', $classement->equipe)->first(); if ($rank == null) { $rank = new Rank(); } $rank->team_id = $id; $rank->clt = $classement->clt; $rank->clt_h = $i; $rank->equipe = $classement->equipe; $rank->joue = $classement->joue; $rank->pts = $classement->pts; $rank->save(); $i++; } }
/** * Update an rank. * Responds to requests to PATCH /rank * * @param \App\Http\Requests\RankRequest $request * @return Response */ public function update(RankRequest $request) { $currentRank1 = Rank::where('rank', 1)->first(); $currentRank2 = Rank::where('rank', 2)->first(); $currentRank3 = Rank::where('rank', 3)->first(); $currentRank4 = Rank::where('rank', 4)->first(); $currentRank1->update(['min' => $request->get('rank_1')]); $currentRank2->update(['min' => $request->get('rank_2'), 'max' => $request->get('rank_1') - 1]); $currentRank3->update(['min' => $request->get('rank_3'), 'max' => $request->get('rank_2') - 1]); $currentRank4->update(['max' => $request->get('rank_3') - 1]); return back()->with('success', 'Ranks are updated successfully!'); }
public function postRent(Request $request, $stopId, $bikeId) { if (OTPCheck::check(Stop::find($stopId)->code, $request->input('code'))) { $bike = Bike::find($bikeId); if ($stopId != $bike->stop_id) { return view('errors.error')->withTitle('借车失败')->withError('该车不在您选定的车站,请重试!'); } $stop = Stop::find($stopId); $rank = Rank::fromScore($this->user->score)->first(); // 检查车辆状态 if ($bike->state == 'rented') { return view('errors.error')->withTitle('借车失败')->withError('真不巧,这辆车已被其他童鞋抢先借出。'); } else { if ($bike->state != 'normal') { return view('errors.error')->withTitle('借车失败')->withError('对不起,这辆车已经报修,请重新选择车辆。'); } } // 本次借车与上次还车时间间隔应当在20分钟以上 $lastRent = $this->user->rent()->lastReturn()->first(); if ($lastRent) { $diffMinutes = $lastRent->created_at->diffInMinutes(Carbon::now()); if ($diffMinutes < 20) { return view('errors.error')->withTitle('借车失败')->withError('本次借车与上次还车时间间隔应在20分钟以上(含20分钟),您还需等待 ' . (20 - $diffMinutes) . ' 分钟'); } } // 记录Rent $rent = new Rent(); $rent->type = 'rent'; $rent->user_id = $this->user->id; $rent->max_time = Cache::get('special_time', false) ? $rank->max_time_special : $rank->max_time; $rent->bike_id = $bikeId; $rent->stop_id = $stopId; $rent->password = $bike->password; $rent->save(); // 更新user $this->user->state = 'rented'; $this->user->save(); // 更新bike $bike->state = 'rented'; $bike->stop_id = null; $bike->save(); // 成功 return view('rent.success')->withPassword($rent->password); } else { return view('errors.error')->withTitle('车站码错误')->withError('请输入正确的车站动态码。车站码位于车站站牌证明,轻按按钮即可显示。'); } }
/** * Execute the job. * * @return void */ public function handle() { $categoriesData = json_decode(file_get_contents("app/Jobs/categories.json")); DB::table('categories')->truncate(); DB::table('ranks')->truncate(); DB::table('places')->truncate(); foreach ($categoriesData as $categoryData) { if (!isset($categoryData->parents) || !$categoryData->parents) { continue; } if (!in_array("restaurants", $categoryData->parents)) { continue; } Category::create(['name' => $categoryData->title, 'code' => $categoryData->alias]); } $allCities = City::all(); foreach ($allCities as $city) { Log::info('City: ' . $city->name); $allCategories = Category::all(); foreach ($allCategories as $category) { $yelp = new Yelp(); Log::info('Category: ' . $category->code); $businesses = $yelp->best($category->code, $city->name . ', ' . $city->country); for ($i = 0; $i < count($businesses); $i++) { $business = $businesses[$i]; if (!isset($business->location->coordinate)) { continue; } Log::info('Business: ' . $business->name); $place = Place::where('name', '=', $business->name)->first(); if (!$place) { $place = Place::create(['name' => $business->name, 'image_url' => $this->getImageUrl($business), 'external_url' => $business->mobile_url, 'description' => $this->getDescription($business), 'rating' => $business->rating, 'latitude' => $business->location->coordinate->latitude, 'longitude' => $business->location->coordinate->longitude, 'address' => join(', ', $business->location->display_address), 'city_id' => $city->id]); } Rank::create(['category_id' => $category->id, 'place_id' => $place->id, 'rank' => $i + 1, 'city_id' => $city->id]); } sleep(1); } } }
/** * 个人信息 * * @return View */ public function profile() { if (empty($this->user->state)) { return redirect()->action('IndexController@redirect'); } // 查看个人信息 $response = view('index.profile')->with('user', $this->user); // 获取系统公告 /* Cache::forever('tip', [ 'type' => 'info', 'message' => '踏鸽行 2.0 正在研发中……', ]);*/ // 系统公告每个会话提示3次 $tipShown = session('tip_shown', 0); if ($tipShown < 3) { session(['tip_shown' => $tipShown + 1]); $response->with('tip', Cache::get('tip')); } // 随机昵称 $nick = ['童鞋', '小盆友', '小伙伴', '小公举']; if (in_array($this->user->state, ['normal', 'rented', 'disabled'])) { if ($this->user->gender == 'male') { $nick = array_merge($nick, ['小帅哥', '大哥哥', '汉纸']); } else { $nick = array_merge($nick, ['小公主', '大美女', '女神']); } if (preg_match('/(信息|计算机|软件)/', $this->user->department)) { $nick = array_merge($nick, ['程序猿', '工程狮']); if ($this->user->gender == 'male') { $nick = array_merge($nick, ['好男人']); } else { $nick = array_merge($nick, ['程序媛']); } } $response->withRank(Rank::fromScore($this->user->score)->first()); } switch ($this->user->state) { case 'normal': $rent = $this->user->rent()->lastRent()->first(); $return = $this->user->rent()->lastReturn()->first(); if ($return && $return->created_at->diffInMinutes() < 5) { $response->with('unlockPassword', $rent->password); $response->with('lockPassword', $return->password); } break; case 'rented': $rent = $this->user->rent()->lastRent()->first(); if ($rent->created_at->diffInMinutes() < 5) { // 借车5分钟内可以报告借车问题,直接重新借车 $response->withReport(true); } $returnTime = $rent->created_at->addHours($rent->max_time); $dateInterval = $returnTime->diff(Carbon::now()); $response->with('rent', $rent); $response->with('returnTime', $returnTime); $response->with('interval', $dateInterval); break; } return $response->with('nick', $nick[rand(0, count($nick) - 1)])->with('stops', Stop::with('bikes')->get()->sortBy(function ($stop) { return $stop->bikes->count(); }, null, true)); }
/** * Scope a query to only include ranks that needs the lowest min points. * * @param \Illuminate\Database\Eloquent\Builder $query the query to ranks to be scoped * @return \Illuminate\Database\Eloquent\Builder */ public function scopeLowest($query) { $query->where('min', '=', Rank::all()->min('min')); }
/** * Retrieves information for volunteer leaderboard. * * @param \Illuminate\Http\Request $request * @return JSON array with top 10 users and position */ public function volunteerLeaderboard(Request $request) { if ($request->get('token') != null) { $authenticatedUser = JWTAuth::setToken($request->get('token'))->authenticate(); $id = $authenticatedUser->volunteer_id; $volunteerEnquired = Volunteer::findOrFail($id); $volunteerName = $volunteerEnquired->name; // user rank $rankid = Volunteer::where('volunteer_id', $id)->value('rank_id'); $rank = Rank::findOrFail($rankid)->name; $totalMinutes = Volunteer::where('volunteer_id', $id)->value('minutes_volunteered'); $volunteerIdList = Volunteer::where('is_approved', 'approved')->orderBy('minutes_volunteered', 'desc')->lists('volunteer_id'); $count = 0; $xCount = 1; $pos = 0; $returnArray = []; $listSize = count($volunteerIdList) - 1; do { $volunteerID = $volunteerIdList[$count]; $volunteer = Volunteer::find($volunteerID); $volunteerName = $volunteer->name; $volunteerMinutes = $volunteer->minutes_volunteered; $stringToAdd = $volunteerMinutes . "," . $volunteerName . "," . $xCount; $returnArray[] = $stringToAdd; if ($id == $volunteerID) { $pos = $xCount; } $count = $count + 1; $xCount = $xCount + 1; } while ($count <= $listSize); return response()->json(compact('rank', 'totalMinutes', 'returnArray', 'pos')); } else { $status = ["Missing parameter"]; return response()->json(compact('status')); } }
/** * Deletes old player_totals table and reload everything from * scratches into it. * * @return string */ public function calculate() { \DB::table('player_totals')->truncate(); $aliases = Alias::with('players')->whereNotIn('name', DeletedPlayer::lists('player_name'))->get(); $totalServerScore = Player::sum('score'); foreach ($aliases as $alias) { $playerTotal = new PlayerTotal(); $playerTotal->name = $alias->name; $playerTotal->alias_id = $alias->id; $playerTotal->profile_id = $alias->profile_id; /*$playerTotal->last_loadout_id = $alias->profile->loadout_id;*/ $playerTotal->last_team = $alias->profile->team; //$playerTotal->first_game_id = $alias->profile->game_first; //$playerTotal->last_game_id = $alias->profile->game_last; $playerTotal->country_id = $alias->players->last()->country_id; $playersCollection = $alias->players; //Permanent Solution if ($alias->profile->loadout->kyaKhali()) { foreach ($playersCollection->reverse() as $item) { if (!$item->loadout->kyaKhali()) { $playerTotal->last_loadout_id = $item->loadout_id; break; } else { $playerTotal->last_loadout_id = $item->loadout_id; } } } else { $playerTotal->last_loadout_id = $alias->profile->loadout_id; } $playerTotal->first_game_id = $playersCollection->min('game_id'); $playerTotal->last_game_id = $playersCollection->max('game_id'); $playerTotal->is_admin = $playersCollection->max('is_admin'); $playerTotal->total_score = $playersCollection->sum('score'); $playerTotal->highest_score = $playersCollection->max('score'); $playerTotal->total_time_played = $playersCollection->sum('time_played'); $playerTotal->total_kills = $playersCollection->sum('kills'); $playerTotal->total_team_kills = $playersCollection->sum('team_kills'); $playerTotal->total_deaths = $playersCollection->sum('deaths'); $playerTotal->total_suicides = $playersCollection->sum('suicides'); $playerTotal->total_arrests = $playersCollection->sum('arrests'); $playerTotal->total_arrested = $playersCollection->sum('arrested'); $playerTotal->best_killstreak = $playersCollection->max('kill_streak'); $playerTotal->best_deathstreak = $playersCollection->max('death_streak'); $playerTotal->best_arreststreak = $playersCollection->max('arrest_streak'); $playerTotal->total_round_played = $playersCollection->unique('game_id')->count('game_id'); $playerTotal->last_ip_address = $alias->ip_address; $playerTotal->killdeath_ratio = $playerTotal->total_deaths == 0 ? $playerTotal->total_kills : round($playerTotal->total_kills / $playerTotal->total_deaths, 2); $playerTotal->arr_ratio = $playerTotal->total_arrested == 0 ? $playerTotal->total_arrests : round($playerTotal->total_arrests / $playerTotal->total_arrested, 2); $playerTotal->score_per_min = $playerTotal->total_time_played == 0 ? $playerTotal->total_score : round($playerTotal->total_score / $playerTotal->total_time_played * 60, 2); $playerTotal->score_percentile = $playerTotal->total_score == 0 || $totalServerScore == 0 ? 0 : round($playerTotal->total_score / $totalServerScore * 100, 2); $won = 0; $lost = 0; $draw = 0; foreach ($playersCollection->unique('game_id') as $player) { switch ($player->game->isWinner($player->team)) { case 0: $lost++; break; case 1: $won++; break; case -1: $draw++; break; default: break; } } $playerTotal->game_won = $won; $playerTotal->game_lost = $lost; $playerTotal->game_draw = $draw; $playerTotal->total_points = max($playerTotal->total_kills * 4 + $playerTotal->total_arrests * 13 - $playerTotal->total_deaths - $playerTotal->total_arrested * 3 - $playerTotal->total_team_kills * 2, 0); /** * This give extra points to the player from PlayerPoints Model */ $playerPoints = PlayerPoint::where('name', $playerTotal->name)->get(); if (!$playerPoints->isEmpty()) { $pointsToGive = $playerPoints->sum('points'); $playerTotal->total_points += $pointsToGive; } /** * Calculation of player_rating * * Calculate only if player with this alias has played more than 10 hours in server * and also is active and seen in last 7 days */ $last_seen_game = Game::find($playerTotal->last_game_id); if ($playerTotal->total_time_played > 60 * 60 * 10 && \Carbon\Carbon::now()->timestamp - $last_seen_game->updated_at->timestamp <= 60 * 60 * 24 * 7) { $playerTotal->player_rating = max($playerTotal->killdeath_ratio + $playerTotal->arr_ratio + $playerTotal->score_per_min * 1.25, 0); $playerTotal->player_rating = min($playerTotal->player_rating, 10); } /** * Calculation of rank_id using total_points and Rank table * * Add this if want time played(rank_seconds) also used to calculate ranks * ->where('rank_seconds', '<=' ,$playerTotal->total_time_played) * * Make sure that there are ranks in ranks table if not, * Run php artisan db:seed */ $playerTotal->rank_id = Rank::where('rank_points', '>=', $playerTotal->total_points)->orderBy('rank_points')->first()->id; $playerTotal->save(); } /** * Getting all PlayerTotal and updating its position one by one. */ $pTs = PlayerTotal::orderBy('player_rating', 'DESC')->orderBy('total_points', 'DESC')->orderBy('total_score', 'DESC')->get(); $position = 0; foreach ($pTs as $pT) { $pT->position = ++$position; $pT->save(); } // Put to Top Player so that some bugs are fixed. $topPlayers = PlayerTotal::with(['country', 'rank'])->orderBy('position')->limit(10)->get(); Cache::put('top_players', $topPlayers, 31); return "Players total has been logged into player_total table successfully!"; }
public function store(Request $request) { $this->validate($request, ['rank' => 'required|unique:ranks']); Rank::create($request->all()); return redirect(url('/dashboard')); }
public function getAlllogin() { if (!empty($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $login = Rank::select(['uid', 'alllogin'])->orderBy('alllogin', 'desc')->paginate(2); foreach ($login as &$v) { $aa = DB::table('user')->select(['email', 'remark', 'username'])->where("_id", "=", $v['uid'])->first(); $v['username'] = $aa['username']; $v['email'] = $aa['email']; $v['remark'] = $aa['remark']; $v['aa'] = $page * 2; } $login->setPath('alllogin'); return view('rank.alllogin', ['login' => $login]); }
/** * Handles the status updates through activity. If completed, compute points and add points to user. * * @param \Illuminate\Http\Request $request * @return JSON array with Status */ public function updateActivityStatus(Request $request) { if ($request->get('volunteer_id') == null || $request->get('activity_id') == null || $request->get('status') == null) { $status = ["Missing parameter"]; return response()->json(compact('status')); } else { $volunteer_id = $request->get('volunteer_id'); $activity_id = $request->get('activity_id'); $status = $request->get('status'); $task = Task::where('volunteer_id', $volunteer_id)->where('activity_id', $activity_id)->update(['status' => $status]); if ($status == "completed") { $activity = Activity::findOrFail($activity_id); $timeToAdd = $activity->expected_duration_minutes; $volunteer = Volunteer::findOrFail($volunteer_id); $currentTime = $volunteer->minutes_volunteered; $volunteer->minutes_volunteered = $timeToAdd + $currentTime; $newTime = floor($volunteer->minutes_volunteered / 60); if ($newTime > 0) { $newRank = Rank::where('min', '<', $newTime)->value('rank_id'); $volunteer->rank_id = $newRank; } $volunteer->save(); } $status = ["Update Successful"]; return response()->json(compact('status')); } }
return view('welcome'); }); Route::get('/push', function () { $devices = \App\Device::all(); foreach ($devices as $device) { \Davibennun\LaravelPushNotification\Facades\PushNotification::app('appNameIOS')->to($device->token)->send('Hello World, i`m a push message'); } echo 'pushed'; }); Route::get('/categories', function () { $categories = \App\Category::all(); return view('categories.index', compact('categories')); }); Route::get('/categories/{categoryId}', function ($categoryId) { $category = \App\Category::find($categoryId); $ranks = \App\Rank::where('category_id', '=', $categoryId)->with('place')->get(); $lat = 48.83213; $lon = 2.3218; $radius = 3; $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->orderby('distance', 'asc')->whereHas('ranks', function ($query) use($categoryId) { $query->where('category_id', '=', $categoryId); })->with('ranks', 'ranks.category')->get(); return view('categories.show', compact('category', 'places')); }); Route::get('/nearby', function () { // -27.49611, 153.00207 -> brisbane $lat = 48.842147; $lon = 2.321984; $radius = 3; $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->with('ranks', 'ranks.category')->get(); return view('places.index', compact('places'));