study-api-v2/app/Models/System/SystemRole.php
hx a621de91ff feat(system): 添加系统菜单、角色菜单关联和用户角色关联功能- 新增系统菜单模型、控制器、请求验证和业务逻辑
- 新增角色菜单关联模型、控制器、请求验证和业务逻辑
- 新增用户角色关联模型、控制器、请求验证和业务逻辑
- 更新系统角色模型,增加与用户和菜单的关联
- 更新用户模型,增加与角色的关联和相关方法
- 在路由文件中添加新功能的路由定义
2025-07-15 01:14:15 +08:00

91 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models\System;
use App\Models\BaseModel;
/**
* 系统角色模型
*
* @property int $id 角色ID
* @property string $name 角色名称
* @property string $code 角色权限字符串
* @property int $sort 显示顺序
* @property int $data_scope 数据范围1全部数据权限 2自定数据权限 3本部门数据权限 4本部门及以下数据权限
* @property string|null $data_scope_dept_ids 数据范围(指定部门数组)
* @property int $status 角色状态0正常 1停用
* @property int $type 角色类型
* @property string|null $remark 备注
* @property int|null $creator 创建者
* @property string|null $create_time 创建时间
* @property int|null $updater 更新者
* @property string|null $update_time 更新时间
* @property int $deleted 删除标识
* @property int|null $tenant_id 租户ID
*/
class SystemRole extends BaseModel
{
protected $table = 'system_role';
protected $fillable = [
'name',
'code',
'sort',
'data_scope',
'data_scope_dept_ids',
'status',
'type',
'remark',
];
protected $hidden = [
'deleted',
];
protected $casts = [
'id' => 'integer',
'sort' => 'integer',
'data_scope' => 'integer',
'status' => 'integer',
'type' => 'integer',
'creator' => 'integer',
'updater' => 'integer',
'deleted' => 'integer',
'tenant_id' => 'integer',
'create_time' => 'datetime',
'update_time' => 'datetime',
];
/**
* 角色用户关联
*/
public function userRoles()
{
return $this->hasMany(SystemUserRole::class, 'role_id');
}
/**
* 角色的用户(多对多)
*/
public function users()
{
return $this->belongsToMany(\App\Models\User::class, 'system_user_role', 'role_id', 'user_id');
}
/**
* 角色菜单关联
*/
public function roleMenus()
{
return $this->hasMany(SystemRoleMenu::class, 'role_id');
}
/**
* 角色的菜单(多对多)
*/
public function menus()
{
return $this->belongsToMany(SystemMenu::class, 'system_role_menu', 'role_id', 'menu_id');
}
}