mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-10 03:42:49 +08:00
调整admin下的类库代码,将主要逻辑调整到extend下
This commit is contained in:
@@ -1,146 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller;
|
namespace app\admin\controller;
|
||||||
|
|
||||||
use app\admin\model\SystemUploadfile;
|
use base\admin\controller\AjaxClass;
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\common\service\MenuService;
|
|
||||||
use app\common\service\UploadService;
|
|
||||||
use think\db\Query;
|
|
||||||
use think\facade\Cache;
|
|
||||||
|
|
||||||
|
class Ajax extends AjaxClass
|
||||||
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'),
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
$upload_service = new UploadService($data['upload_type']);
|
|
||||||
|
|
||||||
$upload_service->validateException($data['file']);
|
|
||||||
|
|
||||||
$result = $upload_service->save($data['file']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw $e;
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->success('上传成功', $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传图片至编辑器
|
|
||||||
* @return \think\response\Json
|
|
||||||
*/
|
|
||||||
public function uploadEditor()
|
|
||||||
{
|
|
||||||
$this->checkPostRequest();
|
|
||||||
$data = [
|
|
||||||
'upload_type' => $this->request->post('upload_type'),
|
|
||||||
'file' => $this->request->file('upload'),
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
|
||||||
$upload_service = new UploadService($data['upload_type']);
|
|
||||||
|
|
||||||
$upload_service->validateException($data['file']);
|
|
||||||
|
|
||||||
$result = $upload_service->save($data['file']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return json([
|
|
||||||
'error' => [
|
|
||||||
'message' => '上传成功',
|
|
||||||
'number' => 201,
|
|
||||||
],
|
|
||||||
'fileName' => '',
|
|
||||||
'uploaded' => 1,
|
|
||||||
'url' => $result['url'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取上传文件列表
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,119 +2,8 @@
|
|||||||
|
|
||||||
namespace app\admin\controller;
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use base\admin\controller\IndexClass;
|
||||||
|
|
||||||
use app\admin\model\SystemAdmin;
|
class Index extends IndexClass
|
||||||
use app\admin\model\SystemQuick;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use think\App;
|
|
||||||
use think\facade\Env;
|
|
||||||
|
|
||||||
class Index extends AdminController
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* 后台主页
|
|
||||||
* @return string
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
return $this->fetch('', [
|
|
||||||
'admin' => session('admin'),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后台欢迎页
|
|
||||||
* @return string
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function welcome()
|
|
||||||
{
|
|
||||||
$quicks = SystemQuick::field('id,title,icon,href')
|
|
||||||
->where(['status' => 1])
|
|
||||||
->order('sort', 'desc')
|
|
||||||
->autoCache('welcome_list')
|
|
||||||
->limit(8)
|
|
||||||
->select();
|
|
||||||
$this->assign('quicks', $quicks);
|
|
||||||
return $this->fetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改管理员信息
|
|
||||||
* @return string
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改密码
|
|
||||||
* @return string
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,98 +2,11 @@
|
|||||||
|
|
||||||
namespace app\admin\controller;
|
namespace app\admin\controller;
|
||||||
|
|
||||||
use app\admin\model\SystemAdmin;
|
use base\admin\controller\LoginClass;
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use think\captcha\facade\Captcha;
|
|
||||||
use think\facade\Env;
|
|
||||||
use think\facade\Event;
|
|
||||||
use trait\admin\controller\LoginTrait;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Login.
|
* Class Login.
|
||||||
*/
|
*/
|
||||||
class Login extends AdminController
|
class Login extends LoginClass
|
||||||
{
|
{
|
||||||
use LoginTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化方法.
|
|
||||||
*/
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
event_response('AdminLoginIndex', [
|
|
||||||
'controller' => $this,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$captcha = Env::get('adminsystem.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();
|
|
||||||
|
|
||||||
Event::trigger('AdminLoginSuccess', $admin);
|
|
||||||
|
|
||||||
$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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户退出.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function out()
|
|
||||||
{
|
|
||||||
session('admin', null);
|
|
||||||
$this->success('退出登录成功');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码
|
|
||||||
* @return \think\Response
|
|
||||||
*/
|
|
||||||
public function captcha()
|
|
||||||
{
|
|
||||||
return Captcha::create();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,12 @@
|
|||||||
|
|
||||||
namespace app\admin\controller\debug;
|
namespace app\admin\controller\debug;
|
||||||
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\debug\LogClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ControllerAnnotation(title="debug_log")
|
* @ControllerAnnotation(title="debug_log")
|
||||||
*/
|
*/
|
||||||
class Log extends AdminController
|
class Log extends LogClass
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $sort = [
|
|
||||||
'uid' => 'desc',
|
|
||||||
'id' => 'asc',
|
|
||||||
];
|
|
||||||
|
|
||||||
use \app\admin\traits\Curd;
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
|
|
||||||
$this->model = new \app\admin\model\DebugLog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\mall;
|
namespace app\admin\controller\mall;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\MallCate;
|
|
||||||
use app\admin\traits\Curd;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\mall\CateClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Admin
|
* Class Admin.
|
||||||
* @package app\admin\controller\system
|
|
||||||
* @ControllerAnnotation(title="商品分类管理")
|
* @ControllerAnnotation(title="商品分类管理")
|
||||||
*/
|
*/
|
||||||
class Cate extends AdminController
|
class Cate extends CateClass
|
||||||
{
|
{
|
||||||
|
|
||||||
use Curd;
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
$this->model = new MallCate();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,121 +2,13 @@
|
|||||||
|
|
||||||
namespace app\admin\controller\mall;
|
namespace app\admin\controller\mall;
|
||||||
|
|
||||||
use app\admin\model\MallCate;
|
|
||||||
use app\admin\model\MallGoods;
|
|
||||||
use app\admin\model\MallTag;
|
|
||||||
use app\admin\traits\Curd;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\mall\GoodsClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Goods
|
* Class Goods.
|
||||||
* @package app\admin\controller\mall
|
|
||||||
* @ControllerAnnotation(title="商城商品管理")
|
* @ControllerAnnotation(title="商城商品管理")
|
||||||
*/
|
*/
|
||||||
class Goods extends AdminController
|
class Goods extends GoodsClass
|
||||||
{
|
{
|
||||||
use Curd;
|
|
||||||
|
|
||||||
protected $relationSearch = true;
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
$this->model = new MallGoods();
|
|
||||||
|
|
||||||
$this->assign('select_list_cate', MallCate::select(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function read($id)
|
|
||||||
{
|
|
||||||
|
|
||||||
$row = $this->model->find($id);
|
|
||||||
|
|
||||||
$this->assign('row', $row);
|
|
||||||
|
|
||||||
return $this->fetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @NodeAnotation(title="导出")
|
|
||||||
*/
|
|
||||||
public function export()
|
|
||||||
{
|
|
||||||
list($page, $limit, $where) = $this->buildTableParames();
|
|
||||||
|
|
||||||
$this->model = $this->model
|
|
||||||
->withJoin('cate', 'LEFT');
|
|
||||||
|
|
||||||
$fields = $this->request->param('fields', '{}', null);
|
|
||||||
$image_fields = $this->request->param('image_fields', '{}', null);
|
|
||||||
$select_fields = $this->request->param('select_fields', '{}', null);
|
|
||||||
$date_fields = $this->request->param('date_fields', '{}', null);
|
|
||||||
|
|
||||||
$fields = json_decode($fields, true);
|
|
||||||
$image_fields = json_decode($image_fields, true);
|
|
||||||
$select_fields = json_decode($select_fields, true);
|
|
||||||
$date_fields = json_decode($date_fields, true);
|
|
||||||
|
|
||||||
$content = \app\common\tools\ExportTools::excel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
|
|
||||||
|
|
||||||
return download($content, $this->model->getName() . date('YmdHis') . '.xlsx', true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,12 @@
|
|||||||
|
|
||||||
namespace app\admin\controller\mall;
|
namespace app\admin\controller\mall;
|
||||||
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\mall\TagClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ControllerAnnotation(title="mall_tag")
|
* @ControllerAnnotation(title="mall_tag")
|
||||||
*/
|
*/
|
||||||
class Tag extends AdminController
|
class Tag extends TagClass
|
||||||
{
|
{
|
||||||
|
|
||||||
use \app\admin\traits\Curd;
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
|
|
||||||
$this->model = new \app\admin\model\MallTag();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,9 @@
|
|||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
use app\admin\model\SystemAdmin;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
use app\admin\service\TriggerService;
|
use base\admin\controller\system\AdminClass;
|
||||||
use app\common\constants\AdminConstant;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use think\App;
|
|
||||||
use think\facade\Validate;
|
|
||||||
use think\validate\ValidateRule;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Admin.
|
* Class Admin.
|
||||||
@@ -18,202 +12,6 @@ use think\validate\ValidateRule;
|
|||||||
*
|
*
|
||||||
* @NodeAnotation(title="自定义权限标识符",name="customFlag")
|
* @NodeAnotation(title="自定义权限标识符",name="customFlag")
|
||||||
*/
|
*/
|
||||||
class Admin extends AdminController
|
class Admin extends AdminClass
|
||||||
{
|
{
|
||||||
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(), true);
|
|
||||||
|
|
||||||
$this->setDataBrage('count', 10);
|
|
||||||
$this->setDataBrage('tips', '请谨慎操作');
|
|
||||||
|
|
||||||
$this->setDataBrage('adminCustomFlag', $this->checkAuth('system.admin/customFlag', false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 = Validate::rule('username|用户登录名', ValidateRule::isRequire());
|
|
||||||
$post['password'] = password(sysconfig('site', 'site_default_password', '123456'));
|
|
||||||
$this->validate($post, $rule);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$model_admin = SystemAdmin::where('username', $post['username'])->find();
|
|
||||||
|
|
||||||
if (!empty($model_admin)) {
|
|
||||||
throw new \Exception('同名用户已存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
$save = $this->model->save($post);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('保存失败:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$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)
|
|
||||||
{
|
|
||||||
$row = $this->model->find($id);
|
|
||||||
empty($row) && $this->error('数据不存在');
|
|
||||||
if ($this->request->isAjax()) {
|
|
||||||
$this->checkPostRequest();
|
|
||||||
$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('保存成功');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
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 app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\system\AuthClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ControllerAnnotation(title="角色权限管理")
|
* @ControllerAnnotation(title="角色权限管理")
|
||||||
* Class Auth
|
* Class Auth
|
||||||
* @package app\admin\controller\system
|
|
||||||
*/
|
*/
|
||||||
class Auth extends AdminController
|
class Auth extends AuthClass
|
||||||
{
|
{
|
||||||
|
|
||||||
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('保存成功');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,82 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\SystemConfig;
|
|
||||||
use app\admin\service\TriggerService;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\system\ConfigClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Config
|
* Class Config.
|
||||||
* @package app\admin\controller\system
|
|
||||||
* @ControllerAnnotation(title="系统配置管理")
|
* @ControllerAnnotation(title="系统配置管理")
|
||||||
*/
|
*/
|
||||||
class Config extends AdminController
|
class Config extends ConfigClass
|
||||||
{
|
{
|
||||||
|
|
||||||
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->except(['group_name'], 'post');
|
|
||||||
|
|
||||||
$group_name = $this->request->post('group_name');
|
|
||||||
|
|
||||||
try {
|
|
||||||
foreach ($post as $key => $val) {
|
|
||||||
|
|
||||||
if (empty($group_name)) {
|
|
||||||
|
|
||||||
$this->model
|
|
||||||
->where('name', $key)
|
|
||||||
->update([
|
|
||||||
'value' => $val,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$model_config = SystemConfig::where('group', $group_name)
|
|
||||||
->where('name', $key)
|
|
||||||
->find();
|
|
||||||
|
|
||||||
if (empty($model_config)) {
|
|
||||||
$model_config = SystemConfig::create([
|
|
||||||
'group' => $group_name,
|
|
||||||
'name' => $key,
|
|
||||||
'value' => $val
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$model_config->save([
|
|
||||||
'value' => $val
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TriggerService::updateMenu();
|
|
||||||
TriggerService::updateSysconfig();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('保存失败');
|
|
||||||
}
|
|
||||||
$this->success('保存成功');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,217 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
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 app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\system\MenuClass;
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Menu
|
* Class Menu.
|
||||||
* @package app\admin\controller\system
|
|
||||||
* @ControllerAnnotation(title="菜单管理",auth=true)
|
* @ControllerAnnotation(title="菜单管理",auth=true)
|
||||||
*/
|
*/
|
||||||
class Menu extends AdminController
|
class Menu extends MenuClass
|
||||||
{
|
{
|
||||||
|
|
||||||
use \app\admin\traits\Curd;
|
|
||||||
|
|
||||||
protected $sort = [
|
|
||||||
'sort' => 'desc',
|
|
||||||
'id' => 'asc',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
$this->model = new SystemMenu();
|
|
||||||
|
|
||||||
$this->assign('menu_home_pid', MenuConstant::HOME_PID, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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);
|
|
||||||
|
|
||||||
//防止首页pid被修改而导致渲染时报错
|
|
||||||
if ($row->pid == MenuConstant::HOME_PID) {
|
|
||||||
unset($post['pid']);
|
|
||||||
}
|
|
||||||
|
|
||||||
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',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,112 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\SystemNode;
|
|
||||||
use app\admin\service\TriggerService;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\system\NodeClass;
|
||||||
use app\admin\service\NodeService;
|
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ControllerAnnotation(title="系统节点管理")
|
* @ControllerAnnotation(title="系统节点管理")
|
||||||
* Class Node
|
* Class Node
|
||||||
* @package app\admin\controller\system
|
|
||||||
*/
|
*/
|
||||||
class Node extends AdminController
|
class Node extends NodeClass
|
||||||
{
|
{
|
||||||
|
|
||||||
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('节点更新成功');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\SystemQuick;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\system\QuickClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ControllerAnnotation(title="快捷入口管理")
|
* @ControllerAnnotation(title="快捷入口管理")
|
||||||
* Class Quick
|
* Class Quick
|
||||||
* @package app\admin\controller\system
|
|
||||||
*/
|
*/
|
||||||
class Quick extends AdminController
|
class Quick extends QuickClass
|
||||||
{
|
{
|
||||||
|
|
||||||
use \app\admin\traits\Curd;
|
|
||||||
|
|
||||||
protected $sort = [
|
|
||||||
'sort' => 'desc',
|
|
||||||
'id' => 'desc',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
$this->model = new SystemQuick();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\SystemUploadfile;
|
|
||||||
use app\common\controller\AdminController;
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\controller\system\UploadfileClass;
|
||||||
use think\App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ControllerAnnotation(title="上传文件管理")
|
* @ControllerAnnotation(title="上传文件管理")
|
||||||
* Class Uploadfile
|
* Class Uploadfile
|
||||||
* @package app\admin\controller\system
|
|
||||||
*/
|
*/
|
||||||
class Uploadfile extends AdminController
|
class Uploadfile extends UploadfileClass
|
||||||
{
|
{
|
||||||
|
|
||||||
use \app\admin\traits\Curd;
|
|
||||||
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
parent::__construct($app);
|
|
||||||
$this->model = new SystemUploadfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,36 +2,8 @@
|
|||||||
|
|
||||||
namespace app\admin\middleware;
|
namespace app\admin\middleware;
|
||||||
|
|
||||||
use think\Request;
|
use base\admin\middleware\CsrfMiddlewareClass;
|
||||||
|
|
||||||
class CsrfMiddleware
|
class CsrfMiddleware extends CsrfMiddlewareClass
|
||||||
{
|
{
|
||||||
use \app\common\traits\JumpTrait;
|
|
||||||
|
|
||||||
public function handle(Request $request, \Closure $next)
|
|
||||||
{
|
|
||||||
if (env('adminsystem.IS_CSRF', true)) {
|
|
||||||
if (!in_array($request->method(), ['GET', 'HEAD', 'OPTIONS'])) {
|
|
||||||
// 跨域校验
|
|
||||||
$refererUrl = $request->header('REFERER', null);
|
|
||||||
$refererInfo = parse_url($refererUrl);
|
|
||||||
$host = $request->host(true);
|
|
||||||
if (!isset($refererInfo['host']) || $refererInfo['host'] != $host) {
|
|
||||||
$this->error('当前请求不合法!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// CSRF校验
|
|
||||||
// @todo 兼容CK编辑器上传功能
|
|
||||||
$ckCsrfToken = $request->post('ckCsrfToken', null);
|
|
||||||
$data = !empty($ckCsrfToken) ? ['__token__' => $ckCsrfToken] : [];
|
|
||||||
|
|
||||||
$check = $request->checkToken('__token__', $data);
|
|
||||||
if (!$check) {
|
|
||||||
$this->error('请求验证失败,请重新刷新页面!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,55 +2,12 @@
|
|||||||
|
|
||||||
namespace app\admin\middleware;
|
namespace app\admin\middleware;
|
||||||
|
|
||||||
use think\facade\Log;
|
use base\admin\middleware\SystemLogClass;
|
||||||
use think\facade\Request as FacadeRequest;
|
|
||||||
use think\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统操作日志中间件
|
* 系统操作日志中间件
|
||||||
* Class SystemLog.
|
* Class SystemLog.
|
||||||
*/
|
*/
|
||||||
class SystemLog
|
class SystemLog extends SystemLogClass
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* 敏感信息字段,日志记录时需要加密.
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $sensitiveParams = [
|
|
||||||
'password',
|
|
||||||
'password_again',
|
|
||||||
'phone',
|
|
||||||
'mobile',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function handle(Request $request, \Closure $next)
|
|
||||||
{
|
|
||||||
$params = $request->param();
|
|
||||||
if (isset($params['s'])) {
|
|
||||||
unset($params['s']);
|
|
||||||
}
|
|
||||||
foreach ($params as $key => $val) {
|
|
||||||
in_array($key, $this->sensitiveParams) && $params[$key] = '***********';
|
|
||||||
}
|
|
||||||
$method = strtolower($request->method());
|
|
||||||
$url = $request->url();
|
|
||||||
|
|
||||||
if ($request->isAjax()) {
|
|
||||||
if (in_array($method, ['post', 'put', 'delete'])) {
|
|
||||||
$ip = FacadeRequest::ip();
|
|
||||||
$data = [
|
|
||||||
'admin_id' => session('admin.id'),
|
|
||||||
'url' => $url,
|
|
||||||
'method' => $method,
|
|
||||||
'ip' => $ip,
|
|
||||||
'content' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
||||||
'useragent' => $_SERVER['HTTP_USER_AGENT'],
|
|
||||||
'create_time' => time(),
|
|
||||||
];
|
|
||||||
Log::debug(print_r($data, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,8 @@
|
|||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
use base\admin\model\DebugLogClass;
|
||||||
|
|
||||||
class DebugLog extends TimeModel
|
class DebugLog extends DebugLogClass
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $name = "debug_log";
|
|
||||||
|
|
||||||
protected $deleteTime = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\MallCateClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class MallCate extends MallCateClass
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class MallCate extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\MallGoodsClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class MallGoods extends MallGoodsClass
|
||||||
|
|
||||||
class MallGoods extends TimeModel
|
|
||||||
{
|
{
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
public function cate()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTagListTitleAttr()
|
|
||||||
{
|
|
||||||
$tags = $this->getAttr('tag');
|
|
||||||
|
|
||||||
$list_tag = MallTag::whereIn('id', $tags)->column('title');
|
|
||||||
|
|
||||||
return $list_tag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,8 @@
|
|||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
use base\admin\model\MallTagClass;
|
||||||
|
|
||||||
class MallTag extends TimeModel
|
class MallTag extends MallTagClass
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $name = "mall_tag";
|
|
||||||
|
|
||||||
protected $deleteTime = "delete_time";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemAdminClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemAdmin extends SystemAdminClass
|
||||||
|
|
||||||
class SystemAdmin extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
public static $autoCache = [
|
|
||||||
[
|
|
||||||
'name' => 'info',
|
|
||||||
'field' => 'id'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
public function getAuthList()
|
|
||||||
{
|
|
||||||
$list = (new SystemAuth())
|
|
||||||
->where('status', 1)
|
|
||||||
->column('title', 'id');
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemAuthClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemAuth extends SystemAuthClass
|
||||||
|
|
||||||
class SystemAuth extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据角色ID获取授权节点
|
|
||||||
* @param $authId
|
|
||||||
* @return array
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
public function getAuthorizeNodeListByAdminId($authId)
|
|
||||||
{
|
|
||||||
$checkNodeList = (new SystemAuthNode())
|
|
||||||
->where('auth_id', $authId)
|
|
||||||
->column('node_id');
|
|
||||||
$systemNode = new SystemNode();
|
|
||||||
$nodelList = $systemNode
|
|
||||||
->where('is_auth', 1)
|
|
||||||
->field('id,node,title,type,is_auth')
|
|
||||||
->select()
|
|
||||||
->toArray();
|
|
||||||
$newNodeList = [];
|
|
||||||
foreach ($nodelList as $vo) {
|
|
||||||
if ($vo['type'] == 1) {
|
|
||||||
$vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
|
|
||||||
$vo['checked'] = false;
|
|
||||||
$vo['title'] = "{$vo['title']}【{$vo['node']}】";
|
|
||||||
$children = [];
|
|
||||||
foreach ($nodelList as $v) {
|
|
||||||
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
|
||||||
$v = array_merge($v, ['field' => 'node', 'spread' => true]);
|
|
||||||
$v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
|
|
||||||
$v['title'] = "{$v['title']}【{$v['node']}】";
|
|
||||||
$children[] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
!empty($children) && $vo['children'] = $children;
|
|
||||||
$newNodeList[] = $vo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $newNodeList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemAuthNodeClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemAuthNode extends SystemAuthNodeClass
|
||||||
|
|
||||||
class SystemAuthNode extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $autoWriteTimestamp = false;
|
|
||||||
|
|
||||||
protected $deleteTime = false;
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemConfigClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemConfig extends SystemConfigClass
|
||||||
|
|
||||||
class SystemConfig extends TimeModel
|
|
||||||
{
|
{
|
||||||
protected $deleteTime = false;
|
|
||||||
}
|
}
|
||||||
@@ -1,61 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemMenuClass;
|
||||||
|
|
||||||
|
class SystemMenu extends SystemMenuClass
|
||||||
use app\common\constants\MenuConstant;
|
|
||||||
use app\common\model\TimeModel;
|
|
||||||
|
|
||||||
class SystemMenu extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
public function getPidMenuList()
|
|
||||||
{
|
|
||||||
$list = $this->field('id,pid,title')
|
|
||||||
->where([
|
|
||||||
['pid', '<>', MenuConstant::HOME_PID],
|
|
||||||
['status', '=', 1],
|
|
||||||
])
|
|
||||||
->select()
|
|
||||||
->toArray();
|
|
||||||
$pidMenuList = $this->buildPidMenu(0, $list);
|
|
||||||
$pidMenuList = array_merge([[
|
|
||||||
'id' => 0,
|
|
||||||
'pid' => 0,
|
|
||||||
'title' => '顶级菜单',
|
|
||||||
]], $pidMenuList);
|
|
||||||
return $pidMenuList;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildPidMenu($pid, $list, $level = 0)
|
|
||||||
{
|
|
||||||
$newList = [];
|
|
||||||
foreach ($list as $vo) {
|
|
||||||
if ($vo['pid'] == $pid) {
|
|
||||||
$level++;
|
|
||||||
foreach ($newList as $v) {
|
|
||||||
if ($vo['pid'] == $v['pid'] && isset($v['level'])) {
|
|
||||||
$level = $v['level'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$vo['level'] = $level;
|
|
||||||
if ($level > 1) {
|
|
||||||
$repeatString = " ";
|
|
||||||
$markString = str_repeat("{$repeatString}├{$repeatString}", $level - 1);
|
|
||||||
$vo['title'] = $markString . $vo['title'];
|
|
||||||
}
|
|
||||||
$newList[] = $vo;
|
|
||||||
$childList = $this->buildPidMenu($vo['id'], $list, $level);
|
|
||||||
!empty($childList) && $newList = array_merge($newList, $childList);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return $newList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemNodeClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemNode extends SystemNodeClass
|
||||||
|
|
||||||
class SystemNode extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = false;
|
|
||||||
|
|
||||||
public function getNodeTreeList()
|
|
||||||
{
|
|
||||||
$list = $this->select()->toArray();
|
|
||||||
$list = $this->buildNodeTree($list);
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildNodeTree($list)
|
|
||||||
{
|
|
||||||
$newList = [];
|
|
||||||
$repeatString = " ";
|
|
||||||
foreach ($list as $vo) {
|
|
||||||
if ($vo['type'] == 1) {
|
|
||||||
$newList[] = $vo;
|
|
||||||
foreach ($list as $v) {
|
|
||||||
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
|
||||||
$v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
|
|
||||||
$newList[] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $newList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemQuickClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemQuick extends SystemQuickClass
|
||||||
|
|
||||||
class SystemQuick extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
public static $autoCache = [
|
|
||||||
[
|
|
||||||
'name' => 'welcome_list'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use base\admin\model\SystemUploadfileClass;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
class SystemUploadfile extends SystemUploadfileClass
|
||||||
|
|
||||||
class SystemUploadfile extends TimeModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,147 +2,8 @@
|
|||||||
|
|
||||||
namespace app\admin\service;
|
namespace app\admin\service;
|
||||||
|
|
||||||
use app\admin\model\MallCate;
|
use base\admin\service\InitAdminServiceClass;
|
||||||
use app\admin\model\MallGoods;
|
|
||||||
use app\admin\model\MallTag;
|
|
||||||
use app\admin\model\SystemAdmin;
|
|
||||||
use app\admin\model\SystemAuth;
|
|
||||||
use app\admin\model\SystemAuthNode;
|
|
||||||
use app\admin\model\SystemConfig;
|
|
||||||
use app\admin\model\SystemMenu;
|
|
||||||
use app\admin\model\SystemNode;
|
|
||||||
use app\admin\model\SystemQuick;
|
|
||||||
use app\common\constants\AdminConstant;
|
|
||||||
|
|
||||||
class InitAdminService
|
class InitAdminService extends InitAdminServiceClass
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $output = null;
|
|
||||||
|
|
||||||
public function __construct($output)
|
|
||||||
{
|
|
||||||
$this->output = $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
$this->initAdmin();
|
|
||||||
$this->initAuth();
|
|
||||||
$this->initConfig();
|
|
||||||
$this->initMenu();
|
|
||||||
$this->initQuick();
|
|
||||||
$this->initMall();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initMall()
|
|
||||||
{
|
|
||||||
$output = $this->output;
|
|
||||||
|
|
||||||
$output->writeln('开始初始化商城案例');
|
|
||||||
|
|
||||||
$list_cate = $this->requireData('MallCate');
|
|
||||||
|
|
||||||
$list_goods = $this->requireData('MallGoods');
|
|
||||||
|
|
||||||
foreach ($list_cate as $data_cate) {
|
|
||||||
$model_cate = MallCate::create($data_cate);
|
|
||||||
|
|
||||||
foreach ($list_goods as $data_goods) {
|
|
||||||
$data_goods['cate_id'] = $model_cate->id;
|
|
||||||
MallGoods::create($data_goods);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$list_tag = $this->requireData('MallTag');
|
|
||||||
|
|
||||||
$this->installData(MallTag::class, $list_tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initQuick()
|
|
||||||
{
|
|
||||||
$output = $this->output;
|
|
||||||
|
|
||||||
$output->writeln('开始初始化快捷入口');
|
|
||||||
|
|
||||||
$list_quick = $this->requireData('SystemQuick');
|
|
||||||
|
|
||||||
$this->installData(SystemQuick::class, $list_quick);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initMenu()
|
|
||||||
{
|
|
||||||
$output = $this->output;
|
|
||||||
|
|
||||||
$output->writeln('开始初始化系统菜单');
|
|
||||||
|
|
||||||
$list_menu = $this->requireData('SystemMenu');
|
|
||||||
|
|
||||||
$this->installData(SystemMenu::class, $list_menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initConfig()
|
|
||||||
{
|
|
||||||
$output = $this->output;
|
|
||||||
$output->writeln('开始初始化系统设置');
|
|
||||||
|
|
||||||
$list_config = $this->requireData('SystemConfig');
|
|
||||||
|
|
||||||
$this->installData(SystemConfig::class, $list_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initAdmin()
|
|
||||||
{
|
|
||||||
$output = $this->output;
|
|
||||||
|
|
||||||
$output->writeln('创建超级管理员');
|
|
||||||
|
|
||||||
$model_admin = SystemAdmin::find(AdminConstant::SUPER_ADMIN_ID);
|
|
||||||
|
|
||||||
if (empty($model_admin)) {
|
|
||||||
$model_admin = new SystemAdmin();
|
|
||||||
$model_admin->id = AdminConstant::SUPER_ADMIN_ID;
|
|
||||||
$model_admin->head_img = '/static/admin/images/head.jpg';
|
|
||||||
$model_admin->username = 'admin';
|
|
||||||
$model_admin->password = password(123456);
|
|
||||||
$model_admin->status = 1;
|
|
||||||
$model_admin->save();
|
|
||||||
$output->writeln('创建超级管理员成功');
|
|
||||||
} else {
|
|
||||||
$output->writeln('超级管理员已存在,无需初始化');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initAuth()
|
|
||||||
{
|
|
||||||
$output = $this->output;
|
|
||||||
|
|
||||||
$output->writeln('开始初始化权限');
|
|
||||||
|
|
||||||
$list_auth = $this->requireData('SystemAuth');
|
|
||||||
|
|
||||||
$this->installData(SystemAuth::class, $list_auth);
|
|
||||||
|
|
||||||
$output->writeln('开始初始化权限节点');
|
|
||||||
|
|
||||||
$list_auth_node = $this->requireData('SystemAuthNode');
|
|
||||||
|
|
||||||
$this->installData(SystemAuthNode::class, $list_auth_node);
|
|
||||||
|
|
||||||
$output->writeln('开始初始化系统节点');
|
|
||||||
$list_node = $this->requireData('SystemNode');
|
|
||||||
|
|
||||||
$this->installData(SystemNode::class, $list_node);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function installData($model_name, $list)
|
|
||||||
{
|
|
||||||
foreach ($list as $key => $value) {
|
|
||||||
$model_name::create($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function requireData($table_name)
|
|
||||||
{
|
|
||||||
return include __DIR__ . '/initAdminData/' . $table_name . '.php';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\service;
|
namespace app\admin\service;
|
||||||
|
|
||||||
|
use base\admin\service\NodeServiceClass;
|
||||||
|
|
||||||
use app\admin\service\node\Node;
|
class NodeService extends NodeServiceClass
|
||||||
|
|
||||||
class NodeService
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取节点服务
|
|
||||||
* @return array
|
|
||||||
* @throws \Doctrine\Common\Annotations\AnnotationException
|
|
||||||
* @throws \ReflectionException
|
|
||||||
*/
|
|
||||||
public function getNodelist()
|
|
||||||
{
|
|
||||||
$basePath = base_path() . 'admin' . DIRECTORY_SEPARATOR . 'controller';
|
|
||||||
$baseNamespace = "app\admin\controller";
|
|
||||||
|
|
||||||
$nodeList = (new Node($basePath, $baseNamespace))
|
|
||||||
->getNodelist();
|
|
||||||
|
|
||||||
return $nodeList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,52 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\service;
|
namespace app\admin\service;
|
||||||
|
|
||||||
|
use base\admin\service\TriggerServiceClass;
|
||||||
|
|
||||||
use think\facade\Cache;
|
class TriggerService extends TriggerServiceClass
|
||||||
|
|
||||||
class TriggerService
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新菜单缓存
|
|
||||||
* @param null $adminId
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function updateMenu($adminId = null)
|
|
||||||
{
|
|
||||||
if(empty($adminId)){
|
|
||||||
Cache::tag('initAdmin')->clear();
|
|
||||||
}else{
|
|
||||||
Cache::delete('initAdmin_' . $adminId);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新节点缓存
|
|
||||||
* @param null $adminId
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function updateNode($adminId = null)
|
|
||||||
{
|
|
||||||
if(empty($adminId)){
|
|
||||||
Cache::tag('authNode')->clear();
|
|
||||||
}else{
|
|
||||||
Cache::delete('allAuthNode_' . $adminId);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新系统设置缓存
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function updateSysconfig()
|
|
||||||
{
|
|
||||||
Cache::tag('sysconfig')->clear();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
namespace app\admin\service\annotation;
|
namespace app\admin\service\annotation;
|
||||||
|
|
||||||
|
use base\admin\service\annotation\ControllerAnnotationClass;
|
||||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||||
use Doctrine\Common\Annotations\Annotation\Required;
|
|
||||||
use Doctrine\Common\Annotations\Annotation\Target;
|
use Doctrine\Common\Annotations\Annotation\Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ControllerAnnotation
|
* Class ControllerAnnotation.
|
||||||
*
|
*
|
||||||
* @Annotation
|
* @Annotation
|
||||||
* @Target("CLASS")
|
* @Target("CLASS")
|
||||||
@@ -27,23 +27,6 @@ use Doctrine\Common\Annotations\Annotation\Target;
|
|||||||
*
|
*
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
final class ControllerAnnotation
|
final class ControllerAnnotation extends ControllerAnnotationClass
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Route group prefix for the controller
|
|
||||||
*
|
|
||||||
* @Required()
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $title = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否开启权限控制
|
|
||||||
* @Enum({true,false})
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $auth = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace app\admin\service\annotation;
|
namespace app\admin\service\annotation;
|
||||||
|
|
||||||
|
use base\admin\service\annotation\NodeAnotationClass;
|
||||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,25 +24,6 @@ use Doctrine\Common\Annotations\Annotation\Attributes;
|
|||||||
* @Attribute("time", type = "int")
|
* @Attribute("time", type = "int")
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
final class NodeAnotation
|
final class NodeAnotation extends NodeAnotationClass
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* 节点名称.
|
|
||||||
* @Required()
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否开启权限控制.
|
|
||||||
* @Enum({true,false})
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $auth = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 节点 一般无需设置.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $name;
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\service\curd\exceptions;
|
namespace app\admin\service\curd\exceptions;
|
||||||
|
|
||||||
|
use base\admin\service\curd\exceptions\CurdExceptionClass;
|
||||||
|
|
||||||
class CurdException extends \Exception
|
class CurdException extends CurdExceptionClass
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\service\curd\exceptions;
|
namespace app\admin\service\curd\exceptions;
|
||||||
|
|
||||||
|
use base\admin\service\curd\exceptions\FileExceptionClass;
|
||||||
|
|
||||||
class FileException extends \Exception
|
class FileException extends FileExceptionClass
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\service\curd\exceptions;
|
namespace app\admin\service\curd\exceptions;
|
||||||
|
|
||||||
|
use base\admin\service\curd\exceptions\TableExceptionClass;
|
||||||
|
|
||||||
class TableException extends \Exception
|
class TableException extends TableExceptionClass
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,163 +12,12 @@
|
|||||||
|
|
||||||
namespace app\admin\service\node;
|
namespace app\admin\service\node;
|
||||||
|
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
use base\admin\service\node\NodeClass;
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
|
||||||
use Doctrine\Common\Annotations\DocParser;
|
|
||||||
use think\helper\Str;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 节点处理类
|
* 节点处理类
|
||||||
* Class Node.
|
* Class Node.
|
||||||
*/
|
*/
|
||||||
class Node
|
class Node extends NodeClass
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string 当前文件夹
|
|
||||||
*/
|
|
||||||
protected $basePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string 命名空间前缀
|
|
||||||
*/
|
|
||||||
protected $baseNamespace;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造方法
|
|
||||||
* Node constructor.
|
|
||||||
* @param string $basePath 读取的文件夹
|
|
||||||
* @param string $baseNamespace 读取的命名空间前缀
|
|
||||||
*/
|
|
||||||
public function __construct($basePath, $baseNamespace)
|
|
||||||
{
|
|
||||||
$this->basePath = $basePath;
|
|
||||||
$this->baseNamespace = $baseNamespace;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有节点.
|
|
||||||
* @return array
|
|
||||||
* @throws \Doctrine\Common\Annotations\AnnotationException
|
|
||||||
* @throws \ReflectionException
|
|
||||||
*/
|
|
||||||
public function getNodelist()
|
|
||||||
{
|
|
||||||
list($nodeList, $controllerList) = [[], $this->getControllerList()];
|
|
||||||
|
|
||||||
if (!empty($controllerList)) {
|
|
||||||
AnnotationRegistry::registerLoader('class_exists');
|
|
||||||
$parser = new DocParser();
|
|
||||||
$parser->setIgnoreNotImportedAnnotations(true);
|
|
||||||
$reader = new AnnotationReader($parser);
|
|
||||||
|
|
||||||
foreach ($controllerList as $controllerFormat => $controller) {
|
|
||||||
// 获取类和方法的注释信息
|
|
||||||
$reflectionClass = new \ReflectionClass($controller);
|
|
||||||
$methods = $reflectionClass->getMethods();
|
|
||||||
$actionList = [];
|
|
||||||
|
|
||||||
// 遍历读取所有方法的注释的参数信息
|
|
||||||
foreach ($methods as $method) {
|
|
||||||
// 读取NodeAnotation的注解
|
|
||||||
$nodeAnnotation = $reader->getMethodAnnotation($method, NodeAnotation::class);
|
|
||||||
if (!empty($nodeAnnotation) && !empty($nodeAnnotation->title)) {
|
|
||||||
$actionTitle = !empty($nodeAnnotation) && !empty($nodeAnnotation->title) ? $nodeAnnotation->title : null;
|
|
||||||
$actionAuth = !empty($nodeAnnotation) && !empty($nodeAnnotation->auth) ? $nodeAnnotation->auth : false;
|
|
||||||
|
|
||||||
$method_name = $nodeAnnotation->name;
|
|
||||||
|
|
||||||
if (empty($method_name)) {
|
|
||||||
$method_name = $method->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$actionList[] = [
|
|
||||||
'node' => $controllerFormat . '/' . $method_name,
|
|
||||||
'title' => $actionTitle,
|
|
||||||
'is_auth' => $actionAuth,
|
|
||||||
'type' => 2,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取挂载到控制器注解中的节点
|
|
||||||
$nodeAnnotationInController = $reader->getClassAnnotations($reflectionClass);
|
|
||||||
foreach ($nodeAnnotationInController as $nodeAnnotation) {
|
|
||||||
if ($nodeAnnotation instanceof NodeAnotation) {
|
|
||||||
$actionList[] = [
|
|
||||||
'node' => $controllerFormat . '/' . $nodeAnnotation->name,
|
|
||||||
'title' => $nodeAnnotation->title,
|
|
||||||
'is_auth' => $nodeAnnotation->auth,
|
|
||||||
'type' => 2,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 方法非空才读取控制器注解
|
|
||||||
if (!empty($actionList)) {
|
|
||||||
// 读取Controller的注解
|
|
||||||
$controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class);
|
|
||||||
$controllerTitle = !empty($controllerAnnotation) && !empty($controllerAnnotation->title) ? $controllerAnnotation->title : null;
|
|
||||||
$controllerAuth = !empty($controllerAnnotation) && !empty($controllerAnnotation->auth) ? $controllerAnnotation->auth : false;
|
|
||||||
$nodeList[] = [
|
|
||||||
'node' => $controllerFormat,
|
|
||||||
'title' => $controllerTitle,
|
|
||||||
'is_auth' => $controllerAuth,
|
|
||||||
'type' => 1,
|
|
||||||
];
|
|
||||||
$nodeList = array_merge($nodeList, $actionList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $nodeList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有控制器.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getControllerList()
|
|
||||||
{
|
|
||||||
return $this->readControllerFiles($this->basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 遍历读取控制器文件.
|
|
||||||
* @param $path
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function readControllerFiles($path)
|
|
||||||
{
|
|
||||||
list($list, $temp_list, $dirExplode) = [[], scandir($path), explode($this->basePath, $path)];
|
|
||||||
$middleDir = isset($dirExplode[1]) && !empty($dirExplode[1]) ? str_replace('/', '\\', substr($dirExplode[1], 1)) . '\\' : '';
|
|
||||||
|
|
||||||
foreach ($temp_list as $file) {
|
|
||||||
// 排除根目录和没有开启注解的模块
|
|
||||||
if ($file == '..' || $file == '.') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (is_dir($path . DIRECTORY_SEPARATOR . $file)) {
|
|
||||||
// 子文件夹,进行递归
|
|
||||||
$childFiles = $this->readControllerFiles($path . DIRECTORY_SEPARATOR . $file);
|
|
||||||
$list = array_merge($childFiles, $list);
|
|
||||||
} else {
|
|
||||||
// 判断是不是控制器
|
|
||||||
$fileExplodeArray = explode('.', $file);
|
|
||||||
if (count($fileExplodeArray) != 2 || end($fileExplodeArray) != 'php') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 根目录下的文件
|
|
||||||
$className = str_replace('.php', '', $file);
|
|
||||||
$controllerFormat = str_replace('\\', '.', $middleDir) . Str::snake(lcfirst($className));
|
|
||||||
|
|
||||||
$list[$controllerFormat] = "{$this->baseNamespace}\\{$middleDir}" . $className;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,163 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\traits;
|
namespace app\admin\traits;
|
||||||
|
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
use base\admin\traits\CurdTraitClass;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后台CURD复用
|
* 后台CURD复用
|
||||||
* Trait Curd
|
* Trait Curd.
|
||||||
* @package app\admin\traits
|
|
||||||
*/
|
*/
|
||||||
trait Curd
|
trait Curd
|
||||||
{
|
{
|
||||||
|
use CurdTraitClass;
|
||||||
|
|
||||||
/**
|
|
||||||
* @NodeAnotation(title="列表")
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
if ($this->request->isAjax()) {
|
|
||||||
if (input('selectFields')) {
|
|
||||||
return $this->selectList();
|
|
||||||
}
|
|
||||||
list($page, $limit, $where, $excludes, $request_options, $group) = $this->buildTableParames();
|
|
||||||
$count = $this->model
|
|
||||||
->where($where)
|
|
||||||
->group($group)
|
|
||||||
->count();
|
|
||||||
$list = $this->model
|
|
||||||
->where($where)
|
|
||||||
->page($page, $limit)
|
|
||||||
->order($this->sort)
|
|
||||||
->group($group)
|
|
||||||
->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();
|
|
||||||
$rule = [];
|
|
||||||
$this->validate($post, $rule);
|
|
||||||
try {
|
|
||||||
$save = $this->model->save($post);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('保存失败:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$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();
|
|
||||||
$rule = [];
|
|
||||||
$this->validate($post, $rule);
|
|
||||||
try {
|
|
||||||
$save = $row->save($post);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('保存失败:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
|
||||||
}
|
|
||||||
$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('数据不存在');
|
|
||||||
try {
|
|
||||||
$save = $row->delete();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('删除失败:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$save ? $this->success('删除成功') : $this->error('删除失败');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @NodeAnotation(title="导出")
|
|
||||||
*/
|
|
||||||
public function export()
|
|
||||||
{
|
|
||||||
list($page, $limit, $where) = $this->buildTableParames();
|
|
||||||
|
|
||||||
$fields = $this->request->param('fields', '{}', null);
|
|
||||||
$image_fields = $this->request->param('image_fields', '{}', null);
|
|
||||||
$select_fields = $this->request->param('select_fields', '{}', null);
|
|
||||||
$date_fields = $this->request->param('date_fields', '{}', null);
|
|
||||||
|
|
||||||
$fields = json_decode($fields, true);
|
|
||||||
$image_fields = json_decode($image_fields, true);
|
|
||||||
$select_fields = json_decode($select_fields, true);
|
|
||||||
$date_fields = json_decode($date_fields, true);
|
|
||||||
|
|
||||||
$content = \app\common\tools\ExportTools::excel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
|
|
||||||
|
|
||||||
$export_file_name = $this->exportFileName;
|
|
||||||
|
|
||||||
if (empty($export_file_name)) {
|
|
||||||
$export_file_name = $this->model->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return download($content, $export_file_name . date('YmdHis') . '.xlsx', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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']);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$row->save([
|
|
||||||
$post['field'] => $post['value'],
|
|
||||||
]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('修改失败:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$this->success('保存成功');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ use think\helper\Str;
|
|||||||
|
|
||||||
class Query extends DbQuery
|
class Query extends DbQuery
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* autoCache 自动生成缓存
|
* autoCache 自动生成缓存.
|
||||||
*
|
*
|
||||||
* @param null|string $key
|
* @param null|string $key
|
||||||
* @param null|string|int $field_key_value
|
* @param null|string|int $field_key_value
|
||||||
@@ -22,7 +20,6 @@ class Query extends DbQuery
|
|||||||
*/
|
*/
|
||||||
public function autoCache($key = null, $field_key_value = null, $tag = null, $field_tag_value = null)
|
public function autoCache($key = null, $field_key_value = null, $tag = null, $field_tag_value = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$table_name = Str::snake($this->getName());
|
$table_name = Str::snake($this->getName());
|
||||||
|
|
||||||
if (is_null($key)) {
|
if (is_null($key)) {
|
||||||
@@ -35,7 +32,6 @@ class Query extends DbQuery
|
|||||||
$key = $table_name . '_' . $key;
|
$key = $table_name . '_' . $key;
|
||||||
|
|
||||||
if (!is_null($tag)) {
|
if (!is_null($tag)) {
|
||||||
|
|
||||||
if (!is_null($field_tag_value)) {
|
if (!is_null($field_tag_value)) {
|
||||||
$tag = $tag . '_' . $field_tag_value;
|
$tag = $tag . '_' . $field_tag_value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"app\\": "app",
|
"app\\": "app",
|
||||||
"trait\\": "extend/trait",
|
"trait\\": "extend/trait",
|
||||||
|
"class\\": "extend/class",
|
||||||
"Phinx\\": "extend/phinx"
|
"Phinx\\": "extend/phinx"
|
||||||
},
|
},
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
|
|||||||
144
extend/base/admin/controller/AjaxClass.php
Normal file
144
extend/base/admin/controller/AjaxClass.php
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\model\SystemUploadfile;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use app\common\service\MenuService;
|
||||||
|
use app\common\service\UploadService;
|
||||||
|
use think\db\Query;
|
||||||
|
use think\facade\Cache;
|
||||||
|
|
||||||
|
class AjaxClass 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'),
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$upload_service = new UploadService($data['upload_type']);
|
||||||
|
|
||||||
|
$upload_service->validateException($data['file']);
|
||||||
|
|
||||||
|
$result = $upload_service->save($data['file']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->success('上传成功', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传图片至编辑器.
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function uploadEditor()
|
||||||
|
{
|
||||||
|
$this->checkPostRequest();
|
||||||
|
$data = [
|
||||||
|
'upload_type' => $this->request->post('upload_type'),
|
||||||
|
'file' => $this->request->file('upload'),
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$upload_service = new UploadService($data['upload_type']);
|
||||||
|
|
||||||
|
$upload_service->validateException($data['file']);
|
||||||
|
|
||||||
|
$result = $upload_service->save($data['file']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'error' => [
|
||||||
|
'message' => '上传成功',
|
||||||
|
'number' => 201,
|
||||||
|
],
|
||||||
|
'fileName' => '',
|
||||||
|
'uploaded' => 1,
|
||||||
|
'url' => $result['url'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上传文件列表.
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
119
extend/base/admin/controller/IndexClass.php
Normal file
119
extend/base/admin/controller/IndexClass.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\model\SystemAdmin;
|
||||||
|
use app\admin\model\SystemQuick;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
|
||||||
|
class IndexClass extends AdminController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 后台主页.
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return $this->fetch('', [
|
||||||
|
'admin' => session('admin'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台欢迎页.
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function welcome()
|
||||||
|
{
|
||||||
|
$quicks = SystemQuick::field('id,title,icon,href')
|
||||||
|
->where(['status' => 1])
|
||||||
|
->order('sort', 'desc')
|
||||||
|
->autoCache('welcome_list')
|
||||||
|
->limit(8)
|
||||||
|
->select();
|
||||||
|
$this->assign('quicks', $quicks);
|
||||||
|
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改管理员信息.
|
||||||
|
* @return string
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
* @return string
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
96
extend/base/admin/controller/LoginClass.php
Normal file
96
extend/base/admin/controller/LoginClass.php
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\model\SystemAdmin;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\captcha\facade\Captcha;
|
||||||
|
use think\facade\Env;
|
||||||
|
use think\facade\Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Login.
|
||||||
|
*/
|
||||||
|
class LoginClass extends AdminController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 初始化方法.
|
||||||
|
*/
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
event_response('AdminLoginIndex', [
|
||||||
|
'controller' => $this,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$captcha = Env::get('adminsystem.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();
|
||||||
|
|
||||||
|
Event::trigger('AdminLoginSuccess', $admin);
|
||||||
|
|
||||||
|
$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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户退出.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function out()
|
||||||
|
{
|
||||||
|
session('admin', null);
|
||||||
|
$this->success('退出登录成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码
|
||||||
|
* @return \think\Response
|
||||||
|
*/
|
||||||
|
public function captcha()
|
||||||
|
{
|
||||||
|
return Captcha::create();
|
||||||
|
}
|
||||||
|
}
|
||||||
27
extend/base/admin/controller/debug/LogClass.php
Normal file
27
extend/base/admin/controller/debug/LogClass.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\debug;
|
||||||
|
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="debug_log")
|
||||||
|
*/
|
||||||
|
class LogClass extends AdminController
|
||||||
|
{
|
||||||
|
protected $sort = [
|
||||||
|
'uid' => 'desc',
|
||||||
|
'id' => 'asc',
|
||||||
|
];
|
||||||
|
|
||||||
|
use \app\admin\traits\Curd;
|
||||||
|
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
|
||||||
|
$this->model = new \app\admin\model\DebugLog();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
extend/base/admin/controller/mall/CateClass.php
Normal file
24
extend/base/admin/controller/mall/CateClass.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\mall;
|
||||||
|
|
||||||
|
use app\admin\model\MallCate;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\traits\Curd;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Admin.
|
||||||
|
* @ControllerAnnotation(title="商品分类管理")
|
||||||
|
*/
|
||||||
|
class CateClass extends AdminController
|
||||||
|
{
|
||||||
|
use Curd;
|
||||||
|
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->model = new MallCate();
|
||||||
|
}
|
||||||
|
}
|
||||||
122
extend/base/admin/controller/mall/GoodsClass.php
Normal file
122
extend/base/admin/controller/mall/GoodsClass.php
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\mall;
|
||||||
|
|
||||||
|
use app\admin\model\MallCate;
|
||||||
|
use app\admin\model\MallGoods;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use app\admin\traits\Curd;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Goods.
|
||||||
|
* @ControllerAnnotation(title="商城商品管理")
|
||||||
|
*/
|
||||||
|
class GoodsClass extends AdminController
|
||||||
|
{
|
||||||
|
use Curd;
|
||||||
|
|
||||||
|
protected $relationSearch = true;
|
||||||
|
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->model = new MallGoods();
|
||||||
|
|
||||||
|
$this->assign('select_list_cate', MallCate::select(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read($id)
|
||||||
|
{
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
|
||||||
|
$this->assign('row', $row);
|
||||||
|
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NodeAnotation(title="导出")
|
||||||
|
*/
|
||||||
|
public function export()
|
||||||
|
{
|
||||||
|
list($page, $limit, $where) = $this->buildTableParames();
|
||||||
|
|
||||||
|
$this->model = $this->model
|
||||||
|
->withJoin('cate', 'LEFT');
|
||||||
|
|
||||||
|
$fields = $this->request->param('fields', '{}', null);
|
||||||
|
$image_fields = $this->request->param('image_fields', '{}', null);
|
||||||
|
$select_fields = $this->request->param('select_fields', '{}', null);
|
||||||
|
$date_fields = $this->request->param('date_fields', '{}', null);
|
||||||
|
|
||||||
|
$fields = json_decode($fields, true);
|
||||||
|
$image_fields = json_decode($image_fields, true);
|
||||||
|
$select_fields = json_decode($select_fields, true);
|
||||||
|
$date_fields = json_decode($date_fields, true);
|
||||||
|
|
||||||
|
$content = \app\common\tools\ExportTools::excel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
|
||||||
|
|
||||||
|
return download($content, $this->model->getName() . date('YmdHis') . '.xlsx', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
extend/base/admin/controller/mall/TagClass.php
Normal file
22
extend/base/admin/controller/mall/TagClass.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\mall;
|
||||||
|
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="mall_tag")
|
||||||
|
*/
|
||||||
|
class TagClass extends AdminController
|
||||||
|
{
|
||||||
|
use \app\admin\traits\Curd;
|
||||||
|
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
|
||||||
|
$this->model = new \app\admin\model\MallTag();
|
||||||
|
}
|
||||||
|
}
|
||||||
219
extend/base/admin/controller/system/AdminClass.php
Normal file
219
extend/base/admin/controller/system/AdminClass.php
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemAdmin;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use app\admin\service\TriggerService;
|
||||||
|
use app\common\constants\AdminConstant;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
use think\facade\Validate;
|
||||||
|
use think\validate\ValidateRule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Admin.
|
||||||
|
* @ControllerAnnotation(title="管理员管理")
|
||||||
|
*
|
||||||
|
* @NodeAnotation(title="自定义权限标识符",name="customFlag")
|
||||||
|
*/
|
||||||
|
class AdminClass 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(), true);
|
||||||
|
|
||||||
|
$this->setDataBrage('count', 10);
|
||||||
|
$this->setDataBrage('tips', '请谨慎操作');
|
||||||
|
|
||||||
|
$this->setDataBrage('adminCustomFlag', $this->checkAuth('system.admin/customFlag', false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 = Validate::rule('username|用户登录名', ValidateRule::isRequire());
|
||||||
|
$post['password'] = password(sysconfig('site', 'site_default_password', '123456'));
|
||||||
|
$this->validate($post, $rule);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$model_admin = SystemAdmin::where('username', $post['username'])->find();
|
||||||
|
|
||||||
|
if (!empty($model_admin)) {
|
||||||
|
throw new \Exception('同名用户已存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
$save = $this->model->save($post);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error('保存失败:' . $e->getMessage());
|
||||||
|
}
|
||||||
|
$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)
|
||||||
|
{
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
empty($row) && $this->error('数据不存在');
|
||||||
|
if ($this->request->isAjax()) {
|
||||||
|
$this->checkPostRequest();
|
||||||
|
$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('保存成功');
|
||||||
|
}
|
||||||
|
}
|
||||||
78
extend/base/admin/controller/system/AuthClass.php
Normal file
78
extend/base/admin/controller/system/AuthClass.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemAuth;
|
||||||
|
use app\admin\model\SystemAuthNode;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use app\admin\service\TriggerService;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="角色权限管理")
|
||||||
|
* Class Auth
|
||||||
|
*/
|
||||||
|
class AuthClass 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('保存成功');
|
||||||
|
}
|
||||||
|
}
|
||||||
76
extend/base/admin/controller/system/ConfigClass.php
Normal file
76
extend/base/admin/controller/system/ConfigClass.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemConfig;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use app\admin\service\TriggerService;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Config.
|
||||||
|
* @ControllerAnnotation(title="系统配置管理")
|
||||||
|
*/
|
||||||
|
class ConfigClass 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->except(['group_name'], 'post');
|
||||||
|
|
||||||
|
$group_name = $this->request->post('group_name');
|
||||||
|
|
||||||
|
try {
|
||||||
|
foreach ($post as $key => $val) {
|
||||||
|
if (empty($group_name)) {
|
||||||
|
$this->model
|
||||||
|
->where('name', $key)
|
||||||
|
->update([
|
||||||
|
'value' => $val,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$model_config = SystemConfig::where('group', $group_name)
|
||||||
|
->where('name', $key)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (empty($model_config)) {
|
||||||
|
$model_config = SystemConfig::create([
|
||||||
|
'group' => $group_name,
|
||||||
|
'name' => $key,
|
||||||
|
'value' => $val,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$model_config->save([
|
||||||
|
'value' => $val,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TriggerService::updateMenu();
|
||||||
|
TriggerService::updateSysconfig();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error('保存失败');
|
||||||
|
}
|
||||||
|
$this->success('保存成功');
|
||||||
|
}
|
||||||
|
}
|
||||||
219
extend/base/admin/controller/system/MenuClass.php
Normal file
219
extend/base/admin/controller/system/MenuClass.php
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemMenu;
|
||||||
|
use app\admin\model\SystemNode;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use app\admin\service\TriggerService;
|
||||||
|
use app\common\constants\MenuConstant;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Menu.
|
||||||
|
* @ControllerAnnotation(title="菜单管理",auth=true)
|
||||||
|
*/
|
||||||
|
class MenuClass 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();
|
||||||
|
|
||||||
|
$this->assign('menu_home_pid', MenuConstant::HOME_PID, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
//防止首页pid被修改而导致渲染时报错
|
||||||
|
if ($row->pid == MenuConstant::HOME_PID) {
|
||||||
|
unset($post['pid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
extend/base/admin/controller/system/NodeClass.php
Normal file
110
extend/base/admin/controller/system/NodeClass.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemNode;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use app\admin\service\NodeService;
|
||||||
|
use app\admin\service\TriggerService;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="系统节点管理")
|
||||||
|
* Class Node
|
||||||
|
*/
|
||||||
|
class NodeClass 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('节点更新成功');
|
||||||
|
}
|
||||||
|
}
|
||||||
28
extend/base/admin/controller/system/QuickClass.php
Normal file
28
extend/base/admin/controller/system/QuickClass.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemQuick;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="快捷入口管理")
|
||||||
|
* Class Quick
|
||||||
|
*/
|
||||||
|
class QuickClass 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
extend/base/admin/controller/system/UploadfileClass.php
Normal file
23
extend/base/admin/controller/system/UploadfileClass.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\controller\system;
|
||||||
|
|
||||||
|
use app\admin\model\SystemUploadfile;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="上传文件管理")
|
||||||
|
* Class Uploadfile
|
||||||
|
*/
|
||||||
|
class UploadfileClass extends AdminController
|
||||||
|
{
|
||||||
|
use \app\admin\traits\Curd;
|
||||||
|
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->model = new SystemUploadfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
37
extend/base/admin/middleware/CsrfMiddlewareClass.php
Normal file
37
extend/base/admin/middleware/CsrfMiddlewareClass.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\middleware;
|
||||||
|
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class CsrfMiddlewareClass
|
||||||
|
{
|
||||||
|
use \app\common\traits\JumpTrait;
|
||||||
|
|
||||||
|
public function handle(Request $request, \Closure $next)
|
||||||
|
{
|
||||||
|
if (env('adminsystem.IS_CSRF', true)) {
|
||||||
|
if (!in_array($request->method(), ['GET', 'HEAD', 'OPTIONS'])) {
|
||||||
|
// 跨域校验
|
||||||
|
$refererUrl = $request->header('REFERER', null);
|
||||||
|
$refererInfo = parse_url($refererUrl);
|
||||||
|
$host = $request->host(true);
|
||||||
|
if (!isset($refererInfo['host']) || $refererInfo['host'] != $host) {
|
||||||
|
$this->error('当前请求不合法!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// CSRF校验
|
||||||
|
// @todo 兼容CK编辑器上传功能
|
||||||
|
$ckCsrfToken = $request->post('ckCsrfToken', null);
|
||||||
|
$data = !empty($ckCsrfToken) ? ['__token__' => $ckCsrfToken] : [];
|
||||||
|
|
||||||
|
$check = $request->checkToken('__token__', $data);
|
||||||
|
if (!$check) {
|
||||||
|
$this->error('请求验证失败,请重新刷新页面!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
56
extend/base/admin/middleware/SystemLogClass.php
Normal file
56
extend/base/admin/middleware/SystemLogClass.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\middleware;
|
||||||
|
|
||||||
|
use think\facade\Log;
|
||||||
|
use think\facade\Request as FacadeRequest;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统操作日志中间件
|
||||||
|
* Class SystemLog.
|
||||||
|
*/
|
||||||
|
class SystemLogClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 敏感信息字段,日志记录时需要加密.
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $sensitiveParams = [
|
||||||
|
'password',
|
||||||
|
'password_again',
|
||||||
|
'phone',
|
||||||
|
'mobile',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function handle(Request $request, \Closure $next)
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
if (isset($params['s'])) {
|
||||||
|
unset($params['s']);
|
||||||
|
}
|
||||||
|
foreach ($params as $key => $val) {
|
||||||
|
in_array($key, $this->sensitiveParams) && $params[$key] = '***********';
|
||||||
|
}
|
||||||
|
$method = strtolower($request->method());
|
||||||
|
$url = $request->url();
|
||||||
|
|
||||||
|
if ($request->isAjax()) {
|
||||||
|
if (in_array($method, ['post', 'put', 'delete'])) {
|
||||||
|
$ip = FacadeRequest::ip();
|
||||||
|
$data = [
|
||||||
|
'admin_id' => session('admin.id'),
|
||||||
|
'url' => $url,
|
||||||
|
'method' => $method,
|
||||||
|
'ip' => $ip,
|
||||||
|
'content' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
||||||
|
'useragent' => $_SERVER['HTTP_USER_AGENT'],
|
||||||
|
'create_time' => time(),
|
||||||
|
];
|
||||||
|
Log::debug(print_r($data, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
extend/base/admin/model/DebugLogClass.php
Normal file
12
extend/base/admin/model/DebugLogClass.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class DebugLogClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $name = 'debug_log';
|
||||||
|
|
||||||
|
protected $deleteTime = false;
|
||||||
|
}
|
||||||
10
extend/base/admin/model/MallCateClass.php
Normal file
10
extend/base/admin/model/MallCateClass.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class MallCateClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
}
|
||||||
25
extend/base/admin/model/MallGoodsClass.php
Normal file
25
extend/base/admin/model/MallGoodsClass.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\admin\model\MallTag;
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class MallGoodsClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public function cate()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTagListTitleAttr()
|
||||||
|
{
|
||||||
|
$tags = $this->getAttr('tag');
|
||||||
|
|
||||||
|
$list_tag = MallTag::whereIn('id', $tags)->column('title');
|
||||||
|
|
||||||
|
return $list_tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
extend/base/admin/model/MallTagClass.php
Normal file
12
extend/base/admin/model/MallTagClass.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class MallTagClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $name = 'mall_tag';
|
||||||
|
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
}
|
||||||
27
extend/base/admin/model/SystemAdminClass.php
Normal file
27
extend/base/admin/model/SystemAdminClass.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\admin\model\SystemAuth;
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemAdminClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public static $autoCache = [
|
||||||
|
[
|
||||||
|
'name' => 'info',
|
||||||
|
'field' => 'id',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getAuthList()
|
||||||
|
{
|
||||||
|
$list = (new SystemAuth())
|
||||||
|
->where('status', 1)
|
||||||
|
->column('title', 'id');
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
||||||
54
extend/base/admin/model/SystemAuthClass.php
Normal file
54
extend/base/admin/model/SystemAuthClass.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\admin\model\SystemAuthNode;
|
||||||
|
use app\admin\model\SystemNode;
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemAuthClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色ID获取授权节点.
|
||||||
|
* @param $authId
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getAuthorizeNodeListByAdminId($authId)
|
||||||
|
{
|
||||||
|
$checkNodeList = (new SystemAuthNode())
|
||||||
|
->where('auth_id', $authId)
|
||||||
|
->column('node_id');
|
||||||
|
$systemNode = new SystemNode();
|
||||||
|
$nodelList = $systemNode
|
||||||
|
->where('is_auth', 1)
|
||||||
|
->field('id,node,title,type,is_auth')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
$newNodeList = [];
|
||||||
|
foreach ($nodelList as $vo) {
|
||||||
|
if ($vo['type'] == 1) {
|
||||||
|
$vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
|
||||||
|
$vo['checked'] = false;
|
||||||
|
$vo['title'] = "{$vo['title']}【{$vo['node']}】";
|
||||||
|
$children = [];
|
||||||
|
foreach ($nodelList as $v) {
|
||||||
|
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
||||||
|
$v = array_merge($v, ['field' => 'node', 'spread' => true]);
|
||||||
|
$v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
|
||||||
|
$v['title'] = "{$v['title']}【{$v['node']}】";
|
||||||
|
$children[] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
!empty($children) && $vo['children'] = $children;
|
||||||
|
$newNodeList[] = $vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newNodeList;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
extend/base/admin/model/SystemAuthNodeClass.php
Normal file
12
extend/base/admin/model/SystemAuthNodeClass.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemAuthNodeClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $autoWriteTimestamp = false;
|
||||||
|
|
||||||
|
protected $deleteTime = false;
|
||||||
|
}
|
||||||
10
extend/base/admin/model/SystemConfigClass.php
Normal file
10
extend/base/admin/model/SystemConfigClass.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemConfigClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = false;
|
||||||
|
}
|
||||||
57
extend/base/admin/model/SystemMenuClass.php
Normal file
57
extend/base/admin/model/SystemMenuClass.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\constants\MenuConstant;
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemMenuClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public function getPidMenuList()
|
||||||
|
{
|
||||||
|
$list = $this->field('id,pid,title')
|
||||||
|
->where([
|
||||||
|
['pid', '<>', MenuConstant::HOME_PID],
|
||||||
|
['status', '=', 1],
|
||||||
|
])
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
$pidMenuList = $this->buildPidMenu(0, $list);
|
||||||
|
$pidMenuList = array_merge([[
|
||||||
|
'id' => 0,
|
||||||
|
'pid' => 0,
|
||||||
|
'title' => '顶级菜单',
|
||||||
|
]], $pidMenuList);
|
||||||
|
|
||||||
|
return $pidMenuList;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildPidMenu($pid, $list, $level = 0)
|
||||||
|
{
|
||||||
|
$newList = [];
|
||||||
|
foreach ($list as $vo) {
|
||||||
|
if ($vo['pid'] == $pid) {
|
||||||
|
$level++;
|
||||||
|
foreach ($newList as $v) {
|
||||||
|
if ($vo['pid'] == $v['pid'] && isset($v['level'])) {
|
||||||
|
$level = $v['level'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$vo['level'] = $level;
|
||||||
|
if ($level > 1) {
|
||||||
|
$repeatString = ' ';
|
||||||
|
$markString = str_repeat("{$repeatString}├{$repeatString}", $level - 1);
|
||||||
|
$vo['title'] = $markString . $vo['title'];
|
||||||
|
}
|
||||||
|
$newList[] = $vo;
|
||||||
|
$childList = $this->buildPidMenu($vo['id'], $list, $level);
|
||||||
|
!empty($childList) && $newList = array_merge($newList, $childList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newList;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
extend/base/admin/model/SystemNodeClass.php
Normal file
37
extend/base/admin/model/SystemNodeClass.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemNodeClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = false;
|
||||||
|
|
||||||
|
public function getNodeTreeList()
|
||||||
|
{
|
||||||
|
$list = $this->select()->toArray();
|
||||||
|
$list = $this->buildNodeTree($list);
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildNodeTree($list)
|
||||||
|
{
|
||||||
|
$newList = [];
|
||||||
|
$repeatString = ' ';
|
||||||
|
foreach ($list as $vo) {
|
||||||
|
if ($vo['type'] == 1) {
|
||||||
|
$newList[] = $vo;
|
||||||
|
foreach ($list as $v) {
|
||||||
|
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
||||||
|
$v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
|
||||||
|
$newList[] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newList;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
extend/base/admin/model/SystemQuickClass.php
Normal file
16
extend/base/admin/model/SystemQuickClass.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemQuickClass extends TimeModel
|
||||||
|
{
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public static $autoCache = [
|
||||||
|
[
|
||||||
|
'name' => 'welcome_list',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
9
extend/base/admin/model/SystemUploadfileClass.php
Normal file
9
extend/base/admin/model/SystemUploadfileClass.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\model;
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
class SystemUploadfileClass extends TimeModel
|
||||||
|
{
|
||||||
|
}
|
||||||
147
extend/base/admin/service/InitAdminServiceClass.php
Normal file
147
extend/base/admin/service/InitAdminServiceClass.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\service;
|
||||||
|
|
||||||
|
use app\admin\model\MallCate;
|
||||||
|
use app\admin\model\MallGoods;
|
||||||
|
use app\admin\model\MallTag;
|
||||||
|
use app\admin\model\SystemAdmin;
|
||||||
|
use app\admin\model\SystemAuth;
|
||||||
|
use app\admin\model\SystemAuthNode;
|
||||||
|
use app\admin\model\SystemConfig;
|
||||||
|
use app\admin\model\SystemMenu;
|
||||||
|
use app\admin\model\SystemNode;
|
||||||
|
use app\admin\model\SystemQuick;
|
||||||
|
use app\common\constants\AdminConstant;
|
||||||
|
|
||||||
|
class InitAdminServiceClass
|
||||||
|
{
|
||||||
|
protected $output = null;
|
||||||
|
|
||||||
|
public function __construct($output)
|
||||||
|
{
|
||||||
|
$this->output = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->initAdmin();
|
||||||
|
$this->initAuth();
|
||||||
|
$this->initConfig();
|
||||||
|
$this->initMenu();
|
||||||
|
$this->initQuick();
|
||||||
|
$this->initMall();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initMall()
|
||||||
|
{
|
||||||
|
$output = $this->output;
|
||||||
|
|
||||||
|
$output->writeln('开始初始化商城案例');
|
||||||
|
|
||||||
|
$list_cate = $this->requireData('MallCate');
|
||||||
|
|
||||||
|
$list_goods = $this->requireData('MallGoods');
|
||||||
|
|
||||||
|
foreach ($list_cate as $data_cate) {
|
||||||
|
$model_cate = MallCate::create($data_cate);
|
||||||
|
|
||||||
|
foreach ($list_goods as $data_goods) {
|
||||||
|
$data_goods['cate_id'] = $model_cate->id;
|
||||||
|
MallGoods::create($data_goods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$list_tag = $this->requireData('MallTag');
|
||||||
|
|
||||||
|
$this->installData(MallTag::class, $list_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initQuick()
|
||||||
|
{
|
||||||
|
$output = $this->output;
|
||||||
|
|
||||||
|
$output->writeln('开始初始化快捷入口');
|
||||||
|
|
||||||
|
$list_quick = $this->requireData('SystemQuick');
|
||||||
|
|
||||||
|
$this->installData(SystemQuick::class, $list_quick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initMenu()
|
||||||
|
{
|
||||||
|
$output = $this->output;
|
||||||
|
|
||||||
|
$output->writeln('开始初始化系统菜单');
|
||||||
|
|
||||||
|
$list_menu = $this->requireData('SystemMenu');
|
||||||
|
|
||||||
|
$this->installData(SystemMenu::class, $list_menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initConfig()
|
||||||
|
{
|
||||||
|
$output = $this->output;
|
||||||
|
$output->writeln('开始初始化系统设置');
|
||||||
|
|
||||||
|
$list_config = $this->requireData('SystemConfig');
|
||||||
|
|
||||||
|
$this->installData(SystemConfig::class, $list_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initAdmin()
|
||||||
|
{
|
||||||
|
$output = $this->output;
|
||||||
|
|
||||||
|
$output->writeln('创建超级管理员');
|
||||||
|
|
||||||
|
$model_admin = SystemAdmin::find(AdminConstant::SUPER_ADMIN_ID);
|
||||||
|
|
||||||
|
if (empty($model_admin)) {
|
||||||
|
$model_admin = new SystemAdmin();
|
||||||
|
$model_admin->id = AdminConstant::SUPER_ADMIN_ID;
|
||||||
|
$model_admin->head_img = '/static/admin/images/head.jpg';
|
||||||
|
$model_admin->username = 'admin';
|
||||||
|
$model_admin->password = password(123456);
|
||||||
|
$model_admin->status = 1;
|
||||||
|
$model_admin->save();
|
||||||
|
$output->writeln('创建超级管理员成功');
|
||||||
|
} else {
|
||||||
|
$output->writeln('超级管理员已存在,无需初始化');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initAuth()
|
||||||
|
{
|
||||||
|
$output = $this->output;
|
||||||
|
|
||||||
|
$output->writeln('开始初始化权限');
|
||||||
|
|
||||||
|
$list_auth = $this->requireData('SystemAuth');
|
||||||
|
|
||||||
|
$this->installData(SystemAuth::class, $list_auth);
|
||||||
|
|
||||||
|
$output->writeln('开始初始化权限节点');
|
||||||
|
|
||||||
|
$list_auth_node = $this->requireData('SystemAuthNode');
|
||||||
|
|
||||||
|
$this->installData(SystemAuthNode::class, $list_auth_node);
|
||||||
|
|
||||||
|
$output->writeln('开始初始化系统节点');
|
||||||
|
$list_node = $this->requireData('SystemNode');
|
||||||
|
|
||||||
|
$this->installData(SystemNode::class, $list_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function installData($model_name, $list)
|
||||||
|
{
|
||||||
|
foreach ($list as $key => $value) {
|
||||||
|
$model_name::create($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function requireData($table_name)
|
||||||
|
{
|
||||||
|
return include __DIR__ . '/initAdminData/' . $table_name . '.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
25
extend/base/admin/service/NodeServiceClass.php
Normal file
25
extend/base/admin/service/NodeServiceClass.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\service;
|
||||||
|
|
||||||
|
use app\admin\service\node\Node;
|
||||||
|
|
||||||
|
class NodeServiceClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取节点服务
|
||||||
|
* @return array
|
||||||
|
* @throws \Doctrine\Common\Annotations\AnnotationException
|
||||||
|
* @throws \ReflectionException
|
||||||
|
*/
|
||||||
|
public function getNodelist()
|
||||||
|
{
|
||||||
|
$basePath = base_path() . 'admin' . DIRECTORY_SEPARATOR . 'controller';
|
||||||
|
$baseNamespace = "app\admin\controller";
|
||||||
|
|
||||||
|
$nodeList = (new Node($basePath, $baseNamespace))
|
||||||
|
->getNodelist();
|
||||||
|
|
||||||
|
return $nodeList;
|
||||||
|
}
|
||||||
|
}
|
||||||
51
extend/base/admin/service/TriggerServiceClass.php
Normal file
51
extend/base/admin/service/TriggerServiceClass.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\service;
|
||||||
|
|
||||||
|
use think\facade\Cache;
|
||||||
|
|
||||||
|
class TriggerServiceClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 更新菜单缓存.
|
||||||
|
* @param null $adminId
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function updateMenu($adminId = null)
|
||||||
|
{
|
||||||
|
if (empty($adminId)) {
|
||||||
|
Cache::tag('initAdmin')->clear();
|
||||||
|
} else {
|
||||||
|
Cache::delete('initAdmin_' . $adminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新节点缓存.
|
||||||
|
* @param null $adminId
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function updateNode($adminId = null)
|
||||||
|
{
|
||||||
|
if (empty($adminId)) {
|
||||||
|
Cache::tag('authNode')->clear();
|
||||||
|
} else {
|
||||||
|
Cache::delete('allAuthNode_' . $adminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新系统设置缓存.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function updateSysconfig()
|
||||||
|
{
|
||||||
|
Cache::tag('sysconfig')->clear();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | EasyAdmin
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | PHP交流群: 763822524
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 https://mit-license.org
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace base\admin\service\annotation;
|
||||||
|
|
||||||
|
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||||
|
use Doctrine\Common\Annotations\Annotation\Required;
|
||||||
|
use Doctrine\Common\Annotations\Annotation\Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ControllerAnnotation.
|
||||||
|
*
|
||||||
|
* @Annotation
|
||||||
|
* @Target("CLASS")
|
||||||
|
* @Attributes({
|
||||||
|
* @Attribute("title", type="string"),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
class ControllerAnnotationClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Route group prefix for the controller.
|
||||||
|
*
|
||||||
|
* @Required()
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $title = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启权限控制.
|
||||||
|
* @Enum({true,false})
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $auth = true;
|
||||||
|
}
|
||||||
47
extend/base/admin/service/annotation/NodeAnotationClass.php
Normal file
47
extend/base/admin/service/annotation/NodeAnotationClass.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | EasyAdmin
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | PHP交流群: 763822524
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 https://mit-license.org
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace base\admin\service\annotation;
|
||||||
|
|
||||||
|
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建节点注解类.
|
||||||
|
*
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"METHOD","CLASS"})
|
||||||
|
* @Attributes({
|
||||||
|
* @Attribute("time", type = "int")
|
||||||
|
* })
|
||||||
|
*/
|
||||||
|
class NodeAnotationClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 节点名称.
|
||||||
|
* @Required()
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启权限控制.
|
||||||
|
* @Enum({true,false})
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $auth = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点 一般无需设置.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $name;
|
||||||
|
}
|
||||||
1749
extend/base/admin/service/curd/BuildCurdServiceClass.php
Normal file
1749
extend/base/admin/service/curd/BuildCurdServiceClass.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\service\curd\exceptions;
|
||||||
|
|
||||||
|
class CurdExceptionClass extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\service\curd\exceptions;
|
||||||
|
|
||||||
|
class FileExceptionClass extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace base\admin\service\curd\exceptions;
|
||||||
|
|
||||||
|
class TableExceptionClass extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{controllerNamespace}};
|
||||||
|
|
||||||
|
use app\common\controller\AdminController;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
|
use think\App;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ControllerAnnotation(title="{{controllerAnnotation}}")
|
||||||
|
*/
|
||||||
|
class {{controllerName}} extends AdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use \app\admin\traits\Curd;
|
||||||
|
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
|
||||||
|
$this->model = new {{modelFilename}}();
|
||||||
|
{{selectList}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{indexMethod}}
|
||||||
|
|
||||||
|
|
||||||
|
{{exportMethod}}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* @NodeAnotation(title="导出")
|
||||||
|
*/
|
||||||
|
public function export()
|
||||||
|
{
|
||||||
|
list($page, $limit, $where) = $this->buildTableParames();
|
||||||
|
|
||||||
|
|
||||||
|
$this->model = $this->model{{relationIndexMethod}};
|
||||||
|
|
||||||
|
$fields = $this->request->param('fields', '{}', null);
|
||||||
|
$image_fields = $this->request->param('image_fields', '{}', null);
|
||||||
|
$select_fields = $this->request->param('select_fields', '{}', null);
|
||||||
|
$date_fields = $this->request->param('date_fields', '{}', null);
|
||||||
|
|
||||||
|
$fields = json_decode($fields, true);
|
||||||
|
$image_fields = json_decode($image_fields, true);
|
||||||
|
$select_fields = json_decode($select_fields, true);
|
||||||
|
$date_fields = json_decode($date_fields, true);
|
||||||
|
|
||||||
|
$content = \app\common\tools\ExportTools::excel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
|
||||||
|
|
||||||
|
$export_file_name = $this->exportFileName;
|
||||||
|
|
||||||
|
if (empty($export_file_name)) {
|
||||||
|
$export_file_name = $this->model->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return download($content, $export_file_name . date('YmdHis') . '.xlsx', true);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* @NodeAnotation(title="列表")
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
if ($this->request->isAjax()) {
|
||||||
|
if (input('selectFields')) {
|
||||||
|
return $this->selectList();
|
||||||
|
}
|
||||||
|
list($page, $limit, $where) = $this->buildTableParames();
|
||||||
|
$count = $this->model
|
||||||
|
{{relationIndexMethod}}
|
||||||
|
->where($where)
|
||||||
|
->count();
|
||||||
|
$list = $this->model
|
||||||
|
{{relationIndexMethod}}
|
||||||
|
->where($where)
|
||||||
|
->page($page, $limit)
|
||||||
|
->order($this->sort)
|
||||||
|
->select();
|
||||||
|
$data = [
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '',
|
||||||
|
'count' => $count,
|
||||||
|
'data' => $list,
|
||||||
|
];
|
||||||
|
return json($data);
|
||||||
|
}
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
$this->assign('{{var_name}}', $this->model::{{name}}, true);
|
||||||
10
extend/base/admin/service/curd/templates/js/_common.code
Normal file
10
extend/base/admin/service/curd/templates/js/_common.code
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
var init = {
|
||||||
|
table_elem: '#currentTable',
|
||||||
|
table_render_id: 'currentTableRenderId',
|
||||||
|
index_url: '{{controllerUrl}}/index',
|
||||||
|
add_url: '{{controllerUrl}}/add',
|
||||||
|
edit_url: '{{controllerUrl}}/edit',
|
||||||
|
delete_url: '{{controllerUrl}}/delete',
|
||||||
|
export_url: '{{controllerUrl}}/export',
|
||||||
|
modify_url: '{{controllerUrl}}/modify',
|
||||||
|
};
|
||||||
3
extend/base/admin/service/curd/templates/js/add.code
Normal file
3
extend/base/admin/service/curd/templates/js/add.code
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
$(function(){
|
||||||
|
ua.listen();
|
||||||
|
})
|
||||||
3
extend/base/admin/service/curd/templates/js/edit.code
Normal file
3
extend/base/admin/service/curd/templates/js/edit.code
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
$(function(){
|
||||||
|
ua.listen();
|
||||||
|
})
|
||||||
10
extend/base/admin/service/curd/templates/js/index.code
Normal file
10
extend/base/admin/service/curd/templates/js/index.code
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
$(function(){
|
||||||
|
ua.table.render({
|
||||||
|
init: init,
|
||||||
|
cols: [[
|
||||||
|
{{indexCols}}
|
||||||
|
]],
|
||||||
|
});
|
||||||
|
|
||||||
|
ua.listen();
|
||||||
|
})
|
||||||
21
extend/base/admin/service/curd/templates/model/model.code
Normal file
21
extend/base/admin/service/curd/templates/model/model.code
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{modelNamespace}};
|
||||||
|
|
||||||
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
{{doc_content}}
|
||||||
|
*/
|
||||||
|
class {{modelName}} extends TimeModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $name = "{{table}}";
|
||||||
|
|
||||||
|
protected $deleteTime = {{deleteTime}};
|
||||||
|
|
||||||
|
{{selectList}}
|
||||||
|
|
||||||
|
{{relationList}}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
public function {{relationMethod}}()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('{{relationModel}}', '{{foreignKey}}', '{{primaryKey}}');
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
public const {{name}} = {{values}};
|
||||||
11
extend/base/admin/service/curd/templates/view/form.code
Normal file
11
extend/base/admin/service/curd/templates/view/form.code
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<div class="layuimini-container">
|
||||||
|
<form id="app-form" class="layui-form layuimini-form">
|
||||||
|
{{formList}}
|
||||||
|
<div class="hr-line"></div>
|
||||||
|
<div class="layui-form-item text-center">
|
||||||
|
<button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
|
||||||
|
<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
13
extend/base/admin/service/curd/templates/view/index.code
Normal file
13
extend/base/admin/service/curd/templates/view/index.code
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<div class="layuimini-container">
|
||||||
|
<div class="layuimini-main">
|
||||||
|
<table id="currentTable" class="layui-table layui-hide"
|
||||||
|
data-auth-index="{:auth('{{controllerUrl}}/index')}"
|
||||||
|
data-auth-add="{:auth('{{controllerUrl}}/add')}"
|
||||||
|
data-auth-edit="{:auth('{{controllerUrl}}/edit')}"
|
||||||
|
data-auth-delete="{:auth('{{controllerUrl}}/delete')}"
|
||||||
|
data-auth-export="{:auth('{{controllerUrl}}/export')}"
|
||||||
|
data-auth-modify="{:auth('{{controllerUrl}}/modify')}"
|
||||||
|
lay-filter="currentTable">
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">{{comment}}</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
{{define}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{foreach ${{name}} as $k=>$v}
|
||||||
|
<input type="checkbox" name="{{field}}[]" value="{$k}" lay-skin="primary" title="{$v}" {{select}}>
|
||||||
|
{/foreach}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">{{comment}}</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
{{define}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<input class="layui-input" name="{{field}}" data-toggle="city-picker" {{required}} value="{{value}}" type="text" data-level="{{level}}" readonly {{submit_field_content}}>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">{{comment}}</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="text" name="{{field}}" data-date="" data-date-type="{{define}}" class="layui-input" {{required}} placeholder="请输入{{comment}}" value="{{value}}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">{{comment}}</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<textarea name="{{field}}" rows="20" class="layui-textarea editor" placeholder="请输入{{comment}}">{{value}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label required">{{comment}}</label>
|
||||||
|
<div class="layui-input-block layuimini-upload">
|
||||||
|
<input name="{{field}}" class="layui-input layui-col-xs6" {{required}} placeholder="请上传{{comment}}" value="{{value}}">
|
||||||
|
<div class="layuimini-upload-btn">
|
||||||
|
<span><a class="layui-btn" data-upload="{{field}}" data-upload-number="one" data-upload-exts="zip" data-upload-icon="file" data-upload-disable-preview="0"><i class="fa fa-upload"></i> 上传</a></span>
|
||||||
|
<span><a class="layui-btn layui-btn-normal" id="select_{{field}}" data-upload-select="{{field}}" data-upload-number="one" data-upload-mimetype="*"><i class="fa fa-list"></i> 选择</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label required">{{comment}}</label>
|
||||||
|
<div class="layui-input-block layuimini-upload">
|
||||||
|
<input name="{{field}}" class="layui-input layui-col-xs6" {{required}} placeholder="请上传{{comment}}" value="{{value}}">
|
||||||
|
<div class="layuimini-upload-btn">
|
||||||
|
<span><a class="layui-btn" data-upload="{{field}}" data-upload-number="more" data-upload-exts="zip" data-upload-icon="file" data-upload-disable-preview="0"><i class="fa fa-upload" data-upload-sign="{{define}}" ></i> 上传</a></span>
|
||||||
|
<span><a class="layui-btn layui-btn-normal" id="select_{{field}}" data-upload-select="{{field}}" data-upload-number="more" data-upload-mimetype="*" data-upload-sign="{{define}}"><i class="fa fa-list"></i> 选择</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label required">{{comment}}</label>
|
||||||
|
<div class="layui-input-block layuimini-upload">
|
||||||
|
<input name="{{field}}" class="layui-input layui-col-xs6" {{required}} placeholder="请上传{{comment}}" value="{{value}}">
|
||||||
|
<div class="layuimini-upload-btn">
|
||||||
|
<span><a class="layui-btn" data-upload="{{field}}" data-upload-number="one" data-upload-exts="*image" data-upload-icon="image"><i class="fa fa-upload"></i> 上传</a></span>
|
||||||
|
<span><a class="layui-btn layui-btn-normal" id="select_{{field}}" data-upload-select="{{field}}" data-upload-number="one" data-upload-mimetype="image/*"><i class="fa fa-list"></i> 选择</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user