更新功能

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

View File

@@ -133,24 +133,10 @@ class Wechat extends Base {
} }
/** /**
* @title 行为日志列表 * @title 小程序列表
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
*/ */
public function log() { public function miniapp() {
//获取列表数据
$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('行为日志');
return $this->fetch(); return $this->fetch();
} }
/** /**

View File

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

View File

@@ -21,11 +21,9 @@ class Form extends \think\Model {
protected $auto = ['update_time']; 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 $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( protected $type = [
'id' => 'integer', 'id' => 'integer'
'create_time' => 'integer', ];
'update_time' => 'integer',
);
public $addField = [ public $addField = [
['name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''], ['name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''],

View File

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

View File

@@ -6,11 +6,11 @@
<h2>{$meta_title}</h2> <h2>{$meta_title}</h2>
</div> </div>
<div class="pull-right"> <div class="pull-right">
<a href="{:url('Group/addnode',array('type'=>$type))}" class="btn btn-danger"> <a href="{:url('/admin/group/addnode',array('type'=>$type))}" class="btn btn-danger">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
添加节点 添加节点
</a> </a>
<a href="{:url('Group/upnode',array('type'=>$type))}" class="btn btn-danger ajax-get"> <a href="{:url('/admin/group/upnode',array('type'=>$type))}" class="btn btn-danger ajax-get">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
更新节点 更新节点
</a> </a>
@@ -19,9 +19,9 @@
<div class="main-box-body clearfix"> <div class="main-box-body clearfix">
<div class="tabs-wrapper"> <div class="tabs-wrapper">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
{volist name=":config('user_group_type')" id="item"} {volist name="config['user_group_type']" id="item"}
<li {if condition="$key eq $type"}class="active"{/if}> <li {if $item['key'] eq $type}class="active"{/if}>
<a href="{:url('Group/access',array('type'=>$key))}">{$item}</a> <a href="{:url('/admin/group/access', ['type'=>$item['key']])}">{$item['label']}</a>
</li> </li>
{/volist} {/volist}
</ul> </ul>
@@ -59,8 +59,8 @@
{/if} {/if}
</td> </td>
<td> <td>
<a href="{:url('Group/editnode',array('id'=>$item['id']))}">编辑</a> <a href="{:url('/admin/group/editnode',array('id'=>$item['id']))}">编辑</a>
<a href="{:url('Group/delnode',array('id'=>$item['id']))}" class="confirm ajax-get">删除</a> <a href="{:url('/admin/group/delnode',array('id'=>$item['id']))}" class="confirm ajax-get">删除</a>
</td> </td>
</tr> </tr>
{/volist} {/volist}

View File

@@ -50,11 +50,11 @@
{/if} {/if}
</td> </td>
<td> <td>
<a href="{:url('admin/attribute/index?model_id='.$item['id'])}">字段</a> <a href="{:url('/admin/attribute/index', ['model_id'=>$item['id']])}">字段</a>
<a href="{:url('model/status?id='.$item['id'].'&status='.abs(1-$item['status']))}" class="ajax-get">{$item['status'] ? '禁用' : '启用'}</a> <a href="{:url('/admin/model/status?id='.$item['id'].'&status='.abs(1-$item['status']))}" class="ajax-get">{$item['status'] ? '禁用' : '启用'}</a>
<a href="{:url('model/edit?id='.$item['id'])}">编辑</a> <a href="{:url('/admin/model/edit', ['id'=>$item['id']])}">编辑</a>
<a href="{:url('model/del?id='.$item['id'])}" class="confirm ajax-get">删除</a> <a href="{:url('/admin/model/del', ['id'=>$item['id']])}" class="confirm ajax-get">删除</a>
<a href="{:url('admin/content/index?model_id='.$item['id'])}">数据</a> <a href="{:url('/admin/content/index?model_id='.$item['id'])}">数据</a>
</td> </td>
</tr> </tr>
{/volist} {/volist}

View File

@@ -0,0 +1,37 @@
{extend name="admin/public/base"/}
{block name="body"}
<div class="main-box no-header clearfix">
<header class="main-box-header clearfix">
<!-- 标题栏 -->
<div class="pull-left">
<h2>{$meta_title}</h2>
</div>
<div class="pull-right">
<a class="btn btn-warning ajax-get confirm" href="{:url('clear')}">清 空</a>
<button class="btn btn-danger ajax-post confirm" target-form="ids" url="{:url('dellog')}">删 除</button>
</div>
</header>
<div class="main-box-body clearfix">
<!-- 数据列表 -->
<table class="table table-striped">
<thead>
<tr>
<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
<th class="">编号</th>
<th class="">行为名称</th>
<th class="">执行者</th>
<th class="">执行时间</th>
<th class="">操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<!-- 分页 -->
<!-- /分页 -->
</div>
</div>
{/block}