From a9062909a02c249975d746ffe793211b6cd5fe0d Mon Sep 17 00:00:00 2001 From: hdm Date: Sat, 27 Nov 2021 11:13:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=87=8D=E8=AE=BE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/home/common.php | 37 +-- app/home/controller/Admin.php | 2 +- app/home/controller/Api.php | 55 ++-- app/home/model/AdminLog.php | 9 +- app/home/validate/AdminCheck.php | 10 +- app/home/view/admin/edit_password.html | 7 +- app/home/view/admin/edit_personal.html | 56 +++-- app/home/view/admin/log.html | 5 +- app/home/view/conf/index.html | 3 +- app/install/data/gouguoa.sql | 334 +++++++++++++------------ 10 files changed, 280 insertions(+), 238 deletions(-) diff --git a/app/home/common.php b/app/home/common.php index 523efa4..a6a951c 100644 --- a/app/home/common.php +++ b/app/home/common.php @@ -267,31 +267,32 @@ function check_auth($rule, $uid) */ function add_log($type, $param_id = '', $param = []) { - $request = get_params(); - switch ($type) { + $action = '未知操作'; + switch ($type) { case 'login': - $title = '登录'; + $action = '登录'; break; case 'upload': - $title = '上传'; + $action = '上传'; break; case 'add': - $title = '新增'; + $action = '新增'; break; case 'edit': - $title = '编辑'; + $action = '编辑'; break; case 'view': - $title = '查看'; + $action = '查看'; break; case 'delete': - $title = '删除'; + $action = '删除'; break; case 'check': - $title = '审核'; + $action = '审核'; break; - default: - $title = '未知'; + break; + case 'reset': + $action = '重新设置'; break; } if ($type == 'login') { @@ -304,15 +305,23 @@ function add_log($type, $param_id = '', $param = []) $data['uid'] = $login_admin['id']; $data['name'] = $login_admin['name']; $data['type'] = $type; + $data['action'] = $action; $data['param_id'] = $param_id; $data['param'] = json_encode($param); $data['module'] = \think\facade\App::initialize()->http->getName(); $data['controller'] = strtolower(app('request')->controller()); $data['function'] = app('request')->action(); $parameter = $data['module'] . '/' . $data['controller'] . '/' . $data['function']; - $data['rule_menu'] = $parameter; - $data['title'] = Db::name('AdminRule')->where(array('src' => $parameter))->value('title') ?? $title; - $content = $login_admin['name'] . '在' . date('Y-m-d H:i:s') . '执行了' . $data['title'] . '操作'; + $rule_menu = Db::name('AdminRule')->where(array('src' => $parameter))->find(); + if($rule_menu){ + $data['title'] = $rule_menu['title']; + $data['subject'] = $rule_menu['name']; + } + else{ + $data['title'] = ''; + $data['subject'] ='系统'; + } + $content = $login_admin['name'] . '在' . date('Y-m-d H:i:s') . $data['action'] . '了' . $data['subject']; $data['content'] = $content; $data['ip'] = app('request')->ip(); $data['create_time'] = time(); diff --git a/app/home/controller/Admin.php b/app/home/controller/Admin.php index b3f1c1e..dea24b8 100644 --- a/app/home/controller/Admin.php +++ b/app/home/controller/Admin.php @@ -274,7 +274,7 @@ class Admin extends BaseController } $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $content = DB::name('AdminLog') - ->field("id,uid,name,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time") + ->field("id,uid,name,action,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time") ->order('create_time desc') ->where($where) ->paginate($rows, false, ['query' => $param]); diff --git a/app/home/controller/Api.php b/app/home/controller/Api.php index 3306f46..f03349a 100644 --- a/app/home/controller/Api.php +++ b/app/home/controller/Api.php @@ -225,37 +225,54 @@ class Api extends BaseController //修改个人信息 public function edit_personal() { - return view('admin/edit_personal', [ - 'admin' => get_admin($this->uid), - ]); - } - - //保存个人信息修改 - public function personal_submit() - { - if (request()->isAjax()) { + if (request()->isAjax()) { $param = get_params(); - try { - validate(AdminCheck::class)->scene('editPersonal')->check($param); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } - unset($param['username']); $uid = $this->uid; Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); $session_admin = get_config('app.session_admin'); Session::set($session_admin, Db::name('admin')->find($uid)); return to_assign(); } + else{ + return view('admin/edit_personal', [ + 'admin' => get_admin($this->uid), + ]); + } } //修改密码 public function edit_password() { - return view('admin/edit_password', [ - 'admin' => get_admin($this->uid), - ]); + if (request()->isAjax()) { + $param = get_params(); + try { + validate(AdminCheck::class)->scene('editPwd')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $uid = $this->uid; + + $admin = Db::name('Admin')->where(['id' => $uid])->find(); + $old_psw = set_password($param['old_pwd'], $admin['salt']); + if ($admin['pwd'] != $old_psw) { + return to_assign(1, '旧密码错误'); + } + + $salt = set_salt(20); + $param['pwd'] = set_password($param['pwd'], $salt); + $param['reg_pwd'] = ''; + $param['update_time'] = time(); + Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); + $session_admin = get_config('app.session_admin'); + Session::set($session_admin, Db::name('admin')->find($uid)); + return to_assign(); + } + else{ + return view('admin/edit_password', [ + 'admin' => get_admin($this->uid), + ]); + } } //保存密码修改 diff --git a/app/home/model/AdminLog.php b/app/home/model/AdminLog.php index 59e4b6a..4a1e994 100644 --- a/app/home/model/AdminLog.php +++ b/app/home/model/AdminLog.php @@ -36,14 +36,7 @@ class AdminLog extends Model foreach ($content as $k => $v) { $data = $v; $param_array = json_decode($v['param'], true); - $name = ''; - if (!empty($param_array['name'])) { - $name = ':' . $param_array['name']; - } - if (!empty($param_array['title'])) { - $name = ':' . $param_array['title']; - } - $data['content'] = $v['content'] . $name; + $data['content'] = $v['content']; $data['times'] = time_trans($v['create_time']); $content->offsetSet($k, $data); } diff --git a/app/home/validate/AdminCheck.php b/app/home/validate/AdminCheck.php index 9d12f77..f1ba7a6 100644 --- a/app/home/validate/AdminCheck.php +++ b/app/home/validate/AdminCheck.php @@ -23,9 +23,9 @@ class AdminCheck extends Validate 'type' => 'require', 'entry_time' => 'require', 'id' => 'require', + 'pwd' => 'require|min:6|confirm', 'status' => 'require|checkStatus:-1,1', 'old_pwd' => 'require|different:pwd', - 'edit_pwd' => 'min:6|confirm', ]; protected $message = [ @@ -45,9 +45,8 @@ class AdminCheck extends Validate 'entry_time.require' => '请选择入职时间', 'id.require' => '缺少更新条件', 'pwd.require' => '密码不能为空', - 'pwd.min' => '密码至少要6个字符', - 'edit_pwd.min' => '密码至少要6个字符', - 'edit_pwd.confirm' => '两次密码不一致', + 'pwd.min' => '密码至少要6个字符', + 'pwd.confirm' => '两次密码不一致', 'old_pwd.require' => '请提供旧密码', 'old_pwd.different' => '新密码不能和旧密码一样', ]; @@ -55,8 +54,7 @@ class AdminCheck extends Validate protected $scene = [ 'add' => ['name', 'username', 'mobile','reg_pwd', 'did', 'position_id', 'type', 'entry_time'], 'edit' => ['name', 'username', 'mobile', 'did', 'position_id', 'entry_time', 'id'], - 'editPersonal' => ['mobile', 'name', 'id'], - 'editpwd' => ['old_pwd', 'pwd', 'id'], + 'editPwd' => ['old_pwd', 'pwd'], ]; } diff --git a/app/home/view/admin/edit_password.html b/app/home/view/admin/edit_password.html index 1869fb5..d56aeff 100644 --- a/app/home/view/admin/edit_password.html +++ b/app/home/view/admin/edit_password.html @@ -5,13 +5,12 @@

重置密码

- - + + @@ -42,7 +41,7 @@ //监听提交 form.on('submit(webform)', function (data) { $.ajax({ - url: "{:url('home/api/personal_submit')}", + url: "{:url('home/api/edit_password')}", type: 'post', data: data.field, success: function (e) { diff --git a/app/home/view/admin/edit_personal.html b/app/home/view/admin/edit_personal.html index 5b30864..c36ecdc 100644 --- a/app/home/view/admin/edit_personal.html +++ b/app/home/view/admin/edit_personal.html @@ -2,16 +2,17 @@ {block name="body"} -

修改个人信息

+

修改个人信息

用户名 * 旧密码* 用户名{$admin.username}
新密码 *
- - - - + + + + + - + + + - - + + + + + + + + + + + + + +
用户名 *头像 + 用户名{$admin.username}姓名{$admin.name}头像
- +
@@ -20,16 +21,37 @@
昵称*手机号码{$admin.mobile}性别 - + +
手机所在部门{$admin.department}岗位职称{$admin.position}
员工类型 + {eq name="$admin.type" value="0"}实 习 生{/eq} + {eq name="$admin.type" value="1"}试用员工{/eq} + {eq name="$admin.type" value="2"}正式员工{/eq} + 入职日期 + {$admin.entry_time | date='Y-m-d'} +
个人简介 + +
@@ -51,9 +73,9 @@ //头像上传 var uploadInst = upload.render({ - elem: '#test1' - , url: "{:url('home/api/upload')}", - , done: function (e) { + elem: '#test1', + url: "{:url('home/api/upload')}", + done: function (e) { //如果上传失败 if (e.code == 1) { return layer.msg('上传失败'); @@ -69,7 +91,7 @@ //监听提交 form.on('submit(webform)', function (data) { $.ajax({ - url: "{:url('home/api/personal_submit')}", + url: "{:url('home/api/edit_personal')}", type: 'post', data: data.field, success: function (e) { diff --git a/app/home/view/admin/log.html b/app/home/view/admin/log.html index 2dce31b..0f2a9b9 100644 --- a/app/home/view/admin/log.html +++ b/app/home/view/admin/log.html @@ -46,9 +46,10 @@ align: 'center', width: 90 }, { - field: 'title', + field: 'action', title: '操作', - width: 150 + align: 'center', + width: 80 }, { field: 'content', title: '操作描述', diff --git a/app/home/view/conf/index.html b/app/home/view/conf/index.html index 41903ca..334cc82 100644 --- a/app/home/view/conf/index.html +++ b/app/home/view/conf/index.html @@ -19,12 +19,13 @@ {block name="script"}