TaoLer/app/index/controller/Index.php

127 lines
3.3 KiB
PHP
Raw Normal View History

2020-01-01 13:17:19 +08:00
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\App;
2020-01-01 13:17:19 +08:00
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
2020-03-05 20:15:01 +08:00
use think\facade\Cache;
2020-11-30 17:13:55 +08:00
use app\facade\Article;
2020-11-25 15:29:48 +08:00
use app\common\lib\Msgres;
2020-01-01 13:17:19 +08:00
class Index extends BaseController
{
/**
* 首页
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
2020-01-01 13:17:19 +08:00
public function index()
{
2020-01-08 17:37:41 +08:00
$types = input('type');
2020-11-29 17:27:47 +08:00
2020-01-01 13:17:19 +08:00
//幻灯
2020-11-25 15:29:48 +08:00
$slider = new \app\common\model\Slider();
$sliders = $slider->getSliderList();
2020-01-01 13:17:19 +08:00
//置顶文章
2020-11-30 17:13:55 +08:00
$artTop = Article::getArtTop(5);
2020-11-25 15:29:48 +08:00
//首页文章列表,显示20个
2020-11-30 17:13:55 +08:00
$artList = Article::getArtList(20);
2020-11-25 15:29:48 +08:00
//热议文章
2020-11-30 17:13:55 +08:00
$artHot = Article::getArtHot(10);
2020-03-05 20:15:01 +08:00
2020-01-01 13:17:19 +08:00
//首页赞助
2020-03-05 20:15:01 +08:00
$ad_index = Cache::get('adindex');
if(!$ad_index){
$ad_index = Db::name('slider')->where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>3])->whereTime('slid_over','>=',time())->select();
Cache::set('adindex',$ad_index,3600);
}
2020-01-01 13:17:19 +08:00
//首页右栏
2020-03-05 20:15:01 +08:00
$ad_comm = Cache::get('adcomm');
if(!$ad_comm){
$ad_comm = Db::name('slider')->where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>2])->whereTime('slid_over','>=',time())->select();
Cache::set('adcomm',$ad_comm,3600);
}
2020-01-01 13:17:19 +08:00
//友情链接
2020-03-05 20:15:01 +08:00
$friend_links = Cache::get('flinks');
if(!$friend_links){
$friend_links = Db::name('slider')->where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>6])->whereTime('slid_over','>=',time())->field('slid_name,slid_href')->select();
Cache::set('flinks',$friend_links,3600);
}
2020-01-01 13:17:19 +08:00
$vs = [
'slider' => $sliders,
'artTop' => $artTop,
'artList' => $artList,
'artHot' => $artHot,
'type' => $types,
'ad_index' => $ad_index,
'ad_comm' => $ad_comm,
'flinks' => $friend_links,
];
View::assign($vs);
return View::fetch();
}
//回帖榜
public function reply()
{
$comment = new \app\common\model\Comment();
return $comment->reply(20);
2020-01-01 13:17:19 +08:00
}
//搜索功能
public function search()
{
$ser = Request::only(['keywords']);
$search = new \app\index\controller\Search();
$artList = $search->getSearch($ser['keywords']);
$counts = $artList->count();
$searchs = [
'artList' => $artList,
'keywords' => $ser['keywords'],
'counts' => $counts
];
2020-01-01 13:17:19 +08:00
2020-02-27 20:27:55 +08:00
//友情链接
$friend_links = Db::name('slider')->where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>6])->whereTime('slid_over','>=',time())->field('slid_name,slid_href')->select();
// 查询热议
2020-11-30 17:13:55 +08:00
//$article = new Article()1;
$artHot = Article::getArtHot(10);
View::assign($searchs);
2020-02-27 20:27:55 +08:00
View::assign(['flinks'=>$friend_links,'artHot'=>$artHot]);
2020-01-01 13:17:19 +08:00
return View::fetch('search');
}
public function jump()
{
$username = Request::param('username');
$u = Db::name('user')->whereOr('nickname', $username)->whereOr('name', $username)->find();
2020-04-30 18:35:46 +08:00
return redirect((string) url('user/home',['id'=>$u['id']]));
2020-01-01 13:17:19 +08:00
}
2020-11-01 18:13:05 +08:00
2020-11-02 21:54:26 +08:00
public function language()
2020-11-01 18:13:05 +08:00
{
2020-11-02 21:54:26 +08:00
if(request()->isPost()){
$language = new \app\common\controller\Language;
$lang = $language->select(input('language'));
if($lang){
return Msgres::success();
2020-11-02 21:54:26 +08:00
}
}else {
2020-11-25 15:29:48 +08:00
return Msgres::error('illegal_request');
2020-11-01 18:13:05 +08:00
}
}
2020-01-01 13:17:19 +08:00
}