76 lines
1.7 KiB
Plaintext
76 lines
1.7 KiB
Plaintext
<?php
|
|
declare(strict_types=1);
|
|
/**
|
|
* MineAdmin is committed to providing solutions for quickly building web applications
|
|
* Please view the LICENSE file that was distributed with this source code,
|
|
* For the full copyright and license information.
|
|
* Thank you very much for using MineAdmin.
|
|
*
|
|
* @Author X.Mo<root@imoi.cn>
|
|
* @Link https://gitee.com/xmo/MineAdmin
|
|
*/
|
|
|
|
namespace {NAMESPACE};
|
|
|
|
{USE}
|
|
use Hyperf\Database\Model\Builder;
|
|
use Builder\Abstracts\AbstractMapper;
|
|
|
|
/**
|
|
* {COMMENT}
|
|
*/
|
|
class {CLASS_NAME} extends AbstractMapper
|
|
{
|
|
/**
|
|
* @var {MODEL}
|
|
*/
|
|
public $model;
|
|
|
|
public function assignModel()
|
|
{
|
|
$this->model = {MODEL}::class;
|
|
}
|
|
|
|
/**
|
|
* 获取前端选择树
|
|
* @return array
|
|
*/
|
|
public function getSelectTree(): array
|
|
{
|
|
return $this->model::query()
|
|
->select(['{FIELD_ID}', '{FIELD_PID}', '{FIELD_ID} AS value', '{FIELD_NAME} AS label'])
|
|
->get()->toTree();
|
|
}
|
|
|
|
|
|
/**
|
|
* 查询树名称
|
|
* @param array|null $ids
|
|
* @return array
|
|
*/
|
|
public function getTreeName(array $ids = null): array
|
|
{
|
|
return $this->model::withTrashed()->whereIn('{FIELD_ID}', $ids)->pluck('{FIELD_NAME}')->toArray();
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function checkChildrenExists(int $id): bool
|
|
{
|
|
return $this->model::withTrashed()->where('{FIELD_PID}', $id)->exists();
|
|
}
|
|
|
|
/**
|
|
* 搜索处理器
|
|
* @param Builder $query
|
|
* @param array $params
|
|
* @return Builder
|
|
*/
|
|
public function handleSearch(Builder $query, array $params): Builder
|
|
{
|
|
{SEARCH}
|
|
return $query;
|
|
}
|
|
} |