<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\school\model\content\Newscategory;
use think\Db;

class News extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        $newsTitle = Db::name('news_category')->field('title,id')->where('flag','index')->where(['school_id' => $this->school_id,'status'=>["<>",'lock']])->limit(3)->select();
        $this->assign('tabTitle',$newsTitle);
    }
    /**
     * @return string
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 新闻列表
     */
    public function index()
    {
        $param = $this->request->param();
        $list = Db::name("news_content")->where('school_id',$this->school_id)->where(["category_id"=>$param['category_id']])->paginate(10,false,["query"=>request()->param()]);
        $this->assign("list",$list);
        $this->assign("title", $param['title']);
        return $this->view->fetch();
    }

    /**
     * @return string
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 新闻详情
     */
    public function news_detail()
    {
        $param = $this->request->param();
        Db::name("news_content")->where(["id"=>$param['id']])->setInc("visit_count");
        $info = Db::name("news_content")->where(["id"=>$param['id']])->find();
        $this->assign("info",$info);
        $this->assign("title",$param['title']);
        return $this->view->fetch();
    }

}