init: 项目初始代码
This commit is contained in:
135
app/api/controller/v1/News.php
Normal file
135
app/api/controller/v1/News.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\News as NewsModel;
|
||||
use app\api\validate\News as NewsValidate;
|
||||
|
||||
/**
|
||||
* 文章新闻模块
|
||||
* Class News
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class News extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new NewsValidate();
|
||||
$this->model = new NewsModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
|
||||
if (isset($inputData['News_type_id']) && $inputData['News_type_id'] != '' && $inputData['News_type_id'] != 0) {
|
||||
$this->focus['News_type_id'] = $inputData['News_type_id'];
|
||||
}
|
||||
|
||||
if (isset($inputData['title']) && $inputData['title'] != '') {
|
||||
$this->simple['title'] = $inputData['title'];
|
||||
}
|
||||
|
||||
$this->order['create_time'] = 'desc';
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$detail = $this->request->param('detail','','htmlspecialchars');
|
||||
$inputData = $this->request->param();
|
||||
$inputData['detail'] = $detail;
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
||||
} else {
|
||||
unset($inputData['create_time']);
|
||||
}
|
||||
unset($inputData['update_time']);
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user