更新功能

This commit is contained in:
2020-03-28 20:39:39 +08:00
parent 5ef77bb8f4
commit 4893580b70
9 changed files with 149 additions and 119 deletions

View File

@@ -10,6 +10,7 @@ namespace app\controller\admin;
use app\model\AuthGroup;
use app\model\AuthRule;
use app\model\Model;
/**
* @title 用户组管理
@@ -40,20 +41,20 @@ class Group extends Base {
*/
public function add($type = 'admin') {
if ($this->request->isPost()) {
$result = $this->group->change();
if ($result) {
return $this->success("添加成功!", url('admin/group/index'));
$data = $this->request->param();
$result = AuthGroup::create($data);
if (false !== $result) {
return $this->success("添加成功!", url('/admin/group/index'));
} else {
return $this->error("添加失败!");
}
} else {
$data = array(
'info' => array('module' => $type, 'status' => 1),
'keyList' => $this->group->keyList,
$this->data = array(
'info' => ['module' => $type, 'status' => 1],
'keyList' => (new AuthGroup())->keyList,
);
$this->assign($data);
$this->setMeta('添加用户组');
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -61,25 +62,24 @@ class Group extends Base {
* @title 编辑用户组
*/
public function edit($id) {
if (!$id) {
return $this->error("非法操作!");
}
if ($this->request->isPost()) {
$result = $this->group->change();
if ($result) {
return $this->success("编辑成功!", url('admin/group/index'));
$data = $this->request->param();
$result = AuthGroup::update($data);
if (false !== $result) {
return $this->success("编辑成功!", url('/admin/group/index'));
} else {
return $this->error("编辑失败!");
}
} else {
$info = $this->group->where(array('id' => $id))->find();
$data = array(
if (!$id) {
return $this->error("非法操作!");
}
$info = AuthGroup::find($id);
$this->data = array(
'info' => $info,
'keyList' => $this->group->keyList,
'keyList' => (new AuthGroup())->keyList,
);
$this->assign($data);
$this->setMeta('编辑用户组');
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -87,14 +87,13 @@ class Group extends Base {
* @title 编辑用户组单字段
*/
public function editable() {
$pk = input('pk', '', 'trim,intval');
$name = input('name', '', 'trim');
$value = input('value', '', 'trim');
$result = $this->group->where(array('id' => $pk))->setField($name, $value);
if ($result) {
return $this->success("删除成功!");
} else {
return $this->error("删除失败!");
$name = $this->request->param('name', '');
$value = $this->request->param('value', '');
$pk = $this->request->param('pk', '');
if ($name && $value && $pk) {
$save[$name] = $value;
AuthGroup::update($save, ['id' => $pk]);
}
}
@@ -102,12 +101,16 @@ class Group extends Base {
* @title 删除用户组
*/
public function del() {
$id = $this->getArrayParam('id');
if (empty($id)) {
$id = $this->request->param('id', 0);
$map = [];
if (!$id) {
return $this->error("非法操作!");
}
$result = $this->group->where(array('id' => array('IN', $id)))->delete();
if ($result) {
$map[] = is_array($id) ? ['id', 'IN', $id] : ['id', '=', $id];
$result = AuthGroup::where($map)->delete();
if (false !== $result) {
return $this->success("删除成功!");
} else {
return $this->error("删除失败!");
@@ -136,9 +139,12 @@ class Group extends Base {
* @title 更新权限
*/
public function upnode($type) {
//$rule = model('Menu')->getAuthNodes($type);
$reuslt = $this->rule->uprule($type);
return $this->success("更新成功!");
$reuslt = AuthRule::uprule($type);
if (false !== $result) {
return $this->success("更新成功!");
}else{
return $this->error("更新失败!");
}
}
/**
@@ -174,31 +180,28 @@ class Group extends Base {
return $this->error("授权失败!");
}
} else {
$group = $this->group->where(array('id' => $id))->find();
$group = AuthGroup::find($id);
$map['module'] = $group['module'];
$row = db('AuthRule')->where($map)->order('id desc')->select();
$map[] = ['module', '=', $group['module']];
$row = AuthRule::where($map)->order('id desc')->select();
$list = array();
foreach ($row as $key => $value) {
foreach ($row as $value) {
$list[$value['group']][] = $value;
}
//模块
$model = db('model')->field('id,title,name')
->where(array('status' => array('gt', 0)))
->select();
$model = Model::where('status', '>', 0)->field('id,title,name')->select();
//扩展权限
$extend_auth = db('AuthExtend')->where(array('group_id' => $id, 'type' => 2))->column('extend_id');
$data = array(
// $extend_auth = db('AuthExtend')->where(array('group_id' => $id, 'type' => 2))->column('extend_id');
$this->data = array(
'list' => $list,
'model' => $model,
'extend_auth' => $extend_auth,
// 'extend_auth' => $extend_auth,
'extend_auth' => [],
'auth_list' => explode(',', $group['rules']),
'id' => $id,
);
$this->assign($data);
$this->setMeta('授权');
return $this->fetch();
}
}
@@ -208,20 +211,19 @@ class Group extends Base {
*/
public function addnode($type = 'admin') {
if ($this->request->isPost()) {
$result = $this->rule->change();
$data = $this->request->post();
$result = AuthRule::create($data);
if ($result) {
return $this->success("创建成功!", url('admin/group/access'));
return $this->success("创建成功!", url('/admin/group/access'));
} else {
return $this->error($this->rule->getError());
return $this->error('添加失败!');
}
} else {
$data = array(
'info' => array('module' => $type, 'status' => 1),
'keyList' => $this->rule->keyList,
);
$this->assign($data);
$this->setMeta('添加节点');
return $this->fetch('public/edit');
$this->data = [
'info' => ['module' => $type, 'status' => 1],
'keyList' => (new AuthRule())->keyList,
];
return $this->fetch('admin/public/edit');
}
}
@@ -230,9 +232,10 @@ class Group extends Base {
*/
public function editnode($id) {
if ($this->request->isPost()) {
$result = $this->rule->change();
$data = $this->request->post();
$result = AuthRule::update($data);
if (false !== $result) {
return $this->success("更新成功!", url('admin/group/access'));
return $this->success("更新成功!", url('/admin/group/access'));
} else {
return $this->error("更新失败!");
}
@@ -240,14 +243,12 @@ class Group extends Base {
if (!$id) {
return $this->error("非法操作!");
}
$info = $this->rule->find($id);
$data = array(
$info = AuthRule::find($id);
$this->data = [
'info' => $info,
'keyList' => $this->rule->keyList,
);
$this->assign($data);
$this->setMeta('编辑节点');
return $this->fetch('public/edit');
'keyList' => (new AuthRule())->keyList,
];
return $this->fetch('admin/public/edit');
}
}

View File

@@ -133,24 +133,10 @@ class Wechat extends Base {
}
/**
* @title 行为日志列表
* @title 小程序列表
* @author huajie <banhuajie@163.com>
*/
public function log() {
//获取列表数据
$map['status'] = array('gt', -1);
$order = "id desc";
//获取列表数据
$list = model('ActionLog')->where($map)->order($order)->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render(),
);
$this->assign($data);
$this->setMeta('行为日志');
public function miniapp() {
return $this->fetch();
}
/**

View File

@@ -16,4 +16,11 @@ 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', 'help'=>'', 'option'=>''],
['name'=>'description', 'title'=>'分组描述', 'type'=>'textarea', 'help'=>'', 'option'=>''],
['name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=> [['key' => 0, 'label' => '禁用'],['key' => 1, 'label' => '启用']]],
];
}

View File

@@ -23,16 +23,16 @@ class AuthRule extends Model{
'id' => 'integer',
);
public $keyList = array(
array('name'=>'module','title'=>'所属模块','type'=>'hidden'),
array('name'=>'title','title'=>'节点名称','type'=>'text','help'=>''),
array('name'=>'name','title'=>'节点标识','type'=>'text','help'=>''),
array('name'=>'group','title'=>'功能组','type'=>'text','help'=>'功能分组'),
array('name'=>'status','title'=>'状态','type'=>'select','option'=>array('1'=>'用','0'=>'用'),'help'=>''),
array('name'=>'condition','title'=>'条件','type'=>'text','help'=>'')
);
public $keyList = [
['name'=>'module','title'=>'所属模块','type'=>'hidden'],
['name'=>'title','title'=>'节点名称','type'=>'text','help'=>''],
['name'=>'name','title'=>'节点标识','type'=>'text','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 function uprule($data, $type){
public static function uprule($type){
foreach ($data as $value) {
$data = array(
'module' => $type,
@@ -42,13 +42,13 @@ class AuthRule extends Model{
'group' => $value['group'],
'status' => 1,
);
$id = $this->where(array('name' => $data['name']))->value('id');
if ($id) {
$data['id'] = $id;
$this->save($data, array('id' => $id));
} else {
self::create($data);
}
// $id = $this->where(array('name' => $data['name']))->value('id');
// if ($id) {
// $data['id'] = $id;
// $this->save($data, array('id' => $id));
// } else {
// self::create($data);
// }
}
return true;
}

View File

@@ -21,11 +21,9 @@ class Form extends \think\Model {
protected $auto = ['update_time'];
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid' => "id:ID\r\ntitle:标题\r\ncreate_time:添加时间|time_format\r\nupdate_time:更新时间|time_format"];
protected $type = array(
'id' => 'integer',
'create_time' => 'integer',
'update_time' => 'integer',
);
protected $type = [
'id' => 'integer'
];
public $addField = [
['name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''],

View File

@@ -14,6 +14,9 @@ namespace app\model;
*/
class Link extends \think\Model {
protected $auto = ['update_time'];
protected $insert = ['create_time'];
public $keyList = array(
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden'),
array('name' => 'title', 'title' => '友链标题', 'type' => 'text', 'help' => ''),
@@ -30,10 +33,8 @@ class Link extends \think\Model {
array('name' => 'descrip', 'title' => '描述', 'type' => 'textarea', 'help' => ''),
);
protected $auto = array('update_time');
protected $type = array(
'cover_id' => 'integer',
'sort' => 'integer',
'sort' => 'integer'
);
}