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.
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
|
|
class PhoneBookingBan extends Model
|
|
|
|
|
|
{
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
|
'visitor_phone',
|
|
|
|
|
|
'ban_until',
|
|
|
|
|
|
'reason',
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
|
'ban_until' => 'datetime',
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/** 当前是否处于全平台禁约期(ban_until 为期满后可预约的最早时刻)。 */
|
|
|
|
|
|
public static function isGloballyBlocked(string $visitorPhone): bool
|
|
|
|
|
|
{
|
|
|
|
|
|
return static::query()
|
|
|
|
|
|
->where('visitor_phone', $visitorPhone)
|
|
|
|
|
|
->where('ban_until', '>', now())
|
|
|
|
|
|
->exists();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function activeBanUntil(string $visitorPhone): ?Carbon
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = static::query()
|
|
|
|
|
|
->where('visitor_phone', $visitorPhone)
|
|
|
|
|
|
->where('ban_until', '>', now())
|
|
|
|
|
|
->orderByDesc('ban_until')
|
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
|
|
return $row?->ban_until;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|