55 lines
1.5 KiB
PHP
55 lines
1.5 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 plugin\produce\app\model\Material;
|
|
|
|
class MaterialDao extends BaseDao
|
|
{
|
|
protected function setModel(): string
|
|
{
|
|
return Material::class;
|
|
}
|
|
|
|
protected function getKeywordFields(): array
|
|
{
|
|
return ['product_code', 'product_name'];
|
|
}
|
|
|
|
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 {
|
|
return parent::selectList($where, $field, $page, $limit, $order ?: 'id desc', array_unique(array_merge($with, ['category'])), $search, $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('product_code', 'like', $keyword)
|
|
->orWhere('product_name', 'like', $keyword);
|
|
});
|
|
}
|
|
if (($where['category_id'] ?? '') !== '') {
|
|
$query->where('category_id', $where['category_id']);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
}
|