| // +------------------------------------------------+ namespace app\system\controller; use app\common\model\Article as ArticleModel; use app\common\service\Article as ArticleService; use think\Request; class Article extends _Init { /** * 文章列表 * @param string $title 要搜索的文章标题 * @return [type] [description] */ public function index($title = '', $model = '') { $map['status'] = ['egt', 0]; if (!empty($title)) { $map['title'] = ['like', "%$title%"]; } if ($model) { if ($model == 'article') { $map['uid'] = 0; } else { $map['uid'] = ['gt', 0]; } } $this->list = ArticleModel::where($map)->order('create_time desc')->paginate(); return $this->fetch(); } /** * 添加文章 * @param Request $Request 数据集 */ public function add(Request $Request) { if (IS_POST) { $data = $Request->post(); $result = ArticleService::create($data); return $this->back($result); } else { $this->list = ArticleService::categoryList(); return $this->fetch(); } } /** * 编辑文章 * @param Request $Request 数据集 * @param [type] $id 文章id * @return [type] 返回 编辑的结果 */ public function edit(Request $Request, $id) { if (IS_POST) { $data = $Request->post(); $result = ArticleService::edit($data); return $this->back($result); } else { $this->list = ArticleService::categoryList(); $this->info = ArticleModel::get($id); return $this->fetch('add'); } } /** * 删除文章 * @param [type] $id 文章id * @return [type] [description] */ public function del($id) { $result = ArticleService::del($id); return $this->back($result); } /** * 修改文章状态 * @param [type] $id 文章id * @param [type] $status 状态 * @return [type] 修改文章结果 */ public function status($id, $status) { $result = ArticleService::status($id, $status); return $this->back($result); } }