NewsController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. namespace app\index\controller;
  3. use app\index\service\CategoryService;
  4. use app\index\service\JiamengService;
  5. use app\index\service\LinkService;
  6. use app\index\service\NewsCategoryService;
  7. use app\index\service\NewsService;
  8. use cmf\controller\HomeBaseController;
  9. use think\Db;
  10. class NewsController extends HomeBaseController
  11. {
  12. public function index()
  13. {
  14. $map['status'] = 1;
  15. $cate_list = NewsCategoryService::getCates(20);
  16. $catinfo = array('id'=>0);
  17. //排行
  18. $paihang = JiamengService::getHotList(18);
  19. // 最新入驻
  20. $brand_jx = JiamengService::getNewList(12);
  21. $news1 = NewsService::getList(['level'=> 1], 10);
  22. $newsHot = NewsService::getHotList();
  23. // 友情链接
  24. $links = LinkService::getList(['catname'=> 'news'], 50);
  25. $this->assign('news1',$news1);
  26. $this->assign('data',$news1? $news1->toArray(): ['total'=>0]);
  27. $this->assign('page',$news1->render());
  28. $this->assign('brand_jx',$brand_jx);
  29. $this->assign('hots', $newsHot);
  30. $this->assign('cate_list',$cate_list? array_chunk($cate_list, 6) : []);
  31. $this->assign('paihang',$paihang);
  32. $this->assign('catinfo',$catinfo);
  33. $this->assign('searchType', 3);
  34. $this->assign('links',$links);
  35. return $this->fetch();
  36. }
  37. /**
  38. * 详情
  39. * @return mixed
  40. * @throws \think\Exception
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function show(){
  46. $param = $this->request->param();
  47. isset($param['id']) or $this->error('非法访问');
  48. $info = Db::name('news')->where('id',$param['id'])->where('status',1)->find();
  49. if(empty($info)){
  50. header("Location:".url('/404'));
  51. exit;
  52. }
  53. $catinfo = Db::name('news_category')->where('id',$info['ncatid'])->find();
  54. $bcate = Db::name('category')->where('id',$info['catid'])->find();
  55. $info['catname'] = $bcate['catname'];
  56. //更新点击次数
  57. Db::name('news')->where('id',$param['id'])->setInc('hits',1);
  58. //内容
  59. $content = Db::name('news_data')->where('id',$param['id'])->find();
  60. $info['content'] = $content['content'];
  61. $map['status'] = 1;
  62. // 上一篇
  63. $lastInfo = Db::name('news')->field('id,title')->where($map)->where('id','lt',$param['id'])->order('id desc')->limit(1)->find();
  64. //下一篇
  65. $nextInfo = Db::name('news')->field('id,title')->where($map)->where('id','gt',$param['id'])->order('id')->limit(1)->find();
  66. $last = $lastInfo? 1 : 0;
  67. $next = $nextInfo? 1 : 0;
  68. // 最新入驻
  69. $brand_jx = JiamengService::getNewList(12);
  70. // 推荐品牌
  71. $touziarr = config('params.touziLevels');
  72. $jx_jm = Db::name('jiameng')
  73. ->field('id,title,logo,touzi_level,hits')
  74. ->whereNotIn('id',$info['id'])
  75. ->where('status', 1)
  76. ->orderRaw('rand()')
  77. ->limit(10)
  78. ->select()
  79. ->each(function($item, $k) use ($touziarr){
  80. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  81. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  82. return $item;
  83. });
  84. // 加盟资讯
  85. $jm_news = NewsService::getListByCate(1, 6);
  86. // 相关资讯
  87. $other_news = NewsService::getListByCate($info['ncatid'], 10);
  88. $keywords = [];
  89. if(isset($info['keywords']) && !empty($info['keywords'])){
  90. $keywords = explode(',', $info['keywords']);
  91. }
  92. $this->assign('lastInfo',$lastInfo);
  93. $this->assign('nextInfo',$nextInfo);
  94. $this->assign('last',$last);
  95. $this->assign('next',$next);
  96. $this->assign('catinfo',$catinfo);
  97. $this->assign('info',$info);
  98. $this->assign('brand_jx',$brand_jx);
  99. $this->assign('jx_jm',$jx_jm);
  100. $this->assign('jm_news',$jm_news);
  101. $this->assign('other_news',$other_news);
  102. $this->assign('keywords',$keywords);
  103. //seo
  104. $seo_title = $info['seo_title'];
  105. $seo_keywords = $info['seo_keywords'];;
  106. $seo_desc = strip_tags($info['content']);
  107. $seo_desc = mb_substr($seo_desc,0,200,'utf8');
  108. $this->assign('seo_title',$seo_title);
  109. $this->assign('seo_keywords',$seo_keywords);
  110. $this->assign('seo_desc',$seo_desc);
  111. $this->assign('searchType', 3);
  112. return $this->fetch();
  113. }
  114. public function lists(){
  115. $catinfo = [];
  116. $param = $this->request->param();
  117. $map['status'] = 1;
  118. if(isset($param['catname'])){
  119. $catinfo = Db::name('news_category')->where('enname',$param['catname'])->find();
  120. if(empty($catinfo)){
  121. header("Location:".url('/404'));
  122. exit;
  123. }
  124. $catid = $catinfo['id'];
  125. $map['ncatid'] = $catid;
  126. }
  127. $kw = isset($param['kw'])? trim($param['kw']) : '';
  128. if($kw){
  129. $map['kw'] = $kw;
  130. }
  131. // 分类
  132. $cate_list = NewsCategoryService::getCates(20);
  133. $cate_list = $cate_list? $cate_list->toArray() : [];
  134. $lists = NewsService::getList($map, 10);
  135. //排行
  136. $paihang = JiamengService::getHotList(18);
  137. // 最新入驻
  138. $brand_jx = JiamengService::getNewList(12);
  139. $newsHot = NewsService::getHotList();
  140. // 友情链接
  141. $links = LinkService::getList(['catname'=> 'news'], 50);
  142. $this->assign('news1',$lists);
  143. $this->assign('data',$lists? $lists->toArray(): ['total'=>0]);
  144. $this->assign('page',$lists->render());
  145. $this->assign('brand_jx',$brand_jx);
  146. $this->assign('hots', $newsHot);
  147. $this->assign('cate_list',$cate_list? array_chunk($cate_list, 6) : []);
  148. $this->assign('paihang',$paihang);
  149. $this->assign('catinfo',$catinfo);
  150. $this->assign('links',$links);
  151. //seo
  152. $seo_title = $catinfo['seo_title'];
  153. $seo_keywords = $catinfo['seo_keywords'];
  154. $seo_desc = $catinfo['seo_desc'];
  155. $this->assign('seo_title',$seo_title);
  156. $this->assign('seo_keywords',$seo_keywords);
  157. $this->assign('seo_desc',$seo_desc);
  158. //seo
  159. $seo_title = str_replace('|',$catinfo['catname'],$catinfo['seo_title']);
  160. $seo_keywords = str_replace('|',$catinfo['catname'],$catinfo['seo_keywords']);
  161. $seo_desc = str_replace('|',$catinfo['catname'],$catinfo['seo_desc']);
  162. $this->assign('seo_title',$seo_title);
  163. $this->assign('seo_keywords',$seo_keywords);
  164. $this->assign('seo_desc',$seo_desc);
  165. $this->assign('searchType', 3);
  166. return $this->fetch('list');
  167. }
  168. public function message(){
  169. return $this->fetch();
  170. }
  171. public function complaint(){
  172. return $this->fetch();
  173. }
  174. }
  175. ?>