|
@@ -0,0 +1,99 @@
|
|
|
+<?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 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, $create = true, $read = true, $update = true, $delete = true) {
|
|
|
+ $codes = [];
|
|
|
+ if ($create) {
|
|
|
+ $codes[] = [
|
|
|
+ 'code' => "$parent.create",
|
|
|
+ 'cn' => '创建'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($read) {
|
|
|
+ $codes[] = [
|
|
|
+ 'code' => "$parent.read",
|
|
|
+ 'cn' => '创建'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($update) {
|
|
|
+ $codes[] = [
|
|
|
+ 'code' => "$parent.update",
|
|
|
+ 'cn' => '创建'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($delete) {
|
|
|
+ $codes[] = [
|
|
|
+ 'code' => "$parent.delete",
|
|
|
+ 'cn' => '创建'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $codes;
|
|
|
+ };
|
|
|
+
|
|
|
+ $codes = [
|
|
|
+ [
|
|
|
+ 'code' => Role::CODE_SUPER_ADMIN,
|
|
|
+ 'cn' => '超级管理员(所有权限)',
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'code' => 'admin',
|
|
|
+ 'cn' => '人员管理',
|
|
|
+ 'children' => $crud('admin')
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'code' => 'project',
|
|
|
+ 'cn' => '项目',
|
|
|
+ 'children' => [
|
|
|
+ ...$crud('project'),
|
|
|
+ [
|
|
|
+ 'code' => 'project.schedule',
|
|
|
+ 'cn' => '进程',
|
|
|
+ 'children' => $crud('project.schedule')
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'code' => 'project.status',
|
|
|
+ 'cn' => '状态',
|
|
|
+ 'children' => $crud('project.status', delete: false)
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'code' => 'project.contract',
|
|
|
+ 'cn' => '合同',
|
|
|
+ 'children' => $crud('project.contract')
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ Cache::set(self::CODE_CACHE_KEY, $codes, 600);
|
|
|
+ return $codes;
|
|
|
+ }
|
|
|
+}
|