52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Keyword;
|
|
use Slowlyo\OwlAdmin\Services\AdminService;
|
|
|
|
/**
|
|
* 字典管理
|
|
*
|
|
* @method Keyword getModel()
|
|
* @method Keyword|\Illuminate\Database\Query\Builder query()
|
|
*/
|
|
class KeywordService extends AdminService
|
|
{
|
|
protected string $modelName = Keyword::class;
|
|
|
|
public function getTree($filters = [])
|
|
{
|
|
$list = $this->query()->filter($filters)->get();
|
|
|
|
return array2tree($list->toArray(), $list->min('parent_id') ?: 0);
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
return ['items' => $this->getTree(request()->all())];
|
|
}
|
|
|
|
public function addRelations($query, string $scene = 'list')
|
|
{
|
|
if ($scene == 'detail') {
|
|
$query->with(['parent']);
|
|
}
|
|
}
|
|
|
|
public function query()
|
|
{
|
|
return $this->modelName::query()->sort();
|
|
}
|
|
|
|
public function deleted($ids)
|
|
{
|
|
$ids = explode(',', $ids);
|
|
|
|
$this->query()->where(function ($q) use ($ids) {
|
|
foreach ($ids as $id) {
|
|
$q->orWhere('path', 'like', '%-'.$id.'-%');
|
|
}
|
|
})->delete();
|
|
}
|
|
} |