84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class DrawResult extends Model
|
|
{
|
|
public const STATUS_PENDING = 'pending_confirmation';
|
|
public const STATUS_CONFIRMED = 'confirmed';
|
|
public const STATUS_CANCELLED = 'cancelled_absent';
|
|
public const STATUS_REDRAWN = 'redrawn';
|
|
|
|
public const STATUS_LABELS = [
|
|
self::STATUS_PENDING => 'Menunggu Pengesahan',
|
|
self::STATUS_CONFIRMED => 'Disahkan',
|
|
self::STATUS_CANCELLED => 'Dibatalkan (Tiada Di Dewan)',
|
|
self::STATUS_REDRAWN => 'Telah Dicabut Semula',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'draw_session_id',
|
|
'prize_id',
|
|
'member_id',
|
|
'status',
|
|
'attempt_number',
|
|
'spun_at',
|
|
'confirmed_at',
|
|
'cancelled_at',
|
|
'confirmed_by',
|
|
'cancelled_by',
|
|
'sebab_batal',
|
|
'confirmed_member_id',
|
|
'confirmed_prize_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'spun_at' => 'datetime',
|
|
'confirmed_at' => 'datetime',
|
|
'cancelled_at' => 'datetime',
|
|
'attempt_number' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function drawSession(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DrawSession::class);
|
|
}
|
|
|
|
public function prize(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Prize::class);
|
|
}
|
|
|
|
public function member(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Member::class);
|
|
}
|
|
|
|
public function confirmedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'confirmed_by');
|
|
}
|
|
|
|
public function cancelledBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'cancelled_by');
|
|
}
|
|
|
|
public function statusLabel(): string
|
|
{
|
|
return self::STATUS_LABELS[$this->status] ?? $this->status;
|
|
}
|
|
|
|
public function scopeConfirmed(Builder $query): Builder
|
|
{
|
|
return $query->where('status', self::STATUS_CONFIRMED);
|
|
}
|
|
}
|