NewsController.php 6.8 KB

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