NewsController.php 7.0 KB

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