完成管理员管理

This commit is contained in:
augushong
2019-10-05 21:30:05 +08:00
parent 0db279315c
commit 79a78a889e
9 changed files with 392 additions and 36 deletions

View File

@@ -3,9 +3,11 @@
namespace app\admin\controller;
use app\model\Admin as AppAdmin;
use app\model\AdminGroup;
use app\model\AdminLog;
use app\UploadFiles as AppUploadFiles;
use think\facade\View;
use think\helper\Str;
class Admin extends Common
{
@@ -80,12 +82,64 @@ class Admin extends Common
public function create()
{
$admin_group_list = AdminGroup::select();
View::assign('group_list',$admin_group_list);
return View::fetch();
}
public function save()
{
$post_data = $this->request->post();
$admin_model = AppAdmin::where('account',$post_data['account'])->find();
if(!empty($admin_model)){
$this->error('管理员已存在');
}
if(empty($post_data['password'])){
$post_data['password'] = '123456';
}
$post_data['salt'] = Str::random(6);
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
AppAdmin::create($post_data);
$this->success('添加成功','index');
}
public function editAccount($id)
{
$model_admin = AppAdmin::find($id);
$admin_group_list = AdminGroup::select();
View::assign('group_list',$admin_group_list);
View::assign('admin',$model_admin);
return View::fetch();
}
public function updateAccount()
{
$post_data = $this->request->post();
if(!empty($post_data['password'])){
$post_data['salt'] = Str::random(6);
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
}else{
unset($post_data['password']);
}
AppAdmin::update($post_data);
$this->success('修改成功','index');
}
public function adminLog()
@@ -97,4 +151,12 @@ class Admin extends Common
return View::fetch();
}
public function delete($id)
{
AppAdmin::destroy($id);
return json_message();
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace app\admin\controller;
use think\Request;
class User
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}