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

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

@@ -104,6 +104,10 @@ class Admin extends Common
$post_data['password'] = '123456';
}
if($admin_model->getData('avatar') != $post_data['avatar']){
AppUploadFiles::delete($admin_model->getData('avatar'));
AppUploadFiles::use($post_data['avatar']);
}
$post_data['salt'] = Str::random(6);
@@ -128,6 +132,8 @@ class Admin extends Common
{
$post_data = $this->request->post();
$admin_model = AppAdmin::find($post_data['id']);
if(!empty($post_data['password'])){
$post_data['salt'] = Str::random(6);
@@ -136,6 +142,10 @@ class Admin extends Common
unset($post_data['password']);
}
if($admin_model->getData('avatar') != $post_data['avatar']){
AppUploadFiles::delete($admin_model->getData('avatar'));
AppUploadFiles::use($post_data['avatar']);
}
AppAdmin::update($post_data);
$this->success('修改成功','index');

View File

@@ -1,84 +0,0 @@
<?php
namespace app\admin\controller;
use think\Request;
class Member extends Common
{
/**
* 显示资源列表
*
* @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)
{
//
}
}

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();
}
}