NewsController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. $this->error('未找到新闻');
  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. ->orderRaw('rand()')
  76. ->limit(10)
  77. ->select()
  78. ->each(function($item, $k) use ($touziarr){
  79. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  80. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  81. return $item;
  82. });
  83. // 加盟资讯
  84. $jm_news = NewsService::getListByCate(1, 6);
  85. // 相关资讯
  86. $other_news = NewsService::getListByCate($info['catid'], 10);
  87. $keywords = [];
  88. if(isset($info['keywords']) && !empty($info['keywords'])){
  89. $keywords = explode(',', $info['keywords']);
  90. }
  91. $this->assign('lastInfo',$lastInfo);
  92. $this->assign('nextInfo',$nextInfo);
  93. $this->assign('last',$last);
  94. $this->assign('next',$next);
  95. $this->assign('catinfo',$catinfo);
  96. $this->assign('info',$info);
  97. $this->assign('brand_jx',$brand_jx);
  98. $this->assign('jx_jm',$jx_jm);
  99. $this->assign('jm_news',$jm_news);
  100. $this->assign('other_news',$other_news);
  101. $this->assign('keywords',$keywords);
  102. //seo
  103. $seo_title = $info['seo_title'];
  104. $seo_keywords = $info['seo_keywords'];;
  105. $seo_desc = mb_substr($info['content'],0,200,'utf8');
  106. $seo_desc = strip_tags($seo_desc);
  107. $this->assign('seo_title',$seo_title);
  108. $this->assign('seo_keywords',$seo_keywords);
  109. $this->assign('seo_desc',$seo_desc);
  110. $this->assign('searchType', 3);
  111. return $this->fetch();
  112. }
  113. public function lists(){
  114. $catinfo = [];
  115. $param = $this->request->param();
  116. $map['status'] = 1;
  117. if(isset($param['catname'])){
  118. $catinfo = Db::name('news_category')->where('enname',$param['catname'])->find();
  119. if(empty($catinfo)){
  120. $this->error('未找到分类');
  121. }
  122. $catid = $catinfo['id'];
  123. $map['ncatid'] = $catid;
  124. }
  125. $kw = isset($param['kw'])? trim($param['kw']) : '';
  126. if($kw){
  127. $map['kw'] = $kw;
  128. }
  129. // 分类
  130. $cate_list = NewsCategoryService::getCates(20);
  131. $cate_list = $cate_list? $cate_list->toArray() : [];
  132. $lists = NewsService::getList($map, 10);
  133. //排行
  134. $paihang = JiamengService::getHotList(18);
  135. // 最新入驻
  136. $brand_jx = JiamengService::getNewList(12);
  137. $newsHot = NewsService::getHotList();
  138. // 友情链接
  139. $links = LinkService::getList(['catname'=> 'news'], 50);
  140. $this->assign('news1',$lists);
  141. $this->assign('data',$lists? $lists->toArray(): ['total'=>0]);
  142. $this->assign('page',$lists->render());
  143. $this->assign('brand_jx',$brand_jx);
  144. $this->assign('hots', $newsHot);
  145. $this->assign('cate_list',$cate_list? array_chunk($cate_list, 6) : []);
  146. $this->assign('paihang',$paihang);
  147. $this->assign('catinfo',$catinfo);
  148. $this->assign('links',$links);
  149. //seo
  150. $seo_title = $catinfo['seo_title'];
  151. $seo_keywords = $catinfo['seo_keywords'];
  152. $seo_desc = $catinfo['seo_desc'];
  153. $this->assign('seo_title',$seo_title);
  154. $this->assign('seo_keywords',$seo_keywords);
  155. $this->assign('seo_desc',$seo_desc);
  156. //seo
  157. $seo_title = str_replace('|',$catinfo['catname'],$catinfo['seo_title']);
  158. $seo_keywords = str_replace('|',$catinfo['catname'],$catinfo['seo_keywords']);
  159. $seo_desc = str_replace('|',$catinfo['catname'],$catinfo['seo_desc']);
  160. $this->assign('seo_title',$seo_title);
  161. $this->assign('seo_keywords',$seo_keywords);
  162. $this->assign('seo_desc',$seo_desc);
  163. $this->assign('searchType', 3);
  164. return $this->fetch('list');
  165. }
  166. public function message(){
  167. return $this->fetch();
  168. }
  169. public function complaint(){
  170. return $this->fetch();
  171. }
  172. }
  173. ?>