更新目录结构
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthGroup extends Model{
|
||||
|
||||
public $keyList = [
|
||||
['name'=>'id', 'title'=>'ID', 'type'=>'hidden', 'help'=>'', 'option'=>''],
|
||||
['name'=>'module', 'title'=>'所属模块', 'type'=>'hidden', 'help'=>'', 'option'=>''],
|
||||
['name'=>'title', 'title'=>'用户组名', 'type'=>'text', 'is_must'=> true, 'help'=>'', 'option'=>''],
|
||||
['name'=>'description', 'title'=>'分组描述', 'type'=>'textarea', 'help'=>'', 'option'=>''],
|
||||
['name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=> [['key' => 0, 'label' => '禁用'],['key' => 1, 'label' => '启用']]],
|
||||
];
|
||||
|
||||
protected function getRulesAttr($value){
|
||||
return $value ? explode(",", $value) : [];
|
||||
}
|
||||
|
||||
public static function getAuthModels($uid){}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthGroupAccess extends Model{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthRule extends Model{
|
||||
|
||||
const rule_url = 1;
|
||||
const rule_mian = 2;
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public $keyList = [
|
||||
['name'=>'module','title'=>'所属模块','type'=>'hidden'],
|
||||
['name'=>'title','title'=>'节点名称','type'=>'text', 'is_must'=>true,'help'=>''],
|
||||
['name'=>'name','title'=>'节点标识','type'=>'text', 'is_must'=>true,'help'=>''],
|
||||
['name'=>'group','title'=>'功能组','type'=>'text','help'=>'功能分组'],
|
||||
['name'=>'status','title'=>'状态','type'=>'select','option'=>[['key' => '0', 'label'=>'禁用'],['key' => '1', 'label'=>'启用']],'help'=>''],
|
||||
['name'=>'condition','title'=>'条件','type'=>'text','help'=>'']
|
||||
];
|
||||
|
||||
public static function uprule($type){
|
||||
$path = app()->getAppPath() . 'controller' . DIRECTORY_SEPARATOR . $type;
|
||||
$list = [];
|
||||
|
||||
$classname = self::scanFile($path);
|
||||
foreach ($classname as $value) {
|
||||
if($value == 'Base'){
|
||||
continue;
|
||||
}
|
||||
$class = "app\\controller\\" . $type . "\\" . $value;
|
||||
if (class_exists($class)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$group_doc = self::Parser($reflection->getDocComment());
|
||||
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
|
||||
$group_doc['name'] = $value;
|
||||
foreach ($method as $key => $v) {
|
||||
if (!in_array($v->name, ['__construct'])) {
|
||||
$title_doc = self::Parser($v->getDocComment());
|
||||
if (isset($title_doc['title']) && $title_doc['title']) {
|
||||
$list[] = array(
|
||||
'module' => $type,
|
||||
'type' => 2,
|
||||
'name' => $type . '/' . strtolower($value) . '/' . strtolower($v->name),
|
||||
'title' => trim($title_doc['title']),
|
||||
'group' => $group_doc['title'],
|
||||
'status' => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($list as $key => $value) {
|
||||
$id = self::where('name', $value['name'])->value('id');
|
||||
if ($id) {
|
||||
$value['id'] = $id;
|
||||
}
|
||||
$list[$key] = $value;
|
||||
}
|
||||
return (new self())->saveAll($list);
|
||||
}
|
||||
|
||||
protected static function scanFile($path) {
|
||||
$result = array();
|
||||
$files = scandir($path);
|
||||
foreach ($files as $file) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
if (is_dir($path . '/' . $file)) {
|
||||
self::scanFile($path . '/' . $file);
|
||||
} else {
|
||||
$result[] = substr(basename($file), 0, -4);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected static function Parser($text) {
|
||||
$doc = new \doc\Doc();
|
||||
return $doc->parse($text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Department extends Model {
|
||||
|
||||
protected $name = "member_department";
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
use sent\jwt\facade\JWTAuth;
|
||||
use think\Model;
|
||||
use xin\helper\Server;
|
||||
|
||||
class Member extends Model {
|
||||
|
||||
protected $pk = 'uid';
|
||||
|
||||
protected $createTime = 'reg_time';
|
||||
protected $updateTime = 'last_login_time';
|
||||
|
||||
protected $insert = ['reg_ip', 'status' => 1];
|
||||
|
||||
public $editfield = [
|
||||
['name'=>'uid','type'=>'hidden'],
|
||||
['name'=>'username','title'=>'用户名','type'=>'readonly','help'=>''],
|
||||
['name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''],
|
||||
['name'=>'password','title'=>'密码','type'=>'password','help'=>'为空时则不修改'],
|
||||
['name'=>'sex','title'=>'性别','type'=>'select','option'=> [['key' => '0', 'label'=>'保密'],['key' => '1', 'label' =>'男'],['key' => '2', 'label'=>'女']],'help'=>''],
|
||||
['name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'],
|
||||
['name'=>'qq','title'=>'QQ','type'=>'text','help'=>''],
|
||||
['name'=>'score','title'=>'用户积分','type'=>'text','help'=>''],
|
||||
['name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''],
|
||||
['name'=>'status','title'=>'状态','type'=>'select','option'=>[['key' => '0', 'label'=>'禁用'],['key' => '1', 'label'=>'启用']],'help'=>''],
|
||||
];
|
||||
|
||||
public $addfield = [
|
||||
['name'=>'username','title'=>'用户名','type'=>'text', 'is_must'=> true,'help'=>'用户名会作为默认的昵称'],
|
||||
['name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''],
|
||||
['name'=>'password','title'=>'密码','type'=>'password', 'is_must'=> true, 'help'=>'用户密码不能少于6位'],
|
||||
['name'=>'repassword','title'=>'确认密码','type'=>'password', 'is_must'=> true, 'help'=>'确认密码'],
|
||||
['name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'],
|
||||
];
|
||||
|
||||
public static $useredit = [
|
||||
['name'=>'uid','type'=>'hidden'],
|
||||
['name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''],
|
||||
['name'=>'sex','title'=>'性别','type'=>'select','option'=>[['key' => '0', 'label'=>'保密'],['key' => '1', 'label' =>'男'],['key' => '2', 'label'=>'女']],'help'=>''],
|
||||
['name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'],
|
||||
['name'=>'mobile','title'=>'联系电话','type'=>'text','help'=>''],
|
||||
['name'=>'qq','title'=>'QQ','type'=>'text','help'=>''],
|
||||
['name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''],
|
||||
];
|
||||
|
||||
public $userextend = [
|
||||
['name'=>'company','title'=>'单位名称','type'=>'text','help'=>''],
|
||||
['name'=>'company_addr','title'=>'单位地址','type'=>'text','help'=>''],
|
||||
['name'=>'company_contact','title'=>'单位联系人','type'=>'text','help'=>''],
|
||||
['name'=>'company_zip','title'=>'单位邮编','type'=>'text','help'=>''],
|
||||
['name'=>'company_depart','title'=>'所属部门','type'=>'text','help'=>''],
|
||||
['name'=>'company_post','title'=>'所属职务','type'=>'text','help'=>''],
|
||||
['name'=>'company_type','title'=>'单位类型','type'=>'select', 'option'=>'', 'help'=>''],
|
||||
];
|
||||
|
||||
protected $status = [
|
||||
1 => '正常',
|
||||
0 => '禁用',
|
||||
];
|
||||
|
||||
public $loginVisible = ['uid', 'username', 'nickname', 'access_token', 'department']; //用户登录成功返回的字段
|
||||
|
||||
protected function getStatusTextAttr($value, $data) {
|
||||
return isset($this->status[$data['status']]) ? $this->status[$data['status']] : '未知';
|
||||
}
|
||||
|
||||
protected function getAvatarAttr($value, $data) {
|
||||
return $value ? $value : request()->domain() . '/static/common/images/default_avatar.jpg';
|
||||
}
|
||||
|
||||
protected function setPasswordAttr($value, $data) {
|
||||
return md5($value . $data['salt']);
|
||||
}
|
||||
|
||||
protected function setRegIpAttr($value) {
|
||||
return Server::getRemoteIp();
|
||||
}
|
||||
|
||||
protected function getAccessTokenAttr($value, $data) {
|
||||
$token = ['data' => ['uid' => $data['uid'], 'username' => $data['username'], 'password' => $data['password']]];
|
||||
return JWTAuth::builder($token); //参数为用户认证的信息,请自行添加
|
||||
}
|
||||
|
||||
protected function getNicknameAttr($value, $data){
|
||||
return $value ? $value : $data['username'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
public function login($request) {
|
||||
$username = $request->param('username', '');
|
||||
$password = $request->param('password', '');
|
||||
$type = $request->param('type', 1);
|
||||
$map = [];
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$map['username'] = $username;
|
||||
break;
|
||||
case 2:
|
||||
$map['email'] = $username;
|
||||
break;
|
||||
case 3:
|
||||
$map['mobile'] = $username;
|
||||
break;
|
||||
default:
|
||||
throw new \think\Exception('参数错误', 10006);
|
||||
return false; //参数错误
|
||||
}
|
||||
if (!$username) {
|
||||
throw new \think\Exception('用户名不能为空', 10006);
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->where($map)->find();
|
||||
if (isset($user['uid']) && $user['uid'] && $user['status']) {
|
||||
/* 验证用户密码 */
|
||||
if (md5($password . $user['salt']) === $user['password']) {
|
||||
/* 更新登录信息 */
|
||||
$this->record($user);
|
||||
return $user->append(array('access_token', 'avatar'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
|
||||
} else {
|
||||
throw new \think\Exception('密码错误', 10006);
|
||||
return false; //密码错误
|
||||
}
|
||||
} else {
|
||||
throw new \think\Exception('用户不存在或被禁用', 10006);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title: 注册
|
||||
*/
|
||||
public function register($request) {
|
||||
$data = [];
|
||||
$data['username'] = $request->param('username', '');
|
||||
$data['nickname'] = $request->param('nickname', '');
|
||||
$data['password'] = $request->param('password', '');
|
||||
$data['repassword'] = $request->param('repassword', '');
|
||||
$data['email'] = $request->param('email', '');
|
||||
$data['mobile'] = $request->param('mobile', '');
|
||||
$data['salt'] = \xin\helper\Str::random(6);
|
||||
|
||||
$result = self::create($data);
|
||||
if (false !== $result) {
|
||||
$user = $this->where('uid', $result->uid)->find();
|
||||
} else {
|
||||
$this->error = "注册失败!";
|
||||
return false;
|
||||
}
|
||||
/* 更新登录信息 */
|
||||
$this->record($user);
|
||||
return $user->append(['access_token', 'avatar'])->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
|
||||
}
|
||||
|
||||
/**
|
||||
* @title: 获取用户列表
|
||||
*/
|
||||
public function getUserList($request) {
|
||||
$map = [];
|
||||
$param = $request->param();
|
||||
|
||||
$order = "status desc, uid desc";
|
||||
|
||||
$map[] = ['status', '>=', 0];
|
||||
|
||||
if (isset($param['status']) && $param['status'] != '') {
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
}
|
||||
|
||||
if (isset($param['department']) && $param['department'] != '') {
|
||||
$map[] = ['department', '=', $param['department']];
|
||||
}
|
||||
|
||||
if (isset($param['email']) && $param['email'] != '') {
|
||||
$map[] = ['email', '=', $param['email']];
|
||||
}
|
||||
if (isset($param['name']) && $param['name'] != '') {
|
||||
$map[] = ['username|nickname', 'LIKE', '%' . $param['name'] . '%'];
|
||||
}
|
||||
|
||||
if (isset($param['task_id']) && $param['task_id']) {
|
||||
$map[] = ['uid', 'IN', function ($query) use ($param) {
|
||||
$query->name('task_user')->where('task_id', $param['task_id'])->field('user_id');
|
||||
}];
|
||||
}
|
||||
|
||||
$res = self::with(['role', 'group'])->field('uid,username,nickname,status,email,mobile,department,reg_time')->where($map)->order($order)->paginate($request->pageConfig);
|
||||
$list = $res->append(['avatar', 'status_text'])->each(function($item){
|
||||
if($item['group'] === null){
|
||||
$item['group'] = ['title' => '未定义'];
|
||||
$item['group_title'] = '未定义';
|
||||
}else{
|
||||
$item['group_title'] = $item['group']['title'];
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title: 获取用户列表
|
||||
*/
|
||||
public function getUserDetail($request) {
|
||||
$uid = $request->param('uid');
|
||||
if (!$uid) {
|
||||
$uid = $request->user['uid'];
|
||||
}
|
||||
|
||||
$info = $this->where('uid', $uid)->find();
|
||||
return $info->append(['avatar', 'status_text'])->toArray();
|
||||
}
|
||||
|
||||
public function editUser($request, $uid = 0){
|
||||
$data = $request->post();
|
||||
$data['uid'] = $uid ? $uid : $data['uid'];
|
||||
|
||||
if (!$data['uid']) {
|
||||
return false;
|
||||
}
|
||||
if (isset($data['password']) && $data['password'] !== '') {
|
||||
$data['salt'] = \xin\helper\Str::random(6);
|
||||
return self::update($data, ['uid' => $data]);
|
||||
}else{
|
||||
if(isset($data['password'])){
|
||||
unset($data['password']);
|
||||
}
|
||||
return $this->where('uid', $data['uid'])->save($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录信息更新
|
||||
* @param [type] $user [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function record($user) {
|
||||
/* 更新登录信息 */
|
||||
$data = array(
|
||||
'uid' => $user['uid'],
|
||||
'login' => array('inc', '1'),
|
||||
'last_login_time' => time(),
|
||||
'last_login_ip' => get_client_ip(1),
|
||||
);
|
||||
self::where(['uid' => $user['uid']])->update($data);
|
||||
}
|
||||
|
||||
public static function sendFindPaswd($user){
|
||||
$token = \xin\helper\Secure::encrypt($user['username'] . "|" . $user['email'], \think\facade\Env::get('jwt.secret'));
|
||||
$url = url('/user/index/resetpasswd', ['token'=>$token], true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function depart() {
|
||||
return $this->hasOne('Department', 'id', 'department');
|
||||
}
|
||||
|
||||
public function role() {
|
||||
return $this->hasOne('RoleAccess', 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function group(){
|
||||
return $this->hasOneThrough(AuthGroup::class, AuthGroupAccess::class, 'uid', 'id', 'uid', 'group_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
use think\Model;
|
||||
use xin\helper\Server;
|
||||
|
||||
/**
|
||||
* @title: 用户日志模型
|
||||
*/
|
||||
class MemberLog extends Model {
|
||||
|
||||
protected $type = [
|
||||
'param' => 'json',
|
||||
'visite_time' => 'timestamp',
|
||||
];
|
||||
|
||||
public static function record($request) {
|
||||
$data = [
|
||||
'uid' => isset($request->user['uid']) ? $request->user['uid'] : 0,
|
||||
'title' => self::getCurrentTitle($request),
|
||||
'url' => $request->baseUrl(),
|
||||
'param' => $request->param(),
|
||||
'method' => $request->method(),
|
||||
'visite_time' => $request->time(),
|
||||
'client_ip' => Server::getRemoteIp(),
|
||||
'create_time' => time(),
|
||||
];
|
||||
self::create($data);
|
||||
}
|
||||
|
||||
public function getMemberLogList($request) {
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
$order = "id desc";
|
||||
|
||||
return self::with(['user'])->where($map)->order($order)->paginate($request->pageConfig);
|
||||
}
|
||||
|
||||
public function user() {
|
||||
return $this->hasOne('Member', 'uid', 'uid')->field('uid,nickname,username');
|
||||
}
|
||||
|
||||
protected static function getCurrentTitle($request) {
|
||||
$mate = '';
|
||||
$controller = strtr(strtolower($request->controller()), '.', '\\');
|
||||
$action = $request->action();
|
||||
$class = "\\app\\controller\\" . $controller;
|
||||
if (class_exists($class)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$group_doc = self::Parser($reflection->getDocComment());
|
||||
if (isset($group_doc['title'])) {
|
||||
$mate = $group_doc['title'];
|
||||
}
|
||||
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
|
||||
foreach ($method as $key => $v) {
|
||||
if ($action == $v->name) {
|
||||
$title_doc = self::Parser($v->getDocComment());
|
||||
if (isset($title_doc['title'])) {
|
||||
$mate = $title_doc['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $mate;
|
||||
}
|
||||
|
||||
protected static function Parser($text) {
|
||||
$doc = new \doc\Doc();
|
||||
return $doc->parse($text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
/**
|
||||
* 菜单模型类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Menu extends \think\Model {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected function getIsDevTextAttr($value, $data){
|
||||
$is_dev = [0 => '否', 1 => '是'];
|
||||
return isset($is_dev[$data['is_dev']]) ? $is_dev[$data['is_dev']] : '是';
|
||||
}
|
||||
|
||||
protected function getHideTextAttr($value, $data){
|
||||
$is_dev = [0 => '否', 1 => '是'];
|
||||
return isset($is_dev[$data['hide']]) ? $is_dev[$data['hide']] : '是';
|
||||
}
|
||||
|
||||
public function getAuthNodes($type = 'admin') {
|
||||
$map['type'] = $type;
|
||||
$rows = $this->field('id,pid,group,title,url')->where($map)->order('id asc')->select();
|
||||
foreach ($rows as $key => $value) {
|
||||
$data[$value['id']] = $value;
|
||||
}
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value['pid'] > 0) {
|
||||
$value['group'] = $data[$value['pid']]['title'] . '管理';
|
||||
$list[] = $value;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
/**
|
||||
* 角色模型
|
||||
*/
|
||||
class Role extends \think\Model {
|
||||
|
||||
protected $name = "auth_group";
|
||||
public $type = [
|
||||
'api_auth' => 'json',
|
||||
'component_auth' => 'json',
|
||||
];
|
||||
|
||||
public function getStatusTextAttr($value, $data) {
|
||||
$status = [1 => '开启', 0 => '禁用'];
|
||||
return isset($status[$data['status']]) ? $status[$data['status']] : '未知';
|
||||
}
|
||||
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
$list = self::where($map)->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getUserAuthInfo($request){
|
||||
$data = self::where('id', $request->user['role']['group_id'])->find();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\auth;
|
||||
|
||||
/**
|
||||
* 角色模型
|
||||
*/
|
||||
class RoleAccess extends \think\Model {
|
||||
|
||||
protected $name = "auth_group_access";
|
||||
|
||||
public function getStatusTextAttr($value, $data) {
|
||||
$status = [1 => '开启', 0 => '禁用'];
|
||||
return isset($status[$data['status']]) ? $status[$data['status']] : '未知';
|
||||
}
|
||||
|
||||
public function getDataList($request) {
|
||||
$map = [];
|
||||
|
||||
$list = self::where($map)->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getRoleByUid($uid) {
|
||||
return self::where('uid', $uid)->alias('ra')->field('ra.group_id, r.data_auth,r.api_auth')
|
||||
->join('auth_group r', 'r.id = ra.group_id')
|
||||
->find();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user