From 4893580b70bc771e5032805f8fc79823af77f724 Mon Sep 17 00:00:00 2001 From: tensent Date: Sat, 28 Mar 2020 20:39:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/Group.php | 135 ++++++++++++++++---------------- app/controller/admin/Wechat.php | 18 +---- app/model/AuthGroup.php | 7 ++ app/model/AuthRule.php | 32 ++++---- app/model/Form.php | 8 +- app/model/Link.php | 7 +- view/admin/group/access.html | 14 ++-- view/admin/model/index.html | 10 +-- view/admin/wechat/miniapp.html | 37 +++++++++ 9 files changed, 149 insertions(+), 119 deletions(-) create mode 100644 view/admin/wechat/miniapp.html diff --git a/app/controller/admin/Group.php b/app/controller/admin/Group.php index 61645062..f16c836f 100644 --- a/app/controller/admin/Group.php +++ b/app/controller/admin/Group.php @@ -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'); } } diff --git a/app/controller/admin/Wechat.php b/app/controller/admin/Wechat.php index 8ba961ac..4581539e 100644 --- a/app/controller/admin/Wechat.php +++ b/app/controller/admin/Wechat.php @@ -133,24 +133,10 @@ class Wechat extends Base { } /** - * @title 行为日志列表 + * @title 小程序列表 * @author huajie */ - 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(); } /** diff --git a/app/model/AuthGroup.php b/app/model/AuthGroup.php index 774a632c..5fbfdf96 100644 --- a/app/model/AuthGroup.php +++ b/app/model/AuthGroup.php @@ -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' => '启用']]], + ]; } \ No newline at end of file diff --git a/app/model/AuthRule.php b/app/model/AuthRule.php index cf955e8e..74b43e04 100644 --- a/app/model/AuthRule.php +++ b/app/model/AuthRule.php @@ -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; } diff --git a/app/model/Form.php b/app/model/Form.php index 457be463..ced7f6fe 100644 --- a/app/model/Form.php +++ b/app/model/Form.php @@ -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' => ''], diff --git a/app/model/Link.php b/app/model/Link.php index 5b551aa4..ab9cabe6 100644 --- a/app/model/Link.php +++ b/app/model/Link.php @@ -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' ); } \ No newline at end of file diff --git a/view/admin/group/access.html b/view/admin/group/access.html index 26426301..470542a9 100644 --- a/view/admin/group/access.html +++ b/view/admin/group/access.html @@ -6,11 +6,11 @@

{$meta_title}

- + 添加节点 - + 更新节点 @@ -19,9 +19,9 @@
@@ -59,8 +59,8 @@ {/if} - 编辑 - 删除 + 编辑 + 删除 {/volist} diff --git a/view/admin/model/index.html b/view/admin/model/index.html index c2d43a1d..1813d962 100644 --- a/view/admin/model/index.html +++ b/view/admin/model/index.html @@ -50,11 +50,11 @@ {/if} - 字段 - {$item['status'] ? '禁用' : '启用'} - 编辑 - 删除 - 数据 + 字段 + {$item['status'] ? '禁用' : '启用'} + 编辑 + 删除 + 数据 {/volist} diff --git a/view/admin/wechat/miniapp.html b/view/admin/wechat/miniapp.html new file mode 100644 index 00000000..d1ad7cec --- /dev/null +++ b/view/admin/wechat/miniapp.html @@ -0,0 +1,37 @@ +{extend name="admin/public/base"/} + +{block name="body"} +
+
+ +
+

{$meta_title}

+
+
+ 清 空 + +
+
+ +
+ + + + + + + + + + + + + + +
编号行为名称执行者执行时间操作
+ + + +
+
+{/block} \ No newline at end of file