IndexController.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace app\index\controller;
  3. use app\index\service\AdvertService;
  4. use app\index\service\CategoryService;
  5. use app\index\service\IpService;
  6. use app\index\service\JiamengService;
  7. use app\index\service\LinkService;
  8. use app\index\service\MessageService;
  9. use app\index\service\NewsCategoryService;
  10. use app\index\service\NewsService;
  11. use app\index\service\RedisService;
  12. use cmf\controller\HomeBaseController;
  13. use think\Db;
  14. class IndexController extends HomeBaseController
  15. {
  16. public function index()
  17. {
  18. // 热门分类
  19. $recCates = CategoryService::getRecCates(6);
  20. $recCates = $recCates? $recCates->toArray() : [];
  21. $recCates = $recCates? array_chunk($recCates, 3) : [];
  22. // 最新招商
  23. $brandNews = JiamengService::getNewList(10);
  24. /* 轮播广告 */
  25. //横幅广告位
  26. $banner = AdvertService::getListBySlide(1, 6);
  27. // 小图
  28. $bannerMin = AdvertService::getListBySlide(2, 5);
  29. // 特许加盟
  30. $banner1 = AdvertService::getListBySlide(3, 1);
  31. // 严选品牌上方广告
  32. $banner2 = AdvertService::getListBySlide(4, 1);
  33. // 品牌排行榜下方广告
  34. $banner3 = AdvertService::getListBySlide(6, 1);
  35. // 加盟动态下方广告
  36. $banner4 = AdvertService::getListBySlide(5, 1);
  37. /* 品牌栏位列表数据 */
  38. // 今日之星
  39. $brand1 = JiamengService::getListByLevel(1,3);
  40. // 匹配精选
  41. $brand2 = JiamengService::getListByLevel(2);
  42. // 品牌推荐
  43. $brand3 = JiamengService::getListByLevel(3);
  44. // 品牌严选
  45. $brand4 = JiamengService::getListByLevel(4, 21);
  46. // 专题品牌
  47. $brand6 = JiamengService::getListByLevel(6, 10);
  48. // 品牌聚焦
  49. $brand7 = JiamengService::getListByLevel(7, 42);
  50. $brand7 = $brand7? array_chunk($brand7->toArray(), 21, true) : [];
  51. // 最新品牌
  52. $brand8 = JiamengService::getNewList(12);
  53. /* 人气排行榜1 */
  54. $phb1 = JiamengService::getTopList('touzi_level <= 2');
  55. $phb2 = JiamengService::getTopList('touzi_level = 3');
  56. $phb3 = JiamengService::getTopList('touzi_level >= 4');
  57. /* 新闻资讯 */
  58. // 分类1
  59. $cateNews1 = $cateNews2 = [];
  60. $newsCates = NewsCategoryService::getCates(6);
  61. $newsCates1 = NewsCategoryService::getCatesListByIds([17,18,19]);
  62. $newsCates2 = NewsCategoryService::getCatesListByIds([1,4,20]);
  63. if($newsCates1){
  64. foreach($newsCates1 as $k=>$v){
  65. $catid = isset($v['id'])? intval($v['id']): 0;
  66. if($catid){
  67. $dataList = NewsService::getListByCate($catid, 6);
  68. $cateNews1[] = $dataList? $dataList->toArray() : [];
  69. }
  70. }
  71. }
  72. if($newsCates2){
  73. foreach($newsCates2 as $k=>$v){
  74. $catid = isset($v['id'])? intval($v['id']): 0;
  75. if($catid){
  76. $dataList = NewsService::getListByCate($catid, 7);
  77. $cateNews2[] = $dataList? $dataList->toArray() : [];
  78. }
  79. }
  80. }
  81. // 热点新闻
  82. $recNews = NewsService::getNewList(6);
  83. // 加盟问答
  84. $answerList = Db::name('know')->whereIn('status',[1,2])
  85. ->field('id,title,description')
  86. ->order('create_time desc')
  87. ->limit(13)
  88. ->select();
  89. // $answerList = NewsService::getListByLevel(1, 13);
  90. // 课堂列表
  91. $courseList = NewsService::getListByLevel(1, 7);
  92. // 参数
  93. $cateList = CategoryService::getCates();
  94. $cateList = $cateList? $cateList->toArray() : [];
  95. $touziarr = config('params.touziLevels');
  96. // 分类品牌
  97. $cateBrands = [];
  98. $hotCates = $cateList? array_slice($cateList, 0, 6) : [];
  99. if($hotCates){
  100. foreach ($hotCates as $k => $cate){
  101. $catid = isset($cate['id'])? $cate['id'] : '';
  102. if($catid){
  103. $dataList = JiamengService::getList(['pcid'=> $catid], '',16);
  104. $cateBrands[] = $dataList? $dataList : [];
  105. }
  106. }
  107. }
  108. // 热门品牌
  109. $brandHot = JiamengService::getTopList([], 16);
  110. // 加盟动态
  111. // $jmMessages = MessageService::getList(['type'=> 1], 10);
  112. $jmMessages = NewsService::getRandList(10);
  113. // 友情链接
  114. $links = LinkService::getList(['catname'=> 'index'], 50);
  115. // 新增
  116. $this->assign('banner',$banner);
  117. $this->assign('banner1',$banner1);
  118. $this->assign('banner2',$banner2);
  119. $this->assign('banner3',$banner3);
  120. $this->assign('banner4',$banner4);
  121. $this->assign('bannerMin',$bannerMin);
  122. $this->assign('brandNews',$brandNews);
  123. $this->assign('cateList',$cateList);
  124. $this->assign('touziarr',$touziarr);
  125. $this->assign('hotCates',$hotCates);
  126. $this->assign('cateBrands',$cateBrands);
  127. $this->assign('brandHot',$brandHot);
  128. $this->assign('newsCates1',$newsCates1);
  129. $this->assign('newsCates2',$newsCates2);
  130. $this->assign('cateNews1',$cateNews1);
  131. $this->assign('cateNews2',$cateNews2);
  132. $this->assign('cateNews2',$cateNews2);
  133. $this->assign('newsCates',$newsCates);
  134. $this->assign('recNews',$recNews);
  135. $this->assign('answerList',$answerList);
  136. $this->assign('jmMessages',$jmMessages);
  137. $this->assign('courseList',$courseList);
  138. $this->assign('recCates',$recCates);
  139. $this->assign('links',$links);
  140. // 品牌
  141. $this->assign('brand1',$brand1);
  142. $this->assign('brand2',$brand2);
  143. $this->assign('brand3',$brand3);
  144. $this->assign('brand4',$brand4);
  145. // $this->assign('brand5',$brand5);
  146. $this->assign('brand6',$brand6);
  147. $this->assign('brand7',$brand7);
  148. $this->assign('brand8',$brand8);
  149. // 品牌排行榜
  150. $this->assign('phb1',$phb1);
  151. $this->assign('phb2',$phb2);
  152. $this->assign('phb3',$phb3);
  153. // end
  154. return $this->fetch();
  155. }
  156. public function ws()
  157. {
  158. return $this->fetch(':ws');
  159. }
  160. /**
  161. * 投诉
  162. */
  163. public function complaint(){
  164. $param = $this->request->param();
  165. isset($param['mobile'])&&$param['mobile']!='' or $this->error('请填写手机号');
  166. $param['create_time'] = time();
  167. $param['ip'] = get_client_ip();
  168. $param['address'] = IpService::getAddress(get_client_ip());
  169. if(strlen($param['content'])>200){
  170. $this->error('字符长度不超过300个');
  171. }
  172. $param['content'] = strFilter($param['content']);
  173. $param['name'] = strFilter($param['name']);
  174. $param['mobile'] = strFilter($param['mobile']);
  175. $param['type'] = 2;
  176. //判断是否已超过10次 今天这个ip是否投诉过
  177. $sum = MessageService::getTodyCount(['ip'=> $param['ip'],'type'=> 2]);
  178. if($sum>0){
  179. $this->error('今日投诉已超过1次,明天再来吧!');
  180. }
  181. $res = Db::name('message')->insert($param);
  182. if($res){
  183. $this->success('投诉提交成功');
  184. }else{
  185. $this->error('投诉提交失败');
  186. }
  187. }
  188. /**
  189. * 网站地图
  190. * @return mixed
  191. * @throws \think\db\exception\DataNotFoundException
  192. * @throws \think\db\exception\ModelNotFoundException
  193. * @throws \think\exception\DbException
  194. */
  195. public function sitemap(){
  196. $page = input('p', 1);
  197. $cacheKey = 'cache:sitemap:list_';
  198. $datas = RedisService::get($cacheKey.$page);
  199. if(empty($datas)){
  200. $dataList = CategoryService::getCates(500, -1, "enname as id, catname as title, '1' as 'type'");
  201. $dataList = $dataList? $dataList->toArray() : [];
  202. $brands = JiamengService::getList(['status'=> 1], "j.id,j.title, '2' as 'type'", 1000);
  203. $brands = $brands? $brands->toArray() : [];
  204. $news = NewsService::getList(['status'=> 1], 1000,"id,title, '3' as 'type'");
  205. $news= $news? $news->toArray() : [];
  206. $dataList = isset($brands['data']) && $brands['data']? array_merge($dataList, $brands['data']) : $dataList;
  207. $dataList = isset($news['data']) && $news['data']? array_merge($dataList, $news['data']) : $dataList;
  208. $result = $dataList? array_chunk($dataList, 500) : [];
  209. if($result){
  210. foreach ($result as $k => $list){
  211. RedisService::set($cacheKey.($k+1), $dataList, 30*3600);
  212. }
  213. $datas = isset($result[$page-1])? $result[$page-1] : [];
  214. }
  215. }
  216. $nextPage = $page+1;
  217. $this->assign('datas', $datas);
  218. $this->assign('lastPage', $page-1>0? ($page-1) : 1);
  219. $this->assign('nextPage', RedisService::get($cacheKey.$nextPage)? $nextPage : 0);
  220. return $this->fetch('../sitemap');
  221. }
  222. public function clearCache(){
  223. // 清楚Redis缓存
  224. RedisService::delByKeys('cache:*');
  225. // end
  226. }
  227. }
  228. ?>