完成用户管理;基本功能完成;

This commit is contained in:
augushong
2019-10-09 22:25:54 +08:00
parent e0283ec938
commit f00328d030
12 changed files with 513 additions and 124 deletions

View File

@@ -2,9 +2,13 @@
namespace app\admin\controller;
use app\model\User as AppUser;
use app\UploadFiles;
use think\Request;
use think\facade\View;
use think\helper\Str;
class User
class User extends Common
{
/**
* 显示资源列表
@@ -14,6 +18,11 @@ class User
public function index()
{
//
$list = AppUser::paginate();
View::assign('list',$list);
return View::fetch();
}
/**
@@ -24,6 +33,8 @@ class User
public function create()
{
//
return View::fetch();
}
/**
@@ -35,6 +46,31 @@ class User
public function save(Request $request)
{
//
$post_data = $this->request->post();
$admin_model = AppUser::where('account',$post_data['account'])->find();
if(!empty($admin_model)){
$this->error('用户已存在');
}
if(empty($post_data['password'])){
$post_data['password'] = '123456';
}
if(!empty($post_data['avatar'])){
UploadFiles::use($post_data['avatar']);
}
$post_data['salt'] = Str::random(6);
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
AppUser::create($post_data);
$this->success('添加成功','index');
}
/**
@@ -57,6 +93,13 @@ class User
public function edit($id)
{
//
$model_user = AppUser::find($id);
View::assign('user',$model_user);
return View::fetch();
}
/**
@@ -69,6 +112,26 @@ class User
public function update(Request $request, $id)
{
//
$post_data = $this->request->post();
$model_user = AppUser::find($id);
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']);
}
if($post_data['avatar'] != $model_user->getData('avatar')){
UploadFiles::delete($model_user->getData('avatar'));
UploadFiles::use($post_data['avatar']);
}
AppUser::update($post_data);
$this->success('修改成功','index');
}
/**
@@ -80,5 +143,10 @@ class User
public function delete($id)
{
//
AppUser::destroy($id);
return json_message();
}
}