From bee15dfea6405d217d00cc2132284c48a07fb206 Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 23 Sep 2023 17:30:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4admin=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=BA=93=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=B0=86=E4=B8=BB?= =?UTF-8?q?=E8=A6=81=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4=E5=88=B0extend?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Ajax.php | 141 +- app/admin/controller/Index.php | 115 +- app/admin/controller/Login.php | 91 +- app/admin/controller/debug/Log.php | 20 +- app/admin/controller/mall/Cate.php | 24 +- app/admin/controller/mall/Goods.php | 114 +- app/admin/controller/mall/Tag.php | 20 +- app/admin/controller/system/Admin.php | 206 +- app/admin/controller/system/Auth.php | 74 +- app/admin/controller/system/Config.php | 74 +- app/admin/controller/system/Menu.php | 209 +- app/admin/controller/system/Node.php | 104 +- app/admin/controller/system/Quick.php | 26 +- app/admin/controller/system/Uploadfile.php | 21 +- app/admin/middleware/CsrfMiddleware.php | 32 +- app/admin/middleware/SystemLog.php | 47 +- app/admin/model/DebugLog.php | 14 +- app/admin/model/MallCate.php | 13 +- app/admin/model/MallGoods.php | 21 +- app/admin/model/MallTag.php | 15 +- app/admin/model/SystemAdmin.php | 23 +- app/admin/model/SystemAuth.php | 52 +- app/admin/model/SystemAuthNode.php | 12 +- app/admin/model/SystemConfig.php | 10 +- app/admin/model/SystemMenu.php | 58 +- app/admin/model/SystemNode.php | 33 +- app/admin/model/SystemQuick.php | 14 +- app/admin/model/SystemUploadfile.php | 9 +- app/admin/service/InitAdminService.php | 143 +- app/admin/service/NodeService.php | 25 +- app/admin/service/TriggerService.php | 49 +- .../annotation/ControllerAnnotation.php | 27 +- .../service/annotation/NodeAnotation.php | 22 +- app/admin/service/curd/BuildCurdService.php | 1740 +--------------- .../service/curd/exceptions/CurdException.php | 7 +- .../service/curd/exceptions/FileException.php | 7 +- .../curd/exceptions/TableException.php | 7 +- app/admin/service/node/Node.php | 155 +- app/admin/traits/Curd.php | 155 +- app/common/provider/db/Query.php | 6 +- composer.json | 1 + extend/base/admin/controller/AjaxClass.php | 144 ++ extend/base/admin/controller/IndexClass.php | 119 ++ extend/base/admin/controller/LoginClass.php | 96 + .../base/admin/controller/debug/LogClass.php | 27 + .../base/admin/controller/mall/CateClass.php | 24 + .../base/admin/controller/mall/GoodsClass.php | 122 ++ .../base/admin/controller/mall/TagClass.php | 22 + .../admin/controller/system/AdminClass.php | 219 +++ .../admin/controller/system/AuthClass.php | 78 + .../admin/controller/system/ConfigClass.php | 76 + .../admin/controller/system/MenuClass.php | 219 +++ .../admin/controller/system/NodeClass.php | 110 ++ .../admin/controller/system/QuickClass.php | 28 + .../controller/system/UploadfileClass.php | 23 + .../admin/middleware/CsrfMiddlewareClass.php | 37 + .../base/admin/middleware/SystemLogClass.php | 56 + extend/base/admin/model/DebugLogClass.php | 12 + extend/base/admin/model/MallCateClass.php | 10 + extend/base/admin/model/MallGoodsClass.php | 25 + extend/base/admin/model/MallTagClass.php | 12 + extend/base/admin/model/SystemAdminClass.php | 27 + extend/base/admin/model/SystemAuthClass.php | 54 + .../base/admin/model/SystemAuthNodeClass.php | 12 + extend/base/admin/model/SystemConfigClass.php | 10 + extend/base/admin/model/SystemMenuClass.php | 57 + extend/base/admin/model/SystemNodeClass.php | 37 + extend/base/admin/model/SystemQuickClass.php | 16 + .../admin/model/SystemUploadfileClass.php | 9 + .../admin/service/InitAdminServiceClass.php | 147 ++ .../base/admin/service/NodeServiceClass.php | 25 + .../admin/service/TriggerServiceClass.php | 51 + .../annotation/ControllerAnnotationClass.php | 47 + .../service/annotation/NodeAnotationClass.php | 47 + .../service/curd/BuildCurdServiceClass.php | 1749 +++++++++++++++++ .../curd/exceptions/CurdExceptionClass.php | 7 + .../curd/exceptions/FileExceptionClass.php | 7 + .../curd/exceptions/TableExceptionClass.php | 7 + .../curd/templates/controller/controller.code | 30 + .../templates/controller/exportMethod.code | 31 + .../templates/controller/indexMethod.code | 31 + .../curd/templates/controller/select.code | 2 + .../service/curd/templates/js/_common.code | 10 + .../admin/service/curd/templates/js/add.code | 3 + .../admin/service/curd/templates/js/edit.code | 3 + .../service/curd/templates/js/index.code | 10 + .../service/curd/templates/model/model.code | 21 + .../curd/templates/model/relation.code | 5 + .../service/curd/templates/model/select.code | 2 + .../service/curd/templates/view/form.code | 11 + .../service/curd/templates/view/index.code | 13 + .../curd/templates/view/module/checkbox.code | 7 + .../templates/view/module/checkboxInput.code | 3 + .../curd/templates/view/module/city.code | 7 + .../curd/templates/view/module/cityMain.code | 1 + .../curd/templates/view/module/date.code | 7 + .../curd/templates/view/module/editor.code | 7 + .../curd/templates/view/module/file.code | 11 + .../curd/templates/view/module/files.code | 11 + .../curd/templates/view/module/image.code | 11 + .../curd/templates/view/module/images.code | 11 + .../curd/templates/view/module/input.code | 7 + .../curd/templates/view/module/option.code | 4 + .../curd/templates/view/module/radio.code | 7 + .../templates/view/module/radioInput.code | 3 + .../curd/templates/view/module/select.code | 9 + .../curd/templates/view/module/table.code | 7 + .../curd/templates/view/module/tableMain.code | 3 + .../curd/templates/view/module/tag.code | 7 + .../curd/templates/view/module/textarea.code | 7 + .../admin/service/initAdminData/MallCate.php | 12 + .../admin/service/initAdminData/MallGoods.php | 34 + .../admin/service/initAdminData/MallTag.php | 32 + .../service/initAdminData/SystemAuth.php | 21 + .../service/initAdminData/SystemAuthNode.php | 5 + .../service/initAdminData/SystemConfig.php | 256 +++ .../service/initAdminData/SystemMenu.php | 160 ++ .../service/initAdminData/SystemNode.php | 726 +++++++ .../service/initAdminData/SystemQuick.php | 61 + extend/base/admin/service/node/NodeClass.php | 174 ++ extend/base/admin/traits/CurdTraitClass.php | 162 ++ extend/trait/admin/controller/LoginTrait.php | 8 - 122 files changed, 5820 insertions(+), 3837 deletions(-) create mode 100644 extend/base/admin/controller/AjaxClass.php create mode 100644 extend/base/admin/controller/IndexClass.php create mode 100644 extend/base/admin/controller/LoginClass.php create mode 100644 extend/base/admin/controller/debug/LogClass.php create mode 100644 extend/base/admin/controller/mall/CateClass.php create mode 100644 extend/base/admin/controller/mall/GoodsClass.php create mode 100644 extend/base/admin/controller/mall/TagClass.php create mode 100644 extend/base/admin/controller/system/AdminClass.php create mode 100644 extend/base/admin/controller/system/AuthClass.php create mode 100644 extend/base/admin/controller/system/ConfigClass.php create mode 100644 extend/base/admin/controller/system/MenuClass.php create mode 100644 extend/base/admin/controller/system/NodeClass.php create mode 100644 extend/base/admin/controller/system/QuickClass.php create mode 100644 extend/base/admin/controller/system/UploadfileClass.php create mode 100644 extend/base/admin/middleware/CsrfMiddlewareClass.php create mode 100644 extend/base/admin/middleware/SystemLogClass.php create mode 100644 extend/base/admin/model/DebugLogClass.php create mode 100644 extend/base/admin/model/MallCateClass.php create mode 100644 extend/base/admin/model/MallGoodsClass.php create mode 100644 extend/base/admin/model/MallTagClass.php create mode 100644 extend/base/admin/model/SystemAdminClass.php create mode 100644 extend/base/admin/model/SystemAuthClass.php create mode 100644 extend/base/admin/model/SystemAuthNodeClass.php create mode 100644 extend/base/admin/model/SystemConfigClass.php create mode 100644 extend/base/admin/model/SystemMenuClass.php create mode 100644 extend/base/admin/model/SystemNodeClass.php create mode 100644 extend/base/admin/model/SystemQuickClass.php create mode 100644 extend/base/admin/model/SystemUploadfileClass.php create mode 100644 extend/base/admin/service/InitAdminServiceClass.php create mode 100644 extend/base/admin/service/NodeServiceClass.php create mode 100644 extend/base/admin/service/TriggerServiceClass.php create mode 100644 extend/base/admin/service/annotation/ControllerAnnotationClass.php create mode 100644 extend/base/admin/service/annotation/NodeAnotationClass.php create mode 100644 extend/base/admin/service/curd/BuildCurdServiceClass.php create mode 100644 extend/base/admin/service/curd/exceptions/CurdExceptionClass.php create mode 100644 extend/base/admin/service/curd/exceptions/FileExceptionClass.php create mode 100644 extend/base/admin/service/curd/exceptions/TableExceptionClass.php create mode 100644 extend/base/admin/service/curd/templates/controller/controller.code create mode 100644 extend/base/admin/service/curd/templates/controller/exportMethod.code create mode 100644 extend/base/admin/service/curd/templates/controller/indexMethod.code create mode 100644 extend/base/admin/service/curd/templates/controller/select.code create mode 100644 extend/base/admin/service/curd/templates/js/_common.code create mode 100644 extend/base/admin/service/curd/templates/js/add.code create mode 100644 extend/base/admin/service/curd/templates/js/edit.code create mode 100644 extend/base/admin/service/curd/templates/js/index.code create mode 100644 extend/base/admin/service/curd/templates/model/model.code create mode 100644 extend/base/admin/service/curd/templates/model/relation.code create mode 100644 extend/base/admin/service/curd/templates/model/select.code create mode 100644 extend/base/admin/service/curd/templates/view/form.code create mode 100644 extend/base/admin/service/curd/templates/view/index.code create mode 100644 extend/base/admin/service/curd/templates/view/module/checkbox.code create mode 100644 extend/base/admin/service/curd/templates/view/module/checkboxInput.code create mode 100644 extend/base/admin/service/curd/templates/view/module/city.code create mode 100644 extend/base/admin/service/curd/templates/view/module/cityMain.code create mode 100644 extend/base/admin/service/curd/templates/view/module/date.code create mode 100644 extend/base/admin/service/curd/templates/view/module/editor.code create mode 100644 extend/base/admin/service/curd/templates/view/module/file.code create mode 100644 extend/base/admin/service/curd/templates/view/module/files.code create mode 100644 extend/base/admin/service/curd/templates/view/module/image.code create mode 100644 extend/base/admin/service/curd/templates/view/module/images.code create mode 100644 extend/base/admin/service/curd/templates/view/module/input.code create mode 100644 extend/base/admin/service/curd/templates/view/module/option.code create mode 100644 extend/base/admin/service/curd/templates/view/module/radio.code create mode 100644 extend/base/admin/service/curd/templates/view/module/radioInput.code create mode 100644 extend/base/admin/service/curd/templates/view/module/select.code create mode 100644 extend/base/admin/service/curd/templates/view/module/table.code create mode 100644 extend/base/admin/service/curd/templates/view/module/tableMain.code create mode 100644 extend/base/admin/service/curd/templates/view/module/tag.code create mode 100644 extend/base/admin/service/curd/templates/view/module/textarea.code create mode 100644 extend/base/admin/service/initAdminData/MallCate.php create mode 100644 extend/base/admin/service/initAdminData/MallGoods.php create mode 100644 extend/base/admin/service/initAdminData/MallTag.php create mode 100644 extend/base/admin/service/initAdminData/SystemAuth.php create mode 100644 extend/base/admin/service/initAdminData/SystemAuthNode.php create mode 100644 extend/base/admin/service/initAdminData/SystemConfig.php create mode 100644 extend/base/admin/service/initAdminData/SystemMenu.php create mode 100644 extend/base/admin/service/initAdminData/SystemNode.php create mode 100644 extend/base/admin/service/initAdminData/SystemQuick.php create mode 100644 extend/base/admin/service/node/NodeClass.php create mode 100644 extend/base/admin/traits/CurdTraitClass.php delete mode 100644 extend/trait/admin/controller/LoginTrait.php diff --git a/app/admin/controller/Ajax.php b/app/admin/controller/Ajax.php index 5645bca..b0510b9 100644 --- a/app/admin/controller/Ajax.php +++ b/app/admin/controller/Ajax.php @@ -1,146 +1,9 @@ [ - '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); - } } diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index a52a753..ff25bc3 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -2,119 +2,8 @@ namespace app\admin\controller; +use base\admin\controller\IndexClass; -use app\admin\model\SystemAdmin; -use app\admin\model\SystemQuick; -use app\common\controller\AdminController; -use think\App; -use think\facade\Env; - -class Index extends AdminController +class Index extends IndexClass { - - /** - * 后台主页 - * @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(); - } } diff --git a/app/admin/controller/Login.php b/app/admin/controller/Login.php index b7ae349..ec645ab 100644 --- a/app/admin/controller/Login.php +++ b/app/admin/controller/Login.php @@ -2,98 +2,11 @@ namespace app\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; -use trait\admin\controller\LoginTrait; +use base\admin\controller\LoginClass; /** * 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(); - } } diff --git a/app/admin/controller/debug/Log.php b/app/admin/controller/debug/Log.php index 403f39d..75f5954 100644 --- a/app/admin/controller/debug/Log.php +++ b/app/admin/controller/debug/Log.php @@ -2,28 +2,12 @@ namespace app\admin\controller\debug; -use app\common\controller\AdminController; use app\admin\service\annotation\ControllerAnnotation; -use app\admin\service\annotation\NodeAnotation; -use think\App; +use base\admin\controller\debug\LogClass; /** * @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(); - } } diff --git a/app/admin/controller/mall/Cate.php b/app/admin/controller/mall/Cate.php index b3453c3..ab452db 100644 --- a/app/admin/controller/mall/Cate.php +++ b/app/admin/controller/mall/Cate.php @@ -1,30 +1,14 @@ model = new MallCate(); - } - -} \ No newline at end of file +} diff --git a/app/admin/controller/mall/Goods.php b/app/admin/controller/mall/Goods.php index 14fca33..372dcbe 100644 --- a/app/admin/controller/mall/Goods.php +++ b/app/admin/controller/mall/Goods.php @@ -2,121 +2,13 @@ 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\NodeAnotation; -use think\App; +use base\admin\controller\mall\GoodsClass; /** - * Class Goods - * @package app\admin\controller\mall + * Class Goods. * @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); - } } diff --git a/app/admin/controller/mall/Tag.php b/app/admin/controller/mall/Tag.php index 4978110..08f825b 100644 --- a/app/admin/controller/mall/Tag.php +++ b/app/admin/controller/mall/Tag.php @@ -2,26 +2,12 @@ namespace app\admin\controller\mall; -use app\common\controller\AdminController; use app\admin\service\annotation\ControllerAnnotation; -use app\admin\service\annotation\NodeAnotation; -use think\App; +use base\admin\controller\mall\TagClass; /** * @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(); - - } - - -} \ No newline at end of file +} diff --git a/app/admin/controller/system/Admin.php b/app/admin/controller/system/Admin.php index f9ff95e..0c27f0b 100644 --- a/app/admin/controller/system/Admin.php +++ b/app/admin/controller/system/Admin.php @@ -2,15 +2,9 @@ namespace app\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; +use base\admin\controller\system\AdminClass; /** * Class Admin. @@ -18,202 +12,6 @@ use think\validate\ValidateRule; * * @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('保存成功'); - } } diff --git a/app/admin/controller/system/Auth.php b/app/admin/controller/system/Auth.php index 52b6e2a..bfef30b 100644 --- a/app/admin/controller/system/Auth.php +++ b/app/admin/controller/system/Auth.php @@ -1,82 +1,14 @@ '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('保存成功'); - } - -} \ No newline at end of file +} diff --git a/app/admin/controller/system/Config.php b/app/admin/controller/system/Config.php index 01bb8f1..b80c807 100644 --- a/app/admin/controller/system/Config.php +++ b/app/admin/controller/system/Config.php @@ -1,82 +1,14 @@ 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('保存成功'); - } } diff --git a/app/admin/controller/system/Menu.php b/app/admin/controller/system/Menu.php index acc800f..0c54be3 100644 --- a/app/admin/controller/system/Menu.php +++ b/app/admin/controller/system/Menu.php @@ -1,217 +1,14 @@ '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', - ]); - } } diff --git a/app/admin/controller/system/Node.php b/app/admin/controller/system/Node.php index 0fd62e3..d4449b1 100644 --- a/app/admin/controller/system/Node.php +++ b/app/admin/controller/system/Node.php @@ -1,112 +1,14 @@ 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('节点更新成功'); - } -} \ No newline at end of file +} diff --git a/app/admin/controller/system/Quick.php b/app/admin/controller/system/Quick.php index 917eb43..f400eaa 100644 --- a/app/admin/controller/system/Quick.php +++ b/app/admin/controller/system/Quick.php @@ -1,34 +1,14 @@ 'desc', - 'id' => 'desc', - ]; - - public function __construct(App $app) - { - parent::__construct($app); - $this->model = new SystemQuick(); - } - -} \ No newline at end of file +} diff --git a/app/admin/controller/system/Uploadfile.php b/app/admin/controller/system/Uploadfile.php index 192bee3..f3fbdc6 100644 --- a/app/admin/controller/system/Uploadfile.php +++ b/app/admin/controller/system/Uploadfile.php @@ -1,29 +1,14 @@ model = new SystemUploadfile(); - } - -} \ No newline at end of file +} diff --git a/app/admin/middleware/CsrfMiddleware.php b/app/admin/middleware/CsrfMiddleware.php index d5dafbd..1e0803c 100644 --- a/app/admin/middleware/CsrfMiddleware.php +++ b/app/admin/middleware/CsrfMiddleware.php @@ -2,36 +2,8 @@ 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); - } } diff --git a/app/admin/middleware/SystemLog.php b/app/admin/middleware/SystemLog.php index 4f8d5d8..a7f3c26 100644 --- a/app/admin/middleware/SystemLog.php +++ b/app/admin/middleware/SystemLog.php @@ -2,55 +2,12 @@ namespace app\admin\middleware; -use think\facade\Log; -use think\facade\Request as FacadeRequest; -use think\Request; +use base\admin\middleware\SystemLogClass; /** * 系统操作日志中间件 * 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); - } } diff --git a/app/admin/model/DebugLog.php b/app/admin/model/DebugLog.php index 48a4b17..d99a72e 100644 --- a/app/admin/model/DebugLog.php +++ b/app/admin/model/DebugLog.php @@ -2,16 +2,8 @@ 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; - - - - -} \ No newline at end of file +} diff --git a/app/admin/model/MallCate.php b/app/admin/model/MallCate.php index f8fc93a..14ef8ae 100644 --- a/app/admin/model/MallCate.php +++ b/app/admin/model/MallCate.php @@ -1,16 +1,9 @@ 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; - } } diff --git a/app/admin/model/MallTag.php b/app/admin/model/MallTag.php index d088ae3..92e4852 100644 --- a/app/admin/model/MallTag.php +++ b/app/admin/model/MallTag.php @@ -2,17 +2,8 @@ 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"; - - - - - -} \ No newline at end of file +} diff --git a/app/admin/model/SystemAdmin.php b/app/admin/model/SystemAdmin.php index 8fbaf7c..5cda265 100644 --- a/app/admin/model/SystemAdmin.php +++ b/app/admin/model/SystemAdmin.php @@ -1,28 +1,9 @@ 'info', - 'field' => 'id' - ] - ]; - - public function getAuthList() - { - $list = (new SystemAuth()) - ->where('status', 1) - ->column('title', 'id'); - return $list; - } } diff --git a/app/admin/model/SystemAuth.php b/app/admin/model/SystemAuth.php index e326f28..79209f2 100644 --- a/app/admin/model/SystemAuth.php +++ b/app/admin/model/SystemAuth.php @@ -1,55 +1,9 @@ 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; - } - -} \ No newline at end of file +} diff --git a/app/admin/model/SystemAuthNode.php b/app/admin/model/SystemAuthNode.php index b494f05..41ba8d9 100644 --- a/app/admin/model/SystemAuthNode.php +++ b/app/admin/model/SystemAuthNode.php @@ -1,15 +1,9 @@ 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; - } - -} \ No newline at end of file +} diff --git a/app/admin/model/SystemNode.php b/app/admin/model/SystemNode.php index 4ff6d43..5ea4755 100644 --- a/app/admin/model/SystemNode.php +++ b/app/admin/model/SystemNode.php @@ -1,38 +1,9 @@ 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; - } } diff --git a/app/admin/model/SystemQuick.php b/app/admin/model/SystemQuick.php index ad056f9..dd5f165 100644 --- a/app/admin/model/SystemQuick.php +++ b/app/admin/model/SystemQuick.php @@ -1,19 +1,9 @@ 'welcome_list' - ] - ]; } diff --git a/app/admin/model/SystemUploadfile.php b/app/admin/model/SystemUploadfile.php index b154f04..b060fd2 100644 --- a/app/admin/model/SystemUploadfile.php +++ b/app/admin/model/SystemUploadfile.php @@ -1,12 +1,9 @@ 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'; - } } diff --git a/app/admin/service/NodeService.php b/app/admin/service/NodeService.php index ab32fb7..a61939e 100644 --- a/app/admin/service/NodeService.php +++ b/app/admin/service/NodeService.php @@ -1,28 +1,9 @@ getNodelist(); - - return $nodeList; - } -} \ No newline at end of file +} diff --git a/app/admin/service/TriggerService.php b/app/admin/service/TriggerService.php index a5582a9..34dea1c 100644 --- a/app/admin/service/TriggerService.php +++ b/app/admin/service/TriggerService.php @@ -1,52 +1,9 @@ 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; - } - -} \ No newline at end of file +} diff --git a/app/admin/service/annotation/ControllerAnnotation.php b/app/admin/service/annotation/ControllerAnnotation.php index fe7405d..e0c843f 100644 --- a/app/admin/service/annotation/ControllerAnnotation.php +++ b/app/admin/service/annotation/ControllerAnnotation.php @@ -5,19 +5,19 @@ // +---------------------------------------------------------------------- // | PHP交流群: 763822524 // +---------------------------------------------------------------------- -// | 开源协议 https://mit-license.org +// | 开源协议 https://mit-license.org // +---------------------------------------------------------------------- // | github开源项目:https://github.com/zhongshaofa/EasyAdmin // +---------------------------------------------------------------------- namespace app\admin\service\annotation; +use base\admin\service\annotation\ControllerAnnotationClass; use Doctrine\Common\Annotations\Annotation\Attributes; -use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; /** - * Class ControllerAnnotation + * Class ControllerAnnotation. * * @Annotation * @Target("CLASS") @@ -27,23 +27,6 @@ use Doctrine\Common\Annotations\Annotation\Target; * * @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; - -} \ No newline at end of file +} diff --git a/app/admin/service/annotation/NodeAnotation.php b/app/admin/service/annotation/NodeAnotation.php index 55b32c2..e8d004f 100644 --- a/app/admin/service/annotation/NodeAnotation.php +++ b/app/admin/service/annotation/NodeAnotation.php @@ -12,6 +12,7 @@ namespace app\admin\service\annotation; +use base\admin\service\annotation\NodeAnotationClass; use Doctrine\Common\Annotations\Annotation\Attributes; /** @@ -23,25 +24,6 @@ use Doctrine\Common\Annotations\Annotation\Attributes; * @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; } diff --git a/app/admin/service/curd/BuildCurdService.php b/app/admin/service/curd/BuildCurdService.php index a7e0978..518f776 100644 --- a/app/admin/service/curd/BuildCurdService.php +++ b/app/admin/service/curd/BuildCurdService.php @@ -2,1748 +2,12 @@ namespace app\admin\service\curd; -use app\admin\service\curd\exceptions\TableException; -use think\exception\FileException; -use think\facade\Db; -use think\helper\Str; +use base\admin\service\curd\BuildCurdServiceClass; /** * 快速构建系统CURD * Class BuildCurd. */ -class BuildCurdService +class BuildCurdService extends BuildCurdServiceClass { - /** - * 当前目录. - * @var string - */ - protected $dir; - - /** - * 应用目录. - * @var string - */ - protected $rootDir; - - /** - * 分隔符. - * @var string - */ - protected $DS = DIRECTORY_SEPARATOR; - - /** - * 数据库名. - * @var string - */ - protected $dbName; - - /** - * 表前缀 - * @var string - */ - protected $tablePrefix = 'ul'; - - /** - * 主表. - * @var string - */ - protected $table; - - /** - * 表注释名. - * @var string - */ - protected $tableComment; - - /** - * 主表列信息. - * @var array - */ - protected $tableColumns; - - /** - * 数据列表可见字段. - * @var string - */ - protected $fields; - - /** - * 是否软删除模式. - * @var bool - */ - protected $delete = false; - - /** - * 是否强制覆盖. - * @var bool - */ - protected $force = false; - - /** - * 关联模型. - * @var array - */ - protected $relationArray = []; - - /** - * 控制器对应的URL. - * @var string - */ - protected $controllerUrl; - - /** - * 生成的控制器名. - * @var string - */ - protected $controllerFilename; - - /** - * 控制器命名. - * @var string - */ - protected $controllerName; - - /** - * 控制器命名空间. - * @var string - */ - protected $controllerNamespace; - - /** - * 视图名. - * @var string - */ - protected $viewFilename; - - /** - * js文件名. - * @var string - */ - protected $jsFilename; - - /** - * 生成的模型文件名. - * @var string - */ - protected $modelFilename; - - /** - * 主表模型命名. - * @var string - */ - protected $modelName; - - /** - * 复选框字段后缀 - * @var array - */ - protected $checkboxFieldSuffix = []; - - /** - * 单选框字段后缀 - * @var array - */ - protected $radioFieldSuffix = []; - - /** - * 单图片字段后缀 - * @var array - */ - protected $imageFieldSuffix = ['image', 'logo', 'photo', 'icon']; - - /** - * 多图片字段后缀 - * @var array - */ - protected $imagesFieldSuffix = ['images', 'photos', 'icons']; - - /** - * 单文件字段后缀 - * @var array - */ - protected $fileFieldSuffix = ['file']; - - /** - * 多文件字段后缀 - * @var array - */ - protected $filesFieldSuffix = ['files']; - - /** - * 时间字段后缀 - * @var array - */ - protected $dateFieldSuffix = ['time', 'date']; - - /** - * 开关组件字段. - * @var array - */ - protected $switchFields = ['status']; - - /** - * 下拉选择字段. - * @var array - */ - protected $selectFileds = []; - - /** - * 富文本字段. - * @var array - */ - protected $editorFields = []; - - /** - * 排序字段. - * @var array - */ - protected $sortFields = []; - - /** - * 忽略字段. - * @var array - */ - protected $ignoreFields = ['update_time', 'delete_time']; - - /** - * 外键字段. - * @var array - */ - protected $foreignKeyFields = []; - - /** - * 相关生成文件. - * @var array - */ - protected $fileList = []; - - /** - * 表单类型. - * @var array - */ - protected $formTypeArray = ['text', 'image', 'images', 'file', 'files', 'select', 'switch', 'date', 'editor', 'textarea', 'checkbox', 'radio', 'relation', 'table', 'city', 'tag']; - - /** - * 初始化 - * BuildCurd constructor. - */ - public function __construct() - { - $this->tablePrefix = config('database.connections.mysql.prefix'); - $this->dbName = config('database.connections.mysql.database'); - $this->dir = __DIR__; - $this->rootDir = root_path(); - - return $this; - } - - public function getTableColumns() - { - return $this->tableColumns; - } - - public function setRootDir($dir) - { - $this->rootDir = $dir; - - return $this; - } - - /** - * 设置主表. - * @param $table - * @return $this - * @throws TableException - */ - public function setTable($table) - { - $this->table = $table; - try { - // 获取表列注释 - $colums = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$this->table}"); - - foreach ($colums as $vo) { - $colum = [ - 'type' => $vo['Type'], - 'comment' => !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'], - 'required' => $vo['Null'] == 'NO' ? true : false, - 'default' => $vo['Default'], - 'field' => $vo['Field'], - ]; - - // 格式化列数据 - $this->buildColum($colum); - - $this->tableColumns[$vo['Field']] = $colum; - - if ($vo['Field'] == 'delete_time') { - $this->delete = true; - } - } - - // 获取表名注释 - $tableSchema = Db::query("SELECT table_name,table_comment FROM information_schema.TABLES WHERE table_schema = 'ulthon_admin' AND table_name = '{$this->tablePrefix}{$this->table}'"); - $this->tableComment = (isset($tableSchema[0]['table_comment']) && !empty($tableSchema[0]['table_comment'])) ? $tableSchema[0]['table_comment'] : $this->table; - } catch (\Exception $e) { - throw new TableException($e->getMessage()); - } - - $this->controllerFilename = $this->getTableControllerName($this->table); - - // 初始化默认模型名 - $this->modelFilename = Str::studly($this->table); - - // 主表模型命名 - $modelArray = explode($this->DS, $this->modelFilename); - - $this->modelName = array_pop($modelArray); - - $this->buildViewJsUrl(); - - // 构建数据 - $this->buildStructure(); - - return $this; - } - - public function getTableControllerName($table) - { - $controllerFilename = ''; - // 初始化默认控制器名 - $nodeArray = explode('_', $table); - if (count($nodeArray) == 1) { - $controllerFilename = ucfirst($nodeArray[0]); - } else { - foreach ($nodeArray as $k => $v) { - if ($k == 0) { - $controllerFilename = "{$v}{$this->DS}"; - } else { - $controllerFilename .= ucfirst($v); - } - } - } - - return $controllerFilename; - } - - /** - * 设置关联表. - * @param $relationTable - * @param $foreignKey - * @param null $primaryKey - * @param null $modelFilename - * @param array $onlyShowFileds - * @param null $bindSelectField - * @return $this - * @throws TableException - */ - public function setRelation($relationTable, $foreignKey, $primaryKey = null, $modelFilename = null, $onlyShowFileds = [], $bindSelectField = null) - { - if (!isset($this->tableColumns[$foreignKey])) { - throw new TableException("主表不存在外键字段:{$foreignKey}"); - } - if (!empty($modelFilename)) { - $modelFilename = str_replace('/', $this->DS, $modelFilename); - } - try { - $colums = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$relationTable}"); - $formatColums = []; - $delete = false; - if (!empty($bindSelectField) && !in_array($bindSelectField, array_column($colums, 'Field'))) { - throw new TableException("关联表{$relationTable}不存在该字段: {$bindSelectField}"); - } - foreach ($colums as $vo) { - if (empty($primaryKey) && $vo['Key'] == 'PRI') { - $primaryKey = $vo['Field']; - } - if (!empty($onlyShowFileds) && !in_array($vo['Field'], $onlyShowFileds)) { - continue; - } - $colum = [ - 'type' => $vo['Type'], - 'comment' => $vo['Comment'], - 'default' => $vo['Default'], - 'field' => $vo['Field'], - ]; - - $this->buildColum($colum); - - $formatColums[$vo['Field']] = $colum; - if ($vo['Field'] == 'delete_time') { - $delete = true; - } - } - - $modelFilename = empty($modelFilename) ? Str::studly($relationTable) : $modelFilename; - $modelArray = explode($this->DS, $modelFilename); - $modelName = array_pop($modelArray); - - $relation = [ - 'modelFilename' => $modelFilename, - 'modelName' => $modelName, - 'foreignKey' => $foreignKey, - 'primaryKey' => $primaryKey, - 'bindSelectField' => $bindSelectField, - 'delete' => $delete, - 'tableColumns' => $formatColums, - ]; - if (!empty($bindSelectField)) { - $relationArray = explode('\\', $modelFilename); - $this->tableColumns[$foreignKey]['bindSelectField'] = $bindSelectField; - $this->tableColumns[$foreignKey]['bindRelation'] = end($relationArray); - } - $this->relationArray[$relationTable] = $relation; - $this->selectFileds[] = $foreignKey; - } catch (\Exception $e) { - throw new TableException($e->getMessage()); - } - - return $this; - } - - /** - * 设置控制器名. - * @param $controllerFilename - * @return $this - */ - public function setControllerFilename($controllerFilename) - { - $this->controllerFilename = str_replace('/', $this->DS, $controllerFilename); - $this->buildViewJsUrl(); - - return $this; - } - - /** - * 设置模型名. - * @param $modelFilename - * @return $this - */ - public function setModelFilename($modelFilename) - { - $this->modelFilename = str_replace('/', $this->DS, $modelFilename); - $this->buildViewJsUrl(); - - return $this; - } - - /** - * 设置显示字段. - * @param $fields - * @return $this - */ - public function setFields($fields) - { - $this->fields = $fields; - - return $this; - } - - /** - * 设置删除模式. - * @param $delete - * @return $this - */ - public function setDelete($delete) - { - $this->delete = $delete; - - return $this; - } - - /** - * 设置是否强制替换. - * @param $force - * @return $this - */ - public function setForce($force) - { - $this->force = $force; - - return $this; - } - - /** - * 设置复选框字段后缀 - * @param $array - * @return $this - */ - public function setCheckboxFieldSuffix($array) - { - $this->checkboxFieldSuffix = array_merge($this->checkboxFieldSuffix, $array); - - return $this; - } - - /** - * 设置单选框字段后缀 - * @param $array - * @return $this - */ - public function setRadioFieldSuffix($array) - { - $this->radioFieldSuffix = array_merge($this->radioFieldSuffix, $array); - - return $this; - } - - /** - * 设置单图片字段后缀 - * @param $array - * @return $this - */ - public function setImageFieldSuffix($array) - { - $this->imageFieldSuffix = array_merge($this->imageFieldSuffix, $array); - - return $this; - } - - /** - * 设置多图片字段后缀 - * @param $array - * @return $this - */ - public function setImagesFieldSuffix($array) - { - $this->imagesFieldSuffix = array_merge($this->imagesFieldSuffix, $array); - - return $this; - } - - /** - * 设置单文件字段后缀 - * @param $array - * @return $this - */ - public function setFileFieldSuffix($array) - { - $this->fileFieldSuffix = array_merge($this->fileFieldSuffix, $array); - - return $this; - } - - /** - * 设置多文件字段后缀 - * @param $array - * @return $this - */ - public function setFilesFieldSuffix($array) - { - $this->filesFieldSuffix = array_merge($this->filesFieldSuffix, $array); - - return $this; - } - - /** - * 设置时间字段后缀 - * @param $array - * @return $this - */ - public function setDateFieldSuffix($array) - { - $this->dateFieldSuffix = array_merge($this->dateFieldSuffix, $array); - - return $this; - } - - /** - * 设置开关字段. - * @param $array - * @return $this - */ - public function setSwitchFields($array) - { - $this->switchFields = array_merge($this->switchFields, $array); - - return $this; - } - - /** - * 设置下拉选择字段. - * @param $array - * @return $this - */ - public function setSelectFileds($array) - { - $this->selectFileds = array_merge($this->selectFileds, $array); - - return $this; - } - - /** - * 设置排序字段. - * @param $array - * @return $this - */ - public function setSortFields($array) - { - $this->sortFields = array_merge($this->sortFields, $array); - - return $this; - } - - /** - * 设置忽略字段. - * @param $array - * @return $this - */ - public function setIgnoreFields($array) - { - $this->ignoreFields = array_merge($this->ignoreFields, $array); - - return $this; - } - - /** - * 获取相关的文件. - * @return array - */ - public function getFileList() - { - return $this->fileList; - } - - /** - * 构建基础视图、JS、URL. - * @return $this - */ - protected function buildViewJsUrl() - { - $nodeArray = explode($this->DS, $this->controllerFilename); - $formatArray = []; - foreach ($nodeArray as $vo) { - $formatArray[] = Str::snake($vo); - } - $this->controllerUrl = implode('.', $formatArray); - $this->viewFilename = implode($this->DS, $formatArray); - $this->jsFilename = $this->viewFilename; - - // 控制器命名空间 - $namespaceArray = $nodeArray; - $this->controllerName = array_pop($namespaceArray); - $namespaceSuffix = implode('\\', $namespaceArray); - $this->controllerNamespace = empty($namespaceSuffix) ? "app\admin\controller" : "app\admin\controller\\{$namespaceSuffix}"; - - return $this; - } - - /** - * 构建字段. - * @return $this - */ - protected function buildStructure() - { - foreach ($this->tableColumns as $key => $val) { - // 排序 - if (in_array($key, ['sort'])) { - $this->sortFields[] = $key; - } - - // 富文本 - if (in_array($key, ['describe', 'content', 'details'])) { - $this->editorFields[] = $key; - } - } - - return $this; - } - - /** - * 构建必填. - * @param $require - * @return string - */ - protected function buildRequiredHtml($require) - { - return $require ? 'lay-verify="required"' : ''; - } - - /** - * 构建初始化字段信息. - * @param $colum - * @return mixed - */ - protected function buildColum(&$colum) - { - $string = $colum['comment']; - - // 处理定义类型 - preg_match('/{[\s\S]*?}/i', $string, $formTypeMatch); - if (!empty($formTypeMatch) && isset($formTypeMatch[0])) { - $colum['comment'] = str_replace($formTypeMatch[0], '', $colum['comment']); - $formType = trim(str_replace('}', '', str_replace('{', '', $formTypeMatch[0]))); - if (in_array($formType, $this->formTypeArray)) { - $colum['formType'] = $formType; - } - } - - // 处理默认定义 - preg_match('/\([\s\S]*?\)/i', $string, $defineMatch); - if (!empty($formTypeMatch) && isset($defineMatch[0])) { - $colum['comment'] = str_replace($defineMatch[0], '', $colum['comment']); - if (isset($colum['formType']) && in_array($colum['formType'], ['images', 'files', 'select', 'switch', 'radio', 'checkbox', 'date', 'relation', 'table', 'city'])) { - $define = str_replace(')', '', str_replace('(', '', $defineMatch[0])); - if (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox', 'relation', 'table', 'city'])) { - $formatDefine = []; - $explodeArray = explode(',', $define); - foreach ($explodeArray as $vo) { - $voExplodeArray = explode(':', $vo); - if (count($voExplodeArray) == 2) { - $formatDefine[trim($voExplodeArray[0])] = trim($voExplodeArray[1]); - } - } - !empty($formatDefine) && $colum['define'] = $formatDefine; - } else { - $colum['define'] = $define; - } - } - } - - $colum['comment'] = trim($colum['comment']); - - $colum['property_type'] = $this->fieldTypeToVarType($colum['type']); - - $colum['property_name'] = $colum['field']; - - $colum['data_list'] = ''; - - if (isset($colum['formType'])) { - if ($colum['formType'] == 'relation') { - $relation_model_name = '\\app\\admin\\model\\' . Str::studly($colum['define']['table']); - $colum['property_type'] = $relation_model_name; - $colum['property_name'] = Str::camel($colum['define']['table']); - } elseif (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox'])) { - $data_list = ''; - - foreach ($colum['define'] as $define_key => $define_value) { - $data_list .= $define_key . ':' . $define_value . ','; - } - $data_list = substr($data_list, 0, -1); - $colum['data_list'] = $data_list; - } - } - - return $colum; - } - - /** - * 构建下拉控制器. - * @param $field - * @return mixed - */ - protected function buildSelectController($field) - { - $name = $this->getFieldConstentName($field); - $var_name = $this->getFieldVarName($field); - - $selectCode = $this->replaceTemplate( - $this->getTemplate("controller{$this->DS}select"), - [ - 'name' => $name, - 'var_name' => $var_name, - ] - ); - - return $selectCode; - } - - /** - * 构架下拉模型. - * @param $field - * @param $array - * @return mixed - */ - protected function buildSelectModel($field, $array) - { - $name = $this->getFieldConstentName($field); - - $values = '['; - foreach ($array as $k => $v) { - $values .= "'{$k}'=>'{$v}',"; - } - $values .= ']'; - $selectCode = $this->replaceTemplate( - $this->getTemplate("model{$this->DS}select"), - [ - 'name' => $name, - 'values' => $values, - ] - ); - - return $selectCode; - } - - /** - * 构建下拉框视图. - * @param $field - * @param string $select - * @return mixed - */ - protected function buildOptionView($field, $select = '') - { - $name = $this->getFieldVarName($field); - $optionCode = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}module{$this->DS}option"), - [ - 'name' => $name, - 'select' => $select, - ] - ); - - return $optionCode; - } - - protected function buildCityView($field, $options, $value) - { - $default_define = [ - 'comment' => $options['comment'], - 'field' => $field, - 'required' => $this->buildRequiredHtml($options['required']), - 'value' => $value, - 'level' => '', - ]; - - $define = array_merge($default_define, $options['define']); - - $formatTargetList = []; - $formatTargetList['name'] = 1; - $formatTargetList['code'] = 1; - $formatTargetList['name-province'] = 1; - $formatTargetList['name-city'] = 1; - $formatTargetList['name-district'] = 1; - $formatTargetList['code-province'] = 1; - $formatTargetList['code-city'] = 1; - $formatTargetList['code-district'] = 1; - - $submit_field_content = ''; - - foreach ($formatTargetList as $key => $value) { - if (isset($define[$key])) { - $submit_field_content .= 'data-field-' . $key . '="' . $define[$key] . '" '; - } - } - - $define['submit_field_content'] = $submit_field_content; - - $city_main_code = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}module{$this->DS}cityMain"), - $define - ); - - return $city_main_code; - } - - /** - * 构建表格选择器视图. - * @param $field - * @param string $select - * @return mixed - */ - protected function buildTableView($field, $options, $value) - { - $default_define = [ - 'table' => '', - // 必填 - 'type' => 'checkbox', - 'valueField' => 'id', - 'fieldName' => 'title', - // 必填 - 'comment' => $options['comment'], - 'field' => $field, - 'required' => $options['required'], - 'value' => $value, - ]; - - $define = array_merge($default_define, $options['define']); - - $table_controller_name = $this->getTableControllerName($define['table']); - - $nodeArray = explode($this->DS, $table_controller_name); - $formatArray = []; - foreach ($nodeArray as $vo) { - $formatArray[] = Str::snake($vo); - } - $controller_url = implode('.', $formatArray); - - $define['controller_url'] = $controller_url; - - $table_main_code = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}module{$this->DS}tableMain"), - $define - ); - - return $table_main_code; - } - - /** - * 构建单选框视图. - * @param $field - * @param string $select - * @return mixed - */ - protected function buildRadioView($field, $select = '') - { - $name = $this->getFieldVarName($field); - $optionCode = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}module{$this->DS}radioInput"), - [ - 'field' => $field, - 'name' => $name, - 'select' => $select, - ] - ); - - return $optionCode; - } - - /** - * 构建多选框视图. - * @param $field - * @param string $select - * @return mixed - */ - protected function buildCheckboxView($field, $select = '') - { - $name = $this->getFieldVarName($field); - $optionCode = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}module{$this->DS}checkboxInput"), - [ - 'field' => $field, - 'name' => $name, - 'select' => $select, - ] - ); - - return $optionCode; - } - - /** - * 初始化. - * @return $this - */ - public function render() - { - // 初始化数据 - $this->renderData(); - - // 控制器 - $this->renderController(); - - // 模型 - $this->renderModel(); - - // 视图 - $this->renderView(); - - // JS - $this->renderJs(); - - return $this; - } - - /** - * 初始化数据. - * @return $this - */ - protected function renderData() - { - // 主表 - foreach ($this->tableColumns as $field => $val) { - // 过滤字段 - if (in_array($field, $this->ignoreFields)) { - unset($this->tableColumns[$field]); - continue; - } - - // 判断是否已初始化 - if (isset($this->tableColumns[$field]['formType'])) { - continue; - } - - // 判断图片 - if ($this->checkContain($field, $this->imageFieldSuffix)) { - $this->tableColumns[$field]['formType'] = 'image'; - continue; - } - if ($this->checkContain($field, $this->imagesFieldSuffix)) { - $this->tableColumns[$field]['formType'] = 'images'; - continue; - } - - // 判断文件 - if ($this->checkContain($field, $this->fileFieldSuffix)) { - $this->tableColumns[$field]['formType'] = 'file'; - continue; - } - if ($this->checkContain($field, $this->filesFieldSuffix)) { - $this->tableColumns[$field]['formType'] = 'files'; - continue; - } - - // 判断时间 - if ($this->checkContain($field, $this->dateFieldSuffix)) { - $this->tableColumns[$field]['formType'] = 'date'; - continue; - } - - // 判断开关 - if (in_array($field, $this->switchFields)) { - $this->tableColumns[$field]['formType'] = 'switch'; - continue; - } - - // 判断富文本 - if (in_array($field, $this->editorFields)) { - $this->tableColumns[$field]['formType'] = 'editor'; - continue; - } - - // 判断排序 - if (in_array($field, $this->sortFields)) { - $this->tableColumns[$field]['formType'] = 'sort'; - continue; - } - - // 判断下拉选择 - if (in_array($field, $this->selectFileds)) { - $this->tableColumns[$field]['formType'] = 'select'; - continue; - } - - $this->tableColumns[$field]['formType'] = 'text'; - } - - // 关联表 - foreach ($this->relationArray as $table => $tableVal) { - foreach ($tableVal['tableColumns'] as $field => $val) { - // 过滤字段 - if (in_array($field, $this->ignoreFields)) { - unset($this->relationArray[$table]['tableColumns'][$field]); - continue; - } - - // 判断是否已初始化 - if (isset($this->relationArray[$table]['tableColumns'][$field]['formType'])) { - continue; - } - - // 判断图片 - if ($this->checkContain($field, $this->imageFieldSuffix)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'image'; - continue; - } - if ($this->checkContain($field, $this->imagesFieldSuffix)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'images'; - continue; - } - - // 判断文件 - if ($this->checkContain($field, $this->fileFieldSuffix)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'file'; - continue; - } - if ($this->checkContain($field, $this->filesFieldSuffix)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'files'; - continue; - } - - // 判断时间 - if ($this->checkContain($field, $this->dateFieldSuffix)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'date'; - continue; - } - - // 判断开关 - if (in_array($field, $this->switchFields)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'switch'; - continue; - } - - // 判断富文本 - if (in_array($field, $this->editorFields)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'editor'; - continue; - } - - // 判断排序 - if (in_array($field, $this->sortFields)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'sort'; - continue; - } - - // 判断下拉选择 - if (in_array($field, $this->selectFileds)) { - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'select'; - continue; - } - - $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'text'; - } - } - - return $this; - } - - /** - * 初始化控制器. - * @return $this - */ - protected function renderController() - { - $controllerFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}controller{$this->DS}{$this->controllerFilename}.php"; - if (empty($this->relationArray)) { - $controllerIndexMethod = ''; - $controllerExportMethod = ''; - } else { - $relationCode = ''; - $relation_table = []; - - foreach ($this->relationArray as $key => $val) { - $relation = Str::camel($key); - $relation_table[] = $relation; - } - $relationCode = "->withJoin(['" . implode('\',\'', $relation_table) . "'], 'LEFT')\r"; - $controllerIndexMethod = $this->replaceTemplate( - $this->getTemplate("controller{$this->DS}indexMethod"), - [ - 'relationIndexMethod' => $relationCode, - ] - ); - $controllerExportMethod = $this->replaceTemplate( - $this->getTemplate("controller{$this->DS}exportMethod"), - [ - 'relationIndexMethod' => trim($relationCode), - ] - ); - } - $selectList = ''; - - foreach ($this->tableColumns as $field => $val) { - if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) { - $selectList .= $this->buildSelectController($field); - } - } - - $modelFilenameExtend = str_replace($this->DS, '\\', $this->modelFilename); - - $controllerValue = $this->replaceTemplate( - $this->getTemplate("controller{$this->DS}controller"), - [ - 'controllerName' => $this->controllerName, - 'controllerNamespace' => $this->controllerNamespace, - 'controllerAnnotation' => $this->tableComment, - 'modelFilename' => "\app\admin\model\\{$modelFilenameExtend}", - 'indexMethod' => $controllerIndexMethod, - 'exportMethod' => $controllerExportMethod, - 'selectList' => $selectList, - ] - ); - $this->fileList[$controllerFile] = $controllerValue; - - return $this; - } - - /** - * 初始化模型. - * @return $this - */ - protected function renderModel() - { - // 主表模型 - $modelFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}model{$this->DS}{$this->modelFilename}.php"; - if (empty($this->relationArray)) { - $relationList = ''; - } else { - $relationList = ''; - foreach ($this->relationArray as $key => $val) { - $relation = Str::camel($key); - $relationCode = $this->replaceTemplate( - $this->getTemplate("model{$this->DS}relation"), - [ - 'relationMethod' => $relation, - 'relationModel' => "\app\admin\model\\{$val['modelFilename']}", - 'foreignKey' => $val['foreignKey'], - 'primaryKey' => $val['primaryKey'], - ] - ); - $relationList .= $relationCode; - } - } - - $selectList = ''; - - $doc_content = ''; - - foreach ($this->tableColumns as $field => $val) { - if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) { - $selectList .= $this->buildSelectModel($field, $val['define']); - } - $doc_content .= " * @property {$val['property_type']} \${$val['property_name']} {$val['comment']} {$val['data_list']}\n"; - } - - $doc_content = substr($doc_content, 0, -1); - - $extendNamespaceArray = explode($this->DS, $this->modelFilename); - $extendNamespace = null; - if (count($extendNamespaceArray) > 1) { - array_pop($extendNamespaceArray); - $extendNamespace = '\\' . implode('\\', $extendNamespaceArray); - } - - $modelValue = $this->replaceTemplate( - $this->getTemplate("model{$this->DS}model"), - [ - 'modelName' => $this->modelName, - 'modelNamespace' => "app\admin\model{$extendNamespace}", - 'table' => $this->table, - 'deleteTime' => $this->delete ? '"delete_time"' : 'false', - 'relationList' => $relationList, - 'selectList' => $selectList, - 'doc_content' => $doc_content, - ] - ); - $this->fileList[$modelFile] = $modelValue; - - // 关联模型 - foreach ($this->relationArray as $key => $val) { - $relationModelFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}model{$this->DS}{$val['modelFilename']}.php"; - - // todo 判断关联模型文件是否存在, 存在就不重新生成文件, 防止关联模型文件被覆盖 - $relationModelClass = "\\app\\admin\\model\\{$val['modelFilename']}"; - if (class_exists($relationModelClass) && method_exists(new $relationModelClass, 'getName')) { - $tableName = (new $relationModelClass)->getName(); - if (Str::snake($tableName) == Str::snake($key)) { - continue; - } - } - - $extendNamespaceArray = explode($this->DS, $val['modelFilename']); - $extendNamespace = null; - if (count($extendNamespaceArray) > 1) { - array_pop($extendNamespaceArray); - $extendNamespace = '\\' . implode('\\', $extendNamespaceArray); - } - - $relationModelValue = $this->replaceTemplate( - $this->getTemplate("model{$this->DS}model"), - [ - 'modelName' => $val['modelName'], - 'modelNamespace' => "app\admin\model{$extendNamespace}", - 'table' => $key, - 'deleteTime' => $val['delete'] ? '"delete_time"' : 'false', - 'relationList' => '', - 'selectList' => '', - ] - ); - $this->fileList[$relationModelFile] = $relationModelValue; - } - - return $this; - } - - /** - * 初始化视图. - * @return $this - */ - protected function renderView() - { - // 列表页面 - $viewIndexFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}index.html"; - $viewIndexValue = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}index"), - [ - 'controllerUrl' => $this->controllerUrl, - ] - ); - $this->fileList[$viewIndexFile] = $viewIndexValue; - - // 添加页面 - $viewAddFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}add.html"; - $addFormList = ''; - foreach ($this->tableColumns as $field => $val) { - if (in_array($field, ['id', 'create_time'])) { - continue; - } - - $templateFile = "view{$this->DS}module{$this->DS}input"; - $define = ''; - - // 根据formType去获取具体模板 - if ($val['formType'] == 'image') { - $templateFile = "view{$this->DS}module{$this->DS}image"; - } elseif ($val['formType'] == 'images') { - $templateFile = "view{$this->DS}module{$this->DS}images"; - $define = isset($val['define']) ? $val['define'] : '|'; - } elseif ($val['formType'] == 'file') { - $templateFile = "view{$this->DS}module{$this->DS}file"; - } elseif ($val['formType'] == 'files') { - $templateFile = "view{$this->DS}module{$this->DS}files"; - $define = isset($val['define']) ? $val['define'] : '|'; - } elseif ($val['formType'] == 'editor') { - $templateFile = "view{$this->DS}module{$this->DS}editor"; - } elseif ($val['formType'] == 'date') { - $templateFile = "view{$this->DS}module{$this->DS}date"; - if (isset($val['define']) && !empty($val['define'])) { - $define = $val['define']; - } else { - $define = 'datetime'; - } - if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) { - $define = 'datetime'; - } - } elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') { - $templateFile = "view{$this->DS}module{$this->DS}radio"; - if (isset($val['define']) && !empty($val['define'])) { - $define = $this->buildRadioView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}'); - } - } elseif ($val['formType'] == 'checkbox') { - $templateFile = "view{$this->DS}module{$this->DS}checkbox"; - if (isset($val['define']) && !empty($val['define'])) { - $define = $this->buildCheckboxView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}'); - } - } elseif ($val['formType'] == 'select') { - $templateFile = "view{$this->DS}module{$this->DS}select"; - if (isset($val['bindRelation'])) { - // TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理 - $define = $this->buildOptionView($val['bindRelation']); - } elseif (isset($val['define']) && !empty($val['define'])) { - $define = $this->buildOptionView($field); - } - } elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') { - $templateFile = "view{$this->DS}module{$this->DS}textarea"; - } elseif ($val['formType'] == 'relation') { - $val['define']['type'] = 'radio'; - $val['define']['valueField'] = 'id'; - $val['define']['fieldName'] = $val['define']['relationBindSelect']; - - $templateFile = "view{$this->DS}module{$this->DS}table"; - - $define = $this->buildTableView($field, $val, $val['default']); - } elseif ($val['formType'] == 'table') { - $templateFile = "view{$this->DS}module{$this->DS}table"; - $define = $this->buildTableView($field, $val, $val['default']); - } elseif ($val['formType'] == 'city') { - $templateFile = "view{$this->DS}module{$this->DS}city"; - $define = $this->buildCityView($field, $val, $val['default']); - } elseif ($val['formType'] == 'tag') { - $templateFile = "view{$this->DS}module{$this->DS}tag"; - } - - $addFormList .= $this->replaceTemplate( - $this->getTemplate($templateFile), - [ - 'comment' => $val['comment'], - 'field' => $field, - 'required' => $this->buildRequiredHtml($val['required']), - 'required_text' => $val['required'] ? '1' : '', - 'value' => $val['default'], - 'define' => $define, - ] - ); - } - $viewAddValue = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}form"), - [ - 'formList' => $addFormList, - ] - ); - $this->fileList[$viewAddFile] = $viewAddValue; - - // 编辑页面 - $viewEditFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}edit.html"; - $editFormList = ''; - foreach ($this->tableColumns as $field => $val) { - if (in_array($field, ['id', 'create_time'])) { - continue; - } - - $templateFile = "view{$this->DS}module{$this->DS}input"; - - $define = ''; - $value = '{$row.' . $field . '|default=\'\'}'; - - // 根据formType去获取具体模板 - if ($val['formType'] == 'image') { - $templateFile = "view{$this->DS}module{$this->DS}image"; - } elseif ($val['formType'] == 'images') { - $templateFile = "view{$this->DS}module{$this->DS}images"; - } elseif ($val['formType'] == 'file') { - $templateFile = "view{$this->DS}module{$this->DS}file"; - } elseif ($val['formType'] == 'files') { - $templateFile = "view{$this->DS}module{$this->DS}files"; - } elseif ($val['formType'] == 'editor') { - $templateFile = "view{$this->DS}module{$this->DS}editor"; - $value = '{$row.' . $field . '|raw|default=\'\'}'; - } elseif ($val['formType'] == 'date') { - $templateFile = "view{$this->DS}module{$this->DS}date"; - if (isset($val['define']) && !empty($val['define'])) { - $define = $val['define']; - } else { - $define = 'datetime'; - } - if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) { - $define = 'datetime'; - } - } elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') { - $templateFile = "view{$this->DS}module{$this->DS}radio"; - if (isset($val['define']) && !empty($val['define'])) { - $define = $this->buildRadioView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}'); - } - } elseif ($val['formType'] == 'checkbox') { - $templateFile = "view{$this->DS}module{$this->DS}checkbox"; - if (isset($val['define']) && !empty($val['define'])) { - $define = $this->buildCheckboxView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}'); - } - } elseif ($val['formType'] == 'select') { - $templateFile = "view{$this->DS}module{$this->DS}select"; - if (isset($val['bindRelation'])) { - // TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理 - $define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}'); - } elseif (isset($val['define']) && !empty($val['define'])) { - $define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}'); - } - } elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') { - $templateFile = "view{$this->DS}module{$this->DS}textarea"; - $value = '{$row.' . $field . '|raw|default=\'\'}'; - } elseif ($val['formType'] == 'relation') { - $val['define']['type'] = 'radio'; - $val['define']['valueField'] = 'id'; - $val['define']['fieldName'] = $val['define']['relationBindSelect']; - - $templateFile = "view{$this->DS}module{$this->DS}table"; - - $define = $this->buildTableView($field, $val, $value); - } elseif ($val['formType'] == 'table') { - $templateFile = "view{$this->DS}module{$this->DS}table"; - $define = $this->buildTableView($field, $val, $value); - } elseif ($val['formType'] == 'city') { - $templateFile = "view{$this->DS}module{$this->DS}city"; - $define = $this->buildCityView($field, $val, $value); - } elseif ($val['formType'] == 'tag') { - $templateFile = "view{$this->DS}module{$this->DS}tag"; - } - - $editFormList .= $this->replaceTemplate( - $this->getTemplate($templateFile), - [ - 'comment' => $val['comment'], - 'field' => $field, - 'required' => $this->buildRequiredHtml($val['required']), - 'required_text' => $val['required'] ? '1' : '', - 'value' => $value, - 'define' => $define, - ] - ); - } - $viewEditValue = $this->replaceTemplate( - $this->getTemplate("view{$this->DS}form"), - [ - 'formList' => $editFormList, - ] - ); - $this->fileList[$viewEditFile] = $viewEditValue; - - return $this; - } - - /** - * 初始化JS. - * @return $this - */ - protected function renderJs() - { - $index_js_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}index.js"; - - $indexCols = " {type: 'checkbox'},\r"; - - // 主表字段 - foreach ($this->tableColumns as $field => $val) { - $var_name = $this->getFieldVarName($field); - - if ($val['formType'] == 'image') { - $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.image}"; - } elseif ($val['formType'] == 'images') { - continue; - } elseif ($val['formType'] == 'file') { - $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.url}"; - } elseif ($val['formType'] == 'files') { - continue; - } elseif ($val['formType'] == 'editor') { - continue; - } elseif ($val['formType'] == 'table') { - continue; - } elseif (in_array($field, $this->switchFields)) { - if (isset($val['define']) && !empty($val['define'])) { - $templateValue = "{field: '{$field}', search: 'select', selectList: ua.getDataBrage('{$var_name}'), title: '{$val['comment']}', templet: ua.table.switch}"; - } else { - $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.switch}"; - } - } elseif (in_array($val['formType'], ['select', 'checkbox', 'radio', 'switch'])) { - if (isset($val['define']) && !empty($val['define'])) { - $templateValue = "{field: '{$field}', search: 'select', selectList: ua.getDataBrage('{$var_name}'), title: '{$val['comment']}'}"; - } else { - $templateValue = "{field: '{$field}', title: '{$val['comment']}'}"; - } - } elseif (in_array($field, ['remark'])) { - $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.text}"; - } elseif (in_array($field, $this->sortFields)) { - $templateValue = "{field: '{$field}', title: '{$val['comment']}', edit: 'text'}"; - } else { - $templateValue = "{field: '{$field}', title: '{$val['comment']}'}"; - } - - $indexCols .= $this->formatColsRow("{$templateValue},\r"); - } - - // 关联表 - foreach ($this->relationArray as $table => $tableVal) { - $table = Str::camel($table); - foreach ($tableVal['tableColumns'] as $field => $val) { - if ($val['formType'] == 'image') { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.image}"; - } elseif ($val['formType'] == 'images') { - continue; - } elseif ($val['formType'] == 'file') { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.url}"; - } elseif ($val['formType'] == 'files') { - continue; - } elseif ($val['formType'] == 'editor') { - continue; - } elseif ($val['formType'] == 'table') { - continue; - } elseif ($val['formType'] == 'select') { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}"; - } elseif (in_array($field, ['remark'])) { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.text}"; - } elseif (in_array($field, $this->switchFields)) { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.switch}"; - } elseif (in_array($field, $this->sortFields)) { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', edit: 'text'}"; - } else { - $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}"; - } - - $indexCols .= $this->formatColsRow("{$templateValue},\r"); - } - } - - $indexCols .= $this->formatColsRow("{width: 250, title: '操作', templet: ua.table.tool , fixed:'right'},\r"); - - $js_index = $this->replaceTemplate( - $this->getTemplate("js{$this->DS}index"), - [ - 'indexCols' => $indexCols, - ] - ); - $this->fileList[$index_js_file] = $js_index; - - $js_common_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}_common.js"; - - $js_common = $this->replaceTemplate( - $this->getTemplate("js{$this->DS}_common"), - [ - 'controllerUrl' => $this->controllerUrl, - ] - ); - $this->fileList[$js_common_file] = $js_common; - - $js_add_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}add.js"; - $js_edit_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}edit.js"; - - $js_add = $this->replaceTemplate($this->getTemplate("js{$this->DS}add")); - $this->fileList[$js_add_file] = $js_add; - - $js_edit = $this->replaceTemplate($this->getTemplate("js{$this->DS}edit")); - $this->fileList[$js_edit_file] = $js_edit; - - return $this; - } - - /** - * 检测文件. - * @return $this - */ - protected function check() - { - // 是否强制性 - if ($this->force) { - return $this; - } - foreach ($this->fileList as $key => $val) { - if (is_file($key)) { - throw new FileException("文件已存在:{$key}"); - } - } - - return $this; - } - - /** - * 开始生成. - * @return array - */ - public function create() - { - $this->check(); - foreach ($this->fileList as $key => $val) { - // 判断文件夹是否存在,不存在就创建 - $fileArray = explode($this->DS, $key); - array_pop($fileArray); - $fileDir = implode($this->DS, $fileArray); - if (!is_dir($fileDir)) { - mkdir($fileDir, 0775, true); - } - - // 写入 - file_put_contents($key, $val); - } - - return array_keys($this->fileList); - } - - /** - * 开始删除. - * @return array - */ - public function delete() - { - $deleteFile = []; - foreach ($this->fileList as $key => $val) { - if (is_file($key)) { - unlink($key); - $deleteFile[] = $key; - } - } - - return $deleteFile; - } - - /** - * 检测字段后缀 - * @param $string - * @param $array - * @return bool - */ - protected function checkContain($string, $array) - { - foreach ($array as $vo) { - if (substr($string, 0, strlen($vo)) === $vo) { - return true; - } - } - - return false; - } - - /** - * 格式化表单行. - * @param $value - * @return string - */ - protected function formatColsRow($value) - { - return " {$value}"; - } - - /** - * 获取对应的模板信息. - * @param $name - * @return false|string - */ - protected function getTemplate($name) - { - return file_get_contents("{$this->dir}{$this->DS}templates{$this->DS}{$name}.code"); - } - - public function getFieldConstentName($field) - { - $field = Str::studly($field); - - $name = "SelectList{$field}"; - - $name = Str::snake($name); - - $name = Str::upper($name); - - return $name; - } - - public function getFieldVarName($field) - { - $field = Str::studly($field); - $name = "SelectList{$field}"; - $name = Str::snake($name); - - return $name; - } - - public function getFieldMethodName($field) - { - $field = Str::studly($field); - $name = "getList{$field}"; - - return $name; - } - - /** - * 模板值替换. - * @param $string - * @param $array - * @return mixed - */ - public function replaceTemplate($string, $array = []) - { - foreach ($array as $key => $val) { - $string = str_replace('{{' . $key . '}}', $val, $string); - } - - return $string; - } - - public function fieldTypeToVarType($type) - { - $type_prefix_map = [ - 'BIT' => 'bool', - 'TINYINT' => 'int', - 'BOOL' => 'bool', - 'BOOLEAN' => 'bool', - 'SMALLINT' => 'int', - 'MEDIUMINT' => 'int', - 'INT' => 'int', - 'INTEGER' => 'int', - 'BIGINT' => 'int', - 'FLOAT' => 'float|double', - 'DOUBLE' => 'float|double', - 'DECIMAL' => 'float|double', - 'DATE' => 'string', - 'DATETIME' => 'string', - 'TIMESTAMP' => 'int', - 'TIME' => 'string', - 'YEAR' => 'int', - 'CHAR' => 'string', - 'VARCHAR' => 'string', - 'BINARY' => 'string', - 'VARBINARY' => 'string', - 'TINYBLOB' => 'string', - 'BLOB' => 'string', - 'MEDIUMBLOB' => 'string', - 'LONGBLOB' => 'string', - 'TINYTEXT' => 'string', - 'TEXT' => 'string', - 'MEDIUMTEXT' => 'string', - 'LONGTEXT' => 'string', - 'ENUM' => 'string', - 'SET' => 'string', - 'JSON' => 'string', - ]; - - foreach ($type_prefix_map as $sql_type => $var_type) { - if (Str::startsWith(strtolower($type), strtolower($sql_type))) { - return $var_type; - } - } - - return 'mixed'; - } } diff --git a/app/admin/service/curd/exceptions/CurdException.php b/app/admin/service/curd/exceptions/CurdException.php index b3ae2b3..171301a 100644 --- a/app/admin/service/curd/exceptions/CurdException.php +++ b/app/admin/service/curd/exceptions/CurdException.php @@ -1,10 +1,9 @@ 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; - } } diff --git a/app/admin/traits/Curd.php b/app/admin/traits/Curd.php index 304461a..38cab01 100644 --- a/app/admin/traits/Curd.php +++ b/app/admin/traits/Curd.php @@ -1,163 +1,14 @@ 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('保存成功'); - } + use CurdTraitClass; } diff --git a/app/common/provider/db/Query.php b/app/common/provider/db/Query.php index 10f610e..db171a8 100644 --- a/app/common/provider/db/Query.php +++ b/app/common/provider/db/Query.php @@ -9,10 +9,8 @@ use think\helper\Str; class Query extends DbQuery { - - /** - * autoCache 自动生成缓存 + * autoCache 自动生成缓存. * * @param null|string $key * @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) { - $table_name = Str::snake($this->getName()); if (is_null($key)) { @@ -35,7 +32,6 @@ class Query extends DbQuery $key = $table_name . '_' . $key; if (!is_null($tag)) { - if (!is_null($field_tag_value)) { $tag = $tag . '_' . $field_tag_value; } diff --git a/composer.json b/composer.json index 7aecdff..75ee3b0 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ "psr-4": { "app\\": "app", "trait\\": "extend/trait", + "class\\": "extend/class", "Phinx\\": "extend/phinx" }, "psr-0": { diff --git a/extend/base/admin/controller/AjaxClass.php b/extend/base/admin/controller/AjaxClass.php new file mode 100644 index 0000000..ffcb02e --- /dev/null +++ b/extend/base/admin/controller/AjaxClass.php @@ -0,0 +1,144 @@ + [ + '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); + } +} diff --git a/extend/base/admin/controller/IndexClass.php b/extend/base/admin/controller/IndexClass.php new file mode 100644 index 0000000..f9b4636 --- /dev/null +++ b/extend/base/admin/controller/IndexClass.php @@ -0,0 +1,119 @@ +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(); + } +} diff --git a/extend/base/admin/controller/LoginClass.php b/extend/base/admin/controller/LoginClass.php new file mode 100644 index 0000000..edb8e05 --- /dev/null +++ b/extend/base/admin/controller/LoginClass.php @@ -0,0 +1,96 @@ +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(); + } +} diff --git a/extend/base/admin/controller/debug/LogClass.php b/extend/base/admin/controller/debug/LogClass.php new file mode 100644 index 0000000..9bff8da --- /dev/null +++ b/extend/base/admin/controller/debug/LogClass.php @@ -0,0 +1,27 @@ + 'desc', + 'id' => 'asc', + ]; + + use \app\admin\traits\Curd; + + public function __construct(App $app) + { + parent::__construct($app); + + $this->model = new \app\admin\model\DebugLog(); + } +} diff --git a/extend/base/admin/controller/mall/CateClass.php b/extend/base/admin/controller/mall/CateClass.php new file mode 100644 index 0000000..c2fd7bb --- /dev/null +++ b/extend/base/admin/controller/mall/CateClass.php @@ -0,0 +1,24 @@ +model = new MallCate(); + } +} diff --git a/extend/base/admin/controller/mall/GoodsClass.php b/extend/base/admin/controller/mall/GoodsClass.php new file mode 100644 index 0000000..bdd5fe2 --- /dev/null +++ b/extend/base/admin/controller/mall/GoodsClass.php @@ -0,0 +1,122 @@ +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); + } +} diff --git a/extend/base/admin/controller/mall/TagClass.php b/extend/base/admin/controller/mall/TagClass.php new file mode 100644 index 0000000..aebb17a --- /dev/null +++ b/extend/base/admin/controller/mall/TagClass.php @@ -0,0 +1,22 @@ +model = new \app\admin\model\MallTag(); + } +} diff --git a/extend/base/admin/controller/system/AdminClass.php b/extend/base/admin/controller/system/AdminClass.php new file mode 100644 index 0000000..9b6cf2e --- /dev/null +++ b/extend/base/admin/controller/system/AdminClass.php @@ -0,0 +1,219 @@ + '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('保存成功'); + } +} diff --git a/extend/base/admin/controller/system/AuthClass.php b/extend/base/admin/controller/system/AuthClass.php new file mode 100644 index 0000000..cf929f2 --- /dev/null +++ b/extend/base/admin/controller/system/AuthClass.php @@ -0,0 +1,78 @@ + '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('保存成功'); + } +} diff --git a/extend/base/admin/controller/system/ConfigClass.php b/extend/base/admin/controller/system/ConfigClass.php new file mode 100644 index 0000000..01bb975 --- /dev/null +++ b/extend/base/admin/controller/system/ConfigClass.php @@ -0,0 +1,76 @@ +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('保存成功'); + } +} diff --git a/extend/base/admin/controller/system/MenuClass.php b/extend/base/admin/controller/system/MenuClass.php new file mode 100644 index 0000000..5c985ad --- /dev/null +++ b/extend/base/admin/controller/system/MenuClass.php @@ -0,0 +1,219 @@ + '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', + ]); + } +} diff --git a/extend/base/admin/controller/system/NodeClass.php b/extend/base/admin/controller/system/NodeClass.php new file mode 100644 index 0000000..06f3459 --- /dev/null +++ b/extend/base/admin/controller/system/NodeClass.php @@ -0,0 +1,110 @@ +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('节点更新成功'); + } +} diff --git a/extend/base/admin/controller/system/QuickClass.php b/extend/base/admin/controller/system/QuickClass.php new file mode 100644 index 0000000..2fa62b7 --- /dev/null +++ b/extend/base/admin/controller/system/QuickClass.php @@ -0,0 +1,28 @@ + 'desc', + 'id' => 'desc', + ]; + + public function __construct(App $app) + { + parent::__construct($app); + $this->model = new SystemQuick(); + } +} diff --git a/extend/base/admin/controller/system/UploadfileClass.php b/extend/base/admin/controller/system/UploadfileClass.php new file mode 100644 index 0000000..7f33375 --- /dev/null +++ b/extend/base/admin/controller/system/UploadfileClass.php @@ -0,0 +1,23 @@ +model = new SystemUploadfile(); + } +} diff --git a/extend/base/admin/middleware/CsrfMiddlewareClass.php b/extend/base/admin/middleware/CsrfMiddlewareClass.php new file mode 100644 index 0000000..d396c37 --- /dev/null +++ b/extend/base/admin/middleware/CsrfMiddlewareClass.php @@ -0,0 +1,37 @@ +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); + } +} diff --git a/extend/base/admin/middleware/SystemLogClass.php b/extend/base/admin/middleware/SystemLogClass.php new file mode 100644 index 0000000..3457d21 --- /dev/null +++ b/extend/base/admin/middleware/SystemLogClass.php @@ -0,0 +1,56 @@ +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); + } +} diff --git a/extend/base/admin/model/DebugLogClass.php b/extend/base/admin/model/DebugLogClass.php new file mode 100644 index 0000000..709dcec --- /dev/null +++ b/extend/base/admin/model/DebugLogClass.php @@ -0,0 +1,12 @@ +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; + } +} diff --git a/extend/base/admin/model/MallTagClass.php b/extend/base/admin/model/MallTagClass.php new file mode 100644 index 0000000..fb31902 --- /dev/null +++ b/extend/base/admin/model/MallTagClass.php @@ -0,0 +1,12 @@ + 'info', + 'field' => 'id', + ], + ]; + + public function getAuthList() + { + $list = (new SystemAuth()) + ->where('status', 1) + ->column('title', 'id'); + + return $list; + } +} diff --git a/extend/base/admin/model/SystemAuthClass.php b/extend/base/admin/model/SystemAuthClass.php new file mode 100644 index 0000000..b485d7d --- /dev/null +++ b/extend/base/admin/model/SystemAuthClass.php @@ -0,0 +1,54 @@ +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; + } +} diff --git a/extend/base/admin/model/SystemAuthNodeClass.php b/extend/base/admin/model/SystemAuthNodeClass.php new file mode 100644 index 0000000..9b9e66b --- /dev/null +++ b/extend/base/admin/model/SystemAuthNodeClass.php @@ -0,0 +1,12 @@ +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; + } +} diff --git a/extend/base/admin/model/SystemNodeClass.php b/extend/base/admin/model/SystemNodeClass.php new file mode 100644 index 0000000..48376c5 --- /dev/null +++ b/extend/base/admin/model/SystemNodeClass.php @@ -0,0 +1,37 @@ +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; + } +} diff --git a/extend/base/admin/model/SystemQuickClass.php b/extend/base/admin/model/SystemQuickClass.php new file mode 100644 index 0000000..742fd3e --- /dev/null +++ b/extend/base/admin/model/SystemQuickClass.php @@ -0,0 +1,16 @@ + 'welcome_list', + ], + ]; +} diff --git a/extend/base/admin/model/SystemUploadfileClass.php b/extend/base/admin/model/SystemUploadfileClass.php new file mode 100644 index 0000000..59fb54f --- /dev/null +++ b/extend/base/admin/model/SystemUploadfileClass.php @@ -0,0 +1,9 @@ +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'; + } +} diff --git a/extend/base/admin/service/NodeServiceClass.php b/extend/base/admin/service/NodeServiceClass.php new file mode 100644 index 0000000..275ac8f --- /dev/null +++ b/extend/base/admin/service/NodeServiceClass.php @@ -0,0 +1,25 @@ +getNodelist(); + + return $nodeList; + } +} diff --git a/extend/base/admin/service/TriggerServiceClass.php b/extend/base/admin/service/TriggerServiceClass.php new file mode 100644 index 0000000..fc56794 --- /dev/null +++ b/extend/base/admin/service/TriggerServiceClass.php @@ -0,0 +1,51 @@ +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; + } +} diff --git a/extend/base/admin/service/annotation/ControllerAnnotationClass.php b/extend/base/admin/service/annotation/ControllerAnnotationClass.php new file mode 100644 index 0000000..d574ee5 --- /dev/null +++ b/extend/base/admin/service/annotation/ControllerAnnotationClass.php @@ -0,0 +1,47 @@ +tablePrefix = config('database.connections.mysql.prefix'); + $this->dbName = config('database.connections.mysql.database'); + $this->dir = __DIR__; + $this->rootDir = root_path(); + + return $this; + } + + public function getTableColumns() + { + return $this->tableColumns; + } + + public function setRootDir($dir) + { + $this->rootDir = $dir; + + return $this; + } + + /** + * 设置主表. + * @param $table + * @return $this + * @throws TableException + */ + public function setTable($table) + { + $this->table = $table; + try { + // 获取表列注释 + $colums = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$this->table}"); + + foreach ($colums as $vo) { + $colum = [ + 'type' => $vo['Type'], + 'comment' => !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'], + 'required' => $vo['Null'] == 'NO' ? true : false, + 'default' => $vo['Default'], + 'field' => $vo['Field'], + ]; + + // 格式化列数据 + $this->buildColum($colum); + + $this->tableColumns[$vo['Field']] = $colum; + + if ($vo['Field'] == 'delete_time') { + $this->delete = true; + } + } + + // 获取表名注释 + $tableSchema = Db::query("SELECT table_name,table_comment FROM information_schema.TABLES WHERE table_schema = 'ulthon_admin' AND table_name = '{$this->tablePrefix}{$this->table}'"); + $this->tableComment = (isset($tableSchema[0]['table_comment']) && !empty($tableSchema[0]['table_comment'])) ? $tableSchema[0]['table_comment'] : $this->table; + } catch (\Exception $e) { + throw new TableException($e->getMessage()); + } + + $this->controllerFilename = $this->getTableControllerName($this->table); + + // 初始化默认模型名 + $this->modelFilename = Str::studly($this->table); + + // 主表模型命名 + $modelArray = explode($this->DS, $this->modelFilename); + + $this->modelName = array_pop($modelArray); + + $this->buildViewJsUrl(); + + // 构建数据 + $this->buildStructure(); + + return $this; + } + + public function getTableControllerName($table) + { + $controllerFilename = ''; + // 初始化默认控制器名 + $nodeArray = explode('_', $table); + if (count($nodeArray) == 1) { + $controllerFilename = ucfirst($nodeArray[0]); + } else { + foreach ($nodeArray as $k => $v) { + if ($k == 0) { + $controllerFilename = "{$v}{$this->DS}"; + } else { + $controllerFilename .= ucfirst($v); + } + } + } + + return $controllerFilename; + } + + /** + * 设置关联表. + * @param $relationTable + * @param $foreignKey + * @param null $primaryKey + * @param null $modelFilename + * @param array $onlyShowFileds + * @param null $bindSelectField + * @return $this + * @throws TableException + */ + public function setRelation($relationTable, $foreignKey, $primaryKey = null, $modelFilename = null, $onlyShowFileds = [], $bindSelectField = null) + { + if (!isset($this->tableColumns[$foreignKey])) { + throw new TableException("主表不存在外键字段:{$foreignKey}"); + } + if (!empty($modelFilename)) { + $modelFilename = str_replace('/', $this->DS, $modelFilename); + } + try { + $colums = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$relationTable}"); + $formatColums = []; + $delete = false; + if (!empty($bindSelectField) && !in_array($bindSelectField, array_column($colums, 'Field'))) { + throw new TableException("关联表{$relationTable}不存在该字段: {$bindSelectField}"); + } + foreach ($colums as $vo) { + if (empty($primaryKey) && $vo['Key'] == 'PRI') { + $primaryKey = $vo['Field']; + } + if (!empty($onlyShowFileds) && !in_array($vo['Field'], $onlyShowFileds)) { + continue; + } + $colum = [ + 'type' => $vo['Type'], + 'comment' => $vo['Comment'], + 'default' => $vo['Default'], + 'field' => $vo['Field'], + ]; + + $this->buildColum($colum); + + $formatColums[$vo['Field']] = $colum; + if ($vo['Field'] == 'delete_time') { + $delete = true; + } + } + + $modelFilename = empty($modelFilename) ? Str::studly($relationTable) : $modelFilename; + $modelArray = explode($this->DS, $modelFilename); + $modelName = array_pop($modelArray); + + $relation = [ + 'modelFilename' => $modelFilename, + 'modelName' => $modelName, + 'foreignKey' => $foreignKey, + 'primaryKey' => $primaryKey, + 'bindSelectField' => $bindSelectField, + 'delete' => $delete, + 'tableColumns' => $formatColums, + ]; + if (!empty($bindSelectField)) { + $relationArray = explode('\\', $modelFilename); + $this->tableColumns[$foreignKey]['bindSelectField'] = $bindSelectField; + $this->tableColumns[$foreignKey]['bindRelation'] = end($relationArray); + } + $this->relationArray[$relationTable] = $relation; + $this->selectFileds[] = $foreignKey; + } catch (\Exception $e) { + throw new TableException($e->getMessage()); + } + + return $this; + } + + /** + * 设置控制器名. + * @param $controllerFilename + * @return $this + */ + public function setControllerFilename($controllerFilename) + { + $this->controllerFilename = str_replace('/', $this->DS, $controllerFilename); + $this->buildViewJsUrl(); + + return $this; + } + + /** + * 设置模型名. + * @param $modelFilename + * @return $this + */ + public function setModelFilename($modelFilename) + { + $this->modelFilename = str_replace('/', $this->DS, $modelFilename); + $this->buildViewJsUrl(); + + return $this; + } + + /** + * 设置显示字段. + * @param $fields + * @return $this + */ + public function setFields($fields) + { + $this->fields = $fields; + + return $this; + } + + /** + * 设置删除模式. + * @param $delete + * @return $this + */ + public function setDelete($delete) + { + $this->delete = $delete; + + return $this; + } + + /** + * 设置是否强制替换. + * @param $force + * @return $this + */ + public function setForce($force) + { + $this->force = $force; + + return $this; + } + + /** + * 设置复选框字段后缀 + * @param $array + * @return $this + */ + public function setCheckboxFieldSuffix($array) + { + $this->checkboxFieldSuffix = array_merge($this->checkboxFieldSuffix, $array); + + return $this; + } + + /** + * 设置单选框字段后缀 + * @param $array + * @return $this + */ + public function setRadioFieldSuffix($array) + { + $this->radioFieldSuffix = array_merge($this->radioFieldSuffix, $array); + + return $this; + } + + /** + * 设置单图片字段后缀 + * @param $array + * @return $this + */ + public function setImageFieldSuffix($array) + { + $this->imageFieldSuffix = array_merge($this->imageFieldSuffix, $array); + + return $this; + } + + /** + * 设置多图片字段后缀 + * @param $array + * @return $this + */ + public function setImagesFieldSuffix($array) + { + $this->imagesFieldSuffix = array_merge($this->imagesFieldSuffix, $array); + + return $this; + } + + /** + * 设置单文件字段后缀 + * @param $array + * @return $this + */ + public function setFileFieldSuffix($array) + { + $this->fileFieldSuffix = array_merge($this->fileFieldSuffix, $array); + + return $this; + } + + /** + * 设置多文件字段后缀 + * @param $array + * @return $this + */ + public function setFilesFieldSuffix($array) + { + $this->filesFieldSuffix = array_merge($this->filesFieldSuffix, $array); + + return $this; + } + + /** + * 设置时间字段后缀 + * @param $array + * @return $this + */ + public function setDateFieldSuffix($array) + { + $this->dateFieldSuffix = array_merge($this->dateFieldSuffix, $array); + + return $this; + } + + /** + * 设置开关字段. + * @param $array + * @return $this + */ + public function setSwitchFields($array) + { + $this->switchFields = array_merge($this->switchFields, $array); + + return $this; + } + + /** + * 设置下拉选择字段. + * @param $array + * @return $this + */ + public function setSelectFileds($array) + { + $this->selectFileds = array_merge($this->selectFileds, $array); + + return $this; + } + + /** + * 设置排序字段. + * @param $array + * @return $this + */ + public function setSortFields($array) + { + $this->sortFields = array_merge($this->sortFields, $array); + + return $this; + } + + /** + * 设置忽略字段. + * @param $array + * @return $this + */ + public function setIgnoreFields($array) + { + $this->ignoreFields = array_merge($this->ignoreFields, $array); + + return $this; + } + + /** + * 获取相关的文件. + * @return array + */ + public function getFileList() + { + return $this->fileList; + } + + /** + * 构建基础视图、JS、URL. + * @return $this + */ + protected function buildViewJsUrl() + { + $nodeArray = explode($this->DS, $this->controllerFilename); + $formatArray = []; + foreach ($nodeArray as $vo) { + $formatArray[] = Str::snake($vo); + } + $this->controllerUrl = implode('.', $formatArray); + $this->viewFilename = implode($this->DS, $formatArray); + $this->jsFilename = $this->viewFilename; + + // 控制器命名空间 + $namespaceArray = $nodeArray; + $this->controllerName = array_pop($namespaceArray); + $namespaceSuffix = implode('\\', $namespaceArray); + $this->controllerNamespace = empty($namespaceSuffix) ? "app\admin\controller" : "app\admin\controller\\{$namespaceSuffix}"; + + return $this; + } + + /** + * 构建字段. + * @return $this + */ + protected function buildStructure() + { + foreach ($this->tableColumns as $key => $val) { + // 排序 + if (in_array($key, ['sort'])) { + $this->sortFields[] = $key; + } + + // 富文本 + if (in_array($key, ['describe', 'content', 'details'])) { + $this->editorFields[] = $key; + } + } + + return $this; + } + + /** + * 构建必填. + * @param $require + * @return string + */ + protected function buildRequiredHtml($require) + { + return $require ? 'lay-verify="required"' : ''; + } + + /** + * 构建初始化字段信息. + * @param $colum + * @return mixed + */ + protected function buildColum(&$colum) + { + $string = $colum['comment']; + + // 处理定义类型 + preg_match('/{[\s\S]*?}/i', $string, $formTypeMatch); + if (!empty($formTypeMatch) && isset($formTypeMatch[0])) { + $colum['comment'] = str_replace($formTypeMatch[0], '', $colum['comment']); + $formType = trim(str_replace('}', '', str_replace('{', '', $formTypeMatch[0]))); + if (in_array($formType, $this->formTypeArray)) { + $colum['formType'] = $formType; + } + } + + // 处理默认定义 + preg_match('/\([\s\S]*?\)/i', $string, $defineMatch); + if (!empty($formTypeMatch) && isset($defineMatch[0])) { + $colum['comment'] = str_replace($defineMatch[0], '', $colum['comment']); + if (isset($colum['formType']) && in_array($colum['formType'], ['images', 'files', 'select', 'switch', 'radio', 'checkbox', 'date', 'relation', 'table', 'city'])) { + $define = str_replace(')', '', str_replace('(', '', $defineMatch[0])); + if (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox', 'relation', 'table', 'city'])) { + $formatDefine = []; + $explodeArray = explode(',', $define); + foreach ($explodeArray as $vo) { + $voExplodeArray = explode(':', $vo); + if (count($voExplodeArray) == 2) { + $formatDefine[trim($voExplodeArray[0])] = trim($voExplodeArray[1]); + } + } + !empty($formatDefine) && $colum['define'] = $formatDefine; + } else { + $colum['define'] = $define; + } + } + } + + $colum['comment'] = trim($colum['comment']); + + $colum['property_type'] = $this->fieldTypeToVarType($colum['type']); + + $colum['property_name'] = $colum['field']; + + $colum['data_list'] = ''; + + if (isset($colum['formType'])) { + if ($colum['formType'] == 'relation') { + $relation_model_name = '\\app\\admin\\model\\' . Str::studly($colum['define']['table']); + $colum['property_type'] = $relation_model_name; + $colum['property_name'] = Str::camel($colum['define']['table']); + } elseif (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox'])) { + $data_list = ''; + + foreach ($colum['define'] as $define_key => $define_value) { + $data_list .= $define_key . ':' . $define_value . ','; + } + $data_list = substr($data_list, 0, -1); + $colum['data_list'] = $data_list; + } + } + + return $colum; + } + + /** + * 构建下拉控制器. + * @param $field + * @return mixed + */ + protected function buildSelectController($field) + { + $name = $this->getFieldConstentName($field); + $var_name = $this->getFieldVarName($field); + + $selectCode = $this->replaceTemplate( + $this->getTemplate("controller{$this->DS}select"), + [ + 'name' => $name, + 'var_name' => $var_name, + ] + ); + + return $selectCode; + } + + /** + * 构架下拉模型. + * @param $field + * @param $array + * @return mixed + */ + protected function buildSelectModel($field, $array) + { + $name = $this->getFieldConstentName($field); + + $values = '['; + foreach ($array as $k => $v) { + $values .= "'{$k}'=>'{$v}',"; + } + $values .= ']'; + $selectCode = $this->replaceTemplate( + $this->getTemplate("model{$this->DS}select"), + [ + 'name' => $name, + 'values' => $values, + ] + ); + + return $selectCode; + } + + /** + * 构建下拉框视图. + * @param $field + * @param string $select + * @return mixed + */ + protected function buildOptionView($field, $select = '') + { + $name = $this->getFieldVarName($field); + $optionCode = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}module{$this->DS}option"), + [ + 'name' => $name, + 'select' => $select, + ] + ); + + return $optionCode; + } + + protected function buildCityView($field, $options, $value) + { + $default_define = [ + 'comment' => $options['comment'], + 'field' => $field, + 'required' => $this->buildRequiredHtml($options['required']), + 'value' => $value, + 'level' => '', + ]; + + $define = array_merge($default_define, $options['define']); + + $formatTargetList = []; + $formatTargetList['name'] = 1; + $formatTargetList['code'] = 1; + $formatTargetList['name-province'] = 1; + $formatTargetList['name-city'] = 1; + $formatTargetList['name-district'] = 1; + $formatTargetList['code-province'] = 1; + $formatTargetList['code-city'] = 1; + $formatTargetList['code-district'] = 1; + + $submit_field_content = ''; + + foreach ($formatTargetList as $key => $value) { + if (isset($define[$key])) { + $submit_field_content .= 'data-field-' . $key . '="' . $define[$key] . '" '; + } + } + + $define['submit_field_content'] = $submit_field_content; + + $city_main_code = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}module{$this->DS}cityMain"), + $define + ); + + return $city_main_code; + } + + /** + * 构建表格选择器视图. + * @param $field + * @param string $select + * @return mixed + */ + protected function buildTableView($field, $options, $value) + { + $default_define = [ + 'table' => '', + // 必填 + 'type' => 'checkbox', + 'valueField' => 'id', + 'fieldName' => 'title', + // 必填 + 'comment' => $options['comment'], + 'field' => $field, + 'required' => $options['required'], + 'value' => $value, + ]; + + $define = array_merge($default_define, $options['define']); + + $table_controller_name = $this->getTableControllerName($define['table']); + + $nodeArray = explode($this->DS, $table_controller_name); + $formatArray = []; + foreach ($nodeArray as $vo) { + $formatArray[] = Str::snake($vo); + } + $controller_url = implode('.', $formatArray); + + $define['controller_url'] = $controller_url; + + $table_main_code = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}module{$this->DS}tableMain"), + $define + ); + + return $table_main_code; + } + + /** + * 构建单选框视图. + * @param $field + * @param string $select + * @return mixed + */ + protected function buildRadioView($field, $select = '') + { + $name = $this->getFieldVarName($field); + $optionCode = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}module{$this->DS}radioInput"), + [ + 'field' => $field, + 'name' => $name, + 'select' => $select, + ] + ); + + return $optionCode; + } + + /** + * 构建多选框视图. + * @param $field + * @param string $select + * @return mixed + */ + protected function buildCheckboxView($field, $select = '') + { + $name = $this->getFieldVarName($field); + $optionCode = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}module{$this->DS}checkboxInput"), + [ + 'field' => $field, + 'name' => $name, + 'select' => $select, + ] + ); + + return $optionCode; + } + + /** + * 初始化. + * @return $this + */ + public function render() + { + // 初始化数据 + $this->renderData(); + + // 控制器 + $this->renderController(); + + // 模型 + $this->renderModel(); + + // 视图 + $this->renderView(); + + // JS + $this->renderJs(); + + return $this; + } + + /** + * 初始化数据. + * @return $this + */ + protected function renderData() + { + // 主表 + foreach ($this->tableColumns as $field => $val) { + // 过滤字段 + if (in_array($field, $this->ignoreFields)) { + unset($this->tableColumns[$field]); + continue; + } + + // 判断是否已初始化 + if (isset($this->tableColumns[$field]['formType'])) { + continue; + } + + // 判断图片 + if ($this->checkContain($field, $this->imageFieldSuffix)) { + $this->tableColumns[$field]['formType'] = 'image'; + continue; + } + if ($this->checkContain($field, $this->imagesFieldSuffix)) { + $this->tableColumns[$field]['formType'] = 'images'; + continue; + } + + // 判断文件 + if ($this->checkContain($field, $this->fileFieldSuffix)) { + $this->tableColumns[$field]['formType'] = 'file'; + continue; + } + if ($this->checkContain($field, $this->filesFieldSuffix)) { + $this->tableColumns[$field]['formType'] = 'files'; + continue; + } + + // 判断时间 + if ($this->checkContain($field, $this->dateFieldSuffix)) { + $this->tableColumns[$field]['formType'] = 'date'; + continue; + } + + // 判断开关 + if (in_array($field, $this->switchFields)) { + $this->tableColumns[$field]['formType'] = 'switch'; + continue; + } + + // 判断富文本 + if (in_array($field, $this->editorFields)) { + $this->tableColumns[$field]['formType'] = 'editor'; + continue; + } + + // 判断排序 + if (in_array($field, $this->sortFields)) { + $this->tableColumns[$field]['formType'] = 'sort'; + continue; + } + + // 判断下拉选择 + if (in_array($field, $this->selectFileds)) { + $this->tableColumns[$field]['formType'] = 'select'; + continue; + } + + $this->tableColumns[$field]['formType'] = 'text'; + } + + // 关联表 + foreach ($this->relationArray as $table => $tableVal) { + foreach ($tableVal['tableColumns'] as $field => $val) { + // 过滤字段 + if (in_array($field, $this->ignoreFields)) { + unset($this->relationArray[$table]['tableColumns'][$field]); + continue; + } + + // 判断是否已初始化 + if (isset($this->relationArray[$table]['tableColumns'][$field]['formType'])) { + continue; + } + + // 判断图片 + if ($this->checkContain($field, $this->imageFieldSuffix)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'image'; + continue; + } + if ($this->checkContain($field, $this->imagesFieldSuffix)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'images'; + continue; + } + + // 判断文件 + if ($this->checkContain($field, $this->fileFieldSuffix)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'file'; + continue; + } + if ($this->checkContain($field, $this->filesFieldSuffix)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'files'; + continue; + } + + // 判断时间 + if ($this->checkContain($field, $this->dateFieldSuffix)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'date'; + continue; + } + + // 判断开关 + if (in_array($field, $this->switchFields)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'switch'; + continue; + } + + // 判断富文本 + if (in_array($field, $this->editorFields)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'editor'; + continue; + } + + // 判断排序 + if (in_array($field, $this->sortFields)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'sort'; + continue; + } + + // 判断下拉选择 + if (in_array($field, $this->selectFileds)) { + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'select'; + continue; + } + + $this->relationArray[$table]['tableColumns'][$field]['formType'] = 'text'; + } + } + + return $this; + } + + /** + * 初始化控制器. + * @return $this + */ + protected function renderController() + { + $controllerFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}controller{$this->DS}{$this->controllerFilename}.php"; + if (empty($this->relationArray)) { + $controllerIndexMethod = ''; + $controllerExportMethod = ''; + } else { + $relationCode = ''; + $relation_table = []; + + foreach ($this->relationArray as $key => $val) { + $relation = Str::camel($key); + $relation_table[] = $relation; + } + $relationCode = "->withJoin(['" . implode('\',\'', $relation_table) . "'], 'LEFT')\r"; + $controllerIndexMethod = $this->replaceTemplate( + $this->getTemplate("controller{$this->DS}indexMethod"), + [ + 'relationIndexMethod' => $relationCode, + ] + ); + $controllerExportMethod = $this->replaceTemplate( + $this->getTemplate("controller{$this->DS}exportMethod"), + [ + 'relationIndexMethod' => trim($relationCode), + ] + ); + } + $selectList = ''; + + foreach ($this->tableColumns as $field => $val) { + if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) { + $selectList .= $this->buildSelectController($field); + } + } + + $modelFilenameExtend = str_replace($this->DS, '\\', $this->modelFilename); + + $controllerValue = $this->replaceTemplate( + $this->getTemplate("controller{$this->DS}controller"), + [ + 'controllerName' => $this->controllerName, + 'controllerNamespace' => $this->controllerNamespace, + 'controllerAnnotation' => $this->tableComment, + 'modelFilename' => "\app\admin\model\\{$modelFilenameExtend}", + 'indexMethod' => $controllerIndexMethod, + 'exportMethod' => $controllerExportMethod, + 'selectList' => $selectList, + ] + ); + $this->fileList[$controllerFile] = $controllerValue; + + return $this; + } + + /** + * 初始化模型. + * @return $this + */ + protected function renderModel() + { + // 主表模型 + $modelFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}model{$this->DS}{$this->modelFilename}.php"; + if (empty($this->relationArray)) { + $relationList = ''; + } else { + $relationList = ''; + foreach ($this->relationArray as $key => $val) { + $relation = Str::camel($key); + $relationCode = $this->replaceTemplate( + $this->getTemplate("model{$this->DS}relation"), + [ + 'relationMethod' => $relation, + 'relationModel' => "\app\admin\model\\{$val['modelFilename']}", + 'foreignKey' => $val['foreignKey'], + 'primaryKey' => $val['primaryKey'], + ] + ); + $relationList .= $relationCode; + } + } + + $selectList = ''; + + $doc_content = ''; + + foreach ($this->tableColumns as $field => $val) { + if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) { + $selectList .= $this->buildSelectModel($field, $val['define']); + } + $doc_content .= " * @property {$val['property_type']} \${$val['property_name']} {$val['comment']} {$val['data_list']}\n"; + } + + $doc_content = substr($doc_content, 0, -1); + + $extendNamespaceArray = explode($this->DS, $this->modelFilename); + $extendNamespace = null; + if (count($extendNamespaceArray) > 1) { + array_pop($extendNamespaceArray); + $extendNamespace = '\\' . implode('\\', $extendNamespaceArray); + } + + $modelValue = $this->replaceTemplate( + $this->getTemplate("model{$this->DS}model"), + [ + 'modelName' => $this->modelName, + 'modelNamespace' => "app\admin\model{$extendNamespace}", + 'table' => $this->table, + 'deleteTime' => $this->delete ? '"delete_time"' : 'false', + 'relationList' => $relationList, + 'selectList' => $selectList, + 'doc_content' => $doc_content, + ] + ); + $this->fileList[$modelFile] = $modelValue; + + // 关联模型 + foreach ($this->relationArray as $key => $val) { + $relationModelFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}model{$this->DS}{$val['modelFilename']}.php"; + + // todo 判断关联模型文件是否存在, 存在就不重新生成文件, 防止关联模型文件被覆盖 + $relationModelClass = "\\app\\admin\\model\\{$val['modelFilename']}"; + if (class_exists($relationModelClass) && method_exists(new $relationModelClass, 'getName')) { + $tableName = (new $relationModelClass)->getName(); + if (Str::snake($tableName) == Str::snake($key)) { + continue; + } + } + + $extendNamespaceArray = explode($this->DS, $val['modelFilename']); + $extendNamespace = null; + if (count($extendNamespaceArray) > 1) { + array_pop($extendNamespaceArray); + $extendNamespace = '\\' . implode('\\', $extendNamespaceArray); + } + + $relationModelValue = $this->replaceTemplate( + $this->getTemplate("model{$this->DS}model"), + [ + 'modelName' => $val['modelName'], + 'modelNamespace' => "app\admin\model{$extendNamespace}", + 'table' => $key, + 'deleteTime' => $val['delete'] ? '"delete_time"' : 'false', + 'relationList' => '', + 'selectList' => '', + ] + ); + $this->fileList[$relationModelFile] = $relationModelValue; + } + + return $this; + } + + /** + * 初始化视图. + * @return $this + */ + protected function renderView() + { + // 列表页面 + $viewIndexFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}index.html"; + $viewIndexValue = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}index"), + [ + 'controllerUrl' => $this->controllerUrl, + ] + ); + $this->fileList[$viewIndexFile] = $viewIndexValue; + + // 添加页面 + $viewAddFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}add.html"; + $addFormList = ''; + foreach ($this->tableColumns as $field => $val) { + if (in_array($field, ['id', 'create_time'])) { + continue; + } + + $templateFile = "view{$this->DS}module{$this->DS}input"; + $define = ''; + + // 根据formType去获取具体模板 + if ($val['formType'] == 'image') { + $templateFile = "view{$this->DS}module{$this->DS}image"; + } elseif ($val['formType'] == 'images') { + $templateFile = "view{$this->DS}module{$this->DS}images"; + $define = isset($val['define']) ? $val['define'] : '|'; + } elseif ($val['formType'] == 'file') { + $templateFile = "view{$this->DS}module{$this->DS}file"; + } elseif ($val['formType'] == 'files') { + $templateFile = "view{$this->DS}module{$this->DS}files"; + $define = isset($val['define']) ? $val['define'] : '|'; + } elseif ($val['formType'] == 'editor') { + $templateFile = "view{$this->DS}module{$this->DS}editor"; + } elseif ($val['formType'] == 'date') { + $templateFile = "view{$this->DS}module{$this->DS}date"; + if (isset($val['define']) && !empty($val['define'])) { + $define = $val['define']; + } else { + $define = 'datetime'; + } + if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) { + $define = 'datetime'; + } + } elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') { + $templateFile = "view{$this->DS}module{$this->DS}radio"; + if (isset($val['define']) && !empty($val['define'])) { + $define = $this->buildRadioView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}'); + } + } elseif ($val['formType'] == 'checkbox') { + $templateFile = "view{$this->DS}module{$this->DS}checkbox"; + if (isset($val['define']) && !empty($val['define'])) { + $define = $this->buildCheckboxView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}'); + } + } elseif ($val['formType'] == 'select') { + $templateFile = "view{$this->DS}module{$this->DS}select"; + if (isset($val['bindRelation'])) { + // TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理 + $define = $this->buildOptionView($val['bindRelation']); + } elseif (isset($val['define']) && !empty($val['define'])) { + $define = $this->buildOptionView($field); + } + } elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') { + $templateFile = "view{$this->DS}module{$this->DS}textarea"; + } elseif ($val['formType'] == 'relation') { + $val['define']['type'] = 'radio'; + $val['define']['valueField'] = 'id'; + $val['define']['fieldName'] = $val['define']['relationBindSelect']; + + $templateFile = "view{$this->DS}module{$this->DS}table"; + + $define = $this->buildTableView($field, $val, $val['default']); + } elseif ($val['formType'] == 'table') { + $templateFile = "view{$this->DS}module{$this->DS}table"; + $define = $this->buildTableView($field, $val, $val['default']); + } elseif ($val['formType'] == 'city') { + $templateFile = "view{$this->DS}module{$this->DS}city"; + $define = $this->buildCityView($field, $val, $val['default']); + } elseif ($val['formType'] == 'tag') { + $templateFile = "view{$this->DS}module{$this->DS}tag"; + } + + $addFormList .= $this->replaceTemplate( + $this->getTemplate($templateFile), + [ + 'comment' => $val['comment'], + 'field' => $field, + 'required' => $this->buildRequiredHtml($val['required']), + 'required_text' => $val['required'] ? '1' : '', + 'value' => $val['default'], + 'define' => $define, + ] + ); + } + $viewAddValue = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}form"), + [ + 'formList' => $addFormList, + ] + ); + $this->fileList[$viewAddFile] = $viewAddValue; + + // 编辑页面 + $viewEditFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}edit.html"; + $editFormList = ''; + foreach ($this->tableColumns as $field => $val) { + if (in_array($field, ['id', 'create_time'])) { + continue; + } + + $templateFile = "view{$this->DS}module{$this->DS}input"; + + $define = ''; + $value = '{$row.' . $field . '|default=\'\'}'; + + // 根据formType去获取具体模板 + if ($val['formType'] == 'image') { + $templateFile = "view{$this->DS}module{$this->DS}image"; + } elseif ($val['formType'] == 'images') { + $templateFile = "view{$this->DS}module{$this->DS}images"; + } elseif ($val['formType'] == 'file') { + $templateFile = "view{$this->DS}module{$this->DS}file"; + } elseif ($val['formType'] == 'files') { + $templateFile = "view{$this->DS}module{$this->DS}files"; + } elseif ($val['formType'] == 'editor') { + $templateFile = "view{$this->DS}module{$this->DS}editor"; + $value = '{$row.' . $field . '|raw|default=\'\'}'; + } elseif ($val['formType'] == 'date') { + $templateFile = "view{$this->DS}module{$this->DS}date"; + if (isset($val['define']) && !empty($val['define'])) { + $define = $val['define']; + } else { + $define = 'datetime'; + } + if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) { + $define = 'datetime'; + } + } elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') { + $templateFile = "view{$this->DS}module{$this->DS}radio"; + if (isset($val['define']) && !empty($val['define'])) { + $define = $this->buildRadioView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}'); + } + } elseif ($val['formType'] == 'checkbox') { + $templateFile = "view{$this->DS}module{$this->DS}checkbox"; + if (isset($val['define']) && !empty($val['define'])) { + $define = $this->buildCheckboxView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}'); + } + } elseif ($val['formType'] == 'select') { + $templateFile = "view{$this->DS}module{$this->DS}select"; + if (isset($val['bindRelation'])) { + // TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理 + $define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}'); + } elseif (isset($val['define']) && !empty($val['define'])) { + $define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}'); + } + } elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') { + $templateFile = "view{$this->DS}module{$this->DS}textarea"; + $value = '{$row.' . $field . '|raw|default=\'\'}'; + } elseif ($val['formType'] == 'relation') { + $val['define']['type'] = 'radio'; + $val['define']['valueField'] = 'id'; + $val['define']['fieldName'] = $val['define']['relationBindSelect']; + + $templateFile = "view{$this->DS}module{$this->DS}table"; + + $define = $this->buildTableView($field, $val, $value); + } elseif ($val['formType'] == 'table') { + $templateFile = "view{$this->DS}module{$this->DS}table"; + $define = $this->buildTableView($field, $val, $value); + } elseif ($val['formType'] == 'city') { + $templateFile = "view{$this->DS}module{$this->DS}city"; + $define = $this->buildCityView($field, $val, $value); + } elseif ($val['formType'] == 'tag') { + $templateFile = "view{$this->DS}module{$this->DS}tag"; + } + + $editFormList .= $this->replaceTemplate( + $this->getTemplate($templateFile), + [ + 'comment' => $val['comment'], + 'field' => $field, + 'required' => $this->buildRequiredHtml($val['required']), + 'required_text' => $val['required'] ? '1' : '', + 'value' => $value, + 'define' => $define, + ] + ); + } + $viewEditValue = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}form"), + [ + 'formList' => $editFormList, + ] + ); + $this->fileList[$viewEditFile] = $viewEditValue; + + return $this; + } + + /** + * 初始化JS. + * @return $this + */ + protected function renderJs() + { + $index_js_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}index.js"; + + $indexCols = " {type: 'checkbox'},\r"; + + // 主表字段 + foreach ($this->tableColumns as $field => $val) { + $var_name = $this->getFieldVarName($field); + + if ($val['formType'] == 'image') { + $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.image}"; + } elseif ($val['formType'] == 'images') { + continue; + } elseif ($val['formType'] == 'file') { + $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.url}"; + } elseif ($val['formType'] == 'files') { + continue; + } elseif ($val['formType'] == 'editor') { + continue; + } elseif ($val['formType'] == 'table') { + continue; + } elseif (in_array($field, $this->switchFields)) { + if (isset($val['define']) && !empty($val['define'])) { + $templateValue = "{field: '{$field}', search: 'select', selectList: ua.getDataBrage('{$var_name}'), title: '{$val['comment']}', templet: ua.table.switch}"; + } else { + $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.switch}"; + } + } elseif (in_array($val['formType'], ['select', 'checkbox', 'radio', 'switch'])) { + if (isset($val['define']) && !empty($val['define'])) { + $templateValue = "{field: '{$field}', search: 'select', selectList: ua.getDataBrage('{$var_name}'), title: '{$val['comment']}'}"; + } else { + $templateValue = "{field: '{$field}', title: '{$val['comment']}'}"; + } + } elseif (in_array($field, ['remark'])) { + $templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ua.table.text}"; + } elseif (in_array($field, $this->sortFields)) { + $templateValue = "{field: '{$field}', title: '{$val['comment']}', edit: 'text'}"; + } else { + $templateValue = "{field: '{$field}', title: '{$val['comment']}'}"; + } + + $indexCols .= $this->formatColsRow("{$templateValue},\r"); + } + + // 关联表 + foreach ($this->relationArray as $table => $tableVal) { + $table = Str::camel($table); + foreach ($tableVal['tableColumns'] as $field => $val) { + if ($val['formType'] == 'image') { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.image}"; + } elseif ($val['formType'] == 'images') { + continue; + } elseif ($val['formType'] == 'file') { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.url}"; + } elseif ($val['formType'] == 'files') { + continue; + } elseif ($val['formType'] == 'editor') { + continue; + } elseif ($val['formType'] == 'table') { + continue; + } elseif ($val['formType'] == 'select') { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}"; + } elseif (in_array($field, ['remark'])) { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.text}"; + } elseif (in_array($field, $this->switchFields)) { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ua.table.switch}"; + } elseif (in_array($field, $this->sortFields)) { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', edit: 'text'}"; + } else { + $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}"; + } + + $indexCols .= $this->formatColsRow("{$templateValue},\r"); + } + } + + $indexCols .= $this->formatColsRow("{width: 250, title: '操作', templet: ua.table.tool , fixed:'right'},\r"); + + $js_index = $this->replaceTemplate( + $this->getTemplate("js{$this->DS}index"), + [ + 'indexCols' => $indexCols, + ] + ); + $this->fileList[$index_js_file] = $js_index; + + $js_common_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}_common.js"; + + $js_common = $this->replaceTemplate( + $this->getTemplate("js{$this->DS}_common"), + [ + 'controllerUrl' => $this->controllerUrl, + ] + ); + $this->fileList[$js_common_file] = $js_common; + + $js_add_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}add.js"; + $js_edit_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}edit.js"; + + $js_add = $this->replaceTemplate($this->getTemplate("js{$this->DS}add")); + $this->fileList[$js_add_file] = $js_add; + + $js_edit = $this->replaceTemplate($this->getTemplate("js{$this->DS}edit")); + $this->fileList[$js_edit_file] = $js_edit; + + return $this; + } + + /** + * 检测文件. + * @return $this + */ + protected function check() + { + // 是否强制性 + if ($this->force) { + return $this; + } + foreach ($this->fileList as $key => $val) { + if (is_file($key)) { + throw new FileException("文件已存在:{$key}"); + } + } + + return $this; + } + + /** + * 开始生成. + * @return array + */ + public function create() + { + $this->check(); + foreach ($this->fileList as $key => $val) { + // 判断文件夹是否存在,不存在就创建 + $fileArray = explode($this->DS, $key); + array_pop($fileArray); + $fileDir = implode($this->DS, $fileArray); + if (!is_dir($fileDir)) { + mkdir($fileDir, 0775, true); + } + + // 写入 + file_put_contents($key, $val); + } + + return array_keys($this->fileList); + } + + /** + * 开始删除. + * @return array + */ + public function delete() + { + $deleteFile = []; + foreach ($this->fileList as $key => $val) { + if (is_file($key)) { + unlink($key); + $deleteFile[] = $key; + } + } + + return $deleteFile; + } + + /** + * 检测字段后缀 + * @param $string + * @param $array + * @return bool + */ + protected function checkContain($string, $array) + { + foreach ($array as $vo) { + if (substr($string, 0, strlen($vo)) === $vo) { + return true; + } + } + + return false; + } + + /** + * 格式化表单行. + * @param $value + * @return string + */ + protected function formatColsRow($value) + { + return " {$value}"; + } + + /** + * 获取对应的模板信息. + * @param $name + * @return false|string + */ + protected function getTemplate($name) + { + return file_get_contents("{$this->dir}{$this->DS}templates{$this->DS}{$name}.code"); + } + + public function getFieldConstentName($field) + { + $field = Str::studly($field); + + $name = "SelectList{$field}"; + + $name = Str::snake($name); + + $name = Str::upper($name); + + return $name; + } + + public function getFieldVarName($field) + { + $field = Str::studly($field); + $name = "SelectList{$field}"; + $name = Str::snake($name); + + return $name; + } + + public function getFieldMethodName($field) + { + $field = Str::studly($field); + $name = "getList{$field}"; + + return $name; + } + + /** + * 模板值替换. + * @param $string + * @param $array + * @return mixed + */ + public function replaceTemplate($string, $array = []) + { + foreach ($array as $key => $val) { + $string = str_replace('{{' . $key . '}}', $val, $string); + } + + return $string; + } + + public function fieldTypeToVarType($type) + { + $type_prefix_map = [ + 'BIT' => 'bool', + 'TINYINT' => 'int', + 'BOOL' => 'bool', + 'BOOLEAN' => 'bool', + 'SMALLINT' => 'int', + 'MEDIUMINT' => 'int', + 'INT' => 'int', + 'INTEGER' => 'int', + 'BIGINT' => 'int', + 'FLOAT' => 'float|double', + 'DOUBLE' => 'float|double', + 'DECIMAL' => 'float|double', + 'DATE' => 'string', + 'DATETIME' => 'string', + 'TIMESTAMP' => 'int', + 'TIME' => 'string', + 'YEAR' => 'int', + 'CHAR' => 'string', + 'VARCHAR' => 'string', + 'BINARY' => 'string', + 'VARBINARY' => 'string', + 'TINYBLOB' => 'string', + 'BLOB' => 'string', + 'MEDIUMBLOB' => 'string', + 'LONGBLOB' => 'string', + 'TINYTEXT' => 'string', + 'TEXT' => 'string', + 'MEDIUMTEXT' => 'string', + 'LONGTEXT' => 'string', + 'ENUM' => 'string', + 'SET' => 'string', + 'JSON' => 'string', + ]; + + foreach ($type_prefix_map as $sql_type => $var_type) { + if (Str::startsWith(strtolower($type), strtolower($sql_type))) { + return $var_type; + } + } + + return 'mixed'; + } +} diff --git a/extend/base/admin/service/curd/exceptions/CurdExceptionClass.php b/extend/base/admin/service/curd/exceptions/CurdExceptionClass.php new file mode 100644 index 0000000..7e67d2a --- /dev/null +++ b/extend/base/admin/service/curd/exceptions/CurdExceptionClass.php @@ -0,0 +1,7 @@ +model = new {{modelFilename}}(); + {{selectList}} + } + + {{indexMethod}} + + + {{exportMethod}} +} \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/controller/exportMethod.code b/extend/base/admin/service/curd/templates/controller/exportMethod.code new file mode 100644 index 0000000..eef4c7a --- /dev/null +++ b/extend/base/admin/service/curd/templates/controller/exportMethod.code @@ -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); + } \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/controller/indexMethod.code b/extend/base/admin/service/curd/templates/controller/indexMethod.code new file mode 100644 index 0000000..d1a6724 --- /dev/null +++ b/extend/base/admin/service/curd/templates/controller/indexMethod.code @@ -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(); + } \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/controller/select.code b/extend/base/admin/service/curd/templates/controller/select.code new file mode 100644 index 0000000..ac7ddda --- /dev/null +++ b/extend/base/admin/service/curd/templates/controller/select.code @@ -0,0 +1,2 @@ + + $this->assign('{{var_name}}', $this->model::{{name}}, true); diff --git a/extend/base/admin/service/curd/templates/js/_common.code b/extend/base/admin/service/curd/templates/js/_common.code new file mode 100644 index 0000000..cf96015 --- /dev/null +++ b/extend/base/admin/service/curd/templates/js/_common.code @@ -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', +}; \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/js/add.code b/extend/base/admin/service/curd/templates/js/add.code new file mode 100644 index 0000000..4a445e0 --- /dev/null +++ b/extend/base/admin/service/curd/templates/js/add.code @@ -0,0 +1,3 @@ +$(function(){ + ua.listen(); +}) \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/js/edit.code b/extend/base/admin/service/curd/templates/js/edit.code new file mode 100644 index 0000000..4a445e0 --- /dev/null +++ b/extend/base/admin/service/curd/templates/js/edit.code @@ -0,0 +1,3 @@ +$(function(){ + ua.listen(); +}) \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/js/index.code b/extend/base/admin/service/curd/templates/js/index.code new file mode 100644 index 0000000..8f4cb8e --- /dev/null +++ b/extend/base/admin/service/curd/templates/js/index.code @@ -0,0 +1,10 @@ +$(function(){ + ua.table.render({ + init: init, + cols: [[ + {{indexCols}} + ]], + }); + + ua.listen(); +}) \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/model/model.code b/extend/base/admin/service/curd/templates/model/model.code new file mode 100644 index 0000000..31dd34c --- /dev/null +++ b/extend/base/admin/service/curd/templates/model/model.code @@ -0,0 +1,21 @@ +belongsTo('{{relationModel}}', '{{foreignKey}}', '{{primaryKey}}'); + } diff --git a/extend/base/admin/service/curd/templates/model/select.code b/extend/base/admin/service/curd/templates/model/select.code new file mode 100644 index 0000000..574ba95 --- /dev/null +++ b/extend/base/admin/service/curd/templates/model/select.code @@ -0,0 +1,2 @@ + + public const {{name}} = {{values}}; diff --git a/extend/base/admin/service/curd/templates/view/form.code b/extend/base/admin/service/curd/templates/view/form.code new file mode 100644 index 0000000..9e92c33 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/form.code @@ -0,0 +1,11 @@ +
+
+ {{formList}} +
+
+ + +
+ +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/index.code b/extend/base/admin/service/curd/templates/view/index.code new file mode 100644 index 0000000..5d171c0 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/index.code @@ -0,0 +1,13 @@ +
+
+ +
+
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/checkbox.code b/extend/base/admin/service/curd/templates/view/module/checkbox.code new file mode 100644 index 0000000..d9f1b1d --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/checkbox.code @@ -0,0 +1,7 @@ + +
+ +
+{{define}} +
+
diff --git a/extend/base/admin/service/curd/templates/view/module/checkboxInput.code b/extend/base/admin/service/curd/templates/view/module/checkboxInput.code new file mode 100644 index 0000000..3a3bddf --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/checkboxInput.code @@ -0,0 +1,3 @@ + {foreach ${{name}} as $k=>$v} + + {/foreach} \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/city.code b/extend/base/admin/service/curd/templates/view/module/city.code new file mode 100644 index 0000000..04df697 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/city.code @@ -0,0 +1,7 @@ + +
+ +
+ {{define}} +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/cityMain.code b/extend/base/admin/service/curd/templates/view/module/cityMain.code new file mode 100644 index 0000000..b118c2d --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/cityMain.code @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/date.code b/extend/base/admin/service/curd/templates/view/module/date.code new file mode 100644 index 0000000..8458b4b --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/date.code @@ -0,0 +1,7 @@ + +
+ +
+ +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/editor.code b/extend/base/admin/service/curd/templates/view/module/editor.code new file mode 100644 index 0000000..11380d0 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/editor.code @@ -0,0 +1,7 @@ + +
+ +
+ +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/file.code b/extend/base/admin/service/curd/templates/view/module/file.code new file mode 100644 index 0000000..a045801 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/file.code @@ -0,0 +1,11 @@ + +
+ +
+ + +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/files.code b/extend/base/admin/service/curd/templates/view/module/files.code new file mode 100644 index 0000000..f343dfe --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/files.code @@ -0,0 +1,11 @@ + +
+ +
+ + +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/image.code b/extend/base/admin/service/curd/templates/view/module/image.code new file mode 100644 index 0000000..f735437 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/image.code @@ -0,0 +1,11 @@ + +
+ +
+ + +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/images.code b/extend/base/admin/service/curd/templates/view/module/images.code new file mode 100644 index 0000000..4bd8de8 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/images.code @@ -0,0 +1,11 @@ + +
+ +
+ + +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/input.code b/extend/base/admin/service/curd/templates/view/module/input.code new file mode 100644 index 0000000..7656fcd --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/input.code @@ -0,0 +1,7 @@ + +
+ +
+ +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/option.code b/extend/base/admin/service/curd/templates/view/module/option.code new file mode 100644 index 0000000..7593045 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/option.code @@ -0,0 +1,4 @@ + + {foreach ${{name}} as $k=>$v} + + {/foreach} \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/radio.code b/extend/base/admin/service/curd/templates/view/module/radio.code new file mode 100644 index 0000000..d9f1b1d --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/radio.code @@ -0,0 +1,7 @@ + +
+ +
+{{define}} +
+
diff --git a/extend/base/admin/service/curd/templates/view/module/radioInput.code b/extend/base/admin/service/curd/templates/view/module/radioInput.code new file mode 100644 index 0000000..1a033ec --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/radioInput.code @@ -0,0 +1,3 @@ + {foreach ${{name}} as $k=>$v} + + {/foreach} \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/select.code b/extend/base/admin/service/curd/templates/view/module/select.code new file mode 100644 index 0000000..c638a79 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/select.code @@ -0,0 +1,9 @@ + +
+ +
+ +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/table.code b/extend/base/admin/service/curd/templates/view/module/table.code new file mode 100644 index 0000000..24ec507 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/table.code @@ -0,0 +1,7 @@ + +
+ +
+{{define}} +
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/tableMain.code b/extend/base/admin/service/curd/templates/view/module/tableMain.code new file mode 100644 index 0000000..3fdf4e0 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/tableMain.code @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/tag.code b/extend/base/admin/service/curd/templates/view/module/tag.code new file mode 100644 index 0000000..75938c8 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/tag.code @@ -0,0 +1,7 @@ + +
+ +
+
+
+
\ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/module/textarea.code b/extend/base/admin/service/curd/templates/view/module/textarea.code new file mode 100644 index 0000000..c7bc984 --- /dev/null +++ b/extend/base/admin/service/curd/templates/view/module/textarea.code @@ -0,0 +1,7 @@ + +
+ +
+ +
+
\ No newline at end of file diff --git a/extend/base/admin/service/initAdminData/MallCate.php b/extend/base/admin/service/initAdminData/MallCate.php new file mode 100644 index 0000000..389f965 --- /dev/null +++ b/extend/base/admin/service/initAdminData/MallCate.php @@ -0,0 +1,12 @@ + "手机", + "image" => "http://admin.demo.ulthon.com/upload/20220417/72ef1d769595627af51d76c612a789bf.png", + "sort" => 0, + "status" => 1, + "remark" => "", + ) +); + +return $ul_mall_cate; diff --git a/extend/base/admin/service/initAdminData/MallGoods.php b/extend/base/admin/service/initAdminData/MallGoods.php new file mode 100644 index 0000000..f6f74a0 --- /dev/null +++ b/extend/base/admin/service/initAdminData/MallGoods.php @@ -0,0 +1,34 @@ + "落地-风扇", + "logo" => "http://admin.demo.ulthon.com/upload/20220417/72ef1d769595627af51d76c612a789bf.png", + "images" => "http://admin.host/upload/20200514/95496713918290f6315ea3f87efa6bf2.jpg|http://admin.host/upload/20200514/ae29fa9cba4fc02defb7daed41cb2b13.jpg|http://admin.host/upload/20200514/f0a104d88ec7dc6fb42d2f87cbc71b76.jpg|http://admin.host/upload/20200514/3b88be4b1934690e5c1bd6b54b9ab5c8.jpg", + "describe" => "<p>76654757</p>\n\n<p><img alt="" src="http://admin.host/upload/20200515/198070421110fa01f2c2ac2f52481647.jpg" style="height:689px; width:790px" /></p>\n\n<p><img alt="" src="http://admin.host/upload/20200515/a07a742c15a78781e79f8a3317006c1d.jpg" style="height:877px; width:790px" /></p>\n", + "market_price" => 599.00, + "discount_price" => 368.00, + "sales" => 0, + "virtual_sales" => 594, + "stock" => 0, + "total_stock" => 0, + "sort" => 675, + "status" => 1, + "remark" => "", + ), + array( + "title" => "电脑", + "logo" => "http://admin.demo.ulthon.com/upload/20220417/72ef1d769595627af51d76c612a789bf.png", + "images" => "http://admin.host/upload/20200514/f0a104d88ec7dc6fb42d2f87cbc71b76.jpg", + "describe" => "<p>477</p>\n", + "market_price" => 0.00, + "discount_price" => 0.00, + "sales" => 0, + "virtual_sales" => 0, + "stock" => 115, + "total_stock" => 320, + "sort" => 0, + "status" => 1, + "remark" => "", + ) +); +return $ul_mall_goods; diff --git a/extend/base/admin/service/initAdminData/MallTag.php b/extend/base/admin/service/initAdminData/MallTag.php new file mode 100644 index 0000000..771971e --- /dev/null +++ b/extend/base/admin/service/initAdminData/MallTag.php @@ -0,0 +1,32 @@ + 1, + "title" => "便宜", + "create_time" => 1657347818, + "update_time" => 1657347818, + "delete_time" => 0 + ), + array( + "id" => 2, + "title" => "售后", + "create_time" => 1657347825, + "update_time" => 1657347825, + "delete_time" => 0 + ), + array( + "id" => 3, + "title" => "黑科技", + "create_time" => 1657347836, + "update_time" => 1657347836, + "delete_time" => 0 + ), + array( + "id" => 4, + "title" => "大厂", + "create_time" => 1657347850, + "update_time" => 1657347850, + "delete_time" => 0 + ) +); +return $ul_mall_tag; \ No newline at end of file diff --git a/extend/base/admin/service/initAdminData/SystemAuth.php b/extend/base/admin/service/initAdminData/SystemAuth.php new file mode 100644 index 0000000..cfb0567 --- /dev/null +++ b/extend/base/admin/service/initAdminData/SystemAuth.php @@ -0,0 +1,21 @@ + 1, + "title" => "管理员", + "sort" => 1, + "status" => 1, + "remark" => "测试管理员", + ), + array( + "id" => 6, + "title" => "游客权限", + "sort" => 0, + "status" => 1, + "remark" => "", + + ) +); + + +return $ul_system_auth; diff --git a/extend/base/admin/service/initAdminData/SystemAuthNode.php b/extend/base/admin/service/initAdminData/SystemAuthNode.php new file mode 100644 index 0000000..5e63e29 --- /dev/null +++ b/extend/base/admin/service/initAdminData/SystemAuthNode.php @@ -0,0 +1,5 @@ + "alisms_access_key_id", + "group" => "sms", + "value" => "填你的", + "remark" => "阿里大于公钥", + "sort" => 0, + ), + array( + "name" => "alisms_access_key_secret", + "group" => "sms", + "value" => "填你的", + "remark" => "阿里大鱼私钥", + "sort" => 0, + ), + array( + "name" => "upload_type", + "group" => "upload", + "value" => "local_public", + "remark" => "当前上传方式 local_public,alioss,qnoss,txoss)", + "sort" => 0, + ), + array( + "name" => "upload_allow_ext", + "group" => "upload", + "value" => "jpg,jpeg,png,gif,bmp,doc,docx,xls,xlsx,ppt,pptx,pdf,zip,rar,7z,txt,mp3,wma,wav,mid,m4a,mp4,avi,wmv,3gp,flv,webp,svg,ico", + "remark" => "允许上传的文件类型", + "sort" => 0, + ), + array( + "name" => "upload_allow_size", + "group" => "upload", + "value" => "1024000", + "remark" => "允许上传的大小", + "sort" => 0, + ), + array( + "name" => "upload_allow_mime", + "group" => "upload", + "value" => "image/gif,image/jpeg,video/x-msvideo,text/plain,image/png", + "remark" => "允许上传的文件mime", + "sort" => 0, + ), + array( + "name" => "upload_allow_type", + "group" => "upload", + "value" => "local_public,alioss,qnoss,txcos", + "remark" => "可用的上传文件方式", + "sort" => 0, + ), + array( + "name" => "alioss_access_key_id", + "group" => "upload", + "value" => "填你的", + "remark" => "阿里云oss公钥", + "sort" => 0, + ), + array( + "name" => "alioss_access_key_secret", + "group" => "upload", + "value" => "填你的", + "remark" => "阿里云oss私钥", + "sort" => 0, + ), + array( + "name" => "alioss_endpoint", + "group" => "upload", + "value" => "填你的", + "remark" => "阿里云oss数据中心", + "sort" => 0, + ), + array( + "name" => "alioss_bucket", + "group" => "upload", + "value" => "填你的", + "remark" => "阿里云oss空间名称", + "sort" => 0, + ), + array( + "name" => "alioss_domain", + "group" => "upload", + "value" => "填你的", + "remark" => "阿里云oss访问域名", + "sort" => 0, + ), + array( + "name" => "logo_title", + "group" => "site", + "value" => "ulthon_admin", + "remark" => "LOGO标题", + "sort" => 0, + ), + array( + "name" => "logo_image", + "group" => "site", + "value" => "/static/common/images/logo-2.png", + "remark" => "logo图片", + "sort" => 0, + ), + array( + "name" => "site_name", + "group" => "site", + "value" => "ulthon_admin后台系统", + "remark" => "站点名称", + "sort" => 0, + ), + array( + "name" => "site_ico", + "group" => "site", + "value" => "/favicon.ico", + "remark" => "浏览器图标", + "sort" => 0, + ), + array( + "name" => "site_copyright", + "group" => "site", + "value" => "填你的", + "remark" => "版权信息", + "sort" => 0, + ), + array( + "name" => "site_beian", + "group" => "site", + "value" => "填你的", + "remark" => "备案信息", + "sort" => 0, + ), + array( + "name" => "site_version", + "group" => "site", + "value" => "2.0.0", + "remark" => "版本信息", + "sort" => 0, + ), + array( + "name" => "sms_type", + "group" => "sms", + "value" => "alisms", + "remark" => "短信类型", + "sort" => 0, + ), + array( + "name" => "miniapp_appid", + "group" => "wechat", + "value" => "填你的", + "remark" => "小程序公钥", + "sort" => 0, + ), + array( + "name" => "miniapp_appsecret", + "group" => "wechat", + "value" => "填你的", + "remark" => "小程序私钥", + "sort" => 0, + ), + array( + "name" => "web_appid", + "group" => "wechat", + "value" => "填你的", + "remark" => "公众号公钥", + "sort" => 0, + ), + array( + "name" => "web_appsecret", + "group" => "wechat", + "value" => "填你的", + "remark" => "公众号私钥", + "sort" => 0, + ), + array( + "name" => "txcos_secret_id", + "group" => "upload", + "value" => "填你的", + "remark" => "腾讯云cos密钥", + "sort" => 0, + ), + array( + "name" => "txcos_secret_key", + "group" => "upload", + "value" => "填你的", + "remark" => "腾讯云cos私钥", + "sort" => 0, + ), + array( + "name" => "txcos_region", + "group" => "upload", + "value" => "填你的", + "remark" => "存储桶地域", + "sort" => 0, + ), + array( + "name" => "txcos_bucket", + "group" => "upload", + "value" => "填你的", + "remark" => "存储桶名称", + "sort" => 0, + ), + array( + "name" => "qnoss_access_key", + "group" => "upload", + "value" => "填你的", + "remark" => "访问密钥", + "sort" => 0, + ), + array( + "name" => "qnoss_secret_key", + "group" => "upload", + "value" => "填你的", + "remark" => "安全密钥", + "sort" => 0, + ), + array( + "name" => "qnoss_bucket", + "group" => "upload", + "value" => "填你的", + "remark" => "存储空间", + "sort" => 0, + ), + array( + "name" => "qnoss_domain", + "group" => "upload", + "value" => "填你的", + "remark" => "访问域名", + "sort" => 0, + ), + array( + "name" => "txcos_domain", + "group" => "upload", + "value" => "填你的", + "remark" => "访问域名", + "sort" => 0, + ), + array( + "name" => "txcos_appid", + "group" => "upload", + "value" => "填你的", + "remark" => "APPID", + "sort" => 0, + ), + array( + "name" => "file", + "group" => "site", + "value" => "", + "remark" => "", + "sort" => 0, + ), + array( + "name" => "site_domain", + "group" => "site", + "value" => "http://admin.demo.ulthon.com", + "remark" => "", + "sort" => 0, + ) +); +return $ul_system_config; diff --git a/extend/base/admin/service/initAdminData/SystemMenu.php b/extend/base/admin/service/initAdminData/SystemMenu.php new file mode 100644 index 0000000..44ea1a7 --- /dev/null +++ b/extend/base/admin/service/initAdminData/SystemMenu.php @@ -0,0 +1,160 @@ + 227, + "pid" => 99999999, + "title" => "后台首页", + "icon" => "fa fa-home", + "href" => "index/welcome", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 228, + "pid" => 0, + "title" => "系统管理", + "icon" => "fa fa-cog", + "href" => "", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 234, + "pid" => 228, + "title" => "菜单管理", + "icon" => "fa fa-tree", + "href" => "system.menu/index", + "params" => "", + "target" => "_self", + "sort" => 10, + "status" => 1, + ), + array( + "id" => 244, + "pid" => 228, + "title" => "管理员管理", + "icon" => "fa fa-user", + "href" => "system.admin/index", + "params" => "", + "target" => "_self", + "sort" => 12, + "status" => 1, + ), + array( + "id" => 245, + "pid" => 228, + "title" => "角色管理", + "icon" => "fa fa-bitbucket-square", + "href" => "system.auth/index", + "params" => "", + "target" => "_self", + "sort" => 11, + "status" => 1, + ), + array( + "id" => 246, + "pid" => 228, + "title" => "节点管理", + "icon" => "fa fa-list", + "href" => "system.node/index", + "params" => "", + "target" => "_self", + "sort" => 9, + "status" => 1, + ), + array( + "id" => 247, + "pid" => 228, + "title" => "配置管理", + "icon" => "fa fa-asterisk", + "href" => "system.config/index", + "params" => "", + "target" => "_self", + "sort" => 8, + "status" => 1, + ), + array( + "id" => 248, + "pid" => 228, + "title" => "上传管理", + "icon" => "fa fa-arrow-up", + "href" => "system.uploadfile/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 249, + "pid" => 0, + "title" => "商城管理", + "icon" => "fa fa-list", + "href" => "", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 250, + "pid" => 249, + "title" => "商品分类", + "icon" => "fa fa-calendar-check-o", + "href" => "mall.cate/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 251, + "pid" => 249, + "title" => "商品管理", + "icon" => "fa fa-list", + "href" => "mall.goods/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 252, + "pid" => 228, + "title" => "快捷入口", + "icon" => "fa fa-list", + "href" => "system.quick/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 253, + "pid" => 228, + "title" => "日志管理", + "icon" => "fa fa-connectdevelop", + "href" => "debug.log/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 254, + "pid" => 249, + "title" => "商品标签", + "icon" => "fa fa-connectdevelop", + "href" => "mall.tag/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), +); + + +return $ul_system_menu; diff --git a/extend/base/admin/service/initAdminData/SystemNode.php b/extend/base/admin/service/initAdminData/SystemNode.php new file mode 100644 index 0000000..00db427 --- /dev/null +++ b/extend/base/admin/service/initAdminData/SystemNode.php @@ -0,0 +1,726 @@ + 1, + "node" => "system.admin", + "title" => "管理员管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 2, + "node" => "system.admin/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 3, + "node" => "system.admin/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 4, + "node" => "system.admin/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 5, + "node" => "system.admin/password", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 6, + "node" => "system.admin/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 7, + "node" => "system.admin/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347263, + "update_time" => 1657347263 + ), + array( + "id" => 8, + "node" => "system.admin/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 9, + "node" => "system.auth", + "title" => "角色权限管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 10, + "node" => "system.auth/authorize", + "title" => "授权", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 11, + "node" => "system.auth/saveAuthorize", + "title" => "授权保存", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 12, + "node" => "system.auth/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 13, + "node" => "system.auth/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 14, + "node" => "system.auth/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347264, + "update_time" => 1657347264 + ), + array( + "id" => 15, + "node" => "system.auth/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 16, + "node" => "system.auth/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 17, + "node" => "system.auth/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 18, + "node" => "system.config", + "title" => "系统配置管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 19, + "node" => "system.config/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 20, + "node" => "system.config/save", + "title" => "保存", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 21, + "node" => "system.menu", + "title" => "菜单管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 22, + "node" => "system.menu/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347265, + "update_time" => 1657347265 + ), + array( + "id" => 23, + "node" => "system.menu/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 24, + "node" => "system.menu/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 25, + "node" => "system.menu/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 26, + "node" => "system.menu/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 27, + "node" => "system.menu/getMenuTips", + "title" => "添加菜单提示", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 28, + "node" => "system.menu/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 29, + "node" => "system.node", + "title" => "系统节点管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 30, + "node" => "system.node/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347266, + "update_time" => 1657347266 + ), + array( + "id" => 31, + "node" => "system.node/refreshNode", + "title" => "系统节点更新", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 32, + "node" => "system.node/clearNode", + "title" => "清除失效节点", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 33, + "node" => "system.node/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 34, + "node" => "system.node/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 35, + "node" => "system.node/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 36, + "node" => "system.node/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 37, + "node" => "system.node/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347267, + "update_time" => 1657347267 + ), + array( + "id" => 38, + "node" => "system.uploadfile", + "title" => "上传文件管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 39, + "node" => "system.uploadfile/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 40, + "node" => "system.uploadfile/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 41, + "node" => "system.uploadfile/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 42, + "node" => "system.uploadfile/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 43, + "node" => "system.uploadfile/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 44, + "node" => "system.uploadfile/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 45, + "node" => "mall.cate", + "title" => "商品分类管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347268, + "update_time" => 1657347268 + ), + array( + "id" => 46, + "node" => "mall.cate/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 47, + "node" => "mall.cate/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 48, + "node" => "mall.cate/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 49, + "node" => "mall.cate/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 50, + "node" => "mall.cate/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 51, + "node" => "mall.cate/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 52, + "node" => "mall.goods", + "title" => "商城商品管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347269, + "update_time" => 1657347269 + ), + array( + "id" => 53, + "node" => "mall.goods/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 54, + "node" => "mall.goods/stock", + "title" => "入库", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 55, + "node" => "mall.goods/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 56, + "node" => "mall.goods/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 57, + "node" => "mall.goods/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 58, + "node" => "mall.goods/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 59, + "node" => "mall.goods/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 60, + "node" => "system.quick", + "title" => "快捷入口管理", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347270, + "update_time" => 1657347270 + ), + array( + "id" => 61, + "node" => "system.quick/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 62, + "node" => "system.quick/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 63, + "node" => "system.quick/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 64, + "node" => "system.quick/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 65, + "node" => "system.quick/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 66, + "node" => "system.quick/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 69, + "node" => "debug.log", + "title" => "debug_log", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347271, + "update_time" => 1657347271 + ), + array( + "id" => 70, + "node" => "debug.log/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347272, + "update_time" => 1657347272 + ), + array( + "id" => 71, + "node" => "debug.log/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347272, + "update_time" => 1657347272 + ), + array( + "id" => 72, + "node" => "debug.log/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347272, + "update_time" => 1657347272 + ), + array( + "id" => 73, + "node" => "debug.log/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347272, + "update_time" => 1657347272 + ), + array( + "id" => 74, + "node" => "debug.log/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347272, + "update_time" => 1657347272 + ), + array( + "id" => 75, + "node" => "debug.log/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347272, + "update_time" => 1657347272 + ), + array( + "id" => 76, + "node" => "mall.tag", + "title" => "mall_tag", + "type" => 1, + "is_auth" => 1, + "create_time" => 1657347614, + "update_time" => 1657347614 + ), + array( + "id" => 77, + "node" => "mall.tag/index", + "title" => "列表", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347614, + "update_time" => 1657347614 + ), + array( + "id" => 78, + "node" => "mall.tag/add", + "title" => "添加", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347615, + "update_time" => 1657347615 + ), + array( + "id" => 79, + "node" => "mall.tag/edit", + "title" => "编辑", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347615, + "update_time" => 1657347615 + ), + array( + "id" => 80, + "node" => "mall.tag/delete", + "title" => "删除", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347615, + "update_time" => 1657347615 + ), + array( + "id" => 81, + "node" => "mall.tag/export", + "title" => "导出", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347615, + "update_time" => 1657347615 + ), + array( + "id" => 82, + "node" => "mall.tag/modify", + "title" => "属性修改", + "type" => 2, + "is_auth" => 1, + "create_time" => 1657347615, + "update_time" => 1657347615 + ) +); + + +return $ul_system_node; diff --git a/extend/base/admin/service/initAdminData/SystemQuick.php b/extend/base/admin/service/initAdminData/SystemQuick.php new file mode 100644 index 0000000..622493b --- /dev/null +++ b/extend/base/admin/service/initAdminData/SystemQuick.php @@ -0,0 +1,61 @@ + "管理员管理", + "icon" => "fa fa-user", + "href" => "system.admin/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "角色管理", + "icon" => "fa fa-bitbucket-square", + "href" => "system.auth/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "菜单管理", + "icon" => "fa fa-tree", + "href" => "system.menu/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "节点管理", + "icon" => "fa fa-list", + "href" => "system.node/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "配置管理", + "icon" => "fa fa-asterisk", + "href" => "system.config/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "上传管理", + "icon" => "fa fa-arrow-up", + "href" => "system.uploadfile/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "商品分类", + "icon" => "fa fa-calendar-check-o", + "href" => "mall.cate/index", + "sort" => 0, + "status" => 1, + ), + array( + "title" => "商品管理", + "icon" => "fa fa-list", + "href" => "mall.goods/index", + "sort" => 0, + "status" => 1, + ) +); + +return $ul_system_quick; diff --git a/extend/base/admin/service/node/NodeClass.php b/extend/base/admin/service/node/NodeClass.php new file mode 100644 index 0000000..8957850 --- /dev/null +++ b/extend/base/admin/service/node/NodeClass.php @@ -0,0 +1,174 @@ +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; + } +} diff --git a/extend/base/admin/traits/CurdTraitClass.php b/extend/base/admin/traits/CurdTraitClass.php new file mode 100644 index 0000000..e1d2fdd --- /dev/null +++ b/extend/base/admin/traits/CurdTraitClass.php @@ -0,0 +1,162 @@ +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('保存成功'); + } +} diff --git a/extend/trait/admin/controller/LoginTrait.php b/extend/trait/admin/controller/LoginTrait.php deleted file mode 100644 index 870b4dc..0000000 --- a/extend/trait/admin/controller/LoginTrait.php +++ /dev/null @@ -1,8 +0,0 @@ -