init
This commit is contained in:
167
app/admin/controller/AuthAccess.php
Executable file
167
app/admin/controller/AuthAccess.php
Executable file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Config;
|
||||
|
||||
class AuthAccess extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$this->redirect('/admin/auth_access/lists');
|
||||
}
|
||||
|
||||
public function lists() {
|
||||
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
||||
$arg_where = array('aa.stat' => 0);
|
||||
$arg_order = array('aa.id' => 'asc');
|
||||
$arg_field = array('aa.id', 'aa.name', 'aa.gid', 'ag.name' => 'group', 'aa.access', 'aa.stat', 'aa.module');
|
||||
if (!empty($skeyword)) {
|
||||
$skeyword = trim($skeyword);
|
||||
$arg_where['aa.name'] = ['like', '%' . $skeyword . '%'];
|
||||
$search['skeyword'] = $skeyword;
|
||||
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
||||
} else {
|
||||
$search['skeyword'] = '';
|
||||
}
|
||||
$dataObject = Loader::model('AuthAccess')->getAuthAccessLists($arg_where, $arg_order, $arg_field, 24);
|
||||
$value = [
|
||||
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
||||
'page' => $dataObject->render(),
|
||||
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
|
||||
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
|
||||
'search' => $search,
|
||||
];
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function edit($id = 0) {
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$auth_access = Loader::model('AuthAccess')->getRow($id);
|
||||
if (empty($auth_access)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$value['auth_access'] = $auth_access;
|
||||
} else {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$groupOption = Loader::model('AuthGroup')->getOption($auth_access['gid'], ['stat' => 0], ['id' => 'asc'], ['id', 'name',], 50);
|
||||
$value['groupOption'] = $groupOption;
|
||||
$ctrlOption = get_ctrl_names('admin');
|
||||
$value['ctrlOption'] = $ctrlOption;
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function update() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (empty($data) || !is_array($data)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
} else {
|
||||
foreach ($data as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
$data[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
$validaterule = ['id' => 'require', 'name' => 'require', 'gid' => 'between:0,2147483647', 'module' => 'require', 'agree' => 'require|accepted',];
|
||||
$validatemsg = ['name.require' => '名称不能为空', 'gid.between' => '权限组不能为空', 'module.require' => '模块不能为空',
|
||||
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$access_row['id'] = $data['id'];
|
||||
$access_row['name'] = $data['name'];
|
||||
$access_row['gid'] = $data['gid'];
|
||||
$access_row['module'] = $data['module'];
|
||||
$access_row['access'] = implode(',', $data['access']);
|
||||
$model = Loader::model('AuthAccess')->updateRow($access_row);
|
||||
if ($model && $model->getData('id')) {
|
||||
$this->cacheClear('AuthAccessTag');
|
||||
return $this->redirect(url('/admin/auth_access/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$groupOption = Loader::model('AuthGroup')->getOption(0, ['stat' => 0], ['id' => 'asc'], [ 'id', 'name',], 50);
|
||||
$value['groupOption'] = $groupOption;
|
||||
$ctrlOption = get_ctrl_names('admin');
|
||||
$value['ctrlOption'] = $ctrlOption;
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (empty($data) || !is_array($data)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
} else {
|
||||
foreach ($data as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
$data[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
$validaterule = ['name' => 'require', 'gid' => 'between:0,2147483647', 'module' => 'require', 'agree' => 'require|accepted',];
|
||||
$validatemsg = ['name.require' => '名称不能为空', 'gid.between' => '权限组不能为空', 'module.require' => '模块不能为空',
|
||||
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$access_row['name'] = $data['name'];
|
||||
$access_row['gid'] = $data['gid'];
|
||||
$access_row['module'] = $data['module'];
|
||||
$access_row['access'] = implode(',', $data['access']);
|
||||
$model = Loader::model('AuthAccess')->insertRow($access_row);
|
||||
if ($model && $model->getData('id')) {
|
||||
$this->cacheClear('AuthAccessTag');
|
||||
return $this->redirect(url('/admin/auth_access/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
|
||||
public function delete($id = 0) {
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$result = Loader::model('AuthAccess')->deleteRow($id);
|
||||
if ($result) {
|
||||
$this->cacheClear('AuthAccessTag');
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/auth_access/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function deletes() {
|
||||
$data = $this->request->post();
|
||||
if ($this->request->isPost() && $data['ids']) {
|
||||
$result = Loader::model('AuthAccess')->deleteRows($data['ids']);
|
||||
if ($result) {
|
||||
$this->cacheClear('AuthAccessTag');
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/auth_access/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user