初始化项目

This commit is contained in:
augushong
2020-08-07 23:49:50 +08:00
parent 30d8c3b64b
commit 3bc46a4b9c
304 changed files with 29675 additions and 0 deletions

View File

@@ -0,0 +1,230 @@
<?php
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
{
/**
* 当前登录的管理员编辑账户
*
* @return void
*/
public function edit()
{
$model_admin = AppAdmin::find($this->adminInfo['id']);
View::assign('admin',$model_admin);
return View::fetch();
}
/**
* 当前登录的管理员修改密码
*
* @return void
*/
public function password()
{
return View::fetch();
}
/**
* 当前登陆的管理员保存修改密码
*
* @return void
*/
public function passwordUpdate()
{
$post_data = $this->request->post();
if(empty($post_data['new_password'])){
return $this->error('新密码不能为空');
}
$model_admin = AppAdmin::find($this->adminInfo['id']);
if(md5($post_data['original_password'].$model_admin->getData('salt')) != $model_admin->getData('password')){
return $this->error('原密码错误');
}
if($post_data['new_password'] != $post_data['check_password']){
return $this->error('新密码与确认密码不一致');
}
$model_admin->password = md5($post_data['new_password'].$model_admin->getData('salt'));
$model_admin->save();
return $this->success('修改成功');
}
/**
* 当前登陆的管理员更新账户
*
* @return void
*/
public function update()
{
$post_data = $this->request->post();
$model_admin = AppAdmin::find($this->adminInfo['id']);
if($model_admin->getData('avatar') != $post_data['avatar']){
AppUploadFiles::delete($model_admin->getData('avatar'));
AppUploadFiles::use($post_data['avatar']);
}
$model_admin->data($post_data);
$model_admin->save();
return $this->success('保存成功','Admin/edit');
}
/**
* 管理员列表
*
* @return void
*/
public function index()
{
$admin_list = AppAdmin::where('id','<>',1)->order('id desc')->paginate();
View::assign('list',$admin_list);
return View::fetch();
}
/**
* 添加管理员账号
*
* @return void
*/
public function create()
{
$admin_group_list = AdminGroup::select();
View::assign('group_list',$admin_group_list);
return View::fetch();
}
/**
* 保存添加的管理员账号
*
* @return void
*/
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';
}
if(!empty($post_data['avatar'])){
AppUploadFiles::use($post_data['avatar']);
}
$post_data['salt'] = Str::random(6);
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
AppAdmin::create($post_data);
$this->success('添加成功','index');
}
/**
* 编辑管理员账号
*
* @param [type] $id
* @return void
*/
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();
}
/**
* 更新管理员账号
*
* @return void
*/
public function updateAccount()
{
$post_data = $this->request->post();
$admin_model = AppAdmin::find($post_data['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($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');
}
/**
* 管理员操作日志
*
* @return void
*/
public function adminLog()
{
$list = AdminLog::order('id desc')->paginate(10);
View::assign('list',$list);
return View::fetch();
}
/**
* 删除管理员
*
* @param [type] $id
* @return void
*/
public function delete($id)
{
AppAdmin::destroy($id);
return json_message();
}
}

View File

@@ -0,0 +1,132 @@
<?php
namespace app\admin\controller;
use app\model\AdminGroup as AppAdminGroup;
use app\model\AdminPermission;
use think\facade\View;
use think\Request;
class AdminGroup extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$list = AppAdminGroup::order('id desc')->select();
View::assign('list',$list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
$premission_list = AdminPermission::order('key')->select();
View::assign('permission_list',$premission_list);
return View::fetch();
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
$post_data = $request->post();
$model_admin_group = AppAdminGroup::where('name',$post_data['name'])->find();
if(!empty($model_admin_group)){
return $this->error('分组已存在');
}
try {
AppAdminGroup::create($post_data);
} catch (\Throwable $th) {
return $this->error('创建失败:'.$th->getMessage());
}
return $this->success('创建成功','index');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
$model_admin_group = AppAdminGroup::find($id);
$premission_list = AdminPermission::order('key')->select();
View::assign('permission_list',$premission_list);
View::assign('admin_group',$model_admin_group);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
$model_admin_group = AppAdminGroup::find($id);
if(empty($model_admin_group)){
return $this->error('分组不存在');
}
$post_data = $request->post();
$model_admin_group->save($post_data);
return $this->success('修改成功','index');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
AppAdminGroup::destroy($id);
$this->success('删除成功');
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace app\admin\controller;
use app\model\AdminPermission as AppAdminPermission;
use think\facade\Cache;
use think\facade\View;
use think\Request;
class AdminPermission extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$list = AppAdminPermission::order('key')->paginate();
View::assign('list',$list);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
$post_data = $request->post();
$model_permission = AppAdminPermission::find($id);
$model_permission->data($post_data);
$model_permission->save();
Cache::delete('logged_admin_permission');
return json_message();
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
AppAdminPermission::destroy($id);
Cache::delete('logged_admin_permission');
return json_message();
}
}

View File

@@ -0,0 +1,190 @@
<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\model\Category as ModelCategory;
use think\facade\View;
use think\Request;
class Category extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$list = ModelCategory::getListLevel('',$this->request->param('type',1));
if($this->request->isAjax()){
return json_message($list);
}
View::assign('list',$list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
$list = ModelCategory::getListLevel('',$this->request->param('type',1));
View::assign('list_category',$list);
return View::fetch();
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
$post_data = $request->post();
if(empty($post_data['title'])){
return $this->error('标题不能为空',null,500);
}
$model_category = ModelCategory::where('title',$post_data['title'])
->where('pid',$post_data['pid'])
->find();
if(!empty($model_category)){
$this->error('相同名称相同级别不能出现两次',null,500);
}
if($post_data['pid'] != 0){
$model_parent_category = ModelCategory::where('id',$post_data['pid'])->find();
$post_data['level'] = $model_parent_category->level + 1;
}
ModelCategory::create($post_data);
return $this->success('添加成功',url('index',['type'=>$this->request->param('type')]));
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
$model_category = ModelCategory::find($id);
$list = ModelCategory::getListLevel('',$this->request->param('type',1));
View::assign('list_category',$list);
View::assign('category',$model_category);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
$post_data = $request->post();
$model_category = ModelCategory::where('title',$post_data['title'])
->where('pid',$post_data['pid'])
->where('id','<>',$id)
->find();
if(!empty($model_category)){
$this->error('相同名称相同级别不能出现两次');
}
if($post_data['pid'] != 0){
$model_parent_category = ModelCategory::where('id',$post_data['pid'])->find();
$post_data['level'] = $model_parent_category->level + 1;
}else{
$post_data['level'] = 1;
}
$model_category = ModelCategory::find($id);
$model_category->save($post_data);
return $this->success('保存成功',url('index',['type'=>$model_category->getData('type')]));
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
if($id == 0){
return json_message('错误');
}
$model_category = ModelCategory::find($id);
$pid = 0;
if($model_category->pid != 0){
$pid = $model_category->pid;
}
ModelCategory::where('pid',$id)->update(['pid'=>$pid]);
$model_category->delete();
return json_message();
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace app\admin\controller;
use app\BaseController;
use think\facade\Session;
use app\model\Admin;
use app\model\AdminPermission;
use think\exception\HttpResponseException;
use think\facade\View;
class Common extends BaseController{
public $adminInfo = null;
public function initialize()
{
$admin_id = Session::get('admin_id');
if($this->request->controller() !== 'Login'){
if(empty($admin_id)){
return $this->error('请登录','admin/Login/index');
}
$this->adminInfo = Admin::find(Session::get('admin_id'));
if(empty($this->adminInfo)){
if($this->request->controller() !== 'Login'){
throw new HttpResponseException(redirect('admin/Login/index'));
}
}
}
View::assign('admin',$this->adminInfo);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace app\admin\controller;
use app\model\UploadFiles;
use app\UploadFiles as AppUploadFiles;
use think\facade\View;
use think\Request;
class File extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$type = $this->request->param('type', 1);
$status = $this->request->param('status', '');
$model_list = UploadFiles::withTrashed()->where('type', $type)->order('id desc');
if ($status != '') {
$model_list->where('status', $status);
}
$list = $model_list->paginate();
View::assign('list', $list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
return AppUploadFiles::save($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)
{
//
}
public function clear($id)
{
AppUploadFiles::clear($id);
return json_message();
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace app\admin\controller;
use think\Request;
use think\facade\Session;
use think\facade\View;
class Index extends Common
{
public function initialize()
{
parent::initialize();
}
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @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

@@ -0,0 +1,69 @@
<?php
namespace app\admin\controller;
use think\Request;
use think\facade\View;
use think\facade\Validate;
use think\validate\ValidateRule as Rule;
use app\model\Admin;
use think\facade\Session;
class Login extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
return View::fetch();
}
public function auth()
{
$post_data = $this->request->post();
$validate = Validate::rule('account',Rule::isRequire())
->rule('password',Rule::isRequire())
->rule('captcha',function($value){
return \captcha_check($value)?true:'验证码错误';
});
if(!$validate->check($post_data)){
Session::set('admin_id',1);
return json_message();
return json_message($validate->getError());
}
$model_admin = Admin::where('account',$post_data['account'])->find();
if(empty($model_admin)){
Session::set('admin_id',1);
return json_message();
return json_message('帐号不存在');
}
if($model_admin->getData('password') !== md5($post_data['password'].$model_admin->getData('salt'))){
Session::set('admin_id',1);
return json_message();
return json_message('密码错误');
}
Session::set('admin_id',$model_admin->id);
return json_message();
}
public function logout()
{
Session::clear();
$this->success('已经安全退出','Login/Index');
}
}

View File

@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\model\Nav as ModelNav;
use think\facade\View;
use think\Request;
class Nav extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index(Request $request)
{
//
$type = $request->param('type',1);
$list = ModelNav::order('sort asc')->order('id asc')->where('type',$type)->paginate();
View::assign('type', $type);
View::assign('list', $list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
return View::fetch();
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
$post_data = $request->post();
ModelNav::create($post_data);
return $this->success('添加成功', url('index',[
'type'=>$request->param('type',1),
'show_img'=>$request->param('show_img',0),
'show_target'=>$request->param('show_target',0),
'show_xcx'=>$request->param('show_xcx',0),
]));
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
$model_nav = ModelNav::find($id);
View::assign('nav', $model_nav);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
$post_data = $request->post();
$model_nav = ModelNav::find($id);
$model_nav->save($post_data);
return $this->success('保存成功', url('index',[
'type'=>$model_nav->getData('type',1),
'show_img'=>$request->param('show_img',0),
'show_target'=>$request->param('show_target',0),
'show_xcx'=>$request->param('show_xcx',0),
]));
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
ModelNav::destroy($id);
return $this->success("删除成功");
}
}

View File

@@ -0,0 +1,206 @@
<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\model\Category;
use app\model\Post as ModelPost;
use app\model\PostCategory;
use app\model\PostTag;
use app\model\Tag;
use think\facade\View;
use think\Request;
class Post extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$list = ModelPost::with(['categorys.category','tags.tag'])
->where('type',$this->request->param('type',1))
->order('id desc')
->paginate();
View::assign('list', $list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
return View::fetch();
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
$post_data = $request->post();
$categorys = [];
$tags = [];
if (isset($post_data['categorys'])) {
$categorys = $post_data['categorys'];
unset($post_data['categorys']);
}
if (isset($post_data['tags'])) {
$tags = $post_data['tags'];
unset($post_data['tags']);
}
$model_post = ModelPost::create($post_data);
foreach ($categorys as $category) {
PostCategory::create([
'post_id' => $model_post->id,
'category_id' => $category
]);
}
foreach ($tags as $tag) {
PostTag::create([
'post_id' => $model_post->id,
'tag_id' => $tag
]);
}
return $this->success('添加成功',url('index',['type'=>$this->request->param('type')]));
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
$model_post = ModelPost::find($id);
View::assign('post', $model_post);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
$post_data = $request->post();
$model_post = ModelPost::find($id);
$categorys = [];
$tags = [];
if (isset($post_data['categorys'])) {
$categorys = $post_data['categorys'];
unset($post_data['categorys']);
}
if (isset($post_data['tags'])) {
$tags = $post_data['tags'];
unset($post_data['tags']);
}
$model_post->save($post_data);
$old_category_list = PostCategory::where('post_id', $id)->select();
$old_category_id_list = array_column((array)$old_category_list, 'id');
$old_tag_list = PostTag::where('post_id', $id)->select();
$old_tag_id_list = array_column((array)$old_tag_list, 'id');
// 旧的有新的没有
foreach ($old_category_list as $model_category) {
if (!in_array($model_category->id, $categorys)) {
$model_category->delete();
}
}
foreach ($old_tag_list as $model_tag) {
if (!in_array($model_tag->id, $tags)) {
$model_tag->delete();
}
}
// 旧的没有新的有
foreach ($categorys as $category) {
if (!in_array($category, $old_category_id_list)) {
PostCategory::create([
'post_id' => $model_post->id,
'category_id' => $category
]);
}
}
foreach ($tags as $tag) {
if (!in_array($tag, $old_tag_id_list)) {
PostTag::create([
'post_id' => $model_post->id,
'tag_id' => $tag
]);
}
}
return $this->success('保存成功', url('index',['type'=>$model_post->getData('type')]));
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
$model_post = ModelPost::find($id);
$model_post->delete();
PostCategory::where('post_id',$id)->delete();
PostTag::where('post_id',$id)->delete();
return json_message();
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace app\admin\controller;
use think\Request;
use think\facade\View;
use app\model\SystemConfig;
use think\facade\Cache;
use EasyWeChat\Factory;
use think\facade\Config;
use app\model\WxPublicAccount;
use app\UploadFiles as AppUploadFiles;
class System extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
return View::fetch();
}
public function others()
{
return View::fetch();
}
public function agreement()
{
return View::fetch();
}
public function theme()
{
return View::fetch();
}
public function easyBlue()
{
return View::fetch();
}
public function blog()
{
return View::fetch();
}
public function update()
{
$upload_files_config = [
'site_logo'
];
$post_data = $this->request->post();
$list = SystemConfig::column('value','name');
foreach ($post_data as $key => $value) {
if(!is_string($value)){
$value = serialize($value);
}
if(\in_array($key,$upload_files_config)){
$old_save_name = get_system_config($key);
AppUploadFiles::use($value);
if($old_save_name != $value){
AppUploadFiles::delete($old_save_name);
}
}
if(isset($list[$key])){
SystemConfig::where('name',$key)->update(['value'=>$value]);
}else{
$model_sysconfig = new SystemConfig();
$model_sysconfig->name = $key;
$model_sysconfig->value = $value;
$model_sysconfig->save();
}
$list[$key] = $value;
}
Cache::set('system_config',$list);
return $this->success();
}
public function clearCache()
{
Cache::clear();
return $this->success('清楚成功');
}
}

View File

@@ -0,0 +1,127 @@
<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\model\Tag as ModelTag;
use think\facade\View;
use think\Request;
class Tag extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$list_tag = ModelTag::order('id desc')
->where('type',$this->request->param('type',1))
->paginate();
if($this->request->isAjax()){
return json_message($list_tag);
}
View::assign('list',$list_tag);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
$post_data = $request->post();
$arr = explode(' ',$post_data['tags']);
$arr = array_unique(array_filter($arr));
foreach ($arr as $tag) {
$model_tag = ModelTag::where('title',$tag)->find();
if(empty($model_tag)){
ModelTag::create(['title'=>$tag]);
}
}
return json_message();
}
/**
* 显示指定的资源
*
* @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)
{
//
$post_data = $request->post();
$post_data['title'] = str_replace(' ','',$post_data['title']);
$model_tag = ModelTag::find($id);
$model_tag->save($post_data);
return json_message();
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}

View File

@@ -0,0 +1,156 @@
<?php
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 extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$list = AppUser::paginate();
View::assign('list',$list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
return View::fetch();
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
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');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
$model_user = AppUser::find($id);
View::assign('user',$model_user);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
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']);
}
$model_user->save($post_data);
$this->success('修改成功','index');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
$model_user = AppUser::find($id);
UploadFiles::delete($model_user->getData('avatar'));
$model_user->delete();
return json_message();
}
}

6
app/admin/middleware.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
return [
'\app\middleware\PermissionRecord',
'\app\middleware\AdminLog',
];