From 3471a2bfa8ff962c0253ecbd898fe39160c149cb Mon Sep 17 00:00:00 2001 From: 1099438829 <1099438829@qq.com> Date: Sat, 20 Feb 2021 13:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/User.php | 107 ++++++++++++++-- app/admin/model/User.php | 7 +- app/admin/view/user/index.html | 228 ++++++++++++++++++++++++--------- 3 files changed, 267 insertions(+), 75 deletions(-) diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 66d44b3..d19348d 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -5,8 +5,12 @@ namespace app\admin\controller; use app\admin\model\User as aModel; use app\Request; use app\admin\services\UtilService as Util; +use FormBuilder\Factory\Elm; +use app\admin\services\FormBuilderService as Form; +use think\facade\Route as Url; /** + * 用户管理 * Class User * @package app\admin\controller\system * @author 李玉坤 @@ -15,11 +19,9 @@ use app\admin\services\UtilService as Util; class User extends AuthController { /** - * 活动列表 + * 账号列表 * @return string * @throws \Exception - * @author 李玉坤 - * @date 2021-02-16 13:15 */ public function index() { @@ -27,20 +29,19 @@ class User extends AuthController } /** - * 文章列表 + * 账号列表 * @param Request $request - * @return mixed + * @return * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException - * @author 李玉坤 - * @date 2021-02-15 23:26 */ public function lst(Request $request) { $where = Util::postMore([ - ['name',''], + ['username',''], ['tel',''], + ['is_admin',''], ['start_time',''], ['end_time',''], ['status',''], @@ -49,4 +50,94 @@ class User extends AuthController ]); return app("json")->layui(aModel::systemPage($where)); } + + /** + * 添加账号 + * @param Request $request + * @return string + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function add(Request $request) + { + $form = array(); + $form[] = Elm::input('username','登录账号')->col(10); + $form[] = Elm::input('nickname','昵称')->col(10); + $form[] = Elm::frameImage('avatar','头像',Url::buildUrl('admin/images/index',array('fodder'=>'avatar','limit'=>1)))->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::password('password','密码')->col(10); + $form[] = Elm::input('tel','电话')->col(10); + $form[] = Elm::email('email','邮箱')->col(10); + $form[] = Elm::radio('is_admin','管理员',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(10); + $form[] = Elm::radio('status','状态',1)->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10); + $form = Form::make_post_form($form, url('save')->build()); + $this->assign(compact('form')); + return $this->fetch("public/form-builder"); + } + + /** + * 修改账号 + * @return string + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id="") + { + if (!$id) return app("json")->fail("账号id不能为空"); + $ainfo = aModel::get($id); + if (!$ainfo) return app("json")->fail("没有该账号"); + $form = array(); + $form[] = Elm::input('username','登录账号',$ainfo['username'])->col(10); + $form[] = Elm::input('nickname','昵称',$ainfo['nickname'])->col(10); + $form[] = Elm::frameImage('avatar','头像',Url::buildUrl('admin/images/index',array('fodder'=>'avatar','limit'=>1)),$ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::password('password','密码',$ainfo['password'])->col(10); + $form[] = Elm::input('tel','电话',$ainfo['tel'])->col(10); + $form[] = Elm::email('email','邮箱',$ainfo['email'])->col(10); + $form[] = Elm::radio('is_admin','管理员',$ainfo['is_admin'])->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(10); + $form[] = Elm::radio('status','状态',$ainfo['status'])->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10); + $form = Form::make_post_form($form, url('save',['id'=>$id])->build()); + $this->assign(compact('form')); + return $this->fetch("public/form-builder"); + } + + /** + * 保存修改 + * @param string $id + * @return mixed + */ + public function save($id="") + { + $data = Util::postMore([ + ['username',''], + ['nickname',''], + ['avatar',''], + ['password',''], + ['tel',''], + ['email',''], + ['is_admin',''], + ['status',''] + ]); + if ($data['username'] == "") return app("json")->fail("登录账号不能为空"); + if ($data['password'] == "") return app("json")->fail("密码不能为空"); + if ($data['tel'] == "") return app("json")->fail("手机号不能为空"); + if ($data['email'] == "") return app("json")->fail("邮箱不能为空"); + if (is_array($data['avatar'])) $data['avatar'] = $data['avatar'][0]; + if ($id=="") + { + //判断下用户是否存在 + $info = aModel::where('username',$data['username'])->find(); + if ($info){ + return app("json")->fail("用户已存在"); + } + $data['password'] = md5(md5($data['password'])); + $data['ip'] = $this->request->ip(); + $data['create_user'] = $this->adminId; + $res = aModel::create($data); + }else + { + $ainfo = aModel::get($id); + if ($ainfo['password'] != $data['password']) $data['password'] = md5(md5($data['password'])); + $data['update_user'] = $this->adminId; + $res = aModel::update($data,['id'=>$id]); + } + return $res ? app("json")->success("操作成功",'code') : app("json")->fail("操作失败"); + } + } \ No newline at end of file diff --git a/app/admin/model/User.php b/app/admin/model/User.php index 489d4ae..3c80aaf 100644 --- a/app/admin/model/User.php +++ b/app/admin/model/User.php @@ -26,7 +26,7 @@ class User extends BaseModel */ public static function login(string $name,string $pwd): bool { - $info = self::where("name|tel","=", $name)->find(); + $info = self::where("username|tel","=", $name)->find(); if (!$info) return self::setErrorInfo("登录账号不存在"); if ($info['pwd'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!"); if ($info['status'] == 2) return self::setErrorInfo("账号已被冻结!"); @@ -78,11 +78,12 @@ class User extends BaseModel public static function systemPage(array $where): array { $model = new self; - if ($where['name'] != '') $model = $model->where("username|nickname","like","%$where[name]%"); + if ($where['username'] != '') $model = $model->where("username|nickname","like","%$where[name]%"); if ($where['start_time'] != '') $model = $model->where("create_time",">",strtotime($where['start_time']." 00:00:00")); if ($where['end_time'] != '') $model = $model->where("create_time","<", strtotime($where['end_time']." 23:59:59")); - if ($where['tel'] != '') $model = $model->where("tel|mail", "like","%$where[tel]%"); + if ($where['tel'] != '') $model = $model->where("tel|email", "like","%$where[tel]%"); if ($where['status'] != '') $model = $model->where("status",$where['status']); + if ($where['is_admin'] != '') $model = $model->where("is_admin",$where['is_admin']); $count = self::counts($model); if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'],(int)$where['limit']); $data = $model->select(); diff --git a/app/admin/view/user/index.html b/app/admin/view/user/index.html index b49385d..978f0f1 100644 --- a/app/admin/view/user/index.html +++ b/app/admin/view/user/index.html @@ -13,26 +13,35 @@
- +
- - ~ - +
+ +
- - + +
+
+ +
+
- - + ~ + +
+
+
+ +
@@ -42,10 +51,19 @@
-

用户留言

+

用户管理

- + + +
@@ -55,7 +73,7 @@
-{include file="public/footer" /} +{include file="public/footer"/}