You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
64 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class TicketGrabVenueReleaseDay extends Model
|
|
{
|
|
protected $table = 'ticket_grab_venue_release_days';
|
|
|
|
protected $fillable = [
|
|
'ticket_grab_event_id',
|
|
'venue_id',
|
|
'release_date',
|
|
'day_quota',
|
|
'booked_count',
|
|
'carry_in',
|
|
];
|
|
|
|
protected $casts = [
|
|
'release_date' => 'date',
|
|
'day_quota' => 'integer',
|
|
'booked_count' => 'integer',
|
|
'carry_in' => 'integer',
|
|
];
|
|
|
|
public function ticketGrabEvent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TicketGrabEvent::class, 'ticket_grab_event_id');
|
|
}
|
|
|
|
public function venue(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Venue::class);
|
|
}
|
|
|
|
public function availableRemaining(): int
|
|
{
|
|
return max(0, (int) $this->carry_in + (int) $this->day_quota - (int) $this->booked_count);
|
|
}
|
|
|
|
/** 昨日及以前未约完的票会滚入次日,在后台展示时「过去放票日」余量为 0。 */
|
|
public function remainingForDisplay(): int
|
|
{
|
|
$tz = (string) config('app.timezone');
|
|
$today = Carbon::now($tz)->toDateString();
|
|
$rd = $this->release_date instanceof Carbon
|
|
? $this->release_date->format('Y-m-d')
|
|
: Carbon::parse($this->release_date)->format('Y-m-d');
|
|
if ($rd < $today) {
|
|
return 0;
|
|
}
|
|
|
|
return $this->availableRemaining();
|
|
}
|
|
|
|
public function totalDayPool(): int
|
|
{
|
|
return (int) $this->carry_in + (int) $this->day_quota;
|
|
}
|
|
}
|