141 lines
4.4 KiB
PHP
Raw Permalink Normal View History

2025-05-20 16:33:23 +08:00
<?php
namespace app\api\controller\home;
use app\common\model\home\News as NewsModel;
use app\common\model\home\NewsCate;
/**
* 新闻接口
*/
class News extends Base
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @var \app\common\model\home\News
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new NewsModel;
}
/**
* @ApiTitle( 新闻列表)
* @ApiSummary(新闻列表)
* @ApiMethod(GET)
* @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
* @ApiParams(name = "page", type = "string",required=true,description = "页数")
* @ApiParams(name = "limit", type = "string",required=true,description = "条数")
* @ApiParams(name = "recommend", type = "string",required=false,description = "置顶:0=否,1=是")
* @ApiParams(name = "cate_id", type = "int",required=false,description = "新闻类目id")
* @ApiParams(name = "hot", type = "string",required=false,description = "热门:0=否,1=是")
* @ApiParams(name = "fine", type = "string",required=false,description = "精选:0=否,1=是")
2025-05-20 16:33:23 +08:00
* @ApiReturn({
*
*})
*/
public function index()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
2025-05-23 18:34:56 +08:00
$page = $this->request->param('page/d', 0); //页数
$limit = $this->request->param('limit/d', 0); //条数
$keywords = $this->request->param('keywords/s', ''); //搜索关键字
$recommend = $this->request->param('recommend/s', ''); //搜索关键字
$params =[];
2025-05-23 18:34:56 +08:00
$cate_id = $this->request->param('cate_id/s', ''); //搜索关键字
$params["flag"] = $this->request->param('flag/s', ''); //搜索关键字
$params["hot"] = $this->request->param('hot/s', ''); //搜索关键字
$params["fine"] = $this->request->param('fine/s', ''); //搜索关键字
2025-05-20 16:33:23 +08:00
// $type = $this->request->get('type/s', ''); //筛选学员和教练单
try{
//当前申请状态
$res = $this->model::allList($page, $limit,$keywords,$recommend,$cate_id,$params);
2025-05-20 16:33:23 +08:00
// var_dump($this->model->getLastSql());
}catch (\Exception $e){
$this->error($e->getMessage());
}
$this->success('查询成功', $res);
}
/**
* @ApiTitle( 新闻分类)
* @ApiSummary(新闻分类)
* @ApiMethod(GET)
* @ApiParams(name = "page", type = "string",required=true,description = "页数")
* @ApiParams(name = "limit", type = "string",required=true,description = "条数")
* @ApiParams(name = "hot", type = "string",required=false,description = "热门:0=否,1=是")
* @ApiParams(name = "home", type = "string",required=false,description = "首页:0=否,1=是")
* @ApiParams(name = "flag", type = "string",required=false,description = "分类标识")
2025-05-20 16:33:23 +08:00
* @ApiReturn({
*
*})
*/
public function cate()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$params=[];
2025-05-23 18:34:56 +08:00
$page = $this->request->param('page/d', 0); //页数
$limit = $this->request->param('limit/d', 0); //条数
2025-05-20 16:33:23 +08:00
2025-05-23 18:34:56 +08:00
$params["flag"] = $this->request->param('flag/s', ''); //搜索关键字
$params["hot"] = $this->request->param('hot/s', ''); //搜索关键字
$params["home"] = $this->request->param('home/s', ''); //搜索关键字
2025-05-20 16:33:23 +08:00
try{
//当前申请状态
$res = NewsCate::allList($page, $limit,$params);
2025-05-20 16:33:23 +08:00
}catch (\Exception $e){
$this->error($e->getMessage());
}
$this->success('查询成功', $res);
}
/**
* 查看新闻详情
*
* @ApiMethod (GET)
* @ApiParams (name="id", type="string", required=true, description="ID")
*/
public function detail()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
2025-05-23 18:34:56 +08:00
$id = $this->request->param('id/d');
2025-05-20 16:33:23 +08:00
try{
$menulist = $this->model->detail($id,$show_field=[],$except_field=[],$user_id);
2025-05-20 16:33:23 +08:00
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$this->success('查询成功', $menulist);
}
}