NewsController.php 6.9 KB

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