| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- namespace app\index\controller;
- use app\index\service\CategoryService;
- use app\index\service\JiamengService;
- use app\index\service\LinkService;
- use app\index\service\NewsCategoryService;
- use app\index\service\NewsService;
- use app\index\service\RedisService;
- use cmf\controller\HomeBaseController;
- use think\Db;
- class NewsController extends HomeBaseController
- {
- public function index()
- {
- $map['status'] = 1;
- $cate_list = NewsCategoryService::getCates(20);
- $catinfo = array('id'=>0);
- //排行
- $paihang = NewsService::getRankList(cmf_is_mobile()? 5: 18);
- // 最新入驻
- $brand_jx = JiamengService::getNewList(12);
-
- $news1 = NewsService::getList(['level'=> 1,'status'=> 1], 10);
- $newsHot = NewsService::getHotList();
- // 友情链接
- $links = LinkService::getList(['catname'=> 'news'], 50);
- $this->assign('news1',$news1);
- $this->assign('data',$news1? $news1->toArray(): ['total'=>0]);
- $this->assign('page',$news1->render());
- $this->assign('brand_jx',$brand_jx);
- $this->assign('hots', $newsHot);
- $this->assign('cate_list',$cate_list? array_chunk($cate_list, 6) : []);
- $this->assign('paihang',$paihang);
- $this->assign('catinfo',$catinfo);
- $this->assign('searchType', 3);
- $this->assign('links',$links);
- return $this->fetch();
- }
- /**
- * 详情
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function show(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('非法访问');
- $cacheKey = 'cache:news_pages:show_' . $param['id'].'_'.intval(cmf_is_mobile());
- $pageHtml = RedisService::get($cacheKey);
- //更新点击次数
- Db::name('jiameng')->where('id', $param['id'])->setInc('hits', 1);
- if ($pageHtml) {
- return $pageHtml;
- }
- $info = Db::name('news')->where('id',$param['id'])->where('status',1)->find();
- if(empty($info)){
- header("Location:".url('/404'));
- exit;
- }
- $catinfo = Db::name('news_category')->where('id',$info['ncatid'])->find();
- $bcate = Db::name('category')->where('id',$info['catid'])->find();
- $info['catname'] = $bcate['catname'];
- //内容
- $content = Db::name('news_data')->where('id',$param['id'])->find();
- $info['content'] = $content['content'];
- $map['status'] = 1;
- // 上一篇
- $lastInfo = Db::name('news')->field('id,title')->where($map)->where('id','lt',$param['id'])->order('id desc')->limit(1)->find();
- //下一篇
- $nextInfo = Db::name('news')->field('id,title')->where($map)->where('id','gt',$param['id'])->order('id')->limit(1)->find();
- $last = $lastInfo? 1 : 0;
- $next = $nextInfo? 1 : 0;
- // 最新入驻
- $brand_jx = JiamengService::getNewList(12);
- // 推荐品牌
- $touziarr = config('params.touziLevels');
- $jx_jm = Db::name('jiameng')
- ->field('id,title,logo,touzi_level,hits')
- ->whereNotIn('id',$info['id'])
- ->where('status', 1)
- ->orderRaw('rand()')
- ->limit(10)
- ->select()
- ->each(function($item, $k) use ($touziarr){
- $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
- $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
- return $item;
- });
- // 加盟资讯
- $jm_news = NewsService::getListByCate(1, 6);
- // 相关资讯
- $other_news = NewsService::getListByCate($info['ncatid'], 10);
- $id=$param['id'];
- //相关动态和品牌动态 2020-08-24
- $about_news = Db::name('news')->field('id,title,thumb,create_time')->where(['status'=> 1])
- ->where(function($query) use ($id){
- $query->where('id','lt',$id);
- })
- ->order('id desc')
- ->limit(6)->select();
- //echo Db::name('news')->getLastSql();die();
- // $brand_news = Db::name('news')->field('id,title,thumb,create_time')->where(['catid'=>$info['catid'],'status'=> 1])->order('id desc')->limit(6)->select();
- $brand_news = Db::name('news')->field('id,title,thumb,create_time')->where(['status'=> 1])
- ->where(function($query) use ($id){
- $query->where('id','gt',$id);
- })
-
- ->limit(6)->select();
- $keywords = [];
- if(isset($info['keywords']) && !empty($info['keywords'])){
- $keywords = explode(',', $info['keywords']);
- }
- $this->assign('lastInfo',$lastInfo);
- $this->assign('nextInfo',$nextInfo);
- $this->assign('last',$last);
- $this->assign('next',$next);
- $this->assign('catinfo',$catinfo);
- $this->assign('info',$info);
- $this->assign('brand_jx',$brand_jx);
- $this->assign('jx_jm',$jx_jm);
- $this->assign('jm_news',$jm_news);
- $this->assign('other_news',$other_news);
- $this->assign('keywords',$keywords);
- //print_r(array_reverse($about_news->toArray()));die();
- //seo
- $this->assign('about_news',array_reverse($about_news->toArray()));
- $this->assign('brand_news',$brand_news);
- $seo_title = $info['seo_title'];
- $seo_keywords = $info['seo_keywords'];;
- $seo_desc = strip_tags($info['content']);
- $seo_desc = mb_substr($seo_desc,0,200,'utf8');
- $this->assign('seo_title',$seo_title);
- //$this->assign('seo_keywords',$seo_keywords);
- $this->assign('seo_keywords',$info['keywords']); //2020/8/16
- $this->assign('seo_desc',$seo_desc);
- $this->assign('searchType', 3);
- $pageHtml = $this->fetch();
- RedisService::set($cacheKey, $pageHtml, 24*3600);
- return $pageHtml;
- }
- public function lists(){
- $catinfo = [];
- $param = $this->request->param();
- $cacheKey = 'cache:news_pages:list:' . md5(json_encode($param)).'_'.intval(cmf_is_mobile());
- $pageHtml = RedisService::get($cacheKey);
- if ($pageHtml) {
- return $pageHtml;
- }
- $map['status'] = 1;
- if(isset($param['catname'])){
- $catinfo = Db::name('news_category')->where('enname',$param['catname'])->find();
- if(empty($catinfo)){
- header("Location:".url('/404'));
- exit;
- }
- $catid = $catinfo['id'];
- $map['ncatid'] = $catid;
- }
- $kw = isset($param['kw'])? trim($param['kw']) : '';
- if($kw){
- $map['kw'] = $kw;
- }
- // 分类
- $cate_list = NewsCategoryService::getCates(20);
- $cate_list = $cate_list ? $cate_list : [];
- $lists = NewsService::getList($map, 10);
- //排行
- $paihang = NewsService::getRankList(cmf_is_mobile()? 5: 18);
- // $paihang = JiamengService::getHotList(18);
- // 最新入驻
- $brand_jx = JiamengService::getNewList(cmf_is_mobile()? 5: 12);
- $newsHot = NewsService::getHotList();
- // 友情链接
- $links = LinkService::getList(['catname'=> 'news'], 50);
- $this->assign('news1',$lists);
- $this->assign('data',$lists? $lists->toArray(): ['total'=>0]);
- $this->assign('page',$lists->render());
- $this->assign('brand_jx',$brand_jx);
- $this->assign('hots', $newsHot);
- $this->assign('cate_list',$cate_list? array_chunk($cate_list, 6) : []);
- $this->assign('paihang',$paihang);
- $this->assign('catinfo',$catinfo);
- $this->assign('links',$links);
- //seo
- $seo_title = $catinfo['seo_title'];
- $seo_keywords = $catinfo['seo_keywords'];
- $seo_desc = $catinfo['seo_desc'];
- $this->assign('seo_title',$seo_title);
- $this->assign('seo_keywords',$seo_keywords);
- $this->assign('seo_desc',$seo_desc);
- //seo
- $seo_title = str_replace('|',$catinfo['catname'],$catinfo['seo_title']);
- $seo_keywords = str_replace('|',$catinfo['catname'],$catinfo['seo_keywords']);
- $seo_desc = str_replace('|',$catinfo['catname'],$catinfo['seo_desc']);
- $this->assign('seo_title',$seo_title);
- $this->assign('seo_keywords',$seo_keywords);
- $this->assign('seo_desc',$seo_desc);
- $this->assign('searchType', 3);
- $pageHtml = $this->fetch('list');
- RedisService::set($cacheKey, $pageHtml, 24*3600);
- return $pageHtml;
- }
-
- public function message(){
- return $this->fetch();
- }
- public function complaint(){
- return $this->fetch();
- }
- }
- ?>
|