94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace app\common\service;
|
|
|
|
use app\common\validate\ResourceValidate;
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
use app\common\model\Resource;
|
|
use app\common\utils\Tree;
|
|
use support\Request;
|
|
|
|
class ResourceService
|
|
{
|
|
|
|
use CrudServiceTrait;
|
|
|
|
/**
|
|
* 指定当前要操作的模型
|
|
*/
|
|
protected string $modelClass = Resource::class;
|
|
|
|
/**
|
|
* 验证器
|
|
*/
|
|
protected $validator = ResourceValidate::class;
|
|
|
|
/**
|
|
* 获取验证器
|
|
*/
|
|
public function getValidator()
|
|
{
|
|
return new $this->validator;
|
|
}
|
|
|
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
|
{
|
|
$p = $request->all();
|
|
|
|
$config = [];
|
|
$config['model'] = $this->modelClass;
|
|
switch ($scene) {
|
|
case 'default':
|
|
$config['where']['status'] = 1;
|
|
$config['order']['sort'] = 'asc';
|
|
$config['order']['id'] = 'asc';
|
|
break;
|
|
case 'menuList':
|
|
$config['where']['status'] = 1;
|
|
$config['where']['type'] = ['!=', 'permission'];
|
|
$config['order']['sort'] = 'asc';
|
|
$config['order']['id'] = 'asc';
|
|
break;
|
|
case 'index':
|
|
$config['where']['status'] = 1;
|
|
$config['order']['sort'] = 'asc';
|
|
$config['order']['id'] = 'asc';
|
|
break;
|
|
case 'show':
|
|
$config['where']['id'] = $p['id'];
|
|
$config['where']['status'] = 1;
|
|
break;
|
|
case 'store':
|
|
break;
|
|
case 'update':
|
|
$config['where']['id'] = $p['id'];
|
|
break;
|
|
case 'destroy':
|
|
$config['where']['id'] = $p['id'];
|
|
break;
|
|
}
|
|
|
|
return $config;
|
|
}
|
|
|
|
public function serviceMenuList(Request $request)
|
|
{
|
|
$config = $this->buildQueryConfig($request, 'menuList');
|
|
$result = $this->logicListAll($config);
|
|
return $this->postProcess('MenuList', $result);
|
|
}
|
|
|
|
|
|
protected function afterServiceListAll($data)
|
|
{
|
|
$data = Tree::buildWithAuthListAndReference($data->toArray());
|
|
return $data;
|
|
}
|
|
|
|
protected function afterServiceMenuList($data)
|
|
{
|
|
$data = Tree::buildWithReference($data->toArray());
|
|
return $data;
|
|
}
|
|
} |