2017-08-16 17:30:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Log;
|
|
|
|
|
use DB;
|
2018-01-23 10:56:18 +01:00
|
|
|
use App\ManualPayout;
|
2017-08-16 17:30:32 +02:00
|
|
|
|
|
|
|
|
class Quota extends Model
|
|
|
|
|
{
|
2018-01-31 09:12:56 +01:00
|
|
|
/*
|
|
|
|
|
* "tagessieg"
|
|
|
|
|
"platz1" =>
|
|
|
|
|
"platz2" =>
|
|
|
|
|
"platz3" =>
|
|
|
|
|
"platz4" =>
|
|
|
|
|
"platz5" =>
|
|
|
|
|
"platz6" =>
|
|
|
|
|
"platz7" =>
|
|
|
|
|
"platz8" =>
|
|
|
|
|
"platz9" =>
|
|
|
|
|
"platz10" =
|
|
|
|
|
"liga_platz
|
|
|
|
|
"liga_platz
|
|
|
|
|
"liga_platz
|
|
|
|
|
"liga_platz
|
|
|
|
|
"liga_platz
|
|
|
|
|
"gshirt" =>
|
|
|
|
|
"pokal" =>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
public static function getPayouts() {
|
|
|
|
|
$season_id = Season::getCurrent()->id;
|
|
|
|
|
|
|
|
|
|
$quotas = Quota::getQuotas();
|
|
|
|
|
|
|
|
|
|
$roundCount=Round::getCount();
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
//Quotas fuer Season wegwerfen falls vorhanden und default Wert reinschreiben
|
|
|
|
|
if (sizeof($quotas)==0) {
|
2017-11-10 15:32:54 +01:00
|
|
|
Quota::createDefaultQuota();
|
|
|
|
|
$quotas = Quota::getQuotas();
|
2017-08-19 16:53:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-03 09:03:39 +02:00
|
|
|
$active_user_count = sizeof(User::getActives());
|
2018-01-26 10:09:20 +01:00
|
|
|
$euro_pott = $active_user_count * $quotas["einsatz"];
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2018-01-26 10:09:20 +01:00
|
|
|
$euro_tagessieg_sum = intval ($euro_pott * ( $quotas["tagessieg"] / 100 ) );
|
2017-11-10 15:32:54 +01:00
|
|
|
|
|
|
|
|
$euro_tagessieg = Quota::get6Divisor( intval($euro_tagessieg_sum / $roundCount));
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2018-01-26 10:09:20 +01:00
|
|
|
$euro_gruenes_trikot = intval($euro_pott * (($quotas["gshirt"] / 100)));
|
2017-08-19 16:53:39 +02:00
|
|
|
$euro_gruenes_trikot = Quota::get6Divisor($euro_gruenes_trikot);
|
2018-01-25 08:31:59 +01:00
|
|
|
$euro_pokal= intval ($euro_pott * (($quotas["pokal"] / 100)));
|
2018-01-10 08:45:01 +01:00
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$euro_pokal= Quota::get6Divisor($euro_pokal);
|
|
|
|
|
|
2018-01-26 10:09:20 +01:00
|
|
|
$euro_platzierung = intval ( $euro_pott * (($quotas["platzierung"] / 100)));
|
2017-11-10 15:32:54 +01:00
|
|
|
$tagessieg_rest = $euro_tagessieg_sum - ($euro_tagessieg * $roundCount);
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2017-08-31 07:36:27 +02:00
|
|
|
//Log::info("Tagessieg Rest=".$tagessieg_rest." €");
|
2017-08-19 16:53:39 +02:00
|
|
|
$euro_platzierung += $tagessieg_rest;
|
|
|
|
|
|
2018-01-26 10:09:20 +01:00
|
|
|
$euro_platz1 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz1"] / 100))));
|
2017-08-31 07:36:27 +02:00
|
|
|
//Log::info("Platz 1=".$euro_platz1);
|
2018-01-07 15:40:30 +01:00
|
|
|
|
2018-01-26 10:09:20 +01:00
|
|
|
$euro_platz2 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz2"] / 100))));
|
|
|
|
|
$euro_platz3 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz3"] / 100))));
|
|
|
|
|
$euro_platz4 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz4"] / 100))));
|
|
|
|
|
$euro_platz5 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz5"] / 100))));
|
|
|
|
|
$euro_platz6 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz6"] / 100))));
|
|
|
|
|
$euro_platz7 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz7"] / 100))));
|
|
|
|
|
$euro_platz8 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz8"] / 100))));
|
|
|
|
|
$euro_platz9 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz9"] / 100))));
|
|
|
|
|
$euro_platz10= Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["platz10"] / 100))));
|
|
|
|
|
|
|
|
|
|
$euro_liga=intval($euro_pott *(($quotas["liga"] / 100)));
|
|
|
|
|
$euro_liga_platz1 = Quota::get6Divisor(intval($euro_liga*(($quotas["liga_platz1"] / 100))));
|
|
|
|
|
$euro_liga_platz2 = Quota::get6Divisor(intval($euro_liga*(($quotas["liga_platz2"] / 100))));
|
|
|
|
|
$euro_liga_platz3 = Quota::get6Divisor(intval($euro_liga*(($quotas["liga_platz3"] / 100))));
|
|
|
|
|
$euro_liga_platz2_1 = Quota::get6Divisor(intval($euro_liga*(($quotas["liga_platz2_1"] / 100))));
|
|
|
|
|
$euro_liga_platz3_1 = Quota::get6Divisor(intval($euro_liga*(($quotas["liga_platz3_1"] / 100))));
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
$finaler_rest = $euro_pott - ( $roundCount*$euro_tagessieg + $euro_gruenes_trikot + $euro_pokal + $euro_platz1
|
2017-08-30 14:52:21 +02:00
|
|
|
+ $euro_platz2 + $euro_platz3+ $euro_platz4 + $euro_platz5
|
|
|
|
|
+ $euro_platz6 + $euro_platz7 + $euro_platz8 + $euro_platz9 + $euro_platz10
|
2018-01-07 15:40:30 +01:00
|
|
|
+ $euro_liga_platz1 + $euro_liga_platz2 + $euro_liga_platz3 + $euro_liga_platz2_1
|
|
|
|
|
+ $euro_liga_platz3_1);
|
|
|
|
|
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
$euro_platz1 = $euro_platz1 + $finaler_rest;
|
2017-08-31 07:36:27 +02:00
|
|
|
//Log::info("PLatz 1 mit Rest(".$finaler_rest.") = ".$euro_platz1);
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
$payouts=array();
|
2017-08-30 14:52:21 +02:00
|
|
|
$payouts['tagessieg'] = $euro_tagessieg;
|
2017-08-19 16:53:39 +02:00
|
|
|
$payouts['platz1'] = $euro_platz1;
|
|
|
|
|
$payouts['platz2'] = $euro_platz2;
|
|
|
|
|
$payouts['platz3'] = $euro_platz3;
|
|
|
|
|
$payouts['platz4'] = $euro_platz4;
|
|
|
|
|
$payouts['platz5'] = $euro_platz5;
|
|
|
|
|
$payouts['platz6'] = $euro_platz6;
|
|
|
|
|
$payouts['platz7'] = $euro_platz7;
|
|
|
|
|
$payouts['platz8'] = $euro_platz8;
|
|
|
|
|
$payouts['platz9'] = $euro_platz9;
|
|
|
|
|
$payouts['platz10'] = $euro_platz10;
|
|
|
|
|
$payouts['liga_platz1'] = $euro_liga_platz1;
|
|
|
|
|
$payouts['liga_platz2'] = $euro_liga_platz2;
|
|
|
|
|
$payouts['liga_platz3'] = $euro_liga_platz3;
|
2018-01-10 08:45:01 +01:00
|
|
|
$payouts['liga_platz2_1'] = $euro_liga_platz2_1;
|
|
|
|
|
$payouts['liga_platz3_1'] = $euro_liga_platz3_1;
|
2018-01-26 10:09:20 +01:00
|
|
|
$payouts['gshirt'] = $euro_gruenes_trikot;
|
2017-08-19 16:53:39 +02:00
|
|
|
$payouts['pokal'] = $euro_pokal;
|
|
|
|
|
return $payouts;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-05 11:49:39 +02:00
|
|
|
// Subfunction of setQuotas
|
2017-11-10 15:32:54 +01:00
|
|
|
public static function setQuota($name, $value) {
|
|
|
|
|
$season_id = Season::getCurrent()->id;
|
2017-09-05 11:49:39 +02:00
|
|
|
$quota = Quota::all()->where('season_id','=',$season_id)->where('name','=',$name)->first();
|
|
|
|
|
if (!$quota) {
|
|
|
|
|
$quota = new Quota();
|
|
|
|
|
}
|
|
|
|
|
$quota->season_id = $season_id;
|
|
|
|
|
$quota->name = $name;
|
|
|
|
|
$quota->prc = $value;
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2017-09-05 11:49:39 +02:00
|
|
|
$quota->save();
|
|
|
|
|
}
|
2017-12-21 08:36:05 +01:00
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
public static function getQuota($quota_name) {
|
2017-12-21 08:36:05 +01:00
|
|
|
$season_id=Season::getCurrent()->id;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota=Quota::all()->where('season_id','=', $season_id)->where('name','=', $quota_name)->first();
|
|
|
|
|
return $quota['prc'];
|
|
|
|
|
}
|
2017-12-21 08:36:05 +01:00
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
public static function getQuotas() {
|
|
|
|
|
$season_id = Season::getCurrent()->id;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quotas=Quota::all()->where('season_id','=', $season_id);
|
|
|
|
|
$arr=array();
|
|
|
|
|
foreach($quotas as $quota) {
|
|
|
|
|
$arr[$quota['name']]=$quota['prc'];
|
|
|
|
|
}
|
|
|
|
|
return $arr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 08:45:01 +01:00
|
|
|
public static function getQuotasForDisplay() {
|
|
|
|
|
$quotas=Quota::getQuotas();
|
|
|
|
|
foreach($quotas as $key => $val) {
|
|
|
|
|
$quotas[$key]=str_replace(".",",", $val);
|
|
|
|
|
}
|
|
|
|
|
return $quotas;
|
|
|
|
|
}
|
2017-10-06 12:17:49 +02:00
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
public static function setQuotas($quotas) {
|
|
|
|
|
$season_id = Season::getCurrent()->id;
|
2017-08-19 16:53:39 +02:00
|
|
|
foreach ($quotas as $key => $quota) {
|
|
|
|
|
setQuota($key, $quota, $season_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-11-10 15:32:54 +01:00
|
|
|
public static function createDefaultQuota()
|
2017-08-16 17:30:32 +02:00
|
|
|
{
|
2017-11-10 15:32:54 +01:00
|
|
|
$season_id = Season::getCurrent()->id;
|
2017-08-19 16:53:39 +02:00
|
|
|
Log::info('Creating default quotas');
|
2017-08-16 17:30:32 +02:00
|
|
|
DB::table('quotas')->where('season_id', '=', $season_id)->delete();
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2017-10-06 12:17:49 +02:00
|
|
|
$roundCount=Season::getCurrent()->rounds;
|
2017-08-16 17:30:32 +02:00
|
|
|
Log::info("Creating new Quota");
|
2017-08-19 16:53:39 +02:00
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "einsatz";
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->prc = 40;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "tagessieg";
|
2017-12-29 19:08:46 +01:00
|
|
|
$quota->prc = 45;
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platzierung";
|
2017-12-29 19:08:46 +01:00
|
|
|
$quota->prc = 45;
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->save();
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "gshirt";
|
2017-12-29 19:08:46 +01:00
|
|
|
$quota->prc = 10;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "liga";
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->prc = 20;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-25 08:31:59 +01:00
|
|
|
$quota->name = "pokal";
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->prc = 15;
|
|
|
|
|
$quota->save();
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz1";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 1;
|
|
|
|
|
$quota->prc = 21;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz2";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 2;
|
|
|
|
|
$quota->prc = 17;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz3";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 3;
|
|
|
|
|
$quota->prc = 13;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz4";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 4;
|
|
|
|
|
$quota->prc = 10;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz5";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 5;
|
|
|
|
|
$quota->prc = 9;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz6";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 6;
|
|
|
|
|
$quota->prc = 8;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz7";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 7;
|
|
|
|
|
$quota->prc = 7;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz8";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 8;
|
|
|
|
|
$quota->prc = 6;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz9";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 9;
|
|
|
|
|
$quota->prc = 5;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-26 10:09:20 +01:00
|
|
|
$quota->name = "platz10";
|
2017-08-16 17:30:32 +02:00
|
|
|
$quota->order = 10;
|
|
|
|
|
$quota->prc = 4;
|
|
|
|
|
$quota->save();
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2017-12-29 19:08:46 +01:00
|
|
|
///////////////////////////////////
|
|
|
|
|
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-25 08:31:59 +01:00
|
|
|
$quota->name = "liga_platz1";
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->order = 10;
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->prc = 50;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-25 08:31:59 +01:00
|
|
|
$quota->name = "liga_platz2";
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->order = 10;
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->prc = 20;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-25 08:31:59 +01:00
|
|
|
$quota->name = "liga_platz3";
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->order = 10;
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->prc = 17;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-25 08:31:59 +01:00
|
|
|
$quota->name = "liga_platz2_1";
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->order = 10;
|
|
|
|
|
$quota->prc = 8;
|
|
|
|
|
$quota->save();
|
|
|
|
|
|
|
|
|
|
$quota = new Quota;
|
|
|
|
|
$quota->season_id = $season_id;
|
2018-01-25 08:31:59 +01:00
|
|
|
$quota->name = "liga_platz3_1";
|
2018-01-07 15:40:30 +01:00
|
|
|
$quota->order = 10;
|
|
|
|
|
$quota->prc = 5;
|
2017-08-19 16:53:39 +02:00
|
|
|
$quota->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Senkt die Zahl solange, bis sie durch 6 teilbar ist,
|
|
|
|
|
// Abrundungsvorgabe für Ausschüttungs-Grundbeträge.
|
|
|
|
|
public static function get6Divisor($number) {
|
|
|
|
|
// Eine Zahl ist durch 6 teilbar, wenn sie durch 2 und 3 teilbar ist.
|
|
|
|
|
while ($number % 2 or $number %3 ) { $number--; }
|
|
|
|
|
return $number;
|
2017-08-16 17:30:32 +02:00
|
|
|
}
|
2017-08-19 16:53:39 +02:00
|
|
|
|
2018-02-04 08:20:40 +01:00
|
|
|
// Beinhaltet Liste der Payouts für alle User.
|
|
|
|
|
// User ohne Payout sind mit leerer Liste ebenfalls enthalten.
|
|
|
|
|
public static function getPayoutList($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) {
|
|
|
|
|
|
|
|
|
|
foreach($user_ids as $userId) {
|
|
|
|
|
$key = $round_id . "_" . $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();
|
|
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
|
$item = array();
|
|
|
|
|
$item['roundname'] = "Grünes Trikot";
|
|
|
|
|
$item['payout'] = $payoutPerLeader;
|
|
|
|
|
array_push($payoutList[$leaderId], $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) {
|
|
|
|
|
$item = array();
|
|
|
|
|
$item['roundname']=$names[$quota];
|
|
|
|
|
$item['payout']=$_payouts[$quota];
|
2018-02-06 08:24:41 +01:00
|
|
|
array_push($payoutList[$uId],$item);
|
2018-02-04 08:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $payoutList;
|
|
|
|
|
}
|
2018-01-08 10:09:44 +01:00
|
|
|
|
|
|
|
|
|
2018-02-04 08:20:40 +01:00
|
|
|
public static function getPayoutPerUserDetails($userId, $response=null) {
|
|
|
|
|
if (!$response) {
|
|
|
|
|
$response = Tipp::getRoundTipps();
|
|
|
|
|
}
|
2018-01-08 10:09:44 +01:00
|
|
|
$roundtipps = $response['roundtipps'];
|
2018-02-04 08:20:40 +01:00
|
|
|
$round_ids = $response['round_ids'];
|
2018-01-31 09:12:56 +01:00
|
|
|
$user_ids = $response['user_ids'];
|
2018-01-08 10:09:44 +01:00
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 09:12:56 +01:00
|
|
|
// Gshirt START
|
|
|
|
|
if (Season::hasGreenShirtGame() ) {
|
|
|
|
|
$gshirtTotalPayout = Quota::getPayouts()['gshirt'];
|
|
|
|
|
$leaderCount = 0;
|
|
|
|
|
$leaderIds = array();
|
|
|
|
|
foreach ($user_ids as $uid) {
|
2018-02-04 08:20:40 +01:00
|
|
|
|
|
|
|
|
$key = Round::getLastRoundId() . "_" . $uid; // $key could be nonexistenen if we are not in the last round
|
|
|
|
|
if (!array_key_exists($key, $roundtipps)) continue;
|
2018-01-31 09:12:56 +01:00
|
|
|
if ($roundtipps[$key]['gshirt_leader'] == 1) {
|
|
|
|
|
$leaderCount += 1;
|
|
|
|
|
array_push($leaderIds,$uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-04 08:20:40 +01:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2018-01-31 09:12:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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"
|
|
|
|
|
];
|
2018-01-23 10:56:18 +01:00
|
|
|
$_payouts = Quota::getPayouts();
|
|
|
|
|
$winners = ManualPayout::getWinners();
|
2018-01-31 09:12:56 +01:00
|
|
|
foreach ($winners as $quota => $uId) {
|
|
|
|
|
if ($uId != $userId) continue;
|
2018-01-23 10:56:18 +01:00
|
|
|
$item = array();
|
2018-01-31 09:12:56 +01:00
|
|
|
$item['roundname']=$names[$quota];
|
2018-01-23 10:56:18 +01:00
|
|
|
$item['payout']=$_payouts[$quota];
|
|
|
|
|
array_push($payouts,$item);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 10:09:44 +01:00
|
|
|
return $payouts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getPayoutPerUser($seasonId=-1)
|
|
|
|
|
{
|
2018-01-23 10:56:18 +01:00
|
|
|
Log::info("starting payout per user");
|
2018-01-08 10:09:44 +01:00
|
|
|
$season = Season::get($seasonId);
|
|
|
|
|
|
|
|
|
|
$response = Tipp::getRoundTipps();
|
|
|
|
|
$roundtipps = $response['roundtipps'];
|
|
|
|
|
$user_ids = $response['user_ids'];
|
|
|
|
|
$round_ids = $response['round_ids'];
|
|
|
|
|
|
|
|
|
|
$payoutTotal = array();
|
|
|
|
|
$cnt = 0;
|
2018-01-31 09:12:56 +01:00
|
|
|
|
2018-01-08 10:09:44 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 09:12:56 +01:00
|
|
|
// 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
|
2018-01-23 10:56:18 +01:00
|
|
|
|
|
|
|
|
// Manuelle Payouts hinzufügen
|
|
|
|
|
$payouts = Quota::getPayouts();
|
|
|
|
|
$winners = ManualPayout::getWinners();
|
|
|
|
|
Log::info("Winners content:");
|
|
|
|
|
|
|
|
|
|
foreach ($winners as $quota => $userId) {
|
2018-01-31 09:12:56 +01:00
|
|
|
Log::Info("Manual Payout: quota=".$quota.", Amount=".$payouts[$quota].", userId=".$userId);
|
|
|
|
|
if ($userId) $payoutTotal[$userId]['amount'] += $payouts[$quota];
|
2018-01-23 10:56:18 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-08 10:09:44 +01:00
|
|
|
$sortedPayout = array();
|
|
|
|
|
foreach ($payoutTotal as $payout) {
|
|
|
|
|
$payment = array();
|
|
|
|
|
$payment['user_id'] = $payout['user_id'];
|
|
|
|
|
$payment['name'] = $payout['name'];
|
|
|
|
|
$payment['amount'] = $payout['amount'];
|
|
|
|
|
array_push($sortedPayout, $payment);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 10:56:18 +01:00
|
|
|
usort($sortedPayout,array('App\Quota','cmpPayment'));
|
2018-01-08 10:09:44 +01:00
|
|
|
|
|
|
|
|
return $sortedPayout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function cmpPayment($payment1, $payment2) {
|
|
|
|
|
return ($payment1['amount'] < $payment2['amount']);
|
|
|
|
|
}
|
2017-08-16 17:30:32 +02:00
|
|
|
}
|