From 52aacdc76f59f3620b8a895ef58971ac6711128f Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 31 Jan 2018 09:12:56 +0100 Subject: [PATCH] GSHirt Payout Anzeige in Geldrangliste eingebaut --- pfosten/app/Quota.php | 99 ++++++++++++++++++++++++++++++++++--------- pfosten/app/Round.php | 7 ++- pfosten/app/Tipp.php | 3 +- 3 files changed, 87 insertions(+), 22 deletions(-) diff --git a/pfosten/app/Quota.php b/pfosten/app/Quota.php index 9a91c5e1..a304f986 100644 --- a/pfosten/app/Quota.php +++ b/pfosten/app/Quota.php @@ -9,6 +9,28 @@ use App\ManualPayout; class Quota extends Model { +/* + * "tagessieg" + "platz1" => + "platz2" => + "platz3" => + "platz4" => + "platz5" => + "platz6" => + "platz7" => + "platz8" => + "platz9" => + "platz10" = + "liga_platz + "liga_platz + "liga_platz + "liga_platz + "liga_platz + "gshirt" => + "pokal" => + */ + + public static function getPayouts() { $season_id = Season::getCurrent()->id; @@ -313,6 +335,7 @@ class Quota extends Model $response = Tipp::getRoundTipps(); $roundtipps = $response['roundtipps']; $round_ids = $response['round_ids']; + $user_ids = $response['user_ids']; $payouts = array(); $cnt=0; @@ -338,14 +361,46 @@ class Quota extends Model } } - // Manuelle Payouts hinzufügen + // Gshirt START + if (Season::hasGreenShirtGame() ) { + $gshirtTotalPayout = Quota::getPayouts()['gshirt']; + $leaderCount = 0; + $leaderIds = array(); + foreach ($user_ids as $uid) { + Log::info(Round::getLastRoundId()); + $key = Round::getLastRoundId() . "_" . $uid; + Log::info("ok"); + if ($roundtipps[$key]['gshirt_leader'] == 1) { + $leaderCount += 1; + array_push($leaderIds,$uid); + } + } + $payoutPerLeader = round($gshirtTotalPayout / $leaderCount, 2); + foreach($leaderIds as $leaderId) { + if ($userId == $leaderId) { + $item = array(); + $item['roundname']="Grünes Trikot"; + $item['payout']=$payoutPerLeader; + array_push($payouts,$item); + } + } + } + // GSHirt End + + + + // Manuelle Payouts hinzufügen + $names = ["pokal" => "Pokal", "liga_platz1"=>"Liga 1, Platz 1", + "liga_platz2"=>"Liga 1, Platz 2 ", "liga_platz3" => "Liga 1, Platz 3", + "liga_platz2_1" =>"Liga 2, Platz 1", "liga_platz3_1"=>"Liga 3, Platz 1" + ]; $_payouts = Quota::getPayouts(); $winners = ManualPayout::getWinners(); - foreach ($winners as $quota => $userId) { - if (!array_key_exists($quota, $_payouts)) continue; + foreach ($winners as $quota => $uId) { + if ($uId != $userId) continue; $item = array(); - $item['roundname']=$quota; + $item['roundname']=$names[$quota]; $item['payout']=$_payouts[$quota]; array_push($payouts,$item); } @@ -365,6 +420,7 @@ class Quota extends Model $payoutTotal = array(); $cnt = 0; + foreach ($round_ids as $round_id) { foreach ($user_ids as $user_id) { $key = $round_id . "_" . $user_id; @@ -387,7 +443,24 @@ class Quota extends Model } } - + // Gshirt START + if (Season::hasGreenShirtGame() ) { + $gshirtTotalPayout = Quota::getPayouts()['gshirt']; + $leaderCount = 0; + $leaderIds = array(); + foreach ($user_ids as $userId) { + $key = Round::getLastRoundId() . "_" . $userId; + if ($roundtipps[$key]['gshirt_leader'] == 1) { + $leaderCount += 1; + array_push($leaderIds,$userId); + } + } + $payoutPerLeader = round($gshirtTotalPayout / $leaderCount, 2); + foreach($leaderIds as $leaderId) { + $payoutTotal[$leaderId]['amount'] += $payoutPerLeader; + } + } + // GSHirt End // Manuelle Payouts hinzufügen $payouts = Quota::getPayouts(); @@ -395,16 +468,8 @@ class Quota extends Model Log::info("Winners content:"); foreach ($winners as $quota => $userId) { - Log::info($quota." => ".$userId); - - if (!array_key_exists($userId, $winners)) { - Log::info("Key not found: ".$quota); - continue; - } - - Log::Info("Manual Payout: quota=".$quota.", Amount=".$payout[$quota].", userId=".$userId); - - $payoutTotal[$userId]['amount'] += $payouts[$quota]; + Log::Info("Manual Payout: quota=".$quota.", Amount=".$payouts[$quota].", userId=".$userId); + if ($userId) $payoutTotal[$userId]['amount'] += $payouts[$quota]; } $sortedPayout = array(); @@ -416,10 +481,6 @@ class Quota extends Model array_push($sortedPayout, $payment); } - - - - usort($sortedPayout,array('App\Quota','cmpPayment')); return $sortedPayout; diff --git a/pfosten/app/Round.php b/pfosten/app/Round.php index 409c5307..6bb52718 100755 --- a/pfosten/app/Round.php +++ b/pfosten/app/Round.php @@ -220,8 +220,11 @@ class Round extends Model return $roundnames; } - public static function getLastRoundId($seasonId) { - $round = Round::where('season_id', '=', $seasonId)->orderBy('id','desc')->first(); // get last entry + public static function getLastRoundId($seasonId=-1) { + $season= Season::getCurrent(); + if ($seasonId!=-1) { $season = Season::where('id','=',$seasonId)->first(); } + + $round = Round::where('season_id', '=', $season->id)->orderBy('id','desc')->first(); // get last entry return $round->id; } diff --git a/pfosten/app/Tipp.php b/pfosten/app/Tipp.php index 0400b206..d3a42d7a 100755 --- a/pfosten/app/Tipp.php +++ b/pfosten/app/Tipp.php @@ -542,7 +542,8 @@ class Tipp extends Model } } - // C) Set gscore_leader + // C) Set gscore_leader for each round + foreach ($round_ids as $round_id) { foreach($user_ids as $user_id) { $key = $round_id . "_" . $user_id;