Harmonized getPayoutPerUserDetails with Quota::getPayoutList
This commit is contained in:
parent
def862bc13
commit
07283421e5
2 changed files with 29 additions and 150 deletions
|
|
@ -165,7 +165,7 @@ class SeasonsController extends Controller
|
|||
|
||||
|
||||
// Create and save the season
|
||||
Quota::setQuota('runden', request('round_count'));
|
||||
Quota::setQuota('runden', request('round_count'));
|
||||
Quota::setQuota('einsatz', request('einsatz'));
|
||||
Quota::setQuota('tagessieg', str_replace(",",".",request('tagessieg')));
|
||||
Quota::setQuota('gshirt', str_replace(",",".",request('gshirt')));
|
||||
|
|
|
|||
|
|
@ -336,29 +336,32 @@ class Quota extends Model
|
|||
$round_ids = $response['round_ids'];
|
||||
$user_ids = $response['user_ids'];
|
||||
|
||||
foreach($user_ids as $userId) {
|
||||
$payoutList[$userId]=array();
|
||||
}
|
||||
|
||||
$payouts = array();
|
||||
$cnt=0;
|
||||
foreach($round_ids as $round_id) {
|
||||
foreach($round_ids as $roundId) {
|
||||
|
||||
foreach($user_ids as $userId) {
|
||||
$key = $round_id . "_" . $userId;
|
||||
$key = $roundId . "_" . $userId;
|
||||
$payout = $roundtipps[$key]['payout'];
|
||||
$payoutList[$userId]=array(); // Wird unten fuer ManualPayout+GreenShirt benötigt. Eine PayoutListe für jeden User
|
||||
|
||||
if (strlen($payout) > 0) {
|
||||
$round = Round::where('id', '=', $round_id)->first();
|
||||
$round = Round::where('id', '=', $roundId)->first();
|
||||
|
||||
$item = array();
|
||||
$item['roundname'] = $round->name . " (Tagessieg)";
|
||||
$item['payout'] = $payout;
|
||||
array_push($payouts, $item);
|
||||
$item['payout'] = str_replace(",",".",$payout);
|
||||
array_push($payoutList[$userId], $item);
|
||||
}
|
||||
|
||||
if ($roundtipps[$key]['ranking_payout'] > 0) {
|
||||
$item = array();
|
||||
$item['roundname'] = "Platzierungssieg Rang " . $roundtipps[$key]['rank'];
|
||||
$item['payout'] = $roundtipps[$key]['ranking_payout'];
|
||||
array_push($payouts, $item);
|
||||
$item['payout'] = str_replace(",",".",$roundtipps[$key]['ranking_payout']);
|
||||
array_push($payoutList[$userId], $item);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -410,161 +413,37 @@ class Quota extends Model
|
|||
|
||||
|
||||
public static function getPayoutPerUserDetails($userId, $response=null) {
|
||||
if (!$response) {
|
||||
$response = Tipp::getRoundTipps();
|
||||
}
|
||||
$roundtipps = $response['roundtipps'];
|
||||
$round_ids = $response['round_ids'];
|
||||
$user_ids = $response['user_ids'];
|
||||
|
||||
$payouts = array();
|
||||
$cnt=0;
|
||||
foreach($round_ids as $round_id) {
|
||||
|
||||
$key=$round_id."_".$userId;
|
||||
$payout = $roundtipps[$key]['payout'];
|
||||
|
||||
if (strlen( $payout )>0) {
|
||||
$round = Round::where('id','=',$round_id)->first();
|
||||
|
||||
$item=array();
|
||||
$item['roundname']=$round->name . " (Tagessieg)";
|
||||
$item['payout'] =$payout;
|
||||
array_push($payouts,$item);
|
||||
}
|
||||
|
||||
if ($roundtipps[$key]['ranking_payout']>0) {
|
||||
$item=array();
|
||||
$item['roundname']="Platzierungssieg Rang ".$roundtipps[$key]['rank'];
|
||||
$item['payout']=$roundtipps[$key]['ranking_payout'];
|
||||
array_push($payouts,$item);
|
||||
}
|
||||
}
|
||||
|
||||
// Gshirt START
|
||||
if (Season::hasGreenShirtGame() ) {
|
||||
$gshirtTotalPayout = Quota::getPayouts()['gshirt'];
|
||||
$leaderCount = 0;
|
||||
$leaderIds = array();
|
||||
foreach ($user_ids as $uid) {
|
||||
|
||||
$key = Round::getLastRoundId() . "_" . $uid; // $key could be nonexistenen if we are not in the last round
|
||||
if (!array_key_exists($key, $roundtipps)) continue;
|
||||
if ($roundtipps[$key]['gshirt_leader'] == 1) {
|
||||
$leaderCount += 1;
|
||||
array_push($leaderIds,$uid);
|
||||
}
|
||||
}
|
||||
|
||||
if ($leaderCount) {
|
||||
$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 => $uId) {
|
||||
if ($uId != $userId) continue;
|
||||
$item = array();
|
||||
$item['roundname']=$names[$quota];
|
||||
$item['payout']=$_payouts[$quota];
|
||||
array_push($payouts,$item);
|
||||
}
|
||||
|
||||
return $payouts;
|
||||
$allPayouts = Quota::getPayoutList($response);
|
||||
return $allPayouts[$userId];
|
||||
}
|
||||
|
||||
public static function getPayoutPerUser($seasonId=-1)
|
||||
{
|
||||
Log::info("starting payout per user");
|
||||
$season = Season::get($seasonId);
|
||||
$payoutList = Quota::getPayoutList();
|
||||
$usernames = User::getNames();
|
||||
|
||||
$response = Tipp::getRoundTipps();
|
||||
$roundtipps = $response['roundtipps'];
|
||||
$user_ids = $response['user_ids'];
|
||||
$round_ids = $response['round_ids'];
|
||||
|
||||
$payoutTotal = array();
|
||||
$cnt = 0;
|
||||
|
||||
foreach ($round_ids as $round_id) {
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
|
||||
$payout = str_replace(",", ".", $roundtipps[$key]['payout']);
|
||||
if (strlen($payout) == 0) {
|
||||
$payout = 0;
|
||||
}
|
||||
|
||||
if (!array_key_exists($user_id, $payoutTotal)) {
|
||||
$payoutTotal[$user_id]['amount'] = 0;
|
||||
$payoutTotal[$user_id]['name'] = $roundtipps[$key]['user_name'];
|
||||
$payoutTotal[$user_id]['user_id'] = $roundtipps[$key]['user_id'];
|
||||
}
|
||||
|
||||
$payoutTotal[$user_id]['amount'] += $payout;
|
||||
|
||||
$payout_ranking = $roundtipps[$key]['ranking_payout'];
|
||||
$payoutTotal[$user_id]['amount'] += $payout_ranking;
|
||||
// Details pro UserId addieren
|
||||
$payoutPerUser=array();
|
||||
foreach ( $payoutList as $userId => $payoutItems) {
|
||||
$payoutPerUser[$userId]=0;
|
||||
foreach ($payoutItems as $payoutItem) {
|
||||
$payoutPerUser[$userId] += $payoutItem['payout'];
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
$winners = ManualPayout::getWinners();
|
||||
Log::info("Winners content:");
|
||||
|
||||
foreach ($winners as $quota => $userId) {
|
||||
Log::Info("Manual Payout: quota=".$quota.", Amount=".$payouts[$quota].", userId=".$userId);
|
||||
if ($userId) $payoutTotal[$userId]['amount'] += $payouts[$quota];
|
||||
}
|
||||
|
||||
// Nach Payout-Betrag absteigend sortieren
|
||||
$sortedPayout = array();
|
||||
foreach ($payoutTotal as $payout) {
|
||||
foreach ($payoutPerUser as $userId => $amount) {
|
||||
$payment = array();
|
||||
$payment['user_id'] = $payout['user_id'];
|
||||
$payment['name'] = $payout['name'];
|
||||
$payment['amount'] = $payout['amount'];
|
||||
$payment['user_id'] = $userId;
|
||||
$payment['name'] = $usernames[$userId];
|
||||
$payment['amount'] = $amount;
|
||||
array_push($sortedPayout, $payment);
|
||||
}
|
||||
|
||||
usort($sortedPayout,array('App\Quota','cmpPayment'));
|
||||
|
||||
return $sortedPayout;
|
||||
|
||||
}
|
||||
|
||||
public static function cmpPayment($payment1, $payment2) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue