123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-02-17
- // +—————————————————————————————————————————————————————————————————————
- namespace app\portal\controller;
- use app\admin\model\RouteModel;
- use cmf\controller\AdminBaseController;
- use app\portal\model\PortalPostModel;
- use app\portal\service\PostService;
- use app\admin\model\ThemeModel;
- use think\Db;
- class AdminPageController extends AdminBaseController
- {
- /**
- * 页面管理
- * @adminMenu(
- * 'name' => '页面管理',
- * 'parent' => 'portal/AdminIndex/default',
- * 'display'=> true,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '页面管理',
- * 'param' => ''
- * )
- */
- public function index()
- {
- $content = hook_one('portal_admin_page_index_view');
- if (!empty($content)) {
- return $content;
- }
- $param = $this->request->param();
- $postService = new PostService();
- $data = $postService->adminPageList($param);
- $data->appends($param);
- $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
- $this->assign('pages', $data->items());
- $this->assign('page', $data->render());
- return $this->fetch();
- }
-
- //排序
- public function listOrder() {
-
- $model = DB::name('portal_post');
- parent::listOrders($model);
-
-
-
- $this->success("排序更新成功!");
- }
- /**
- * 添加页面
- * @adminMenu(
- * 'name' => '添加页面',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '添加页面',
- * 'param' => ''
- * )
- */
- public function add()
- {
- $content = hook_one('portal_admin_page_add_view');
- if (!empty($content)) {
- return $content;
- }
- $themeModel = new ThemeModel();
- $pageThemeFiles = $themeModel->getActionThemeFiles('portal/Page/index');
- $this->assign('page_theme_files', $pageThemeFiles);
- return $this->fetch();
- }
- /**
- * 添加页面提交
- * @adminMenu(
- * 'name' => '添加页面提交',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '添加页面提交',
- * 'param' => ''
- * )
- */
- public function addPost()
- {
- $data = $this->request->param();
- $result = $this->validate($data['post'], 'AdminPage');
- if ($result !== true) {
- $this->error($result);
- }
- if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
- $data['post']['more']['photos'] = [];
- foreach ($data['photo_urls'] as $key => $url) {
- $photoUrl = cmf_asset_relative_url($url);
- array_push($data['post']['more']['photos'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
- }
- }
- if (!empty($data['file_names']) && !empty($data['file_urls'])) {
- $data['post']['more']['files'] = [];
- foreach ($data['file_urls'] as $key => $url) {
- $fileUrl = cmf_asset_relative_url($url);
- array_push($data['post']['more']['files'], ["url" => $fileUrl, "name" => $data['file_names'][$key]]);
- }
- }
- $portalPostModel = new PortalPostModel();
- $portalPostModel->adminAddPage($data['post']);
-
-
-
- $this->success(lang('ADD_SUCCESS'), url('AdminPage/edit', ['id' => $portalPostModel->id]));
-
-
- }
- /**
- * 编辑页面
- * @adminMenu(
- * 'name' => '编辑页面',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '编辑页面',
- * 'param' => ''
- * )
- */
- public function edit()
- {
- $content = hook_one('portal_admin_page_edit_view');
- if (!empty($content)) {
- return $content;
- }
- $id = $this->request->param('id', 0, 'intval');
- $portalPostModel = new PortalPostModel();
- $post = $portalPostModel->where('id', $id)->find();
- $themeModel = new ThemeModel();
- $pageThemeFiles = $themeModel->getActionThemeFiles('portal/Page/index');
- $routeModel = new RouteModel();
- $alias = $routeModel->getUrl('portal/Page/index', ['id' => $id]);
- $post['post_alias'] = $alias;
- $this->assign('page_theme_files', $pageThemeFiles);
- $this->assign('post', $post);
- return $this->fetch();
- }
- /**
- * 编辑页面提交
- * @adminMenu(
- * 'name' => '编辑页面提交',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '编辑页面提交',
- * 'param' => ''
- * )
- */
- public function editPost()
- {
- $data = $this->request->param();
- $result = $this->validate($data['post'], 'AdminPage');
- if ($result !== true) {
- $this->error($result);
- }
- if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
- $data['post']['more']['photos'] = [];
- foreach ($data['photo_urls'] as $key => $url) {
- $photoUrl = cmf_asset_relative_url($url);
- array_push($data['post']['more']['photos'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
- }
- }
- if (!empty($data['file_names']) && !empty($data['file_urls'])) {
- $data['post']['more']['files'] = [];
- foreach ($data['file_urls'] as $key => $url) {
- $fileUrl = cmf_asset_relative_url($url);
- array_push($data['post']['more']['files'], ["url" => $fileUrl, "name" => $data['file_names'][$key]]);
- }
- }
- $portalPostModel = new PortalPostModel();
- $portalPostModel->adminEditPage($data['post']);
-
- $this->success(lang('SAVE_SUCCESS'));
- }
- /**
- * 删除页面
- * @author iyting@foxmail.com
- * @adminMenu(
- * 'name' => '删除页面',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '删除页面',
- * 'param' => ''
- * )
- */
- public function delete()
- {
- $portalPostModel = new PortalPostModel();
- $data = $this->request->param();
-
- $result = $portalPostModel->adminDeletePage($data);
- if ($result) {
-
-
- $this->success(lang('DELETE_SUCCESS'));
- } else {
- $this->error(lang('DELETE_FAILED'));
- }
- }
- }
|