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.

78 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Laravel\Sanctum\HasApiTokens;
class VerifyPortalCredential extends Model
{
use HasApiTokens;
public const KIND_ACTIVITY = 'activity';
public const KIND_TICKET_GRAB = 'ticket_grab';
/** 抢票核销:按场馆 6 位口令portal_id = venue_id */
public const KIND_TICKET_GRAB_VENUE = 'ticket_grab_venue';
protected $fillable = [
'portal_kind',
'portal_id',
'venue_id',
'username',
'password',
'password_plain_enc',
'note',
];
protected $hidden = [
'password',
'password_plain_enc',
];
protected function casts(): array
{
return [
'portal_id' => 'integer',
'venue_id' => 'integer',
];
}
public function venue(): BelongsTo
{
return $this->belongsTo(Venue::class);
}
/** 活动/抢票结束日(含当日)内可核销;超过 end 日则失效 */
public function portalAcceptsVerification(): bool
{
if ($this->portal_kind === self::KIND_ACTIVITY) {
$a = Activity::query()->find($this->portal_id);
if (! $a || ! $a->end_at) {
return false;
}
return now()->toDateString() <= $a->end_at->toDateString();
}
if ($this->portal_kind === self::KIND_TICKET_GRAB) {
$e = TicketGrabEvent::query()->find($this->portal_id);
if (! $e || ! $e->end_at) {
return false;
}
return now()->toDateString() <= $e->end_at->toDateString();
}
if ($this->portal_kind === self::KIND_TICKET_GRAB_VENUE) {
$v = Venue::query()->find($this->portal_id);
return $v !== null
&& $v->is_active
&& $v->audit_status === Venue::AUDIT_APPROVED;
}
return false;
}
}