87 lines
2.5 KiB
PHP
87 lines
2.5 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
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 = '')
|
||
{
|
||
$map['status'] = ['egt', 0];
|
||
if (!empty($title)) {
|
||
$map['title'] = ['like', "%$title%"];
|
||
}
|
||
$this->list = ArticleModel::where($map)->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);
|
||
}
|
||
}
|