GSHirt Payout Anzeige in Geldrangliste eingebaut
This commit is contained in:
parent
3bdb32ae75
commit
52aacdc76f
3 changed files with 87 additions and 22 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue