You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.9 KiB
87 lines
2.9 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
namespace app\admin\model\system;
|
|
|
|
use traits\ModelTrait;
|
|
use basic\ModelBasic;
|
|
|
|
/**
|
|
* 身份管理 model
|
|
* Class SystemRole
|
|
* @package app\admin\model\system
|
|
*/
|
|
class SystemRole extends ModelBasic
|
|
{
|
|
use ModelTrait;
|
|
|
|
public static function setRulesAttr($value)
|
|
{
|
|
return is_array($value) ? implode(',', $value) : $value;
|
|
}
|
|
|
|
/**
|
|
* 选择管理员身份
|
|
* @param int $level
|
|
* @param string $field
|
|
* @return array
|
|
*/
|
|
public static function getRole($level = 0, $field = 'id,role_name')
|
|
{
|
|
return self::where('status', 1)->where('level', '=', $level)->column($field);
|
|
}
|
|
|
|
|
|
public static function rolesByAuth($rules)
|
|
{
|
|
if (empty($rules)) return [];
|
|
$rules = self::where('id', 'IN', $rules)->where('status', '1')->column('rules');
|
|
$rules = array_unique(explode(',', implode(',', $rules)));
|
|
$_auth = SystemMenus::all(function ($query) use ($rules) {
|
|
$query->where('id', 'IN', $rules)
|
|
->where('controller|action', '<>', '')
|
|
->field('module,controller,action,params');
|
|
});
|
|
return self::tidyAuth($_auth ?: []);
|
|
}
|
|
|
|
public static function getAllAuth()
|
|
{
|
|
static $auth = null;
|
|
$auth === null && ($auth = self::tidyAuth(SystemMenus::all(function ($query) {
|
|
$query->where('controller|action', '<>', '')->field('module,controller,action,params');
|
|
}) ?: []));
|
|
return $auth;
|
|
}
|
|
|
|
protected static function tidyAuth($_auth)
|
|
{
|
|
$auth = [];
|
|
foreach ($_auth as $k => $val) {
|
|
$auth[] = SystemMenus::getAuthName($val['action'], $val['controller'], $val['module'], $val['params']);
|
|
}
|
|
return $auth;
|
|
}
|
|
|
|
|
|
public static function systemPage($where)
|
|
{
|
|
$model = new self;
|
|
if ($where['role_name'] != '') $model = $model->where('role_name', 'LIKE', "%$where[role_name]%");
|
|
if ($where['status'] != '') $model = $model->where('status', $where['status']);
|
|
$model->where('level', '=', bcadd($where['level'], 1, 0));
|
|
return self::page($model, (function ($item, $key) {
|
|
$item->rules = SystemMenus::where('id', 'IN', $item->rules)->column('menu_name');
|
|
}), $where);
|
|
}
|
|
|
|
}
|
|
|