feat: add article and production modules
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user