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.
68 lines
1.6 KiB
68 lines
1.6 KiB
|
1 week ago
|
<?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';
|
||
|
|
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|