38 lines
1,023 B
PHP
38 lines
1,023 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Season;
|
|
use App\User;
|
|
|
|
class ManualPayout extends Model
|
|
{
|
|
protected $fillable = [
|
|
'season_id','quota_name','user_id'
|
|
];
|
|
|
|
public static function getWinner($quotaName) {
|
|
$season = Season::getCurrent();
|
|
|
|
$entry = ManualPayout::where('season_id','=', $season->id)->where('quota_name','=',$quotaName)->first();
|
|
if (!$entry) return null;
|
|
$user = User::where('id','=',$entry->user_id);
|
|
return $user->first();
|
|
}
|
|
|
|
public static function setWinner( $userId, $quotaName) {
|
|
|
|
$season = Season::getCurrent();
|
|
|
|
$entry = ManualPayout::where('season_id','=',$season->id)->where('quota_name','=',$quotaName)->first();
|
|
if (!$entry) {
|
|
$entry = new ManualPayout;
|
|
$entry->user_id = $userId;
|
|
$entry->season_id = $season->id;
|
|
$entry->quota_name = $quotaName;
|
|
}
|
|
$entry->user_id = $userId;
|
|
$entry->save();
|
|
}
|
|
}
|