Files
MrleeAdmin/backend/plugin/produce/app/dao/SpecificRuleDao.php
T

71 lines
2.0 KiB
PHP
Raw Normal View History

2026-08-31 13:16:46 +08:00
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use plugin\produce\app\model\SpecificRule;
class SpecificRuleDao extends BaseDao
{
protected function setModel(): string
{
return SpecificRule::class;
}
protected function getKeywordFields(): array
{
return ['rule_name', 'rule_pattern', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['createds']));
$order = $order ?: 'sort asc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
{
$with = array_unique(array_merge($with ?? [], ['createds']));
return parent::get($id, $field, $with, $order, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$query->where(function (Builder $builder) use ($where) {
$keyword = '%' . $where['keyword'] . '%';
$builder->where('rule_name', 'like', $keyword)
->orWhere('rule_pattern', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
if (($where['rule_type'] ?? '') !== '') {
$query->where('rule_type', $where['rule_type']);
}
if (($where['is_enabled'] ?? '') !== '') {
$query->where('is_enabled', $where['is_enabled']);
}
return $query;
}
}