123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace app\common\service;
- use app\common\model\Role;
- use app\common\service\Service;
- use think\facade\Cache;
- class RoleService extends Service
- {
- public function list()
- {
- return (new Role)->select();
- }
- public function create($param = [])
- {
- $param = $this->autoParams($param);
- return Role::create($param);
- }
- public function update($param = [])
- {
- $param = $this->autoParams($param);
- return Role::update($param);
- }
- const CODE_CACHE_KEY = 'ROLE_CODE_CACHE';
- public function codes()
- {
- // 从缓存获取之前生成好的值
- // $cache = Cache::get(self::CODE_CACHE_KEY);
- // if ($cache) {
- // return $cache;
- // }
- $crud = function($parent, $name, $create = true, $read = true, $update = true, $delete = true) {
- $codes = [];
- if ($create) {
- $codes[] = [
- 'id' => "$parent.create",
- 'lable' => "创建-$name"
- ];
- }
- if ($read) {
- $codes[] = [
- 'id' => "$parent.read",
- 'lable' => "读取-$name"
- ];
- }
- if ($update) {
- $codes[] = [
- 'id' => "$parent.update",
- 'lable' => "编辑-$name"
- ];
- }
- if ($delete) {
- $codes[] = [
- 'id' => "$parent.delete",
- 'lable' => "删除-$name"
- ];
- }
- return $codes;
- };
- $codes = [
- [
- 'id' => Role::CODE_SUPER_ADMIN,
- 'lable' => '超级管理员(所有权限)',
- ],
- [
- 'id' => 'admin',
- 'lable' => '人员管理',
- 'children' => $crud('admin', '人员管理')
- ],
- [
- 'id' => 'role',
- 'lable' => '角色管理',
- 'children' => $crud('role', '角色管理')
- ],
- [
- 'id' => 'project',
- 'lable' => '项目',
- 'children' => [
- ...$crud('project', '项目'),
- [
- 'id' => 'project.schedule',
- 'lable' => '进程',
- 'children' => $crud('project.schedule', '进程', read: false)
- ],
- [
- 'id' => 'project.status',
- 'lable' => '状态',
- 'children' => $crud('project.status', '状态', read: false, delete: false)
- ],
- [
- 'id' => 'project.contract',
- 'lable' => '合同',
- 'children' => $crud('project.contract', '合同')
- ]
- ]
- ]
- ];
- Cache::set(self::CODE_CACHE_KEY, $codes, 600);
- return $codes;
- }
- }
|