Files
2020-08-06 15:26:41 +08:00

114 lines
3.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\system\controller;
use app\common\model\Direct as DirectModel;
use app\common\service\Direct as DirectService;
use think\Request;
class Direct extends _Init
{
/**
* 文章列表
* @param string $title 要搜索的文章标题
* @return [type] [description]
*/
public function index($type = '', $title = '')
{
$map['status'] = ['egt', 0];
if (!empty($type)) {
$map['type'] = $type;
}
if (!empty($title)) {
$map['title'] = ['like', "%$title%"];
}
$this->list = DirectModel::where($map)->order("sort asc,create_time desc")->paginate();
return $this->fetch();
}
/**
* 添加文章
* @param Request $Request 数据集
*/
public function add(Request $Request)
{
if (IS_POST) {
$data = $Request->post();
$result = DirectService::create($data);
return $this->back($result);
} else {
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 = DirectService::edit($data);
return $this->back($result);
} else {
$this->info = DirectModel::get($id);
return $this->fetch('add');
}
}
/**
* 删除文章
* @param [type] $id 文章id
* @return [type] [description]
*/
public function del($id)
{
$result = DirectService::del($id);
return $this->back($result);
}
/**
* 修改文章状态
* @param [type] $id 文章id
* @param [type] $status 状态
* @return [type] 修改文章结果
*/
public function status($id, $status)
{
$result = DirectService::status($id, $status);
return $this->back($result);
}
public function upload($type = '')
{
if (!in_array($type, ['image', 'file', 'video', 'audio'])) {
$result = ['code' => 0, 'msg' => '不支持的上传类型'];
} else {
$file = request()->file($type);
dump($file);die();
// $result = StorageService::upload($type);
}
if (is_array($result) && !empty($result)) {
$ret = [
'code' => 1,
'data' => $result,
];
} else {
$ret = [
'code' => 0,
'msg' => $result,
];
}
return Response::create($ret, 'json');
}
}