198 lines
6.0 KiB
PHP
198 lines
6.0 KiB
PHP
<?php
|
||
|
||
namespace app\adminapi\controller\home;
|
||
|
||
use app\common\controller\AdminApi;
|
||
use app\adminapi\model\home\NewsCate as NewsCateModel;
|
||
|
||
/**
|
||
* 新闻分类管理
|
||
*/
|
||
class NewsCate extends AdminApi
|
||
{
|
||
protected $model = null;
|
||
|
||
/**
|
||
* 初始化操作
|
||
* @access protected
|
||
*/
|
||
public function _initialize()
|
||
{
|
||
$this->model = new NewsCateModel;
|
||
parent::_initialize();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* @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 = "status", type = "string",required=true,description = "状态:1=上架,2=下架")
|
||
* @ApiParams(name = "hot", type = "string",required=false,description = "状态搜索条件:0=非热门分类,1=热门分类")
|
||
* @ApiReturn({
|
||
*
|
||
*})
|
||
*/
|
||
public function index()
|
||
{
|
||
$user_id = 0;
|
||
$user = $this->auth->getUser();//登录用户
|
||
if($user)$user_id = $user['id'];
|
||
$page = $this->request->get('page/d', 0); //页数
|
||
$limit = $this->request->get('limit/d', 0); //条数
|
||
$params = [];
|
||
|
||
$params["keywords"] = $this->request->get('keywords/s', ''); //搜索关键字
|
||
$params["status"] = $this->request->get('status/s', ''); //搜索关键字
|
||
$params["hot"] = $this->request->get('hot/s', ''); //搜索关键字
|
||
// $type = $this->request->get('type/s', ''); //筛选学员和教练单
|
||
|
||
try{
|
||
//当前申请状态
|
||
$res = $this->model::allList($page, $limit,$params);
|
||
// if($user_id =='670153'){
|
||
// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql());
|
||
// }
|
||
}catch (\Exception $e){
|
||
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success('查询成功', $res);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 查看新闻分类详情
|
||
*
|
||
* @ApiMethod (GET)
|
||
* @ApiParams (name="id", type="string", required=true, description="ID")
|
||
*/
|
||
public function detail()
|
||
{
|
||
$admin_id = $this->auth->id;
|
||
$id = $this->request->get('id/d');
|
||
|
||
try{
|
||
$menulist = $this->model->detail($id,$show_field=[],$except_field=[]);
|
||
} catch (\Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
|
||
|
||
$this->success('查询成功', $menulist);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 删除新闻分类
|
||
*
|
||
* @ApiMethod (POST)
|
||
* @ApiParams (name="ids", type="string", required=true, description="要删除的ids")
|
||
*/
|
||
public function del()
|
||
{
|
||
// $admin_id = $this->auth->id;
|
||
$ids = $this->request->post('ids/s');
|
||
|
||
try{
|
||
$menulist = $this->model->del($ids,true);
|
||
} catch (\Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
$this->success('删除成功', $menulist);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* @ApiTitle(添加分类)
|
||
* @ApiSummary(添加分类)
|
||
* @ApiMethod(POST)
|
||
* @ApiParams(name = "image", type = "string",required=true,description = "icon")
|
||
* @ApiParams(name = "name", type = "int",required=true,description = "类目名")
|
||
* @ApiParams(name = "status", type = "string",required=true,description = "状态:1=上架,2=下架")
|
||
* @ApiParams(name = "hot", type = "string",required=true,description = "热门:0=否,1=是")
|
||
* @ApiParams(name = "weigh", type = "string",required=false,description = "权重")
|
||
* @ApiReturn({
|
||
*
|
||
*})
|
||
*/
|
||
public function add(){
|
||
|
||
// $user_id = 73;
|
||
// $user = $this->auth->getUser();//登录用户
|
||
// if($user)$user_id = $user['id'];
|
||
$params = [];
|
||
// $params["user_id"] = $user_id; //老师id
|
||
$params["image"] = $this->request->post('image/s', ''); //课程标签
|
||
$params["name"] = $this->request->post('name/s', ''); //课程标签
|
||
|
||
$params["status"] = $this->request->post('status/s', ''); //课程标签
|
||
|
||
$params["hot"] = $this->request->post('hot/s', ''); //老师id
|
||
$params["weigh"] = $this->request->post('weigh/s', ''); //老师id
|
||
|
||
try{
|
||
$res = $this->model->add($params,true);
|
||
}catch (\Throwable $e){
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success('添加成功', $res);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @ApiTitle(编辑分类)
|
||
* @ApiSummary(编辑分类)
|
||
* @ApiMethod(POST)
|
||
* @ApiRoute (/adminapi/home.news_cate/edit/ids/{ids})
|
||
* @ApiParams (name="ids", type="string", required=true, description="需要编辑的id")
|
||
* @ApiParams(name = "image", type = "string",required=true,description = "icon")
|
||
* @ApiParams(name = "name", type = "int",required=true,description = "类目名")
|
||
* @ApiParams(name = "status", type = "string",required=true,description = "状态:1=上架,2=下架")
|
||
* @ApiParams(name = "hot", type = "string",required=true,description = "热门:0=否,1=是")
|
||
* @ApiParams(name = "weigh", type = "string",required=false,description = "权重")
|
||
* @ApiReturn({
|
||
*
|
||
*})
|
||
*/
|
||
public function edit($ids = null){
|
||
|
||
// $user_id = 73;
|
||
// $user = $this->auth->getUser();//登录用户
|
||
// if($user)$user_id = $user['id'];
|
||
$params = [];
|
||
// $params["user_id"] = $user_id; //老师id
|
||
$params["image"] = $this->request->post('image/s', ''); //课程标签
|
||
$params["name"] = $this->request->post('name/s', ''); //课程标签
|
||
|
||
$params["status"] = $this->request->post('status/s', ''); //课程标签
|
||
|
||
$params["hot"] = $this->request->post('hot/s', ''); //老师id
|
||
$params["weigh"] = $this->request->post('weigh/s', ''); //老师id
|
||
|
||
try{
|
||
$res = $this->model->edit($ids,$params,true);
|
||
}catch (\Throwable $e){
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success('编辑成功', $res);
|
||
}
|
||
|
||
|
||
|
||
} |