Commit b3ba72e6 authored by zfc's avatar zfc

添加角色

parent 7621cdd3
<?php <?php
//打印
function prt($arr){
echo '<pre/>';
print_r($arr);
}
\ No newline at end of file
...@@ -12,6 +12,8 @@ use app\index\extend\Basic; ...@@ -12,6 +12,8 @@ use app\index\extend\Basic;
use app\model\AuthGroup; use app\model\AuthGroup;
class Auth extends Basic class Auth extends Basic
{ {
/** /**
* 权限列表页 * 权限列表页
* *
...@@ -21,12 +23,6 @@ class Auth extends Basic ...@@ -21,12 +23,6 @@ class Auth extends Basic
return view('index'); return view('index');
} }
/**
* 角色编辑
*/
public function roleedit() {
return view('roleedit');
}
/** /**
* 权限分配 * 权限分配
...@@ -55,10 +51,72 @@ class Auth extends Basic ...@@ -55,10 +51,72 @@ class Auth extends Basic
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize']; $pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$auth_group = New AuthGroup(); $auth_group = New AuthGroup();
$where = 'status <> 0'; $where = 'status <> 0';
$data['list'] = $auth_group->getList($pageNo, $pageSize, '','*', $where); $info['list'] = $auth_group->getList($pageNo, $pageSize, '','*', $where);
$data['total'] = $auth_group->getTotal($where); $data['total'] = $auth_group->getTotal($where);
return $this->response(200, '', $data); return $this->response(200, '', $data);
} }
/**
* 角色编辑
*/
public function roleedit() {
//$this->assign('type','1');
// return $this->display();
return view('roleedit');
}
/**
* 验证数据
* @param string $validate 验证器名或者验证规则数组
* @param array $data [description]
* @return [type] [description]
*/
protected function validateData($data,$validate)
{
if (!$validate || empty($data)) return false;
$result = $this->validate($data,$validate);
if(true !== $result){
// 验证失败 输出错误信息
return $result;
}
return 1;
}
//添加角色
public function addAuth($group_id=0){
$data['status'] = 200;
$data['msg'] = '';
$title = $group_id ? '编辑':'新增';
$table= New AuthGroup();
$info= $table->find();
if (empty($group_id)) {
$data = input('post.');
$err=$this->validateData($data,
[
['title','require|chsAlpha','用户组名称不能为空|用户组名称只能是汉字和字母'],
['description','chsAlphaNum','描述只能是汉字字母数字']
]
);
if($err!=1){
return $this->response(100, $err);
}
$id = isset($data['id']) && $data['id']>0 ? $data['id']:false;
if ($table->editData($data,$id)) {
return $this->response(200, '成功');
} else {
return $this->response(101, '失败');
}
} else {
return $this->response(200, $title, $info);
}
}
} }
\ No newline at end of file
{layout name="global/frame_tpl" /} {layout name="global/frame_tpl" /}
<h4>权限管理</h4>
<a href="/index/roleedit">添加角色</a>
<input type="hidden" class="page-load" id="auth" /> <input type="hidden" class="page-load" id="auth" />
<div id="page-content-wrapper"> <div id="page-content-wrapper">
<div class="container"> <div class="container">
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<div class="successModel"> <div class="successModel">
<div class="successModel-center"> <div class="successModel-center">
<p> <p>
提交成功! <!--提交成功!-->
</p> </p>
</div> </div>
</div> </div>
......
...@@ -24,6 +24,29 @@ class BaseModel extends Model ...@@ -24,6 +24,29 @@ class BaseModel extends Model
return $this->where($params)->count(); return $this->where($params)->count();
} }
/**
* 新增或编辑数据
* @param array/object $data 来源数据
* @param boolean $kv 主键值
* @param string $key 主键名
* @return [type] 执行结果
*/
public function editData($data,$kv=false,$key='id',$confirm=false)
{
$this->allowField(true);
if ($confirm) {//是否验证
$this->validate($confirm);
}
if($kv){//编辑
$res=$this->save($data,[$key=>$kv]);
}else{
$res=$this->data($data)->save();
}
return $res;
}
/** /**
* 列表 * 列表
* *
......
...@@ -75,6 +75,7 @@ Route::group('index', [ ...@@ -75,6 +75,7 @@ Route::group('index', [
'addVersion' => ['index/version/addVersion',['method'=>'post']], 'addVersion' => ['index/version/addVersion',['method'=>'post']],
'getAuth' => ['index/auth/getAuth', ['method' => 'get']], //权限列表 'getAuth' => ['index/auth/getAuth', ['method' => 'get']], //权限列表
'access' => ['index/auth/access', ['method' => 'get']], //权限分配 'access' => ['index/auth/access', ['method' => 'get']], //权限分配
'addAuth' => ['index/auth/addAuth', ['method' => 'post']], //添加角色
'roleedit' => ['index/auth/roleedit', ['method' => 'get']], //编辑角色 'roleedit' => ['index/auth/roleedit', ['method' => 'get']], //编辑角色
'accessUser' => ['index/auth/accessUser', ['method' => 'get']], //成员授权 'accessUser' => ['index/auth/accessUser', ['method' => 'get']], //成员授权
'BusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'get']], //商圈列表 'BusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'get']], //商圈列表
...@@ -85,7 +86,8 @@ Route::group('index', [ ...@@ -85,7 +86,8 @@ Route::group('index', [
'houseEdit' => ['index/Houses/edit', ['method' => 'get|post']], //编辑商铺 'houseEdit' => ['index/Houses/edit', ['method' => 'get|post']], //编辑商铺
'houseDel' => ['index/Houses/del', ['method' => 'get']], //删除商铺 'houseDel' => ['index/Houses/del', ['method' => 'get']], //删除商铺
'regions' => ['index/BusinessDistrict/regions', ['method' => 'get']], //获取省市区数据 'regions' => ['index/BusinessDistrict/regions', ['method' => 'get']], //获取省市区数据
'getHouseList' => ['index/houses/getHouseList', ['method' => 'get']] 'getHouseList' => ['index/houses/getHouseList', ['method' => 'get']],
'regions' => ['index/BusinessDistrict/regions', ['method' => 'get']], //删除商铺
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment