Minor view and usability fixes, refactoring for Quota/Payout

This commit is contained in:
Torsten 2017-08-30 14:52:21 +02:00
parent 76947b1df9
commit b9e4fcca7f
12 changed files with 5736 additions and 139 deletions

View file

@ -240,7 +240,7 @@ class RoundmailController extends Controller
$r->send_date = Carbon\Carbon::now();
$r->recipients = implode(",", $emailsOfUsersWithIncompleteTipps);
$r->topic = "Fehlende Tipps/Joker";
$r->mail_message = "Es fehlen noch Tipps/Joker für: " . $firstTippableRound->name . "<br/>Die Runde sperrt sich: " . $roundLockTime . "<br/><br/>Link zum Spiel: " . Round::getTippSpielLink();
$r->mail_message = 'Es fehlen noch Tipps/Joker für: ' . $firstTippableRound->name . '<br/>Die Runde sperrt sich: ' . $roundLockTime . '<br/><br/>Link zum Spiel: <a href="' . Round::getTippSpielLink(). '">( Hier klicken )</a>';
Log::info("Sending Reminder Mails");
\Mail::to($emailsOfUsersWithIncompleteTipps)->send($r);

View file

@ -8,6 +8,7 @@ use App\Round;
use App\Game;
use App\User;
use App\Tipp;
use App\Quota;
use DB;
use Auth;
use Log;
@ -21,15 +22,15 @@ class RoundsController extends Controller
$activeSeason=Season::getCurrent();
$rounds =null;
//$rounds=Round::all();
if ($activeSeason) {
$activeSeasonId = Season::getCurrent()->id;
$rounds = Round::all()->where('season_id', '=', $activeSeasonId);
}
return view('rounds.index', compact('rounds','activeSeason'));
$quotas = Quota::getQuotas($activeSeason->id);
$round_count = $quotas['Runden'];
return view('rounds.index', compact('rounds','activeSeason', 'round_count'));
}

View file

@ -14,83 +14,26 @@ class SeasonsController extends Controller
public function index() {
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$seasons = DB::table('seasons')->get();
$currentSeason=Season::getCurrent();
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
$quotas = Quota::getQuotas($currentSeason->id);
if (!$quotas) { Quota::createDefaultQuota($currentSeason->id);}
if (!$quotas) {
Quota::createDefaultQuota($currentSeason->id);
$quotas = Quota::getQuotas($currentSeason->id);
}
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
$euro_pott = $active_user_count * $quotas["Einsatz"];
$euro_tagessieg_sum = intval ($euro_pott * ( $quotas["Tagessieg"] / 100 ) );
$euro_tagessieg = Quota::get6Divisor( intval($euro_tagessieg_sum / 36));
$euro_gruenes_trikot = intval($euro_pott * (($quotas["Gruenes Trikot"] / 100)));
$euro_gruenes_trikot = Quota::get6Divisor($euro_gruenes_trikot);
$euro_pokal= intval ($euro_pott * (($quotas["Pokal"] / 100)));
$euro_pokal= Quota::get6Divisor($euro_pokal);
$euro_platzierung = intval ( $euro_pott * (($quotas["Platzierung"] / 100)));
$tagessieg_rest = $euro_tagessieg_sum - ($euro_tagessieg * 36);
Log::info("Tagessieg Rest=".$tagessieg_rest." €");
$euro_platzierung += $tagessieg_rest;
$euro_platz1 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 1"] / 100))));
$euro_platz2 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 2"] / 100))));
$euro_platz3 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 3"] / 100))));
$euro_platz4 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 4"] / 100))));
$euro_platz5 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 5"] / 100))));
$euro_platz6 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 6"] / 100))));
$euro_platz7 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 7"] / 100))));
$euro_platz8 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 8"] / 100))));
$euro_platz9 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 9"] / 100))));
$euro_platz10= Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 10"] / 100))));
$euro_liga=intval($euro_pott *(($quotas["Liga-Wertung"] / 100)));
$euro_liga_platz1 = Quota::get6Divisor(intval($euro_liga*(($quotas["Liga Platz 1"] / 100))));
$euro_liga_platz2 = Quota::get6Divisor(intval($euro_liga*(($quotas["Liga Platz 2"] / 100))));
$euro_liga_platz3 = Quota::get6Divisor(intval($euro_liga*(($quotas["Liga Platz 3"] / 100))));
$finaler_rest = $euro_pott - ( 36*$euro_tagessieg + $euro_gruenes_trikot + $euro_pokal + $euro_platz1
+ $euro_platz2 + $euro_platz3+ $euro_platz4 + $euro_platz5 + $euro_platz6 + $euro_platz7 + $euro_platz8 + $euro_platz9 + $euro_platz10);
$euro_platz1 = $euro_platz1 + $finaler_rest;
Log::info("Users: ". $active_user_count);
Log::info("Einsatz: ". $quotas["Einsatz"]);
Log::info("Pott: ".$euro_pott." €");
Log::info("Tagessieg: ".$euro_tagessieg." €");
Log::info("Grünes Trikot: ".$euro_gruenes_trikot." €");
Log::info("Pokal: ".$euro_pokal." €");
$quotas = Quota::getQuotas($currentSeason->id);
$payouts = Quota::getPayouts($currentSeason->id);
Log::info("Liga: ".$euro_liga." €");
Log::info("Platzierung: ".$euro_platzierung." €");
Log::info("Platz 1: ".$euro_platz1." €");
Log::info("Platz 2: ".$euro_platz2." €");
Log::info("Platz 3: ".$euro_platz3." €");
Log::info("Platz 4: ".$euro_platz4." €");
Log::info("Platz 5: ".$euro_platz5." €");
Log::info("Platz 6: ".$euro_platz6." €");
Log::info("Platz 7: ".$euro_platz7." €");
Log::info("Platz 8: ".$euro_platz8." €");
Log::info("Platz 9: ".$euro_platz9." €");
Log::info("Platz 10: ".$euro_platz10." €");
Log::info("Finaler Rest: ".$finaler_rest." €");
return view('seasons.index', compact('seasons','currentSeason','quotas','active_user_count','euro_tagessieg','euro_platz1','euro_platz2','euro_platz3','euro_platz4','euro_platz5','euro_platz6','euro_platz7','euro_platz8','euro_platz9','euro_platz10'));
return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts'));
}
public function create() {
@ -133,6 +76,7 @@ class SeasonsController extends Controller
// Validate form
$this->validate(request(), [
'round_count' => 'required',
'season_id' => 'required',
'einsatz' => 'required',
'tagessieg' => 'required',
@ -158,6 +102,7 @@ class SeasonsController extends Controller
// Create and save the season
Quota::setQuota('Runden',request('round_count'), $currentSeason->id);
Quota::setQuota('Einsatz',request('einsatz'), $currentSeason->id);
Quota::setQuota('Tagessieg',request('tagessieg'), $currentSeason->id);
Quota::setQuota('Gruenes Trikot',request('gruenes_trikot'), $currentSeason->id);

View file

@ -187,6 +187,7 @@ class UsersController extends Controller
$max_round_id = Round::getLastLockedRoundId();
if ($max_round_id==-1) {
$sql="select DATE_FORMAT(date_sub(min(games.kickoff), interval 1 hour),'%d.%m.%Y %H:%i') as start_date from rounds,games where rounds.season_id=".$currentSeason->id." and games.round_id=rounds.id;";
dd($sql);
$date = DB::select($sql);
if (count($date)>0) {
@ -198,7 +199,13 @@ class UsersController extends Controller
}
}
// Payment made ?
if (! User::payment_date(Auth::user()->id, $currentSeason->id)) {
return view('users.no_payment');
}
// Hier werden _alle_ Tipps der aktuellen Saison ausgerechnet, die $round_id Begrenzung wird erst später ausgewertet.
// TODO: Nur die Runden durchrechnen, die aktuell sind, oder round_incomplete, alle anderen Runden (bis zur ersten unvollständigen) sollen in eine Cachetabelle gespeichert werden.
$sql = "select users.id as user_id, users.name as user_name, ";
$sql = $sql . "rounds.id as round_id, rounds.name as round_name, ";
$sql = $sql . "games.id as game_id, games.team1, games.team2, games.score1 as game_score1, games.score2 as game_score2, games.kickoff as game_kickoff, ";
@ -208,6 +215,7 @@ class UsersController extends Controller
$sql = $sql . "and games.round_id=rounds.id and tipps.game_id=games.id and users.id = tipps.user_id ";
$sql = $sql . "and payments.season_id=".$currentSeason->id." and payments.user_id = users.id ";
$sql = $sql . "and payments.paid_date is not null ";
$sql = $sql . "and users.deleted is null ";
$sql = $sql . "order by rounds.id, games.id, users.id;";
$result=DB::select($sql);
@ -260,14 +268,6 @@ class UsersController extends Controller
// NOW ALL KEYS FOR ROUNDTIPPS (ROUND & USER) EXIST
// CALCULATION OF SCORES, RANKS, ETC.
// FIRST LOOP: COMPUTE AGGREGATED VALUES
@ -333,14 +333,21 @@ class UsersController extends Controller
// If more than 6 DayScoreWinners: Restrict by dayscore (rank)
// Compute highest dayscore
// Addition: no dayscorewinner && round_completed: Payout goes to next round
$payouts = Quota::getPayouts($currentSeason->id);
$totalDayWinPayout = 0;
foreach ($round_ids as $round_id) {
$totalDayWinPayout += $payouts["tagessieg"];
$highestDayScore = $highestDayscores[$round_id];
$usersWithHighestDayScore = array();
$round_completed=false;
foreach ($user_ids as $user_id) {
$round_completed = $roundtipps[$key]['round_completed']; // TODO: Separaten info array roundData erzeugen, der Rundenspezifische, SPielerübergreifende Infos enthält, so wie round_completed.
$key = $round_id . "_" . $user_id;
if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed']) {
if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed'] && $highestDayScore>0 ) {
array_push($usersWithHighestDayScore, [$user_id, $roundtipps[$key]['dayScoreWithRankScore']]);
}
}
@ -365,31 +372,36 @@ class UsersController extends Controller
}
// Compute Dayscorewin payout (Tagessieg)
$payouts = Quota::getPayouts($currentSeason->id);
$single_payout = 0;
$winnerCount = sizeof($dayScoreWinnersIds);
$single_payout=0;
if ($winnerCount > 0) {
$single_payout = $payouts["Tagessieg"] / $winnerCount;
$single_payout = $totalDayWinPayout / $winnerCount;
$single_payout = number_format((float)$single_payout, 2, '.', '');
$single_payout = str_replace(".", ",", $single_payout);
$totalDayWinPayout=0;
}
foreach ($round_ids as $round_id) {
foreach ($user_ids as $user_id) {
$key = $round_id . "_" . $user_id;
if ($roundtipps[$key]['is_dayscorewinner']) {
foreach ($user_ids as $user_id) {
$key = $round_id . "_" . $user_id;
if ($roundtipps[$key]['is_dayscorewinner']) {
$roundtipps[$key]['payout'] = $single_payout;
$roundtipps[$key]['payout'] = $single_payout;
} else {
$roundtipps[$key]['payout'] = '';
}
} else {
$roundtipps[$key]['payout'] = '';
}
}
}
//////////////////// END OF ROUNDTIPPS CREATION ///////////////////
///////////////////////////// DISPLAY AUFBAU /////////////////////////////
///
@ -471,6 +483,7 @@ class UsersController extends Controller
$roundtipps[$key]["tipps"][6],$roundtipps[$key]["tipps"][7],
$roundtipps[$key]["joker"][3]);
}
$userids = array_keys($rankingDisplay);
@ -478,6 +491,7 @@ class UsersController extends Controller
$games=Game::where('round_id','=',$max_round_id)->get();
$all_rounds=Round::where('season_id','=',$currentSeason->id)->get();
// Sortieren nach Rankscore
$entries = array();
usort($rankingDisplay, array($this,"cmp"));
@ -491,6 +505,7 @@ class UsersController extends Controller
// von Rankingdisplay abgespeichert sind.
$game_results=array(); // 4 Spielergebnisse der angezeigten Runde
$a=$rankingDisplay[0];
array_push($game_results,$rankingDisplay[0]["result_score1"],$rankingDisplay[0]["result_score2"],$rankingDisplay[0]["result_score3"],$rankingDisplay[0]["result_score4"],$rankingDisplay[0]["result_score5"],$rankingDisplay[0]["result_score6"],$rankingDisplay[0]["result_score7"],$rankingDisplay[0]["result_score8"]);
return view('users.ranking', compact('all_rounds','rankingDisplay','userids','round','games','game_results'));
@ -515,12 +530,10 @@ class UsersController extends Controller
$currentSeason = Season::getCurrent();
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
$einsatz = Quota::getQuota($currentSeason->id,"Einsatz");
$quotas = Quota::getQuotas($currentSeason->id);
$payouts = Quota::getPayouts($currentSeason->id);
Log::info("EINSATZ=".$einsatz);
return view('users.show_payouts', compact('payouts','active_user_count','einsatz','currentSeason'));
return view('users.show_payouts', compact('payouts','active_user_count','quotas','currentSeason'));
}
public function mailtest() {