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