123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?php
- /**
- * ArticleBasecontroller.php UTF-8
- * 资讯文章基类
- *
- * @date : 2018/5/8 14:44
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace cmf\controller;
- use cmf\view\Filter;
- use huo\logic\posts\PostsLogic;
- use huo\model\posts\PostsModel;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\constant\NewsConst;
- use huolib\status\CommonStatus;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use think\Exception;
- use think\exception\DbException;
- class ArticleBaseController extends AdminBaseController {
- protected $param = array();
- protected $id;
- public function _initialize() {
- $this->param = $this->request->param();
- }
- /***
- * 资讯类型选择器
- */
- protected function _post_types() {
- $post_types = [
- NewsConst::NEWS_TYPE_NEWS => lang('news'),
- NewsConst::NEWS_TYPE_STRATEGY => lang('activity'),
- NewsConst::NEWS_TYPE_ACTIVITY => lang('strategy'),
- NewsConst::NEWS_TYPE_NOTICE => lang('announcement'),
- NewsConst::NEWS_TYPE_AWARD => lang('awards'),
- ];
- $this->assign('post_types_data', $post_types);
- return $post_types;
- }
- /***
- * 是否允许评论
- */
- protected function _comment_status() {
- $comment_status = [
- NewsConst::NEWS_COMMENT_STATUS_NOT_ALLOW => lang('not allow'),
- NewsConst::NEWS_COMMENT_STATUS_ALLOW => lang('allow')
- ];
- $this->assign('comment_status_data', $comment_status);
- return $comment_status;
- }
- /***
- * 是否置顶
- */
- protected function _is_top() {
- $is_top = [
- NewsConst::NEWS_IS_NOT_TOP => lang('not top'),
- NewsConst::NEWS_IS_TOP => lang('top')
- ];
- $this->assign('is_top_data', $is_top);
- return $is_top;
- }
- /***
- * 是否推荐
- */
- protected function _recommended() {
- $recommended = [
- NewsConst::NEWS_IS_NOT_RECOMMEND => lang('not recommend'),
- NewsConst::NEWS_IS_RECOMMEND => lang('recommend')
- ];
- $this->assign('recommended_data', $recommended);
- return $recommended;
- }
- /**
- * 是否站外活动
- */
- protected function _active_type() {
- $_type = array(
- NewsConst::NEWS_STATION_ACTIVITY => lang('station_activity'),
- NewsConst::NEWS_STATION_OUT_ACTIVITY => lang('station_out_activity')
- );
- $this->assign('active_type_data', $_type);
- return $_type;
- }
- public function index() {
- $param = $this->param;
- /*搜索*/
- $_keyword_input = Filter::text('keyword', $this->request->param('keyword/s', ''), lang('keywords'));
- $this->assign('keyword_input', $_keyword_input);
- $_param['start_time'] = $this->request->param('start_time', date('Y-m-d', strtotime('-1 month')));
- $_param['end_time'] = $this->request->param('end_time', date('Y-m-d'));
- $this->_time($_param['start_time'], $_param['end_time']);
- $param['keyword'] = isset($param['keyword']) ? trim($param['keyword']) : '';
- try {
- $data = (new PostsLogic())->getListByAdmin($param);
- } catch (DbException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::DB_EXCEPTION));
- }
- $_post_type = isset($param['post_type']) ? $param['post_type'] : 0;
- $this->assign('pages', $data->items());
- $this->assign('page', $data->render());
- if (NewsConst::NEWS_TYPE_NOTICE != $_post_type && NewsConst::NEWS_TYPE_AWARD != $_post_type
- && NewsConst::NEWS_TYPE_AGENTNOTICE != $_post_type) {
- $_app_id = isset($param['app_id']) ? $param['app_id'] : 0;
- $this->assign('app_id', $_app_id);
- $this->_games($_app_id, GameConst::GAME_STATUS_ON, CommonConst::CONST_NOT_DELETE);
- }
- }
- public function add() {
- $_post_type = isset($this->param['post_type']) ? $this->param['post_type'] : 1;
- if (NewsConst::NEWS_TYPE_NOTICE != $_post_type && NewsConst::NEWS_TYPE_AWARD != $_post_type
- && NewsConst::NEWS_TYPE_AGENTNOTICE != $_post_type) {
- $this->_games(0, GameConst::GAME_STATUS_ON, CommonConst::CONST_NOT_DELETE);
- $_recommended = Filter::radioCommon($this->_recommended(), 'post[recommended]', 1);
- $this->assign('recommended', $_recommended);
- } elseif (NewsConst::NEWS_TYPE_AWARD == $_post_type) {
- $_type = Filter::radioCommon($this->_active_type(), 'post[active_type]', 1);
- $this->assign('active_type', $_type);
- }
- $_comment_status = Filter::radioCommon($this->_comment_status(), 'post[comment_status]', 1);
- $_is_top = Filter::radioCommon($this->_is_top(), 'post[is_top]', 2);
- $this->assign('comment_status', $_comment_status);
- $this->assign('is_top', $_is_top);
- $this->assign('post_type', $_post_type);
- }
- public function addPost() {
- $data = $this->param;
- $result = $this->validate($data['post'], 'AdminPage');
- if ($result !== true) {
- $this->adminError($result);
- }
- $data['post']['app_id'] = $this->request->param('app_id/d', 0);
- if (5 == $data['post']['post_type']) { //有奖类型
- if (1 == $data['post']['active_type']) {
- $data['post']['url'] = '';
- } else {
- $data['post']['cost_integral'] = 0;
- unset($data['post']['more']['pointer']);
- unset($data['post']['more']['turntable']);
- }
- }
- $PostModel = new PostsModel();
- $PostModel->adminAddPage($data['post']);
- }
- /**
- * 编辑页面
- */
- public function edit() {
- $id = $this->id;
- try {
- $post = (new PostsLogic())->getInfoById($id);
- } catch (DataNotFoundException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::DATA_NOT_FOUND_EXCEPTION));
- } catch (ModelNotFoundException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::MODEL_NOT_FOUND_EXCEPTION));
- } catch (DbException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::DB_EXCEPTION));
- } catch (Exception $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::EXCEPTION));
- }
- $this->assign('post', $post);
- $post['post_excerpt'];
- $_desc_list=explode("\n",$post['post_excerpt']);
- if (NewsConst::NEWS_TYPE_NOTICE != $post['post_type'] && NewsConst::NEWS_TYPE_AWARD != $post['post_type']
- && NewsConst::NEWS_TYPE_AGENTNOTICE != $post['post_type']) {
- $this->_games($post['app_id'], GameConst::GAME_STATUS_ON, CommonConst::CONST_NOT_DELETE);
- $_recommended = Filter::radioCommon($this->_recommended(), 'post[recommended]', $post['recommended']);
- $this->assign('recommended', $_recommended);
- } elseif (NewsConst::NEWS_TYPE_AWARD == $post['post_type']) {
- $_activity_type = NewsConst::NEWS_STATION_ACTIVITY;
- if ($post['url'] != '') {
- $_activity_type = NewsConst::NEWS_STATION_OUT_ACTIVITY;
- }
- $_type = Filter::radioCommon($this->_active_type(), 'post[active_type]', $_activity_type);
- $this->assign('active_type', $_type);
- }
- $_comment_status = Filter::radioCommon(
- $this->_comment_status(), 'post[comment_status]', $post['comment_status']
- );
- $_is_top = Filter::radioCommon($this->_is_top(), 'post[is_top]', $post['is_top']);
- $this->assign('comment_status', $_comment_status);
- $this->assign('is_top', $_is_top);
- }
- /**
- * 编辑页面提交
- */
- public function editPost() {
- $data = $this->param;
- $result = $this->validate($data['post'], 'AdminPage');
- if ($result !== true) {
- $this->adminError($result);
- }
- $data['post']['app_id'] = $this->request->param('app_id/d', 0);
- if (5 == $data['post']['post_type']) { //有奖类型
- if (1 == $data['post']['active_type']) {
- $data['post']['url'] = '';
- } else {
- $data['post']['cost_integral'] = 0;
- unset($data['post']['more']['pointer']);
- unset($data['post']['more']['turntable']);
- }
- }
- $PostModel = new PostsModel();
- $PostModel->adminEditPage($data['post']);
- }
- /**
- * 删除页面
- *
- * @author iyting@foxmail.com
- * @adminMenu(
- * 'name' => '删除页面',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '删除页面',
- * 'param' => ''
- * )
- */
- public function delete() {
- $PostModel = new PostsModel();
- $data = $this->param;
- try {
- $result = $PostModel->adminDeletePage($data);
- } catch (DataNotFoundException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::DATA_NOT_FOUND_EXCEPTION));
- } catch (ModelNotFoundException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::MODEL_NOT_FOUND_EXCEPTION));
- } catch (DbException $e) {
- return $this->adminError(CommonStatus::getMsg(CommonStatus::DB_EXCEPTION));
- }
- if ($result) {
- $this->adminSuccess(lang('DELETE_SUCCESS'));
- } else {
- $this->adminError(lang('DELETE_FAILED'));
- }
- }
- /**
- * 修改发布状态
- */
- public function setPostStatus() {
- $_param = $this->request->param();
- $_map['id'] = $_param['id'];
- $_data['post_status'] = $_param['status'];
- if (2 == $_data['post_status']) {
- $_data['published_time'] = time();
- }
- $_data['update_time'] = time();
- $PostModel = new PostsModel();
- $_res = $PostModel->useGlobalScope(false)->where($_map)->setField($_data);
- if (true == $_res) {
- $this->adminSuccess(lang('edit success'));
- } else {
- $this->adminError(lang('edit failure'));
- }
- }
- }
|