| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 | 
							- <?php
 
- // +----------------------------------------------------------------------
 
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
 
- // +----------------------------------------------------------------------
 
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
 
- // +----------------------------------------------------------------------
 
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 
- // +----------------------------------------------------------------------
 
- // | Author: 小夏 < 449134904@qq.com>
 
- // +----------------------------------------------------------------------
 
- namespace app\portal\controller;
 
- use cmf\controller\AdminBaseController;
 
- use app\portal\model\PortalPostModel;
 
- use app\portal\service\PostService;
 
- use app\portal\model\PortalCategoryModel;
 
- use think\Db;
 
- use app\admin\model\ThemeModel;
 
- class AdminArticleController extends AdminBaseController
 
- {
 
-     /**
 
-      * 文章列表
 
-      * @adminMenu(
 
-      *     'name'   => '文章管理',
 
-      *     'parent' => 'portal/AdminIndex/default',
 
-      *     'display'=> true,
 
-      *     'hasView'=> true,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '文章列表',
 
-      *     'param'  => ''
 
-      * )
 
-      * @return mixed
 
-      * @throws \think\db\exception\DataNotFoundException
 
-      * @throws \think\db\exception\ModelNotFoundException
 
-      * @throws \think\exception\DbException
 
-      */
 
-     public function index()
 
-     {
 
-         $content = hook_one('portal_admin_article_index_view');
 
-         if (!empty($content)) {
 
-             return $content;
 
-         }
 
-         $param = $this->request->param();
 
-         $categoryId = $this->request->param('category', 0, 'intval');
 
-         $postService = new PostService();
 
-         $data        = $postService->adminArticleList($param);
 
-         $data->appends($param);
 
-         $portalCategoryModel = new PortalCategoryModel();
 
-         $categoryTree        = $portalCategoryModel->adminCategoryTree($categoryId);
 
-         $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
 
-         $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
 
-         $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
 
-         $this->assign('articles', $data->items());
 
-         $this->assign('category_tree', $categoryTree);
 
-         $this->assign('category', $categoryId);
 
-         $this->assign('page', $data->render());
 
-         return $this->fetch();
 
-     }
 
-     /**
 
-      * 添加文章
 
-      * @adminMenu(
 
-      *     'name'   => '添加文章',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> true,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '添加文章',
 
-      *     'param'  => ''
 
-      * )
 
-      * @return mixed
 
-      * @throws \think\db\exception\DataNotFoundException
 
-      * @throws \think\db\exception\ModelNotFoundException
 
-      * @throws \think\exception\DbException
 
-      */
 
-     public function add()
 
-     {
 
-         $content = hook_one('portal_admin_article_add_view');
 
-         if (!empty($content)) {
 
-             return $content;
 
-         }
 
-         $themeModel        = new ThemeModel();
 
-         $articleThemeFiles = $themeModel->getActionThemeFiles('portal/Article/index');
 
-         $this->assign('article_theme_files', $articleThemeFiles);
 
-         return $this->fetch();
 
-     }
 
-     /**
 
-      * 添加文章提交
 
-      * @adminMenu(
 
-      *     'name'   => '添加文章提交',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '添加文章提交',
 
-      *     'param'  => ''
 
-      * )
 
-      */
 
-     public function addPost()
 
-     {
 
-         if ($this->request->isPost()) {
 
-             $data = $this->request->param();
 
-             //状态只能设置默认值。未发布、未置顶、未推荐
 
-             $data['post']['post_status'] = 1;
 
-             $data['post']['is_top']      = 0;
 
-             $data['post']['recommended'] = 0;
 
-             $post = $data['post'];
 
-             $result = $this->validate($post, 'AdminArticle');
 
-             if ($result !== true) {
 
-                 $this->error($result);
 
-             }
 
-             $portalPostModel = new PortalPostModel();
 
-             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->adminAddArticle($data['post'], $data['post']['categories']);
 
-             $data['post']['id'] = $portalPostModel->id;
 
-             $hookParam          = [
 
-                 'is_add'  => true,
 
-                 'article' => $data['post']
 
-             ];
 
-             hook('portal_admin_after_save_article', $hookParam);
 
-             $this->success('添加成功!', url('AdminArticle/edit', ['id' => $portalPostModel->id]));
 
-         }
 
-     }
 
-     /**
 
-      * 编辑文章
 
-      * @adminMenu(
 
-      *     'name'   => '编辑文章',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> true,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '编辑文章',
 
-      *     'param'  => ''
 
-      * )
 
-      * @return mixed
 
-      * @throws \think\db\exception\DataNotFoundException
 
-      * @throws \think\db\exception\ModelNotFoundException
 
-      * @throws \think\exception\DbException
 
-      */
 
-     public function edit()
 
-     {
 
-         $content = hook_one('portal_admin_article_edit_view');
 
-         if (!empty($content)) {
 
-             return $content;
 
-         }
 
-         $id = $this->request->param('id', 0, 'intval');
 
-         $portalPostModel = new PortalPostModel();
 
-         $post            = $portalPostModel->where('id', $id)->find();
 
-         $postCategories  = $post->categories()->alias('a')->column('a.name', 'a.id');
 
-         $postCategoryIds = implode(',', array_keys($postCategories));
 
-         $themeModel        = new ThemeModel();
 
-         $articleThemeFiles = $themeModel->getActionThemeFiles('portal/Article/index');
 
-         $this->assign('article_theme_files', $articleThemeFiles);
 
-         $this->assign('post', $post);
 
-         $this->assign('post_categories', $postCategories);
 
-         $this->assign('post_category_ids', $postCategoryIds);
 
-         return $this->fetch();
 
-     }
 
-     /**
 
-      * 编辑文章提交
 
-      * @adminMenu(
 
-      *     'name'   => '编辑文章提交',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '编辑文章提交',
 
-      *     'param'  => ''
 
-      * )
 
-      * @throws \think\Exception
 
-      */
 
-     public function editPost()
 
-     {
 
-         if ($this->request->isPost()) {
 
-             $data = $this->request->param();
 
-             //需要抹除发布、置顶、推荐的修改。
 
-             unset($data['post']['post_status']);
 
-             unset($data['post']['is_top']);
 
-             unset($data['post']['recommended']);
 
-             $post   = $data['post'];
 
-             $result = $this->validate($post, 'AdminArticle');
 
-             if ($result !== true) {
 
-                 $this->error($result);
 
-             }
 
-             $portalPostModel = new PortalPostModel();
 
-             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->adminEditArticle($data['post'], $data['post']['categories']);
 
-             $hookParam = [
 
-                 'is_add'  => false,
 
-                 'article' => $data['post']
 
-             ];
 
-             hook('portal_admin_after_save_article', $hookParam);
 
-             $this->success('保存成功!');
 
-         }
 
-     }
 
-     /**
 
-      * 文章删除
 
-      * @adminMenu(
 
-      *     'name'   => '文章删除',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '文章删除',
 
-      *     'param'  => ''
 
-      * )
 
-      * @throws \think\Exception
 
-      * @throws \think\db\exception\DataNotFoundException
 
-      * @throws \think\db\exception\ModelNotFoundException
 
-      * @throws \think\exception\DbException
 
-      * @throws \think\exception\PDOException
 
-      */
 
-     public function delete()
 
-     {
 
-         $param           = $this->request->param();
 
-         $portalPostModel = new PortalPostModel();
 
-         if (isset($param['id'])) {
 
-             $id           = $this->request->param('id', 0, 'intval');
 
-             $result       = $portalPostModel->where('id', $id)->find();
 
-             $data         = [
 
-                 'object_id'   => $result['id'],
 
-                 'create_time' => time(),
 
-                 'table_name'  => 'portal_post',
 
-                 'name'        => $result['post_title'],
 
-                 'user_id'     => cmf_get_current_admin_id()
 
-             ];
 
-             $resultPortal = $portalPostModel
 
-                 ->where('id', $id)
 
-                 ->update(['delete_time' => time()]);
 
-             if ($resultPortal) {
 
-                 Db::name('portal_category_post')->where('post_id', $id)->update(['status' => 0]);
 
-                 Db::name('portal_tag_post')->where('post_id', $id)->update(['status' => 0]);
 
-                 Db::name('recycleBin')->insert($data);
 
-             }
 
-             $this->success("删除成功!", '');
 
-         }
 
-         if (isset($param['ids'])) {
 
-             $ids     = $this->request->param('ids/a');
 
-             $recycle = $portalPostModel->where('id', 'in', $ids)->select();
 
-             $result  = $portalPostModel->where('id', 'in', $ids)->update(['delete_time' => time()]);
 
-             if ($result) {
 
-                 Db::name('portal_category_post')->where('post_id', 'in', $ids)->update(['status' => 0]);
 
-                 Db::name('portal_tag_post')->where('post_id', 'in', $ids)->update(['status' => 0]);
 
-                 foreach ($recycle as $value) {
 
-                     $data = [
 
-                         'object_id'   => $value['id'],
 
-                         'create_time' => time(),
 
-                         'table_name'  => 'portal_post',
 
-                         'name'        => $value['post_title'],
 
-                         'user_id'     => cmf_get_current_admin_id()
 
-                     ];
 
-                     Db::name('recycleBin')->insert($data);
 
-                 }
 
-                 $this->success("删除成功!", '');
 
-             }
 
-         }
 
-     }
 
-     /**
 
-      * 文章发布
 
-      * @adminMenu(
 
-      *     'name'   => '文章发布',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '文章发布',
 
-      *     'param'  => ''
 
-      * )
 
-      */
 
-     public function publish()
 
-     {
 
-         $param           = $this->request->param();
 
-         $portalPostModel = new PortalPostModel();
 
-         if (isset($param['ids']) && isset($param["yes"])) {
 
-             $ids = $this->request->param('ids/a');
 
-             $portalPostModel->where('id', 'in', $ids)->update(['post_status' => 1, 'published_time' => time()]);
 
-             $this->success("发布成功!", '');
 
-         }
 
-         if (isset($param['ids']) && isset($param["no"])) {
 
-             $ids = $this->request->param('ids/a');
 
-             $portalPostModel->where('id', 'in', $ids)->update(['post_status' => 0]);
 
-             $this->success("取消发布成功!", '');
 
-         }
 
-     }
 
-     /**
 
-      * 文章置顶
 
-      * @adminMenu(
 
-      *     'name'   => '文章置顶',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '文章置顶',
 
-      *     'param'  => ''
 
-      * )
 
-      */
 
-     public function top()
 
-     {
 
-         $param           = $this->request->param();
 
-         $portalPostModel = new PortalPostModel();
 
-         if (isset($param['ids']) && isset($param["yes"])) {
 
-             $ids = $this->request->param('ids/a');
 
-             $portalPostModel->where('id', 'in', $ids)->update(['is_top' => 1]);
 
-             $this->success("置顶成功!", '');
 
-         }
 
-         if (isset($_POST['ids']) && isset($param["no"])) {
 
-             $ids = $this->request->param('ids/a');
 
-             $portalPostModel->where('id', 'in', $ids)->update(['is_top' => 0]);
 
-             $this->success("取消置顶成功!", '');
 
-         }
 
-     }
 
-     /**
 
-      * 文章推荐
 
-      * @adminMenu(
 
-      *     'name'   => '文章推荐',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '文章推荐',
 
-      *     'param'  => ''
 
-      * )
 
-      */
 
-     public function recommend()
 
-     {
 
-         $param           = $this->request->param();
 
-         $portalPostModel = new PortalPostModel();
 
-         if (isset($param['ids']) && isset($param["yes"])) {
 
-             $ids = $this->request->param('ids/a');
 
-             $portalPostModel->where('id', 'in', $ids)->update(['recommended' => 1]);
 
-             $this->success("推荐成功!", '');
 
-         }
 
-         if (isset($param['ids']) && isset($param["no"])) {
 
-             $ids = $this->request->param('ids/a');
 
-             $portalPostModel->where('id', 'in', $ids)->update(['recommended' => 0]);
 
-             $this->success("取消推荐成功!", '');
 
-         }
 
-     }
 
-     /**
 
-      * 文章排序
 
-      * @adminMenu(
 
-      *     'name'   => '文章排序',
 
-      *     'parent' => 'index',
 
-      *     'display'=> false,
 
-      *     'hasView'=> false,
 
-      *     'order'  => 10000,
 
-      *     'icon'   => '',
 
-      *     'remark' => '文章排序',
 
-      *     'param'  => ''
 
-      * )
 
-      */
 
-     public function listOrder()
 
-     {
 
-         parent::listOrders(Db::name('portal_category_post'));
 
-         $this->success("排序更新成功!", '');
 
-     }
 
- }
 
 
  |