mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-08-30 12:45:32 +08:00
引入easyadmin'
This commit is contained in:
@@ -1,230 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
<?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('删除成功');
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
171
app/admin/controller/Ajax.php
Normal file
171
app/admin/controller/Ajax.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\SystemUploadfile;
|
||||
use app\common\controller\AdminController;
|
||||
use app\common\service\MenuService;
|
||||
use EasyAdmin\upload\Uploadfile;
|
||||
use think\db\Query;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Ajax extends AdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* 初始化后台接口地址
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initAdmin()
|
||||
{
|
||||
$cacheData = Cache::get('initAdmin_' . session('admin.id'));
|
||||
if (!empty($cacheData)) {
|
||||
return json($cacheData);
|
||||
}
|
||||
$menuService = new MenuService(session('admin.id'));
|
||||
$data = [
|
||||
'logoInfo' => [
|
||||
'title' => sysconfig('site', 'logo_title'),
|
||||
'image' => sysconfig('site', 'logo_image'),
|
||||
'href' => __url('index/index'),
|
||||
],
|
||||
'homeInfo' => $menuService->getHomeInfo(),
|
||||
'menuInfo' => $menuService->getMenuTree(),
|
||||
];
|
||||
Cache::tag('initAdmin')->set('initAdmin_' . session('admin.id'), $data);
|
||||
return json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理缓存接口
|
||||
*/
|
||||
public function clearCache()
|
||||
{
|
||||
Cache::clear();
|
||||
$this->success('清理缓存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$data = [
|
||||
'upload_type' => $this->request->post('upload_type'),
|
||||
'file' => $this->request->file('file'),
|
||||
];
|
||||
$uploadConfig = sysconfig('upload');
|
||||
empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type'];
|
||||
$rule = [
|
||||
'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}",
|
||||
'file|文件' => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}",
|
||||
];
|
||||
$this->validate($data, $rule);
|
||||
try {
|
||||
$upload = Uploadfile::instance()
|
||||
->setUploadType($data['upload_type'])
|
||||
->setUploadConfig($uploadConfig)
|
||||
->setFile($data['file'])
|
||||
->save();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($upload['save'] == true) {
|
||||
$this->success($upload['msg'], ['url' => $upload['url']]);
|
||||
} else {
|
||||
$this->error($upload['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片至编辑器
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function uploadEditor()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$data = [
|
||||
'upload_type' => $this->request->post('upload_type'),
|
||||
'file' => $this->request->file('upload'),
|
||||
];
|
||||
$uploadConfig = sysconfig('upload');
|
||||
empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type'];
|
||||
$rule = [
|
||||
'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}",
|
||||
'file|文件' => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}",
|
||||
];
|
||||
$this->validate($data, $rule);
|
||||
try {
|
||||
$upload = Uploadfile::instance()
|
||||
->setUploadType($data['upload_type'])
|
||||
->setUploadConfig($uploadConfig)
|
||||
->setFile($data['file'])
|
||||
->save();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($upload['save'] == true) {
|
||||
return json([
|
||||
'error' => [
|
||||
'message' => '上传成功',
|
||||
'number' => 201,
|
||||
],
|
||||
'fileName' => '',
|
||||
'uploaded' => 1,
|
||||
'url' => $upload['url'],
|
||||
]);
|
||||
} else {
|
||||
$this->error($upload['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传文件列表
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getUploadFiles()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$page = isset($get['page']) && !empty($get['page']) ? $get['page'] : 1;
|
||||
$limit = isset($get['limit']) && !empty($get['limit']) ? $get['limit'] : 10;
|
||||
$title = isset($get['title']) && !empty($get['title']) ? $get['title'] : null;
|
||||
$this->model = new SystemUploadfile();
|
||||
$count = $this->model
|
||||
->where(function (Query $query) use ($title) {
|
||||
!empty($title) && $query->where('original_name', 'like', "%{$title}%");
|
||||
})
|
||||
->count();
|
||||
$list = $this->model
|
||||
->where(function (Query $query) use ($title) {
|
||||
!empty($title) && $query->where('original_name', 'like', "%{$title}%");
|
||||
})
|
||||
->page($page, $limit)
|
||||
->order($this->sort)
|
||||
->select();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
return json($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
<?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('type',$post_data['type'])
|
||||
->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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -2,93 +2,119 @@
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\Session;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends Common
|
||||
use app\admin\model\SystemAdmin;
|
||||
use app\admin\model\SystemQuick;
|
||||
use app\common\controller\AdminController;
|
||||
use think\App;
|
||||
use think\facade\Env;
|
||||
|
||||
class Index extends AdminController
|
||||
{
|
||||
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
* 后台主页
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
return $this->fetch('', [
|
||||
'admin' => session('admin'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
* 后台欢迎页
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create()
|
||||
public function welcome()
|
||||
{
|
||||
//
|
||||
$quicks = SystemQuick::field('id,title,icon,href')
|
||||
->where(['status' => 1])
|
||||
->order('sort', 'desc')
|
||||
->limit(8)
|
||||
->select();
|
||||
$this->assign('quicks', $quicks);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
* 修改管理员信息
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function save(Request $request)
|
||||
public function editAdmin()
|
||||
{
|
||||
//
|
||||
$id = session('admin.id');
|
||||
$row = (new SystemAdmin())
|
||||
->withoutField('password')
|
||||
->find($id);
|
||||
empty($row) && $this->error('用户信息不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$this->isDemo && $this->error('演示环境下不允许修改');
|
||||
$rule = [];
|
||||
$this->validate($post, $rule);
|
||||
try {
|
||||
$save = $row
|
||||
->allowField(['head_img', 'phone', 'remark', 'update_time'])
|
||||
->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
* 修改密码
|
||||
* @return string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function read($id)
|
||||
public function editPassword()
|
||||
{
|
||||
//
|
||||
$id = session('admin.id');
|
||||
$row = (new SystemAdmin())
|
||||
->withoutField('password')
|
||||
->find($id);
|
||||
if (!$row) {
|
||||
$this->error('用户信息不存在');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$this->isDemo && $this->error('演示环境下不允许修改');
|
||||
$rule = [
|
||||
'password|登录密码' => 'require',
|
||||
'password_again|确认密码' => 'require',
|
||||
];
|
||||
$this->validate($post, $rule);
|
||||
if ($post['password'] != $post['password_again']) {
|
||||
$this->error('两次密码输入不一致');
|
||||
}
|
||||
|
||||
try {
|
||||
$save = $row->save([
|
||||
'password' => password($post['password']),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
if ($save) {
|
||||
$this->success('保存成功');
|
||||
} else {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
}
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,99 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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
|
||||
use app\admin\model\SystemAdmin;
|
||||
use app\common\controller\AdminController;
|
||||
use think\captcha\facade\Captcha;
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* Class Login
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Login extends AdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
* 初始化方法
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$action = $this->request->action();
|
||||
if (!empty(session('admin')) && !in_array($action, ['out'])) {
|
||||
$adminModuleName = config('app.admin_alias_name');
|
||||
$this->success('已登录,无需再次登录', [], __url("@{$adminModuleName}"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
$captcha = Env::get('easyadmin.captcha', 1);
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$rule = [
|
||||
'username|用户名' => 'require',
|
||||
'password|密码' => 'require',
|
||||
'keep_login|是否保持登录' => 'require',
|
||||
];
|
||||
$captcha == 1 && $rule['captcha|验证码'] = 'require|captcha';
|
||||
$this->validate($post, $rule);
|
||||
$admin = SystemAdmin::where(['username' => $post['username']])->find();
|
||||
if (empty($admin)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
if (password($post['password']) != $admin->password) {
|
||||
$this->error('密码输入有误');
|
||||
}
|
||||
if ($admin->status == 0) {
|
||||
$this->error('账号已被禁用');
|
||||
}
|
||||
$admin->login_num += 1;
|
||||
$admin->save();
|
||||
$admin = $admin->toArray();
|
||||
unset($admin['password']);
|
||||
$admin['expire_time'] = $post['keep_login'] == 1 ? true : time() + 7200;
|
||||
session('admin', $admin);
|
||||
$this->success('登录成功');
|
||||
}
|
||||
$this->assign('captcha', $captcha);
|
||||
$this->assign('demo', $this->isDemo);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
public function auth()
|
||||
/**
|
||||
* 用户退出
|
||||
* @return mixed
|
||||
*/
|
||||
public function out()
|
||||
{
|
||||
$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();
|
||||
session('admin', null);
|
||||
$this->success('退出登录成功');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
/**
|
||||
* 验证码
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function captcha()
|
||||
{
|
||||
Session::clear();
|
||||
|
||||
$this->success('已经安全退出','Login/Index');
|
||||
return Captcha::create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
<?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)->select();
|
||||
|
||||
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("删除成功");
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
<?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 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('清楚成功');
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?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();
|
||||
|
||||
$type = $post_data['type'];
|
||||
|
||||
$arr = explode(' ',$post_data['tags']);
|
||||
|
||||
$arr = array_unique(array_filter($arr));
|
||||
|
||||
foreach ($arr as $tag) {
|
||||
$model_tag = ModelTag::where('title',$tag)->where('type',$type)->find();
|
||||
|
||||
if(empty($model_tag)){
|
||||
ModelTag::create(['title'=>$tag,'type'=>$type]);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
<?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();
|
||||
|
||||
}
|
||||
}
|
||||
30
app/admin/controller/mall/Cate.php
Normal file
30
app/admin/controller/mall/Cate.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\controller\mall;
|
||||
|
||||
|
||||
use app\admin\model\MallCate;
|
||||
use app\admin\traits\Curd;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Admin
|
||||
* @package app\admin\controller\system
|
||||
* @ControllerAnnotation(title="商品分类管理")
|
||||
*/
|
||||
class Cate extends AdminController
|
||||
{
|
||||
|
||||
use Curd;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new MallCate();
|
||||
}
|
||||
|
||||
}
|
||||
87
app/admin/controller/mall/Goods.php
Normal file
87
app/admin/controller/mall/Goods.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\controller\mall;
|
||||
|
||||
|
||||
use app\admin\model\MallGoods;
|
||||
use app\admin\traits\Curd;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Goods
|
||||
* @package app\admin\controller\mall
|
||||
* @ControllerAnnotation(title="商城商品管理")
|
||||
*/
|
||||
class Goods extends AdminController
|
||||
{
|
||||
|
||||
use Curd;
|
||||
|
||||
protected $relationSearch = true;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new MallGoods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
list($page, $limit, $where) = $this->buildTableParames();
|
||||
$count = $this->model
|
||||
->withJoin('cate', 'LEFT')
|
||||
->where($where)
|
||||
->count();
|
||||
$list = $this->model
|
||||
->withJoin('cate', 'LEFT')
|
||||
->where($where)
|
||||
->page($page, $limit)
|
||||
->order($this->sort)
|
||||
->select();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
return json($data);
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="入库")
|
||||
*/
|
||||
public function stock($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$rule = [];
|
||||
$this->validate($post, $rule);
|
||||
try {
|
||||
$post['total_stock'] = $row->total_stock + $post['stock'];
|
||||
$post['stock'] = $row->stock + $post['stock'];
|
||||
$save = $row->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
212
app/admin/controller/system/Admin.php
Normal file
212
app/admin/controller/system/Admin.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemAdmin;
|
||||
use app\admin\service\TriggerService;
|
||||
use app\common\constants\AdminConstant;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Admin
|
||||
* @package app\admin\controller\system
|
||||
* @ControllerAnnotation(title="管理员管理")
|
||||
*/
|
||||
class Admin extends AdminController
|
||||
{
|
||||
|
||||
use \app\admin\traits\Curd;
|
||||
|
||||
protected $sort = [
|
||||
'sort' => 'desc',
|
||||
'id' => 'desc',
|
||||
];
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemAdmin();
|
||||
$this->assign('auth_list', $this->model->getAuthList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
list($page, $limit, $where) = $this->buildTableParames();
|
||||
$count = $this->model
|
||||
->where($where)
|
||||
->count();
|
||||
$list = $this->model
|
||||
->withoutField('password')
|
||||
->where($where)
|
||||
->page($page, $limit)
|
||||
->order($this->sort)
|
||||
->select();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
return json($data);
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="添加")
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$authIds = $this->request->post('auth_ids', []);
|
||||
$post['auth_ids'] = implode(',', array_keys($authIds));
|
||||
$rule = [];
|
||||
$this->validate($post, $rule);
|
||||
try {
|
||||
$save = $this->model->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="编辑")
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$authIds = $this->request->post('auth_ids', []);
|
||||
$post['auth_ids'] = implode(',', array_keys($authIds));
|
||||
$rule = [];
|
||||
$this->validate($post, $rule);
|
||||
if (isset($row['password'])) {
|
||||
unset($row['password']);
|
||||
}
|
||||
try {
|
||||
$save = $row->save($post);
|
||||
TriggerService::updateMenu($id);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
$row->auth_ids = explode(',', $row->auth_ids);
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="编辑")
|
||||
*/
|
||||
public function password($id)
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
if ($this->request->isAjax()) {
|
||||
$post = $this->request->post();
|
||||
$rule = [
|
||||
'password|登录密码' => 'require',
|
||||
'password_again|确认密码' => 'require',
|
||||
];
|
||||
$this->validate($post, $rule);
|
||||
if ($post['password'] != $post['password_again']) {
|
||||
$this->error('两次密码输入不一致');
|
||||
}
|
||||
try {
|
||||
$save = $row->save([
|
||||
'password' => password($post['password']),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
$row->auth_ids = explode(',', $row->auth_ids);
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="删除")
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$row = $this->model->whereIn('id', $id)->select();
|
||||
$row->isEmpty() && $this->error('数据不存在');
|
||||
$id == AdminConstant::SUPER_ADMIN_ID && $this->error('超级管理员不允许修改');
|
||||
if (is_array($id)){
|
||||
if (in_array(AdminConstant::SUPER_ADMIN_ID, $id)){
|
||||
$this->error('超级管理员不允许修改');
|
||||
}
|
||||
}
|
||||
try {
|
||||
$save = $row->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
$save ? $this->success('删除成功') : $this->error('删除失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="属性修改")
|
||||
*/
|
||||
public function modify()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$post = $this->request->post();
|
||||
$rule = [
|
||||
'id|ID' => 'require',
|
||||
'field|字段' => 'require',
|
||||
'value|值' => 'require',
|
||||
];
|
||||
$this->validate($post, $rule);
|
||||
if (!in_array($post['field'], $this->allowModifyFields)) {
|
||||
$this->error('该字段不允许修改:' . $post['field']);
|
||||
}
|
||||
if ($post['id'] == AdminConstant::SUPER_ADMIN_ID && $post['field'] == 'status') {
|
||||
$this->error('超级管理员状态不允许修改');
|
||||
}
|
||||
$row = $this->model->find($post['id']);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
try {
|
||||
$row->save([
|
||||
$post['field'] => $post['value'],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
91
app/admin/controller/system/Auth.php
Normal file
91
app/admin/controller/system/Auth.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemAuth;
|
||||
use app\admin\model\SystemAuthNode;
|
||||
use app\admin\service\TriggerService;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* @ControllerAnnotation(title="角色权限管理")
|
||||
* Class Auth
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class Auth extends AdminController
|
||||
{
|
||||
|
||||
use \app\admin\traits\Curd;
|
||||
|
||||
protected $sort = [
|
||||
'sort' => 'desc',
|
||||
'id' => 'desc',
|
||||
];
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemAuth();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="授权")
|
||||
*/
|
||||
public function authorize($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
if ($this->request->isAjax()) {
|
||||
$list = $this->model->getAuthorizeNodeListByAdminId($id);
|
||||
$this->success('获取成功', $list);
|
||||
}
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="授权保存")
|
||||
*/
|
||||
public function saveAuthorize()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$id = $this->request->post('id');
|
||||
$node = $this->request->post('node', "[]");
|
||||
$node = json_decode($node, true);
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
try {
|
||||
$authNode = new SystemAuthNode();
|
||||
$authNode->where('auth_id', $id)->delete();
|
||||
if (!empty($node)) {
|
||||
$saveAll = [];
|
||||
foreach ($node as $vo) {
|
||||
$saveAll[] = [
|
||||
'auth_id' => $id,
|
||||
'node_id' => $vo,
|
||||
];
|
||||
}
|
||||
$authNode->saveAll($saveAll);
|
||||
}
|
||||
TriggerService::updateMenu();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
}
|
||||
68
app/admin/controller/system/Config.php
Normal file
68
app/admin/controller/system/Config.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemConfig;
|
||||
use app\admin\service\TriggerService;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Config
|
||||
* @package app\admin\controller\system
|
||||
* @ControllerAnnotation(title="系统配置管理")
|
||||
*/
|
||||
class Config extends AdminController
|
||||
{
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="保存")
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$post = $this->request->post();
|
||||
try {
|
||||
foreach ($post as $key => $val) {
|
||||
$this->model
|
||||
->where('name', $key)
|
||||
->update([
|
||||
'value' => $val,
|
||||
]);
|
||||
}
|
||||
TriggerService::updateMenu();
|
||||
TriggerService::updateSysconfig();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
}
|
||||
67
app/admin/controller/system/Log.php
Normal file
67
app/admin/controller/system/Log.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemLog;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* @ControllerAnnotation(title="操作日志管理")
|
||||
* Class Auth
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class Log extends AdminController
|
||||
{
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
[$page, $limit, $where, $excludeFields] = $this->buildTableParames(['month']);
|
||||
|
||||
$month = (isset($excludeFields['month']) && !empty($excludeFields['month']))
|
||||
? date('Ym',strtotime($excludeFields['month']))
|
||||
: date('Ym');
|
||||
|
||||
// todo TP6框架有一个BUG,非模型名与表名不对应时(name属性自定义),withJoin生成的sql有问题
|
||||
|
||||
$count = $this->model
|
||||
->setMonth($month)
|
||||
->with('admin')
|
||||
->where($where)
|
||||
->select();
|
||||
$list = $this->model
|
||||
->setMonth($month)
|
||||
->with('admin')
|
||||
->where($where)
|
||||
->page($page, $limit)
|
||||
->order($this->sort)
|
||||
->select();
|
||||
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
return json($data);
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
219
app/admin/controller/system/Menu.php
Normal file
219
app/admin/controller/system/Menu.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\model\SystemMenu;
|
||||
use app\admin\model\SystemNode;
|
||||
use app\admin\service\TriggerService;
|
||||
use app\common\constants\MenuConstant;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use app\common\controller\AdminController;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Menu
|
||||
* @package app\admin\controller\system
|
||||
* @ControllerAnnotation(title="菜单管理",auth=true)
|
||||
*/
|
||||
class Menu extends AdminController
|
||||
{
|
||||
|
||||
use \app\admin\traits\Curd;
|
||||
|
||||
protected $sort = [
|
||||
'sort' => 'desc',
|
||||
'id' => 'asc',
|
||||
];
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
$count = $this->model->count();
|
||||
$list = $this->model->order($this->sort)->select();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
return json($data);
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="添加")
|
||||
*/
|
||||
public function add($id = null)
|
||||
{
|
||||
$homeId = $this->model
|
||||
->where([
|
||||
'pid' => MenuConstant::HOME_PID,
|
||||
])
|
||||
->value('id');
|
||||
if ($id == $homeId) {
|
||||
$this->error('首页不能添加子菜单');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$rule = [
|
||||
'pid|上级菜单' => 'require',
|
||||
'title|菜单名称' => 'require',
|
||||
'icon|菜单图标' => 'require',
|
||||
];
|
||||
$this->validate($post, $rule);
|
||||
try {
|
||||
$save = $this->model->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
if ($save) {
|
||||
TriggerService::updateMenu();
|
||||
$this->success('保存成功');
|
||||
} else {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
}
|
||||
$pidMenuList = $this->model->getPidMenuList();
|
||||
$this->assign('id', $id);
|
||||
$this->assign('pidMenuList', $pidMenuList);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="编辑")
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$rule = [
|
||||
'pid|上级菜单' => 'require',
|
||||
'title|菜单名称' => 'require',
|
||||
'icon|菜单图标' => 'require',
|
||||
];
|
||||
$this->validate($post, $rule);
|
||||
try {
|
||||
$save = $row->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
if ($save) {
|
||||
TriggerService::updateMenu();
|
||||
$this->success('保存成功');
|
||||
} else {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
}
|
||||
$pidMenuList = $this->model->getPidMenuList();
|
||||
$this->assign([
|
||||
'id' => $id,
|
||||
'pidMenuList' => $pidMenuList,
|
||||
'row' => $row,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="删除")
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$row = $this->model->whereIn('id', $id)->select();
|
||||
empty($row) && $this->error('数据不存在');
|
||||
try {
|
||||
$save = $row->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
if ($save) {
|
||||
TriggerService::updateMenu();
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="属性修改")
|
||||
*/
|
||||
public function modify()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$post = $this->request->post();
|
||||
$rule = [
|
||||
'id|ID' => 'require',
|
||||
'field|字段' => 'require',
|
||||
'value|值' => 'require',
|
||||
];
|
||||
$this->validate($post, $rule);
|
||||
$row = $this->model->find($post['id']);
|
||||
if (!$row) {
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
if (!in_array($post['field'], $this->allowModifyFields)) {
|
||||
$this->error('该字段不允许修改:' . $post['field']);
|
||||
}
|
||||
$homeId = $this->model
|
||||
->where([
|
||||
'pid' => MenuConstant::HOME_PID,
|
||||
])
|
||||
->value('id');
|
||||
if ($post['id'] == $homeId && $post['field'] == 'status') {
|
||||
$this->error('首页状态不允许关闭');
|
||||
}
|
||||
try {
|
||||
$row->save([
|
||||
$post['field'] => $post['value'],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
TriggerService::updateMenu();
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="添加菜单提示")
|
||||
*/
|
||||
public function getMenuTips()
|
||||
{
|
||||
$node = input('get.keywords');
|
||||
$list = SystemNode::whereLike('node', "%{$node}%")
|
||||
->field('node,title')
|
||||
->limit(10)
|
||||
->select();
|
||||
return json([
|
||||
'code' => 0,
|
||||
'content' => $list,
|
||||
'type' => 'success',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
121
app/admin/controller/system/Node.php
Normal file
121
app/admin/controller/system/Node.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemNode;
|
||||
use app\admin\service\TriggerService;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use app\admin\service\NodeService;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* @ControllerAnnotation(title="系统节点管理")
|
||||
* Class Node
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class Node extends AdminController
|
||||
{
|
||||
|
||||
use \app\admin\traits\Curd;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
$count = $this->model
|
||||
->count();
|
||||
$list = $this->model
|
||||
->getNodeTreeList();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
return json($data);
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="系统节点更新")
|
||||
*/
|
||||
public function refreshNode($force = 0)
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$nodeList = (new NodeService())->getNodelist();
|
||||
empty($nodeList) && $this->error('暂无需要更新的系统节点');
|
||||
$model = new SystemNode();
|
||||
try {
|
||||
if ($force == 1) {
|
||||
$updateNodeList = $model->whereIn('node', array_column($nodeList, 'node'))->select();
|
||||
$formatNodeList = array_format_key($nodeList, 'node');
|
||||
foreach ($updateNodeList as $vo) {
|
||||
isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->update([
|
||||
'title' => $formatNodeList[$vo['node']]['title'],
|
||||
'is_auth' => $formatNodeList[$vo['node']]['is_auth'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
$existNodeList = $model->field('node,title,type,is_auth')->select();
|
||||
foreach ($nodeList as $key => $vo) {
|
||||
foreach ($existNodeList as $v) {
|
||||
if ($vo['node'] == $v->node) {
|
||||
unset($nodeList[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$model->saveAll($nodeList);
|
||||
TriggerService::updateNode();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('节点更新失败');
|
||||
}
|
||||
$this->success('节点更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="清除失效节点")
|
||||
*/
|
||||
public function clearNode()
|
||||
{
|
||||
$this->checkPostRequest();
|
||||
$nodeList = (new NodeService())->getNodelist();
|
||||
$model = new SystemNode();
|
||||
try {
|
||||
$existNodeList = $model->field('id,node,title,type,is_auth')->select()->toArray();
|
||||
$formatNodeList = array_format_key($nodeList, 'node');
|
||||
foreach ($existNodeList as $vo) {
|
||||
!isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->delete();
|
||||
}
|
||||
TriggerService::updateNode();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('节点更新失败');
|
||||
}
|
||||
$this->success('节点更新成功');
|
||||
}
|
||||
}
|
||||
43
app/admin/controller/system/Quick.php
Normal file
43
app/admin/controller/system/Quick.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemQuick;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* @ControllerAnnotation(title="快捷入口管理")
|
||||
* Class Quick
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class Quick extends AdminController
|
||||
{
|
||||
|
||||
use \app\admin\traits\Curd;
|
||||
|
||||
protected $sort = [
|
||||
'sort' => 'desc',
|
||||
'id' => 'desc',
|
||||
];
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemQuick();
|
||||
}
|
||||
|
||||
}
|
||||
38
app/admin/controller/system/Uploadfile.php
Normal file
38
app/admin/controller/system/Uploadfile.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\model\SystemUploadfile;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* @ControllerAnnotation(title="上传文件管理")
|
||||
* Class Uploadfile
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class Uploadfile extends AdminController
|
||||
{
|
||||
|
||||
use \app\admin\traits\Curd;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SystemUploadfile();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user