From 2482e6f3040a27ed5679cea1e87eb7f894970138 Mon Sep 17 00:00:00 2001 From: tensent Date: Mon, 27 Apr 2020 18:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E6=A0=8F=E7=9B=AE=E6=97=A0=E6=B3=95=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=9A=84bug=EF=BC=8C=E8=AE=B0=E5=BD=95=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/middleware/Admin.php | 6 ++-- app/model/Attribute.php | 66 +++++++++++++++++------------------ app/model/MemberLog.php | 44 +++++++++++++++++++---- 3 files changed, 74 insertions(+), 42 deletions(-) diff --git a/app/http/middleware/Admin.php b/app/http/middleware/Admin.php index 4fc5356f..3c650896 100755 --- a/app/http/middleware/Admin.php +++ b/app/http/middleware/Admin.php @@ -8,6 +8,7 @@ // +---------------------------------------------------------------------- namespace app\http\middleware; +use app\model\MemberLog; use think\facade\Session; /** @@ -17,14 +18,15 @@ class Admin { public function handle($request, \Closure $next) { $request->rootUid = env('rootuid'); - $request->user = Session::get('userInfo'); + $request->user = Session::get('adminInfo'); $request->url = str_replace(".", "/", strtolower($request->controller())) . '/' . $request->action(); $request->pageConfig = array( 'list_rows' => $request->param('limit', 20), 'page' => $request->param('page', 1), - 'query' => $request->param() + 'query' => $request->param(), ); + MemberLog::record($request); $response = $next($request); return $response; diff --git a/app/model/Attribute.php b/app/model/Attribute.php index a0391ce2..a6875b11 100644 --- a/app/model/Attribute.php +++ b/app/model/Attribute.php @@ -8,10 +8,10 @@ // +---------------------------------------------------------------------- namespace app\model; +use app\model\Model as Models; +use sent\tree\Tree; use think\facade\Config; use think\facade\Db; -use sent\tree\Tree; -use app\model\Model as Models; /** * 设置模型 @@ -25,7 +25,7 @@ class Attribute extends \think\Model { /** * @title 新增后事件 */ - protected static function onAfterInsert($data){ + protected static function onAfterInsert($data) { $data = $data->toArray(); if ($data['model_id']) { $db = new \com\Datatable(); @@ -38,7 +38,7 @@ class Attribute extends \think\Model { /** * @title 更新后事件 */ - protected static function onAfterUpdate($data){ + protected static function onAfterUpdate($data) { $data = $data->toArray(); if (isset($data['model_id']) && isset($data['name'])) { $tablename = Models::where('id', $data['model_id'])->value('name'); @@ -50,7 +50,7 @@ class Attribute extends \think\Model { $data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id asc')->value('name'); $result = $db->columField(strtolower($tablename), $data)->query(); return $result; - }else{ + } else { return false; } } @@ -58,7 +58,7 @@ class Attribute extends \think\Model { /** * @title 删除后事件 */ - protected static function onAfterDelete($data){ + protected static function onAfterDelete($data) { $data = $data->toArray(); if ($data['model_id']) { $tablename = Models::where('id', $data['model_id'])->value('name'); @@ -67,11 +67,11 @@ class Attribute extends \think\Model { $db = new \com\Datatable(); if (!$db->CheckField($tablename, $data['name'])) { $result = true; - }else{ + } else { $result = $db->delField($tablename, $data['name'])->query(); } return $result; - }else{ + } else { return false; } } @@ -85,7 +85,7 @@ class Attribute extends \think\Model { return isset($type[$data['type']]) ? $type[$data['type']] : ''; } - protected function getOptionAttr($value, $data){ + protected function getOptionAttr($value, $data) { $list = []; if ($data == '') { return $list; @@ -96,13 +96,13 @@ class Attribute extends \think\Model { if (strrpos($val, ":")) { list($key, $label) = explode(":", $val); $list[] = ['key' => $key, 'label' => $label]; - }else{ + } else { $list[] = ['key' => $k, 'label' => $val]; } } - }elseif($data['type'] == 'bool'){ - $list = [['key'=>0,'label'=>'禁用'],['key'=>1,'label'=>'启用']]; - }elseif($data['type'] == 'bind'){ + } elseif ($data['type'] == 'bool') { + $list = [['key' => 0, 'label' => '禁用'], ['key' => 1, 'label' => '启用']]; + } elseif ($data['type'] == 'bind') { $map = []; $db = new \com\Datatable(); if (strrpos($data['extra'], ":")) { @@ -110,34 +110,34 @@ class Attribute extends \think\Model { if ($db->CheckField($extra[0], 'model_id')) { $map[] = ['model_id', '=', $data['model_id']]; } - $row = Db::name($extra[0])->where($map)->select()->toArray(); - if(empty($row)){ + $row = Db::name($extra[0])->where($map)->select()->toArray(); + if (empty($row)) { return []; } if ($extra[1] == 'tree') { $row = (new Tree())->toFormatTree($row); foreach ($row as $val) { - $list[] = ['key'=>$val['id'], 'label'=>$val['title_show']]; + $list[] = ['key' => $val['id'], 'label' => $val['title_show']]; } - }else{ + } else { foreach ($row as $val) { - $list[] = ['key'=>$val['id'], 'label'=>$val['title']]; + $list[] = ['key' => $val['id'], 'label' => $val['title']]; } } - }else{ + } else { if ($db->CheckField($data['extra'], 'model_id')) { $map[] = ['model_id', '=', $data['model_id']]; } - $row = Db::name($data['extra'])->select($map)->toArray(); + $row = Db::name($data['extra'])->where($map)->select()->toArray(); foreach ($row as $val) { - $list[] = ['key'=>$val['id'], 'label'=>$val['title']]; + $list[] = ['key' => $val['id'], 'label' => $val['title']]; } } } return $list; } - public static function getField($model, $ac = "add"){ + public static function getField($model, $ac = "add") { $list = []; $group = $model['attr_group']; @@ -145,7 +145,7 @@ class Attribute extends \think\Model { $map[] = ['model_id', '=', $model['id']]; if ($ac == 'add') { $map[] = ['is_show', 'IN', [1, 2]]; - }else if ($ac == 'edit') { + } else if ($ac == 'edit') { $map[] = ['is_show', 'IN', [1, 3]]; } @@ -156,7 +156,7 @@ class Attribute extends \think\Model { foreach ($row as $key => $value) { if (isset($group[$value['group_id']])) { $list[$group[$value['group_id']]['label']][] = $value; - }else{ + } else { $list[$value['group_id']][] = $value; } } @@ -164,26 +164,26 @@ class Attribute extends \think\Model { return $list; } - public static function getfieldList(){ + public static function getfieldList() { $config = \think\facade\Cache::get('system_config_data'); - $time = [['key'=>1, 'label'=>'新增'],['key'=>2, 'label'=>'编辑'],['key'=>3, 'label'=>'始终']]; - $auto_type = [['key'=>'function', 'label'=>'函数'],['key'=>'field', 'label'=>'字段'],['key'=>'string', 'label'=>'字符串']]; - $validate_type = [['key'=>'thinkphp', 'label'=>'thinkphp内置'],['key'=>'regex', 'label'=>'正则验证']]; + $time = [['key' => 1, 'label' => '新增'], ['key' => 2, 'label' => '编辑'], ['key' => 3, 'label' => '始终']]; + $auto_type = [['key' => 'function', 'label' => '函数'], ['key' => 'field', 'label' => '字段'], ['key' => 'string', 'label' => '字符串']]; + $validate_type = [['key' => 'thinkphp', 'label' => 'thinkphp内置'], ['key' => 'regex', 'label' => '正则验证']]; return [ '基础' => [ ['name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'], ['name' => 'model_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'], - ['name' => 'name', 'title' => '字段名', 'help' => '英文字母开头,长度不超过30', 'is_must'=> true, 'type' => 'text'], - ['name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'is_must'=> true, 'type' => 'text'], + ['name' => 'name', 'title' => '字段名', 'help' => '英文字母开头,长度不超过30', 'is_must' => true, 'type' => 'text'], + ['name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'is_must' => true, 'type' => 'text'], ['name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $config['config_type_list'], 'help' => ''], ['name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'], ['name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'], ['name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'], ['name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'], ['name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => [ - ['key'=>'1', 'label' => '始终显示'], ['key'=>'2', 'label' => '新增显示'], ['key'=>'3', 'label' => '编辑显示'], ['key'=>'0', 'label' => '不显示'] - ], 'value' => 1], - ['name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => [['key'=>'0', 'label' => '否'], ['key'=>'1', 'label' => '是']]], + ['key' => '1', 'label' => '始终显示'], ['key' => '2', 'label' => '新增显示'], ['key' => '3', 'label' => '编辑显示'], ['key' => '0', 'label' => '不显示'], + ], 'value' => 1], + ['name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => [['key' => '0', 'label' => '否'], ['key' => '1', 'label' => '是']]], ], '高级' => [ // ['name' => 'validate_type', 'title' => '验证方式', 'type' => 'select', 'option' => $validate_type, 'help' => ''], diff --git a/app/model/MemberLog.php b/app/model/MemberLog.php index d5abf27b..39f14910 100644 --- a/app/model/MemberLog.php +++ b/app/model/MemberLog.php @@ -18,18 +18,19 @@ use xin\helper\Server; class MemberLog extends Model { protected $type = [ - 'param' => 'json', + 'param' => 'json', 'visite_time' => 'timestamp', ]; public static function record($request) { $data = [ - 'uid' => $request->user['uid'], - 'url' => $request->baseUrl(), - 'param' => $request->param(), - 'method' => $request->method(), + 'uid' => $request->user['uid'], + 'title' => self::getCurrentTitle($request), + 'url' => $request->baseUrl(), + 'param' => $request->param(), + 'method' => $request->method(), 'visite_time' => $request->time(), - 'client_ip' => Server::getRemoteIp(), + 'client_ip' => Server::getRemoteIp(), 'create_time' => time(), ]; self::create($data); @@ -37,7 +38,7 @@ class MemberLog extends Model { public function getMemberLogList($request) { $param = $request->param(); - $map = []; + $map = []; $order = "id desc"; return self::with(['user'])->where($map)->order($order)->paginate($request->pageConfig); @@ -46,4 +47,33 @@ class MemberLog extends Model { public function user() { return $this->hasOne('Member', 'uid', 'uid')->field('uid,nickname,username'); } + + protected static function getCurrentTitle($request) { + $mate = ''; + $controller = strtr(strtolower($request->controller()), '.', '\\'); + $action = $request->action(); + $class = "\\app\\controller\\" . $controller; + if (class_exists($class)) { + $reflection = new \ReflectionClass($class); + $group_doc = self::Parser($reflection->getDocComment()); + if (isset($group_doc['title'])) { + $mate = $group_doc['title']; + } + $method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC); + foreach ($method as $key => $v) { + if ($action == $v->name) { + $title_doc = self::Parser($v->getDocComment()); + if (isset($title_doc['title'])) { + $mate = $title_doc['title']; + } + } + } + } + return $mate; + } + + protected static function Parser($text) { + $doc = new \doc\Doc(); + return $doc->parse($text); + } } \ No newline at end of file