Files
dafuweng-saiadmin6.x/server/plugin/saiadmin/app/model/system/SystemRole.php
zhenhui dd264b1e97 1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道
3.优化后台页面设置
2026-05-19 09:49:02 +08:00

87 lines
2.4 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
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 角色模型
*
* sa_system_role 角色表
*
* @property $id
* @property int $dept_id 所属渠道ID0=默认模板
* @property $name 角色名称
* @property $code 角色标识,如: hr_manager
* @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色
* @property $data_scope 数据范围: 1全部, 2本部门及下属, 3本部门, 4仅本人, 5自定义
* @property $remark 备注
* @property $sort
* @property $status 状态: 1启用, 0禁用
* @property $created_by 创建者
* @property $updated_by 更新者
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class SystemRole extends BaseModel
{
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
/**
* 数据表完整名称
* @var string
*/
protected $table = 'sa_system_role';
/** 按渠道筛选 */
public function searchDeptIdAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('dept_id', '=', $value);
}
}
/**
* 权限范围
*/
public function scopeAuth($query, $value)
{
$id = $value['id'];
$roles = $value['roles'];
if ($id > 1) {
$ids = [];
foreach ($roles as $item) {
$ids[] = $item['id'];
$temp = static::whereRaw('FIND_IN_SET("' . $item['id'] . '", level) > 0')->column('id');
$ids = array_merge($ids, $temp);
}
$query->where('id', 'in', array_unique($ids));
}
}
/**
* 通过中间表获取菜单
*/
public function menus()
{
return $this->belongsToMany(SystemMenu::class, SystemRoleMenu::class, 'menu_id', 'role_id');
}
/**
* 通过中间表获取部门
*/
public function depts()
{
return $this->belongsToMany(SystemDept::class, SystemRoleDept::class, 'dept_id', 'role_id');
}
}