215 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			215 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace app\adminapi\controller\home;
 | 
						|
 | 
						|
use app\common\controller\AdminApi;
 | 
						|
use app\adminapi\model\home\News as NewsModel;
 | 
						|
 | 
						|
/**
 | 
						|
 * 新闻管理
 | 
						|
 */
 | 
						|
class News extends AdminApi
 | 
						|
{
 | 
						|
    protected $model = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * 初始化操作
 | 
						|
     * @access protected
 | 
						|
     */
 | 
						|
    public function _initialize()
 | 
						|
    {
 | 
						|
        $this->model = new NewsModel;
 | 
						|
        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 = "recommend", type = "string",required=false,description = "置顶:0=否,1=是")
 | 
						|
     * @ApiParams(name = "cate_id", type = "int",required=false,description = "新闻类目id")
 | 
						|
     * @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); //条数
 | 
						|
        $keywords =  $this->request->get('keywords/s', ''); //搜索关键字
 | 
						|
        $recommend =  $this->request->get('recommend/s', ''); //搜索关键字
 | 
						|
//        $params =[];
 | 
						|
        $cate_id =  $this->request->get('cate_id/s', ''); //搜索关键字
 | 
						|
 | 
						|
 | 
						|
//        $type =  $this->request->get('type/s', ''); //筛选学员和教练单
 | 
						|
 | 
						|
 | 
						|
        try{
 | 
						|
            //当前申请状态
 | 
						|
            $res = $this->model::allList($page, $limit,$keywords,$recommend,$cate_id,[]);
 | 
						|
//             var_dump($this->model->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 = "cate_id", type = "string",required=true,description = "新闻类目")
 | 
						|
     * @ApiParams(name = "title", type = "int",required=true,description = "新闻标题")
 | 
						|
     * @ApiParams(name = "subtitle", type = "int",required=true,description = "新闻副标题")
 | 
						|
     * @ApiParams(name = "image", type = "int",required=true,description = "封面")
 | 
						|
     * @ApiParams(name = "content", type = "int",required=true,description = "内容")
 | 
						|
     * @ApiParams(name = "recommend", type = "string",required=true,description = "置顶:0=否,1=是")
 | 
						|
     * @ApiParams(name = "release_time", type = "string",required=true,description = "发布时间:例子 2025-05-09 17:30:46")
 | 
						|
     * @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["cate_id"] =  $this->request->post('cate_id/d', ''); //课程标签
 | 
						|
        $params["title"] =  $this->request->post('title/s', ''); //课程标签
 | 
						|
 | 
						|
        $params["subtitle"] =  $this->request->post('subtitle/s', ''); //课程标签
 | 
						|
 | 
						|
        $params["image"] =  $this->request->post('image/s', ''); //老师id
 | 
						|
        $params["content"] =  $this->request->post('content/s', ''); //老师id
 | 
						|
 | 
						|
        $params["recommend"] =  $this->request->post('recommend/s', ''); //老师id
 | 
						|
        $params["release_time"] =  $this->request->post('release_time/s', ''); //老师id
 | 
						|
        $params["weigh"] =  $this->request->post('weigh/d', ''); //老师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/edit/ids/{ids})
 | 
						|
     * @ApiParams (name="ids", type="string", required=true, description="需要编辑的id")
 | 
						|
     * @ApiParams(name = "cate_id", type = "string",required=true,description = "新闻类目")
 | 
						|
     * @ApiParams(name = "title", type = "int",required=true,description = "新闻标题")
 | 
						|
     * @ApiParams(name = "subtitle", type = "int",required=true,description = "新闻副标题")
 | 
						|
     * @ApiParams(name = "image", type = "int",required=true,description = "封面")
 | 
						|
     * @ApiParams(name = "content", type = "int",required=true,description = "内容")
 | 
						|
     * @ApiParams(name = "recommend", type = "string",required=true,description = "置顶:0=否,1=是")
 | 
						|
     * @ApiParams(name = "release_time", type = "string",required=true,description = "发布时间:例子 2025-05-09 17:30:46")
 | 
						|
     * @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["cate_id"] =  $this->request->post('cate_id/d', ''); //课程标签
 | 
						|
        $params["title"] =  $this->request->post('title/s', ''); //课程标签
 | 
						|
 | 
						|
        $params["subtitle"] =  $this->request->post('subtitle/s', ''); //课程标签
 | 
						|
 | 
						|
        $params["image"] =  $this->request->post('image/s', ''); //老师id
 | 
						|
        $params["content"] =  $this->request->post('content/s', ''); //老师id
 | 
						|
 | 
						|
        $params["recommend"] =  $this->request->post('recommend/s', ''); //老师id
 | 
						|
        $params["release_time"] =  $this->request->post('release_time/s', ''); //老师id
 | 
						|
        $params["weigh"] =  $this->request->post('weigh/d', ''); //老师id
 | 
						|
 | 
						|
        try{
 | 
						|
            $res = $this->model->edit($ids,$params,true);
 | 
						|
        }catch (\Throwable $e){
 | 
						|
            $this->error($e->getMessage());
 | 
						|
        }
 | 
						|
        $this->success('编辑成功', $res);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
} |