BrokerUserConfigFilter.php 1.16 KB
<?php

namespace App\ModelFilters;

use App\Support\ModelFilter;
use Arr;

class BrokerUserConfigFilter extends ModelFilter
{
    public $relations = [
        'user' => ['userNickName' => 'nickName']
    ];

    /**
     * @param string $title
     * @return void
     */
    public function title(string $title): void
    {
        $this->whereLike('title', $title);
    }

    /**
     * @param int|array $type
     * @return void
     */
    public function pushType(int|array $type): void
    {
        $this->whereIn('push_type', Arr::wrap($type));
    }

    /**
     * @param array $pushBetween
     * @return void
     */
    public function pushBetween(array $pushBetween): void
    {
        $this->whereBetween('push_at', $pushBetween);
    }

    /**
     * @param int $status
     * @return void
     */
    public function status(int $status): void
    {
        $currentTime = now()->toDateTimeString();
        match ($status) {
            0 => $this->where('begin_at', '>', $currentTime),
            1 => $this->where('begin_at', '<=', $currentTime)->where('end_at', '>=', $currentTime),
            2 => $this->where('end_at', '<', $currentTime)
        };
    }
}