diff --git a/app/admin/controller/SystemsController.php b/app/admin/controller/SystemsController.php new file mode 100644 index 0000000..9c300ac --- /dev/null +++ b/app/admin/controller/SystemsController.php @@ -0,0 +1,33 @@ +service = new SystemsService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + // protected function indexFormat($data) + // { + // if (isset($data['created_at'])) + // $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + // if (isset($data['updated_at'])) + // $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + // return $data; + // } +} \ No newline at end of file diff --git a/app/admin/logic/CorpLogic.php b/app/admin/logic/CorpLogic.php deleted file mode 100644 index 99fa0ee..0000000 --- a/app/admin/logic/CorpLogic.php +++ /dev/null @@ -1,17 +0,0 @@ -validator; + } +} \ No newline at end of file diff --git a/app/common/logic/CorpLogic.php b/app/common/logic/CorpLogic.php index cac9672..60e46e6 100644 --- a/app/common/logic/CorpLogic.php +++ b/app/common/logic/CorpLogic.php @@ -2,10 +2,17 @@ namespace app\common\logic; +use app\common\traits\crud\CrudLogicTrait; use app\common\model\Corp; class CorpLogic { + use CrudLogicTrait; + + /** + * 指定当前要操作的模型 + */ + protected string $modelClass = Corp::class; public function getList() { diff --git a/app/common/logic/PermLogic.php b/app/common/logic/PermLogic.php index 16b7feb..b6a2fc9 100644 --- a/app/common/logic/PermLogic.php +++ b/app/common/logic/PermLogic.php @@ -153,7 +153,7 @@ class PermLogic // —— 递归构建子节点 —— $children = []; - if ($node->type === 'directory') { + if (in_array($node->type, ['directory', 'menu'])) { $children = $this->buildTree($resources, $node->id, $currentPath); } diff --git a/app/common/logic/RoleLogic.php b/app/common/logic/RoleLogic.php index 5cb3ae7..bd8f121 100644 --- a/app/common/logic/RoleLogic.php +++ b/app/common/logic/RoleLogic.php @@ -8,86 +8,7 @@ use support\Log; class RoleLogic { - /** - * 获取角色列表 - */ - public function getRoleList(array $params) - { - // 假设我们需要根据system_id进行过滤,其他过滤条件也可以添加 - $query = Role::query(); + - if (isset($params['system_id'])) { - $query->where('system_id', $params['system_id']); - } - if (isset($params['status'])) { - $query->where('status', $params['status']); - } - - // 添加分页 - $roles = $query->paginate($params['per_page'] ?? 15); - - return $roles; - } - - /** - * 获取角色详情 - */ - public function getRoleDetail(int $roleId) - { - $role = Role::find($roleId); - if (!$role) { - throw new BusinessException('角色不存在', 404); - } - - return $role; - } - - /** - * 创建角色 - */ - public function createRole(array $data) - { - $role = new Role(); - $role->fill($data); // 根据字段填充数据 - try { - $role->save(); - } catch (\Throwable $e) { - Log::error('创建角色失败:'.$e->getMessage()); - throw new BusinessException('创建角色失败', 500); - } - - return $role; - } - - /** - * 更新角色 - */ - public function updateRole(array $data) - { - $role = Role::find($data['id']); - if (!$role) { - throw new BusinessException('角色不存在', 404); - } - - $role->update($data); // 更新字段 - return $role; - } - - /** - * 删除角色 - */ - public function deleteRole(int $roleId) - { - $role = Role::find($roleId); - if (!$role) { - throw new BusinessException('角色不存在', 404); - } - - try { - $role->delete(); - } catch (\Throwable $e) { - Log::error('删除角色失败:'.$e->getMessage()); - throw new BusinessException('删除角色失败', 500); - } - } + } diff --git a/app/common/logic/SystemsLogic.php b/app/common/logic/SystemsLogic.php index 5411264..93e40d0 100644 --- a/app/common/logic/SystemsLogic.php +++ b/app/common/logic/SystemsLogic.php @@ -2,13 +2,20 @@ namespace app\common\logic; +use app\common\traits\crud\CrudLogicTrait; use app\common\model\Systems; class SystemsLogic { + use CrudLogicTrait; + + /** + * 指定当前要操作的模型 + */ + protected string $modelClass = Systems::class; public function getList() { - return Systems::where('status', 1)->orderBy('sort', 'asc')->get(['id', 'name', 'code', 'icon', 'type']); + return Systems::where('status', 1)->orderBy('sort', 'asc')->get(['id', 'name', 'code', 'type', 'type']); } } \ No newline at end of file diff --git a/app/common/model/Role.php b/app/common/model/Role.php index ea84200..c758321 100644 --- a/app/common/model/Role.php +++ b/app/common/model/Role.php @@ -43,6 +43,14 @@ class Role extends Model public $timestamps = true; protected $dateFormat = 'U'; + + protected $fillable = [ + 'system_id', + 'name', + 'desc', + 'sort', + 'status' + ]; // 角色下所有用户 public function users() diff --git a/app/common/model/Systems.php b/app/common/model/Systems.php index f9181ec..ddb180e 100644 --- a/app/common/model/Systems.php +++ b/app/common/model/Systems.php @@ -4,21 +4,6 @@ namespace app\common\model; use support\Model; -/** - * systems 系统/应用表 - * @property integer $id 系统ID(主键) - * @property string $code 系统编码(唯一英文标识) - * @property string $name 系统名称 - * @property string $type 系统类型 - * @property string $desc 系统描述 - * @property string $icon 系统图标 - * @property string $domain_url 系统URL - * @property string $is_role 是否区分角色权限 - * @property integer $sort 排序 - * @property integer $status 状态 - * @property integer $created_at 创建时间 - * @property integer $updated_at 更新时间 - */ class Systems extends Model { /** @@ -50,15 +35,15 @@ class Systems extends Model public $timestamps = true; - // 系统下的资源 - public function resources() - { - return $this->hasMany(Resource::class, 'system_id', 'id'); - } + protected $dateFormat = 'U'; - // 拥有该系统访问权限的用户 - public function users() - { - return $this->belongsToMany(User::class, 'user_systems', 'system_id', 'user_id'); - } -} + /** + * 允许自动填充模型字段 + */ + protected $fillable = ['id', 'code', 'name', 'type', 'desc', 'icon', 'domain_url', 'is_role', 'sort', 'status', 'created_at', 'updated_at']; + + /** + * 不允许自动填充模型字段 + */ + protected $guarded = []; +} \ No newline at end of file diff --git a/app/common/utils/scaffold/Generate.php b/app/common/utils/scaffold/Generate.php index fee26b1..7cf52ac 100644 --- a/app/common/utils/scaffold/Generate.php +++ b/app/common/utils/scaffold/Generate.php @@ -64,27 +64,6 @@ class Generate return $ControllerStub . $ServiceStub . $LogicStub . $ModelStub . $ValidatorStub . "文件生成成功!
"; } - /** - * 设置字段 - * - * @param array $fields 字段数组 - */ - public function fillableFields() - { - $tableName = $this->options['table']; - $fields = TableInspector::getColumnNames($tableName); - $str = ''; - foreach ($fields as $key => $val) { - if ($key < (count($fields)-1)) { - $str .= "'{$val}', "; - } else { - $str .= "'{$val}'"; - } - } - $fields = trim($str, '"'); - return $fields; - } - /** * 根据模板生成文件 * @@ -141,6 +120,27 @@ class Generate return "生成文件: {$outputPath}
"; } + /** + * 设置字段 + * + * @param array $fields 字段数组 + */ + public function fillableFields() + { + $tableName = $this->options['table']; + $fields = TableInspector::getColumnNames($tableName); + $str = ''; + foreach ($fields as $key => $val) { + if ($key < (count($fields)-1)) { + $str .= "'{$val}', "; + } else { + $str .= "'{$val}'"; + } + } + $fields = trim($str, '"'); + return $fields; + } + /** * 如果文件存在,删除它 * diff --git a/app/common/validate/SystemsValidate.php b/app/common/validate/SystemsValidate.php new file mode 100644 index 0000000..d0783f5 --- /dev/null +++ b/app/common/validate/SystemsValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index b694a23..125ff1f 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -22,18 +22,17 @@ class IndexController return htmlpage(); } + /** + * 调试飞书 + */ public function view(Request $request) { return view('index/qrcode', ['name' => 'webman']); } - public function json(Request $request) - { - return json(['code' => 0, 'msg' => 'ok']); - } - - - // 临时增加用户权限 + /** + * 临时增加用户权限 + */ public function perm(Request $request) { try { @@ -61,12 +60,13 @@ class IndexController Cache::delete("user_resources_{$data['user_id']}"); return json(['code' => 0, 'msg' => 'success']); } catch (\Throwable $e) { - var_dump($e); return json(['code' => 1, 'msg' => $e->getMessage()]); } } - + /** + * 生成资源 + */ public function createResource() { $options = [ @@ -75,7 +75,7 @@ class IndexController 'name' => 'systems' ], 'model' => [ - 'module' => 'admin', + 'module' => 'common', 'name' => 'systems' ], 'service' => [ @@ -83,11 +83,11 @@ class IndexController 'name' => 'systems' ], 'logic' => [ - 'module' => 'admin', + 'module' => 'common', 'name' => 'systems' ], 'validate' => [ - 'module' => 'admin', + 'module' => 'common', 'name' => 'systems' ], 'table' => 'systems'