@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\model\ContentCategoryModel;
|
||||
use app\common\model\ContentModel;
|
||||
use app\common\model\NoticeModel;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 公告
|
||||
* Class Notice
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Notice extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
/**
|
||||
* 公告列表
|
||||
* @param NoticeModel $noticeModel
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index(NoticeModel $noticeModel)
|
||||
{
|
||||
$page = $this->request->get('page/d', 1);
|
||||
$key = $this->request->get('key', '');
|
||||
$type = $this->request->get('type', 1);
|
||||
|
||||
$result = $noticeModel->getLists([
|
||||
'search' => [
|
||||
'title' => $key,
|
||||
'type' => $type
|
||||
],
|
||||
], 10, $page, [
|
||||
'id',
|
||||
'title',
|
||||
'cover',
|
||||
'desc',
|
||||
'views'
|
||||
]);
|
||||
|
||||
$this->success('获取成功', [
|
||||
'total' => $result['total'],
|
||||
'pageSize' => $result['pageSize'],
|
||||
'totalSize' => $result['totalSize'],
|
||||
'list' => $result['list'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公告详情
|
||||
* @param NoticeModel $noticeModel
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function detail(NoticeModel $noticeModel)
|
||||
{
|
||||
$id = $this->request->get('id/d');
|
||||
|
||||
if (empty($id)) {
|
||||
$this->success('参数错误', [], 501);
|
||||
}
|
||||
|
||||
$detail = $noticeModel->getItem($id, [
|
||||
'id',
|
||||
'title',
|
||||
'views',
|
||||
'content',
|
||||
'create_time',
|
||||
'status'
|
||||
]);
|
||||
|
||||
if (empty($detail)) {
|
||||
$this->success('内容不存在', [], 502);
|
||||
}
|
||||
if ($detail->status == 2) {
|
||||
$this->success('内容以下架', [], 502);
|
||||
}
|
||||
|
||||
// 浏览量+1
|
||||
$detail->views += 1;
|
||||
$noticeModel->where(['id' => $id])->setInc('views');
|
||||
|
||||
$detail->create_time = date('Y-m-d H:i:s', $detail->create_time);
|
||||
|
||||
$this->success('获取成功', [
|
||||
'detail' => $detail
|
||||
]);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户