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

69 lines
2.0 KiB
PHP

<?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\RepairSetting;
class RepairSettingDao extends BaseDao
{
protected function setModel(): string
{
return RepairSetting::class;
}
protected function getKeywordFields(): array
{
return ['code', 'name', '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, ['parent', 'createds']));
$order = $order ?: 'setting_type asc, parent_id asc, sort asc, id asc';
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 ?? [], ['parent', 'createds']));
return parent::get($id, $field, $with, $order, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$keyword = '%' . $where['keyword'] . '%';
$query->where(function (Builder $builder) use ($keyword) {
$builder->where('code', 'like', $keyword)
->orWhere('name', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
foreach (['setting_type', 'parent_id', 'is_enabled'] as $field) {
if (($where[$field] ?? '') !== '') {
$query->where($field, $where[$field]);
}
}
return $query;
}
}