Index.php 4.9 KB
<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;
use function GuzzleHttp\uri_template;
use think\Db;
class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';
    protected $limit = 20;
    protected $page = 1;
    protected $group = 8;//分组
    protected $title = '';
    protected $keys = '';
    protected $description = '';

    public function _initialize()
    {
        parent::_initialize();
        //SEO标题
        $title = Db::table('fa_config')->where('id',1)->find();
        $this->title = $title['value'];
        //SEO关键字
        $keys = Db::table('fa_config')->where('id',18)->find();
        $this->keys = $keys['value'];
        //SEO描述
        $description = Db::table('fa_config')->where('id',19)->find();
        $this->description = $description['value'];
    }

    public function index()
    {
        //普通新闻列表
        $custom = Db::name('custom')
            ->field('id,url,image,weigh')
            ->order('weigh','desc')
            ->select();
        $count = ceil(count($custom)/$this->group);
        $list = 0;
        $arr = [];
        for($i=0;$i<$count;$i++){
            $list += $this->group;
            foreach($custom as $key1=>$c_value){
                if($key1>=$list-$this->group && $key1<$list){
                    $arr[$i]['data'][] = $c_value;
                }
            }
        }
        $this->assign('custom',$arr);

        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function news()
    {
        //普通新闻列表
        $news = Db::name('news')
            ->where('flag','<>','index')
            ->page(1,10)
            ->order('weigh','desc')
            ->select();
        //热门文章
        $hot = Db::name('news')
            ->where(['flag'=>'hot'])
            ->limit(20)
            ->order('weigh','desc')
            ->select();
        //置顶列表
        $top = Db::name('news')
            ->where(['flag'=>'index'])
            ->limit(3)
            ->order('weigh','desc')
            ->select();
        $this->assign('hot',$hot);
        $this->assign('list',$news);
        $this->assign('top',$top);

        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function loadNews(){
        $data = Db::name('news')
            ->where('flag','<>','index')
            ->order('weigh','desc')
            ->select();
        foreach($data as &$v){
            $v['createtime'] = date('Y-m-d',$v['createtime']);
        }
        echo json_encode($data);
    }

    //新闻详情页
    public function news_detail(){
        $id = $this->request->get('id');
        $detail = Db::name('news')
            ->where('id',$id)
            ->find();
        $hot = Db::name('news')
            ->where(['flag'=>'hot'])
            ->limit($this->limit)
            ->order('weigh','desc')
            ->select();
        if($detail){
            $detail['createtime'] = date('Y-m-d',$detail['createtime']);
        }
        $this->assign('hot',$hot);
        $this->assign('detail',$detail);

        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function map()
    {
        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function course()
    {
        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function contact()
    {
        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function business()
    {
        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

    public function about()
    {
        //SEO标题关键字,描述
        $this->assign('title',$this->title);
        $this->assign('keys',$this->keys);
        $this->assign('description',$this->description);
        return $this->fetch();
    }

}